<filename>bin/somaticsniper_filter.py
#!/usr/bin/env python

import argparse
import sys

def parse_args(args=None):
    Description = "Filter and reformat the vcf generated by Somaticsniper."
    Epilog = "Example usage: python check_samplesheet.py <FILE_IN>"

    parser = argparse.ArgumentParser(description=Description, epilog=Epilog)
    parser.add_argument("FILE_IN", help="Input vcf file.")
    return parser.parse_args(args)

def index_column_substring(your_list, substring):
    for i, s in enumerate(your_list):
        if substring in s:
            return i
    return -1

def somaticSniper_filter(input):
    """
    Filters a SomaticSniper VCF to keep only somatic variants
    Some reformatting is also applied to make the VCF correct
    :param input: the input VCF generated with SomaticSniper
    :param output: the name of filtered VCF file
    :return: None
    """
    filtered_vcf = open('tmp_ss.vcf', 'w')
    vcf = open(input)
    for line in vcf:
        if line.startswith('#CHROM'):
            headers = line.strip().split('\t')
            filtered_vcf.write(line)
        elif not line.startswith('#'):
            columns = line.strip().split('\t')
            format = columns[headers.index('FORMAT')]
            tumor = columns[headers.index('TUMOR')]
            somatic_status_index = format.split(':').index('SS')
            somatic_status = int(tumor.split(':')[somatic_status_index])
            if somatic_status == 2:
                filtered_vcf.write(line)
        else:
            filtered_vcf.write(line)
    vcf.close()
    filtered_vcf.close()

def main(args=None):
    args = parse_args(args)
    somaticSniper_filter(args.FILE_IN)

if __name__ == "__main__":
    sys.exit(main())

<filename>bin/somaticsniper_filter.py
#!/usr/bin/env python

import argparse
import sys

def parse_args(args=None):
    Description = "Filter and reformat the vcf generated by Somaticsniper."
    Epilog = "Example usage: python check_samplesheet.py <FILE_IN>"

    parser = argparse.ArgumentParser(description=Description, epilog=Epilog)
    parser.add_argument("FILE_IN", help="Input vcf file.")
    return parser.parse_args(args)

def index_column_substring(your_list, substring):
    for i, s in enumerate(your_list):
        if substring in s:
            return i
    return -1

def somaticSniper_filter(input):
    """
    Filters a SomaticSniper VCF to keep only somatic variants
    Some reformatting is also applied to make the VCF correct
    :param input: the input VCF generated with SomaticSniper
    :param output: the name of filtered VCF file
    :return: None
    """
    filtered_vcf = open('tmp_ss.vcf', 'w')
    vcf = open(input)
    for line in vcf:
        if line.startswith('#CHROM'):
            headers = line.strip().split('\t')
            filtered_vcf.write(line)
        elif not line.startswith('#'):
            columns = line.strip().split('\t')
            format = columns[headers.index('FORMAT')]
            tumor = columns[headers.index('TUMOR')]
            somatic_status_index = format.split(':').index('SS')
            somatic_status = int(tumor.split(':')[somatic_status_index])
            if somatic_status == 2:
                filtered_vcf.write(line)
        else:
            filtered_vcf.write(line)
    vcf.close()
    filtered_vcf.close()

def main(args=None):
    args = parse_args(args)
    somaticSniper_filter(args.FILE_IN)

if __name__ == "__main__":
    sys.exit(main())

#!/usr/bin/env python Filters a SomaticSniper VCF to keep only somatic variants     Some reformatting is also applied to make the VCF correct     :param input: the input VCF generated with SomaticSniper     :param output: the name of filtered VCF file     :return: None