@@ -63,12 +63,28 @@ def run_mutation_aggregator(job, mutation_results, univ_options):
6363 """
6464 # Setup an input data structure for the merge function
6565 out = {}
66- for chrom in mutation_results ['mutect' ].keys ():
67- out [chrom ] = job .addChildJobFn (merge_perchrom_mutations , chrom , mutation_results ,
68- univ_options ).rv ()
69- merged_snvs = job .addFollowOnJobFn (merge_perchrom_vcfs , out , 'merged' , univ_options )
70- job .fileStore .logToMaster ('Aggregated mutations for %s successfully' % univ_options ['patient' ])
71- return merged_snvs .rv ()
66+ chroms = {}
67+ for caller in mutation_results :
68+ if mutation_results [caller ] is None :
69+ continue
70+ else :
71+ if caller == 'strelka' :
72+ if mutation_results ['strelka' ]['snvs' ] is None :
73+ continue
74+ chroms = mutation_results ['strelka' ]['snvs' ].keys ()
75+ else :
76+ chroms = mutation_results [caller ].keys ()
77+ break
78+ if chroms :
79+ for chrom in chroms :
80+ out [chrom ] = job .addChildJobFn (merge_perchrom_mutations , chrom , mutation_results ,
81+ univ_options ).rv ()
82+ merged_snvs = job .addFollowOnJobFn (merge_perchrom_vcfs , out , 'merged' , univ_options )
83+ job .fileStore .logToMaster ('Aggregated mutations for %s successfully' % univ_options ['patient' ])
84+ return merged_snvs .rv ()
85+ else :
86+ return None
87+
7288
7389
7490def merge_perchrom_mutations (job , chrom , mutations , univ_options ):
@@ -105,25 +121,27 @@ def merge_perchrom_mutations(job, chrom, mutations, univ_options):
105121 # For now, let's just say 2 out of n need to call it.
106122 # num_preds = len(mutations)
107123 # majority = int((num_preds + 0.5) / 2)
108- majority = {'snvs' : 2 ,
109- 'indels' : 1 }
110-
111124 accepted_hits = defaultdict (dict )
112125
113126 for mut_type in vcf_processor .keys ():
114127 # Get input files
115128 perchrom_mutations = {caller : vcf_processor [mut_type ][caller ](job , mutations [caller ][chrom ],
116129 work_dir , univ_options )
117- for caller in vcf_processor [mut_type ]}
130+ for caller in vcf_processor [mut_type ]
131+ if mutations [caller ] is not None }
118132 # Process the strelka key
119- perchrom_mutations ['strelka' ] = perchrom_mutations ['strelka_' + mut_type ]
120- perchrom_mutations .pop ('strelka_' + mut_type )
133+ if 'strelka' + mut_type in perchrom_mutations :
134+ perchrom_mutations ['strelka' ] = perchrom_mutations ['strelka_' + mut_type ]
135+ perchrom_mutations .pop ('strelka_' + mut_type )
136+ if not perchrom_mutations :
137+ continue
138+ majority = 1 if len (perchrom_mutations ) <= 2 else len (perchrom_mutations ) / 2
121139 # Read in each file to a dict
122140 vcf_lists = {caller : read_vcf (vcf_file ) for caller , vcf_file in perchrom_mutations .items ()}
123141 all_positions = list (set (itertools .chain (* vcf_lists .values ())))
124142 for position in sorted (all_positions ):
125143 hits = {caller : position in vcf_lists [caller ] for caller in perchrom_mutations .keys ()}
126- if sum (hits .values ()) >= majority [ mut_type ] :
144+ if sum (hits .values ()) >= majority :
127145 callers = ',' .join ([caller for caller , hit in hits .items () if hit ])
128146 assert position [1 ] not in accepted_hits [position [0 ]]
129147 accepted_hits [position [0 ]][position [1 ]] = (position [2 ], position [3 ], callers )
0 commit comments