-
Notifications
You must be signed in to change notification settings - Fork 9
/
Snakefile
1773 lines (1467 loc) · 60.6 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import snakemake.utils
snakemake.utils.min_version('6.5.0')
configfile: 'snakemake_config.yaml'
onsuccess:
print('workflow success')
onerror:
print('workflow error')
DEFAULT_MEM_MB=4 * 1024 # 4 GB
DEFAULT_TIME_HOURS=12
# Specifying this as an input to a rule will disable that rule.
# This can be used in combination with "ruleorder:" to determine what
# rule should be used to create a particular output file.
UNSATISFIABLE_INPUT='unsatisfiable_input_file_path'
def all_input(wildcards):
inputs = dict()
run_all_modules = bool(config.get('run_all_modules'))
run_core_modules = bool(config.get('run_core_modules'))
should_run_sjc = bool(config.get('should_run_sjc_steps'))
if run_core_modules or run_all_modules:
# core modules
inputs.update(iris_epitope_post_out_files())
inputs['visualization'] = os.path.join(result_dir(), 'visualization',
'summary.png')
if should_run_sjc:
if has_tier_1():
inputs['sjc_tier1'] = iris_append_sjc_out_file_name_for_tier('tier1')
if has_tier_3():
inputs['sjc_tier2tier3'] = iris_append_sjc_out_file_name_for_tier('tier2tier3')
return inputs
localrules: all
rule all:
input:
unpack(all_input),
def result_dir():
return os.path.join('results', config['run_name'])
def iris_db_path():
return os.path.join(config['iris_data'], 'db')
def iris_db_sjc_path():
return os.path.join(config['iris_data'], 'db_sjc')
def iris_exp_matrix_out_matrix():
run_name = config['run_name']
basename = 'exp.merged_matrix.{}.txt'.format(run_name)
return os.path.join(result_dir(), 'exp_matrix', basename)
def gene_exp_matrix_path_for_run():
from_config = config.get('gene_exp_matrix')
if from_config:
return from_config
if config.get('run_all_modules'):
return iris_exp_matrix_out_matrix()
return None
def hla_types_list_for_run():
from_config = config.get('mhc_list')
if from_config:
return from_config
return os.path.join(result_dir(), 'hla_typing', 'hla_types.list')
def hla_from_patients_for_run():
from_config = config.get('mhc_by_sample')
if from_config:
return from_config
return os.path.join(result_dir(), 'hla_typing', 'hla_patient.tsv')
def splicing_matrix_path_for_run():
db_path = iris_db_path()
return os.path.join(db_path, config['run_name'], 'splicing_matrix')
def sjc_count_path_for_run():
db_path = iris_db_sjc_path()
return os.path.join(db_path, config['run_name'], 'sjc_matrix')
def splicing_matrix_txt_path_for_run():
matrix_path = splicing_matrix_path_for_run()
file_name = ('splicing_matrix.{}.cov10.{}.txt'
.format(config['splice_event_type'], config['run_name']))
return os.path.join(matrix_path, file_name)
def splicing_matrix_idx_path_for_run():
return '{}.idx'.format(splicing_matrix_txt_path_for_run())
def sjc_count_txt_path_for_run():
matrix_path = sjc_count_path_for_run()
file_name = 'SJ_count.{}.txt'.format(config['run_name'])
return os.path.join(matrix_path, file_name)
def sjc_count_idx_path_for_run():
return '{}.idx'.format(sjc_count_txt_path_for_run())
def format_ref_names(config_key):
configured = config.get(config_key, '')
# if no ref names -> provide a quoted empty string on the command line
if not configured.strip():
return "''"
return configured
# must have either tier 1 or tier 3
def has_tier_1():
return len(tier_1_group_names()) > 0
def has_tier_3():
return len(tier_3_group_names()) > 0
def tier_1_group_names():
return group_names_from_config_key('tissue_matched_normal_reference_group_names')
def tier_3_group_names():
return group_names_from_config_key('normal_reference_group_names')
def group_names_from_config_key(key):
names_str = config.get(key)
split = names_str.split(',')
return [x.strip() for x in split if x]
def reference_file_wildcard_constraints():
reference_files = config.get('reference_files')
if reference_files:
file_names = '|'.join([re.escape(file_name)
for file_name in reference_files])
without_gz = '|'.join([re.escape(file_name[:-3])
for file_name in reference_files
if file_name.endswith('.gz')])
else:
no_match = '^$' # only matches empty string
file_names = no_match
without_gz = no_match
return {'file_names': file_names, 'without_gz': without_gz}
def get_url_for_download_reference_file(wildcards):
file_name = wildcards.file_name
return config['reference_files'][file_name]['url']
rule download_reference_file:
output:
ref_file=os.path.join('references', '{file_name}'),
log:
out=os.path.join('references',
'download_reference_file_{file_name}_log.out'),
err=os.path.join('references',
'download_reference_file_{file_name}_log.err'),
wildcard_constraints:
file_name=reference_file_wildcard_constraints()['file_names']
params:
url=get_url_for_download_reference_file,
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'curl -L \'{params.url}\''
' -o {output.ref_file}'
' 1> {log.out}'
' 2> {log.err}'
rule unzip_reference_file:
input:
gz=os.path.join('references', '{file_name}.gz'),
output:
un_gz=os.path.join('references', '{file_name}'),
log:
out=os.path.join('references',
'unzip_reference_file_{file_name}_log.out'),
err=os.path.join('references',
'unzip_reference_file_{file_name}_log.err'),
wildcard_constraints:
file_name=reference_file_wildcard_constraints()['without_gz']
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
' gunzip -c {input.gz}'
' 1> {output.un_gz}'
' 2> {log.err}'
def write_param_file_blocklist_param():
value = config.get('blocklist')
if value:
return '--blocklist-file {}'.format(value)
return ''
def write_param_file_bigwig_param():
value = config.get('mapability_bigwig')
if value:
return '--mapability-bigwig {}'.format(value)
return ''
def write_param_file_genome_param():
value = config.get('fasta_name')
if value:
reference_path = os.path.join('references', value)
return '--reference-genome {}'.format(reference_path)
return ''
def write_param_file_input(wildcards):
inputs = dict()
fasta = config.get('fasta_name')
if fasta:
inputs['fasta'] = os.path.join('references', fasta)
return inputs
rule write_param_file:
input:
unpack(write_param_file_input),
output:
param_file=os.path.join(result_dir(), 'screen.para'),
log:
out=os.path.join(result_dir(), 'write_param_file_log.out'),
err=os.path.join(result_dir(), 'write_param_file_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_3=config['conda_env_3'],
script=os.path.join('scripts', 'write_param_file.py'),
group_name=config['run_name'],
iris_db=iris_db_path(),
matched_psi_cut=config.get('tissue_matched_normal_psi_p_value_cutoff', ''),
matched_sjc_cut=config.get('tissue_matched_normal_sjc_p_value_cutoff', ''),
matched_delta_psi_cut=config.get('tissue_matched_normal_delta_psi_p_value_cutoff', ''),
matched_fc_cut=config.get('tissue_matched_normal_fold_change_cutoff', ''),
matched_group_cut=config.get('tissue_matched_normal_group_count_cutoff', ''),
matched_ref_names=format_ref_names('tissue_matched_normal_reference_group_names'),
tumor_psi_cut=config.get('tumor_psi_p_value_cutoff', ''),
tumor_sjc_cut=config.get('tumor_sjc_p_value_cutoff', ''),
tumor_delta_psi_cut=config.get('tumor_delta_psi_p_value_cutoff', ''),
tumor_fc_cut=config.get('tumor_fold_change_cutoff', ''),
tumor_group_cut=config.get('tumor_group_count_cutoff', ''),
tumor_ref_names=format_ref_names('tumor_reference_group_names'),
normal_psi_cut=config.get('normal_psi_p_value_cutoff', ''),
normal_sjc_cut=config.get('normal_sjc_p_value_cutoff', ''),
normal_delta_psi_cut=config.get('normal_delta_psi_p_value_cutoff', ''),
normal_fc_cut=config.get('normal_fold_change_cutoff', ''),
normal_group_cut=config.get('normal_group_count_cutoff', ''),
normal_ref_names=format_ref_names('normal_reference_group_names'),
comparison_mode=config['comparison_mode'],
stat_test_type=config['stat_test_type'],
use_ratio='--use-ratio' if config.get('use_ratio') else '',
blocklist=write_param_file_blocklist_param(),
bigwig=write_param_file_bigwig_param(),
genome=write_param_file_genome_param(),
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_3} python {params.script}'
' --out-path {output.param_file}'
' --group-name {params.group_name}'
' --iris-db {params.iris_db}'
' --psi-p-value-cutoffs'
' {params.matched_psi_cut},{params.tumor_psi_cut},{params.normal_psi_cut}'
' --sjc-p-value-cutoffs'
' {params.matched_sjc_cut},{params.tumor_sjc_cut},{params.normal_sjc_cut}'
' --delta-psi-cutoffs'
' {params.matched_delta_psi_cut},{params.tumor_delta_psi_cut},{params.normal_delta_psi_cut}'
' --fold-change-cutoffs'
' {params.matched_fc_cut},{params.tumor_fc_cut},{params.normal_fc_cut}'
' --group-count-cutoffs'
' {params.matched_group_cut},{params.tumor_group_cut},{params.normal_group_cut}'
' --reference-names-tissue-matched-normal {params.matched_ref_names}'
' --reference-names-tumor {params.tumor_ref_names}'
' --reference-names-normal {params.normal_ref_names}'
' --comparison-mode {params.comparison_mode}'
' --statistical-test-type {params.stat_test_type}'
' {params.use_ratio}'
' {params.blocklist}'
' {params.bigwig}'
' {params.genome}'
' 1> {log.out}'
' 2> {log.err}'
# if the necessary files are specified in the config, then
# use them rather than run IRIS format
def copy_splice_matrix_files_input(wildcards):
inputs = dict()
inputs['splice_txt'] = config.get('splice_matrix_txt', UNSATISFIABLE_INPUT)
inputs['splice_idx'] = config.get('splice_matrix_idx', UNSATISFIABLE_INPUT)
if config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
ruleorder: copy_splice_matrix_files > iris_format
localrules: copy_splice_matrix_files
rule copy_splice_matrix_files:
input:
unpack(copy_splice_matrix_files_input),
output:
splice_txt=splicing_matrix_txt_path_for_run(),
splice_idx=splicing_matrix_idx_path_for_run(),
shell:
'cp {input.splice_txt} {output.splice_txt}'
' && cp {input.splice_idx} {output.splice_idx}'
def copy_sjc_count_files_input(wildcards):
inputs = dict()
inputs['count_txt'] = config.get('sjc_count_txt', UNSATISFIABLE_INPUT)
inputs['count_idx'] = config.get('sjc_count_idx', UNSATISFIABLE_INPUT)
if config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
ruleorder: copy_sjc_count_files > iris_sjc_matrix
localrules: copy_sjc_count_files
rule copy_sjc_count_files:
input:
unpack(copy_sjc_count_files_input),
output:
count_txt=sjc_count_txt_path_for_run(),
count_idx=sjc_count_idx_path_for_run(),
shell:
'cp {input.count_txt} {output.count_txt}'
' && cp {input.count_idx} {output.count_idx}'
def create_star_index_out_dir_param(wildcards, output):
return os.path.dirname(output.index)
def create_star_index_input(wildcards):
inputs = dict()
inputs['gtf'] = os.path.join('references', config['gtf_name'])
inputs['fasta'] = os.path.join('references', config['fasta_name'])
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule create_star_index:
input:
unpack(create_star_index_input),
output:
index=os.path.join('references', 'star_index', 'SA'),
log:
out=os.path.join('references', 'create_star_index_log.out'),
err=os.path.join('references', 'create_star_index_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
out_dir=create_star_index_out_dir_param,
overhang=config['star_sjdb_overhang'],
threads: config['create_star_index_threads']
resources:
mem_mb=config['create_star_index_mem_gb'] * 1024,
time_hours=config['create_star_index_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} STAR'
' --runMode genomeGenerate'
' --runThreadN {threads}'
' --genomeDir {params.out_dir}'
' --genomeFastaFiles {input.fasta}'
' --sjdbGTFfile {input.gtf}'
' --sjdbOverhang {params.overhang}'
' 1> {log.out}'
' 2> {log.err}'
def organize_fastqs_sample_details():
details = dict()
fastq_dict = config.get('sample_fastqs')
if not fastq_dict:
return details
sample_names = list()
all_fastqs = list()
for name, fastqs in fastq_dict.items():
for fastq in fastqs:
sample_names.append(name)
all_fastqs.append(fastq)
details['sample_names'] = sample_names
details['fastqs'] = all_fastqs
return details
def unique_sample_names():
fastq_dict = config.get('sample_fastqs')
if not fastq_dict:
return list()
return list(fastq_dict.keys())
def organize_fastqs_input(wildcards):
details = organize_fastqs_sample_details()
if not details:
return {'unsatisfiable': UNSATISFIABLE_INPUT}
return {'fastqs': details['fastqs']}
def organize_fastqs_sample_names_param():
sample_names = organize_fastqs_sample_details().get('sample_names', list())
return sample_names
localrules: organize_fastqs
rule organize_fastqs:
input:
unpack(organize_fastqs_input),
output:
done=touch(os.path.join(result_dir(), 'fastq_dir', 'organize_fastqs.done')),
params:
sample_names=organize_fastqs_sample_names_param(),
out_dir=os.path.join(result_dir(), 'fastq_dir'),
run:
import os
import os.path
out_dir = params.out_dir
if os.path.isdir(out_dir):
files = os.listdir(out_dir)
if files:
raise Exception('organize_fastqs: {} already contains files'
.format(out_dir))
for i, sample_name in enumerate(params.sample_names):
sample_dir = os.path.join(out_dir, sample_name)
orig_fastq_path = input.fastqs[i]
fastq_basename = os.path.basename(orig_fastq_path)
new_fastq_path = os.path.join(sample_dir, fastq_basename)
os.makedirs(sample_dir, exist_ok=True)
os.symlink(orig_fastq_path, new_fastq_path)
def iris_makesubsh_mapping_task_out_file_names():
task_dir = os.path.join(result_dir(), 'mapping_tasks')
sample_names = unique_sample_names()
star_tasks = list()
cuff_tasks = list()
for sample_name in sample_names:
star_name = 'STARmap.{}.sh'.format(sample_name)
cuff_name = 'Cuffquant.{}.sh'.format(sample_name)
star_tasks.append(os.path.join(task_dir, star_name))
cuff_tasks.append(os.path.join(task_dir, cuff_name))
return {'star_tasks': star_tasks, 'cuff_tasks': cuff_tasks}
def iris_makesubsh_mapping_star_done_file_names():
out_dir = os.path.join(result_dir(), 'process_rnaseq')
sample_names = unique_sample_names()
final_bams = list()
for sample in sample_names:
align_dir = os.path.join(out_dir, '{}.aln'.format(sample))
final_bam = os.path.join(align_dir, 'Aligned.sortedByCoord.out.bam')
final_bams.append(final_bam)
return final_bams
def iris_makesubsh_mapping_cuff_done_file_names():
cuff_tasks = iris_makesubsh_mapping_task_out_file_names()['cuff_tasks']
done_names = list()
for task in cuff_tasks:
done_names.append('{}.done'.format(task))
return done_names
def iris_makesubsh_mapping_star_dir_param(wildcards):
input = iris_makesubsh_mapping_input(wildcards)
return os.path.dirname(input['index'])
def iris_makesubsh_mapping_task_dir_param(wildcards, output):
return os.path.dirname(output.star_tasks[0])
def label_string_param():
# IRIS uses this value to tell which files are for read 1 or read 2.
# Specifically it looks for '1{label_string}f' and '1{label_string}f'
return '.'
def iris_makesubsh_mapping_input(wildcards):
inputs = dict()
inputs['organize_fastqs_done'] = os.path.join(result_dir(), 'fastq_dir',
'organize_fastqs.done')
inputs['index'] = os.path.join('references', 'star_index', 'SA')
inputs['gtf'] = os.path.join('references', config['gtf_name'])
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_makesubsh_mapping:
input:
unpack(iris_makesubsh_mapping_input),
output:
**iris_makesubsh_mapping_task_out_file_names()
log:
out=os.path.join(result_dir(), 'iris_makesubsh_mapping_log.out'),
err=os.path.join(result_dir(), 'iris_makesubsh_mapping_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
fastq_dir=os.path.join(result_dir(), 'fastq_dir'),
star_dir=iris_makesubsh_mapping_star_dir_param,
run_name=config['run_name'],
out_dir=os.path.join(result_dir(), 'process_rnaseq'),
label_string=label_string_param(),
task_dir=iris_makesubsh_mapping_task_dir_param,
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_2} IRIS makesubsh_mapping'
' --fastq-folder-dir {params.fastq_dir}'
' --starGenomeDir {params.star_dir}'
' --gtf {input.gtf}'
' --data-name {params.run_name}'
' --outdir {params.out_dir}'
' --label-string {params.label_string}'
' --task-dir {params.task_dir}'
' 1> {log.out}'
' 2> {log.err}'
def iris_star_task_input(wildcards):
inputs = dict()
inputs['star_task'] = os.path.join(
result_dir(), 'mapping_tasks',
'STARmap.{}.sh'.format(wildcards.sample))
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_star_task:
input:
unpack(iris_star_task_input),
output:
unsorted_bam=os.path.join(result_dir(), 'process_rnaseq',
'{sample}.aln', 'Aligned.out.bam'),
sorted_bam=os.path.join(result_dir(), 'process_rnaseq', '{sample}.aln',
'Aligned.sortedByCoord.out.bam'),
log:
out=os.path.join(result_dir(), 'mapping_tasks',
'iris_star_task_{sample}_log.out'),
err=os.path.join(result_dir(), 'mapping_tasks',
'iris_star_task_{sample}_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
threads: config['iris_star_task_threads']
resources:
mem_mb=config['iris_star_task_mem_gb'] * 1024,
time_hours=config['iris_star_task_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} bash'
' {input.star_task}'
' 1> {log.out}'
' 2> {log.err}'
def iris_cuff_task_input(wildcards):
inputs = dict()
inputs['cuff_task'] = os.path.join(
result_dir(), 'mapping_tasks',
'Cuffquant.{}.sh'.format(wildcards.sample))
inputs['star_task_done'] = os.path.join(
result_dir(), 'process_rnaseq',
'{}.aln'.format(wildcards.sample),
'Aligned.sortedByCoord.out.bam')
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_cuff_task:
input:
unpack(iris_cuff_task_input),
output:
cuff_task_done=touch(os.path.join(result_dir(), 'process_rnaseq',
'{sample}.aln', 'cufflinks',
'genes.fpkm_tracking')),
log:
out=os.path.join(result_dir(), 'mapping_tasks',
'iris_cuff_task_{sample}_log.out'),
err=os.path.join(result_dir(), 'mapping_tasks',
'iris_cuff_task_{sample}_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
threads: config['iris_cuff_task_threads']
resources:
mem_mb=config['iris_cuff_task_mem_gb'] * 1024,
time_hours=config['iris_cuff_task_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} bash'
' {input.cuff_task}'
' 1> {log.out}'
' 2> {log.err}'
def iris_makesubsh_hla_task_out_file_names():
task_dir = os.path.join(result_dir(), 'hla_tasks')
sample_names = unique_sample_names()
hla_tasks = list()
for sample_name in sample_names:
hla_name = 'seq2hla.{}.sh'.format(sample_name)
hla_tasks.append(os.path.join(task_dir, hla_name))
return {'hla_tasks': hla_tasks}
def iris_hla_task_done_file_names():
sample_names = unique_sample_names()
done_file_names = list()
hla_dir = os.path.join(result_dir(), 'hla_typing')
for sample in sample_names:
out_dir = os.path.join(hla_dir, sample)
expression = os.path.join(out_dir,
'{}-ClassI.expression'.format(sample))
genotype = os.path.join(out_dir,
'{}-ClassI.HLAgenotype4digits'.format(sample))
done_file_names.append(expression)
done_file_names.append(genotype)
return done_file_names
def iris_makesubsh_hla_task_dir_param(wildcards, output):
return os.path.dirname(output.hla_tasks[0])
def iris_makesubsh_hla_input(wildcards):
inputs = dict()
inputs['organize_fastqs_done'] = os.path.join(result_dir(), 'fastq_dir',
'organize_fastqs.done')
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_makesubsh_hla:
input:
unpack(iris_makesubsh_hla_input),
output:
**iris_makesubsh_hla_task_out_file_names()
log:
out=os.path.join(result_dir(), 'iris_makesubsh_hla_log.out'),
err=os.path.join(result_dir(), 'iris_makesubsh_hla_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
fastq_dir=os.path.join(result_dir(), 'fastq_dir'),
run_name=config['run_name'],
out_dir=os.path.join(result_dir(), 'hla_typing'),
label_string=label_string_param(),
task_dir=iris_makesubsh_hla_task_dir_param,
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_2} IRIS makesubsh_hla'
' --fastq-folder-dir {params.fastq_dir}'
' --data-name {params.run_name}'
' --outdir {params.out_dir}'
' --label-string {params.label_string}'
' --task-dir {params.task_dir}'
' 1> {log.out}'
' 2> {log.err}'
def iris_hla_task_input(wildcards):
inputs = dict()
inputs['hla_task'] = os.path.join(
result_dir(), 'hla_tasks',
'seq2hla.{}.sh'.format(wildcards.sample))
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_hla_task:
input:
unpack(iris_hla_task_input),
output:
expression=os.path.join(result_dir(), 'hla_typing', '{sample}',
'{sample}-ClassI.expression'),
genotype=os.path.join(result_dir(), 'hla_typing', '{sample}',
'{sample}-ClassI.HLAgenotype4digits'),
log:
out=os.path.join(result_dir(), 'hla_tasks',
'iris_hla_task_{sample}_log.out'),
err=os.path.join(result_dir(), 'hla_tasks',
'iris_hla_task_{sample}_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
threads: config['iris_hla_task_threads']
resources:
mem_mb=config['iris_hla_task_mem_gb'] * 1024,
time_hours=config['iris_hla_task_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} bash'
' {input.hla_task}'
' 1> {log.out}'
' 2> {log.err}'
def iris_parse_hla_input(wildcards):
inputs = dict()
inputs['hla_tasks_done'] = iris_hla_task_done_file_names()
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_parse_hla:
input:
unpack(iris_parse_hla_input),
output:
patient=os.path.join(result_dir(), 'hla_typing', 'hla_patient.tsv'),
types=os.path.join(result_dir(), 'hla_typing', 'hla_types.list'),
exp=os.path.join(result_dir(), 'hla_typing', 'hla_exp.list'),
log:
out=os.path.join(result_dir(), 'iris_parse_hla_log.out'),
err=os.path.join(result_dir(), 'iris_parse_hla_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
out_dir=os.path.join(result_dir(), 'hla_typing'),
resources:
mem_mb=config['iris_parse_hla_mem_gb'] * 1024,
time_hours=config['iris_parse_hla_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} IRIS parse_hla'
' --outdir {params.out_dir}'
' 1> {log.out}'
' 2> {log.err}'
def iris_makesubsh_rmats_task_out_file_names():
task_dir = os.path.join(result_dir(), 'rmats_tasks')
sample_names = unique_sample_names()
rmats_tasks = list()
for sample_name in sample_names:
rmats_name = 'rMATS_prep.{}.sh'.format(sample_name)
rmats_tasks.append(os.path.join(task_dir, rmats_name))
return {'rmats_tasks': rmats_tasks}
def iris_makesubsh_rmats_done_file_names():
rmats_tasks = iris_makesubsh_rmats_task_out_file_names()['rmats_tasks']
done_names = list()
for task in rmats_tasks:
done_names.append('{}.done'.format(task))
return done_names
def iris_makesubsh_rmats_task_dir_param(wildcards, output):
return os.path.dirname(output.rmats_tasks[0])
def iris_makesubsh_rmats_input(wildcards):
inputs = dict()
inputs['star_done'] = iris_makesubsh_mapping_star_done_file_names()
inputs['gtf'] = os.path.join('references', config['gtf_name'])
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_makesubsh_rmats:
input:
unpack(iris_makesubsh_rmats_input),
output:
**iris_makesubsh_rmats_task_out_file_names()
log:
out=os.path.join(result_dir(), 'iris_makesubsh_rmats_log.out'),
err=os.path.join(result_dir(), 'iris_makesubsh_rmats_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
rmats_path=config['rmats_path'],
bam_dir=os.path.join(result_dir(), 'process_rnaseq'),
run_name=config['run_name'],
task_dir=iris_makesubsh_rmats_task_dir_param,
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_2} IRIS makesubsh_rmats'
' --rMATS-path {params.rmats_path}'
' --bam-dir {params.bam_dir}'
' --gtf {input.gtf}'
' --data-name {params.run_name}'
' --task-dir {params.task_dir}'
' 1> {log.out}'
' 2> {log.err}'
def iris_rmats_task_input(wildcards):
inputs = dict()
inputs['rmats_task'] = os.path.join(
result_dir(), 'rmats_tasks',
'rMATS_prep.{}.sh'.format(wildcards.sample))
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_rmats_task:
input:
unpack(iris_rmats_task_input),
output:
# The output files have the format:
# result_dir()/process_rnaseq/{run}.RL{readLength}/{sample}.tmp/{datetime}_{n}.rmats
# Just using a .done file instead.
rmats_task_done=touch(os.path.join(result_dir(), 'rmats_tasks',
'rMATS_prep.{sample}.sh.done')),
log:
out=os.path.join(result_dir(), 'rmats_tasks',
'iris_rmats_task_{sample}_log.out'),
err=os.path.join(result_dir(), 'rmats_tasks',
'iris_rmats_task_{sample}_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
threads: config['iris_rmats_task_threads']
resources:
mem_mb=config['iris_rmats_task_mem_gb'] * 1024,
time_hours=config['iris_rmats_task_time_hr'],
shell:
'{params.conda_wrapper} {params.conda_env_2} bash'
' {input.rmats_task}'
' 1> {log.out}'
' 2> {log.err}'
checkpoint check_read_lengths:
input:
rmats_done=iris_makesubsh_rmats_done_file_names(),
output:
read_lengths=os.path.join(result_dir(), 'process_rnaseq',
'read_lengths.txt'),
log:
out=os.path.join(result_dir(), 'process_rnaseq', 'check_read_lengths_log.out'),
err=os.path.join(result_dir(), 'process_rnaseq', 'check_read_lengths_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_3=config['conda_env_3'],
script=os.path.join('scripts', 'check_read_lengths.py'),
parent_dir=os.path.join(result_dir(), 'process_rnaseq'),
run_name=config['run_name'],
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_3} python {params.script}'
' --parent-dir {params.parent_dir}'
' --run-name {params.run_name}'
' --out {output.read_lengths}'
' 1> {log.out}'
' 2> {log.err}'
def iris_makesubsh_rmatspost_input(wildcards):
inputs = dict()
inputs['rmats_done'] = iris_makesubsh_rmats_done_file_names()
inputs['gtf'] = os.path.join('references', config['gtf_name'])
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_makesubsh_rmatspost:
input:
rmats_done=iris_makesubsh_rmats_done_file_names(),
gtf=os.path.join('references', config['gtf_name']),
output:
makesubsh_done=touch(os.path.join(result_dir(), 'iris_makesubsh_rmats_post.done')),
log:
out=os.path.join(result_dir(), 'iris_makesubsh_rmatspost_log.out'),
err=os.path.join(result_dir(), 'iris_makesubsh_rmatspost_log.err'),
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
rmats_path=config['rmats_path'],
bam_dir=os.path.join(result_dir(), 'process_rnaseq'),
run_name=config['run_name'],
task_dir=os.path.join(result_dir(), 'rmats_post_tasks'),
resources:
mem_mb=DEFAULT_MEM_MB,
time_hours=DEFAULT_TIME_HOURS,
shell:
'{params.conda_wrapper} {params.conda_env_2} IRIS makesubsh_rmatspost'
' --rMATS-path {params.rmats_path}'
' --bam-dir {params.bam_dir}'
' --gtf {input.gtf}'
' --data-name {params.run_name}'
' --task-dir {params.task_dir}'
' 1> {log.out}'
' 2> {log.err}'
def iris_rmatspost_task_input(wildcards):
inputs = dict()
inputs['makesubsh_done'] = os.path.join(
result_dir(), 'iris_makesubsh_rmats_post.done')
if not config['run_all_modules']:
inputs['run_all_modules'] = UNSATISFIABLE_INPUT
return inputs
rule iris_rmatspost_task:
input:
unpack(iris_rmatspost_task_input),
output:
summary=os.path.join(result_dir(), 'process_rnaseq',
'{run_name}.RL{read_length}',
'{run_name}_RL{read_length}.matrix',
'summary.txt'),
log:
out=os.path.join(result_dir(), 'rmats_post_tasks',
'iris_rmatspost_task_{run_name}_{read_length}_log.out'),
err=os.path.join(result_dir(), 'rmats_post_tasks',
'iris_rmatspost_task_{run_name}_{read_length}_log.err'),
wildcard_constraints:
run_name=config['run_name'],
params:
conda_wrapper=config['conda_wrapper'],
conda_env_2=config['conda_env_2'],
# post_task is generated by iris_makesubsh_rmatspost, but since the number of
# read_lengths is not known until the check_read_lengths checkpoint,
# that .sh file is not used in the "input" or "output" sections of the snakemake
post_task=os.path.join(result_dir(), 'rmats_post_tasks',
'rMATS_post.{run_name}_RL{read_length}.sh'),
threads: config['iris_rmatspost_task_threads']
resources:
mem_mb=config['iris_rmatspost_task_mem_gb'] * 1024,