9 parser = argparse.ArgumentParser()
10 parser.add_argument('txtfilename', metavar='VCF2TXTFILENAME', help='text file of info to annotate')
11 parser.add_argument('samplename', metavar='SAMPLENAME', help='name of sample to use on report')
12 parser.add_argument('headfile', metavar='REPORTHEADHTML', help='head html for report')
13 parser.add_argument('tailfile', metavar='REPORTTAILHTML', help='tail html for report')
14 args = parser.parse_args()
16 pd.set_option("display.max_colwidth", 10000)
18 # filename = "reportdata.txt"
19 # samplename = "hu34D5B9_var-GS000015891-ASM"
20 # headfile = "head.html"
21 # tailfile = "tail.html"
23 filename = args.txtfilename
24 samplename = args.samplename
25 headfile = args.headfile
26 tailfile = args.tailfile
28 # reading data into dataframe
29 headerlist = ["Variant ID", "Chromosome", "Position", "Ref","Alt","Allele ID", "Clinical Significance","Disease Name","Frequency GO-ESP", "Frequency EXAC", "Frequency 1000 Genomes Project","GT"]
30 reportdata = pd.read_csv(filename,header=0,names=headerlist,sep='\t')
31 reportdata['Zygosity']="."
34 idxHOM1 = reportdata.GT=='1|1'
35 idxHOM2 = reportdata.GT=='1/1'
36 idxHET1 = reportdata.GT=='1|0'
37 idxHET2 = reportdata.GT=='1/0'
38 idxHET3 = reportdata.GT=='0|1'
39 idxHET4 = reportdata.GT=='0/1'
40 idxHOM = idxHOM1 | idxHOM2
41 idxHET = idxHET1 | idxHET2 | idxHET3 | idxHET4
42 reportdata.Zygosity[idxHOM]='HOM'
43 reportdata.Zygosity[idxHET]='HET'
45 # creating url from variant ID
46 reportdata['URL'] = '<a href="http://www.mywebsite.com/about.html">About</a>'
47 reportdata.to_json('test.json',orient='records')
48 str_io = io.StringIO()
50 # creating html table from dataframe
51 reportdatasub = reportdata[["Variant ID", "Allele ID", "Clinical Significance","Disease Name", "Frequency EXAC", "Frequency 1000 Genomes Project","Zygosity","URL"]]
52 reportdatasub.to_html(buf=str_io, classes='table table-bordered',index_names=False,index=False)
53 html_str = str_io.getvalue()
54 html_str_encoded = unicode(html_str).encode('utf8')
55 html_str_encoded = html_str_encoded.replace('<','<')
56 html_str_encoded = html_str_encoded.replace('>','>')
57 html_str_encoded = html_str_encoded.replace('|','<br/>')
59 html_file = open(headfile, 'r')
60 source_code_head = html_file.read()
63 html_file = open(tailfile, 'r')
64 source_code_tail = html_file.read()
67 # combine html table with head and tail html for total report
68 total_html = source_code_head + html_str_encoded + source_code_tail
70 # write out report html
71 f = open(samplename+'.html','wb')
75 if __name__ == '__main__':