|
| 1 | +from os import listdir |
| 2 | +from os.path import isfile, join |
| 3 | +import sys |
| 4 | +import argparse |
| 5 | + |
| 6 | +# Python 3 needed for encoding feature for UTF-8 |
| 7 | +# (ENCODE uses some capital delta chars in summary descriptions of GeneticModifications) |
| 8 | + |
| 9 | +def getParams(): |
| 10 | + '''Parse parameters from the command line''' |
| 11 | + parser = argparse.ArgumentParser(description='Parse metadata file and GenoPipe output to check detection rates of the GenoPipe tool.') |
| 12 | + parser.add_argument('-i','--input-dir', metavar='input_dir', required=True, help='the directory where all the StrainID output files were saved (*strain.tab)') |
| 13 | + parser.add_argument('-v','--vcf-dir', metavar='vcf_dir', required=True, help='the directory where all the StrainID VCF db files are housed (for header formatting purposes)') |
| 14 | + args = parser.parse_args() |
| 15 | + return(args) |
| 16 | + |
| 17 | +# Simulation_11.bam |
| 18 | +# Y55.gatk.vcf 5.893664745278011 |
| 19 | +# BY4741.gatk.vcf 4.3921009156813495 |
| 20 | +# SEY6210.gatk.vcf 6.799588141350312 |
| 21 | +# Sigma1278b-10560-6B.gatk.vcf 6.236837493072714 |
| 22 | +# CEN.PK2-1Ca.gatk.vcf 8.360122378850173 |
| 23 | +# D273-10B.gatk.vcf 6.24252455963084 |
| 24 | +# RM11-1A.gatk.vcf 5.897733174105499 |
| 25 | +# BY4742.gatk.vcf 4.57267316132317 |
| 26 | +# FL100.gatk.vcf 6.480670542594632 |
| 27 | +# X2180-1A.gatk.vcf 4.525367446544814 |
| 28 | +# JK9-3d.gatk.vcf 6.523429642303322 |
| 29 | +# W303.gatk.vcf 6.593092702562104 |
| 30 | +def parse_file(var_file): |
| 31 | + dict = {} |
| 32 | + reader = open(var_file,'r') |
| 33 | + for line in reader: |
| 34 | + tokens = line.strip().split("\t") |
| 35 | + if(len(tokens)==1): |
| 36 | + continue |
| 37 | + dict[tokens[0].split(".")[0]] = tokens[1] |
| 38 | + reader.close() |
| 39 | + return(dict) |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + '''Collect metadata and StrainID results to get detection stats on the cell line ENCODE data''' |
| 44 | + args = getParams() |
| 45 | + |
| 46 | + # Parse strains to track |
| 47 | + strain_keys = [] |
| 48 | + for filename in listdir(args.vcf_dir): |
| 49 | + filename_tokens = filename.split(".") |
| 50 | + if(filename_tokens[-1]=="vcf"): |
| 51 | + strain_keys.append(filename_tokens[0]) |
| 52 | + strain_keys.sort() |
| 53 | + |
| 54 | + # Write header |
| 55 | + sys.stdout.write("#\t%s\n" % "\t".join(strain_keys)) |
| 56 | + |
| 57 | + # Parse metadata |
| 58 | + for sindex in range(1,1001): |
| 59 | + # Check file exists |
| 60 | + id_file = join(args.input_dir,"Simulation_%i_strain.tab" % sindex) |
| 61 | + if(not isfile(id_file)): |
| 62 | + sys.stderr.write("%s: no results generated.\n" % (id_file)) |
| 63 | + continue |
| 64 | + |
| 65 | + # Parse id file for cell line score info |
| 66 | + strain_info = parse_file(id_file) |
| 67 | + |
| 68 | + # Write called strain with metadata |
| 69 | + sys.stdout.write( "Simulation_%i\t%s\n" % (sindex, "\t".join([strain_info.get(s,"-") for s in strain_keys]) )) |
0 commit comments