def merge_mutect(job, perchrom_rvs):
    """
    This module will merge the per-chromosome mutect files created by spawn_mutect into a genome
    vcf.  It will make 2 vcfs, one for PASSing non-germline calls, and one for all calls.

    ARGUMENTS
    1. perchrom_rvs: REFER RETURN VALUE of spawn_mutect()

    RETURN VALUES
    1. output_files: <JSid for mutect_passing_calls.vcf>

    This module corresponds to node 11 on the tree
    """
    job.fileStore.logToMaster('Running merge_mutect')
    work_dir = job.fileStore.getLocalTempDir()
    # We need to squash the input dict of dicts to a single dict such that it can be passed to
    # get_files_from_filestore
    input_files = {filename: jsid for perchrom_files in perchrom_rvs.values()
                   for filename, jsid in perchrom_files.items()}
    input_files = get_files_from_filestore(job, input_files, work_dir, docker=False)
    chromosomes = [''.join(['chr', str(x)]) for x in range(1, 23) + ['X', 'Y']]
    with open('/'.join([work_dir, 'mutect_calls.vcf']), 'w') as mutvcf, \
            open('/'.join([work_dir, 'mutect_calls.out']), 'w') as mutout, \
            open('/'.join([work_dir, 'mutect_passing_calls.vcf']), 'w') as mutpassvcf:
        out_header_not_printed = True
        for chrom in chromosomes:
            with open(input_files[''.join(['mutect_', chrom, '.vcf'])], 'r') as mutfile:
                for line in mutfile:
                    line = line.strip()
                    if line.startswith('#'):
                        if chrom == 'chr1':
                            print(line, file=mutvcf)
                            print(line, file=mutpassvcf)
                        continue
                    else:
                        print(line, file=mutvcf)
                        line = line.split('\t')
                        if line[6] != 'REJECT':
                            print('\t'.join(line), file=mutpassvcf)
            with open(input_files[''.join(['mutect_', chrom,
                                           '.out'])], 'r') as mutfile:
                for line in mutfile:
                    line = line.strip()
                    if line.startswith('#'):
                        if chrom == 'chr1':
                            print(line, file=mutout)
                        continue
                    elif out_header_not_printed:
                        print(line, file=mutout)
                        out_header_not_printed = False
                    else:
                        print(line, file=mutout)
    output_file = job.fileStore.writeGlobalFile(mutpassvcf.name)
    return output_file
def merge_mutect ( job , perchrom_rvs ) : job . fileStore . logToMaster ( 'Running merge_mutect' ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { filename : jsid for perchrom_files in perchrom_rvs . values ( ) for filename , jsid in perchrom_files . items ( ) } input_files = get_files_from_filestore ( job , input_files , work_dir , docker = False ) chromosomes = [ '' . join ( [ 'chr' , str ( x ) ] ) for x in range ( 1 , 23 ) + [ 'X' , 'Y' ] ] with open ( '/' . join ( [ work_dir , 'mutect_calls.vcf' ] ) , 'w' ) as mutvcf , open ( '/' . join ( [ work_dir , 'mutect_calls.out' ] ) , 'w' ) as mutout , open ( '/' . join ( [ work_dir , 'mutect_passing_calls.vcf' ] ) , 'w' ) as mutpassvcf : out_header_not_printed = True for chrom in chromosomes : with open ( input_files [ '' . join ( [ 'mutect_' , chrom , '.vcf' ] ) ] , 'r' ) as mutfile : for line in mutfile : line = line . strip ( ) if line . startswith ( '#' ) : if chrom == 'chr1' : print ( line , file = mutvcf ) print ( line , file = mutpassvcf ) continue else : print ( line , file = mutvcf ) line = line . split ( '\t' ) if line [ 6 ] != 'REJECT' : print ( '\t' . join ( line ) , file = mutpassvcf ) with open ( input_files [ '' . join ( [ 'mutect_' , chrom , '.out' ] ) ] , 'r' ) as mutfile : for line in mutfile : line = line . strip ( ) if line . startswith ( '#' ) : if chrom == 'chr1' : print ( line , file = mutout ) continue elif out_header_not_printed : print ( line , file = mutout ) out_header_not_printed = False else : print ( line , file = mutout ) output_file = job . fileStore . writeGlobalFile ( mutpassvcf . name ) return output_file
This module will merge the per-chromosome mutect files created by spawn_mutect into a genome
    vcf.  It will make 2 vcfs, one for PASSing non-germline calls, and one for all calls.

    ARGUMENTS
    1. perchrom_rvs: REFER RETURN VALUE of spawn_mutect()

    RETURN VALUES
    1. output_files: <JSid for mutect_passing_calls.vcf>

    This module corresponds to node 11 on the tree