Adding in progress code for annotation
[arvados-tutorial.git] / annotation / new / generatereport.py
1 import numpy as np
2 import scipy as scipy
3 import pandas as pd
4 import io
5
6 pd.set_option("display.max_colwidth", 10000)
7
8 filename = "reportdata.txt"
9 samplename = "hu34D5B9_var-GS000015891-ASM"
10 headfile = "head.html"
11 tailfile = "tail.html"
12
13 headerlist = ["Variant ID", "Chromosome", "Position", "Ref","Alt","Allele ID", "Clinical Significance","Disease Name","Frequency GO-ESP", "Frequency EXAC", "Frequency 1000 Genomes Project","GT"]
14 reportdata = pd.read_csv(filename,header=0,names=headerlist,sep='\t')
15 reportdata['Zygosity']="."
16
17 idxHOM1 = reportdata.GT=='1|1' 
18 idxHOM2 = reportdata.GT=='1/1'
19 idxHET1 = reportdata.GT=='1|0'
20 idxHET2 = reportdata.GT=='1/0'
21 idxHET3 = reportdata.GT=='0|1'
22 idxHET4 = reportdata.GT=='0/1'
23 idxHOM = idxHOM1 | idxHOM2
24 idxHET = idxHET1 | idxHET2 | idxHET3 | idxHET4
25 reportdata.Zygosity[idxHOM]='HOM'
26 reportdata.Zygosity[idxHET]='HET'
27
28 #reportdata['URL'] =reportdata['Variant ID'].apply(lambda x: '<a href="www.ncbi.nlm.nih.gov/clinvar/variation/'+str(x)+'> Link </a>')
29 reportdata['URL'] = '<a href="http://www.mywebsite.com/about.html">About</a>'
30 reportdata.to_json('test.json',orient='records')
31 str_io = io.StringIO()
32
33 reportdatasub = reportdata[["Variant ID", "Allele ID", "Clinical Significance","Disease Name", "Frequency EXAC", "Frequency 1000 Genomes Project","Zygosity","URL"]]
34
35 reportdatasub.to_html(buf=str_io, classes='table table-bordered',index_names=False,index=False)
36 html_str = str_io.getvalue()
37 html_str_encoded = unicode(html_str).encode('utf8')
38
39 html_str_encoded = html_str_encoded.replace('&lt;','<')
40 html_str_encoded = html_str_encoded.replace('&gt;','>')
41 html_str_encoded = html_str_encoded.replace('|','<br/>')
42
43 html_file = open(headfile, 'r')
44 source_code_head = html_file.read() 
45 html_file.close()
46
47 html_file = open(tailfile, 'r')
48 source_code_tail = html_file.read()
49 html_file.close()
50
51
52 total_html = source_code_head + html_str_encoded + source_code_tail
53
54 f = open(samplename+'.html','wb')
55
56 f.write(total_html)
57 f.close()