def _postprocess_somatic(in_file, paired):
    """Post-process somatic calls to provide standard output.

    - Converts SGT and NT into standard VCF GT fields
    - Replace generic TUMOR NORMAL names in VCF with sample names.
    """
    out_file = in_file.replace(".vcf.gz", "-fixed.vcf")
    if not utils.file_exists(out_file) and not utils.file_exists(out_file + ".gz"):
        with file_transaction(paired.tumor_data, out_file) as tx_out_file:
            with utils.open_gzipsafe(in_file) as in_handle:
                with open(tx_out_file, "w") as out_handle:
                    added_gt = False
                    normal_index, tumor_index = (None, None)
                    for line in in_handle:
                        if line.startswith("##FORMAT") and not added_gt:
                            added_gt = True
                            out_handle.write('##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">\n')
                            out_handle.write(line)
                        elif line.startswith("#CHROM"):
                            assert added_gt
                            parts = line.strip().split("\t")
                            normal_index = parts.index("NORMAL")
                            tumor_index = parts.index("TUMOR")
                            line = line.replace("NORMAL", paired.normal_name).replace("TUMOR", paired.tumor_name)
                            out_handle.write(line)
                        elif line.startswith("#"):
                            out_handle.write(line)
                        else:
                            parts = line.rstrip().split("\t")
                            tumor_gt, normal_gt = _tumor_normal_genotypes(parts[3], parts[4].split(","),
                                                                          parts[7].split(";"), in_file, parts[:2])
                            parts[8] = "GT:%s" % parts[8]
                            parts[normal_index] = "%s:%s" % (normal_gt, parts[normal_index])
                            parts[tumor_index] = "%s:%s" % (tumor_gt, parts[tumor_index])
                            out_handle.write("\t".join(parts) + "\n")
    return vcfutils.bgzip_and_index(out_file, paired.tumor_data["config"])
def _postprocess_somatic ( in_file , paired ) : out_file = in_file . replace ( ".vcf.gz" , "-fixed.vcf" ) if not utils . file_exists ( out_file ) and not utils . file_exists ( out_file + ".gz" ) : with file_transaction ( paired . tumor_data , out_file ) as tx_out_file : with utils . open_gzipsafe ( in_file ) as in_handle : with open ( tx_out_file , "w" ) as out_handle : added_gt = False normal_index , tumor_index = ( None , None ) for line in in_handle : if line . startswith ( "##FORMAT" ) and not added_gt : added_gt = True out_handle . write ( '##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">\n' ) out_handle . write ( line ) elif line . startswith ( "#CHROM" ) : assert added_gt parts = line . strip ( ) . split ( "\t" ) normal_index = parts . index ( "NORMAL" ) tumor_index = parts . index ( "TUMOR" ) line = line . replace ( "NORMAL" , paired . normal_name ) . replace ( "TUMOR" , paired . tumor_name ) out_handle . write ( line ) elif line . startswith ( "#" ) : out_handle . write ( line ) else : parts = line . rstrip ( ) . split ( "\t" ) tumor_gt , normal_gt = _tumor_normal_genotypes ( parts [ 3 ] , parts [ 4 ] . split ( "," ) , parts [ 7 ] . split ( ";" ) , in_file , parts [ : 2 ] ) parts [ 8 ] = "GT:%s" % parts [ 8 ] parts [ normal_index ] = "%s:%s" % ( normal_gt , parts [ normal_index ] ) parts [ tumor_index ] = "%s:%s" % ( tumor_gt , parts [ tumor_index ] ) out_handle . write ( "\t" . join ( parts ) + "\n" ) return vcfutils . bgzip_and_index ( out_file , paired . tumor_data [ "config" ] )
Post-process somatic calls to provide standard output.

    - Converts SGT and NT into standard VCF GT fields
    - Replace generic TUMOR NORMAL names in VCF with sample names.