In [140]:
path='/home/arya/storage/Data/Human/Kyrgyz/plots/intervals/'
outpath='/home/arya/workspace/bio/Scripts/HLI/Kyrgyz/notebooks/'
relpath=path.replace(utl.home,'../../../../../../')
import glob
import os
pd.options.display.max_colwidth=100
from dominate import document
from dominate.util import raw
from dominate.tags import *
from itertools import product
stats=['D','H','SFSelect','pi']
tails=['-','+']
tailm={'-':'n','+':'p'}
a=pd.read_pickle('/home/arya/storage/Data/Human/Kyrgyz/SFS.df').drop(['i','end'],1).set_index(['stat','tail']).sort_index()
a['genes']=a.set_index('index',append=True).groupby(level=[0,1,2]).apply(lambda x:'<a href="intervals/{}{}.{}.html" target="_blank">{}</a>'.format(x.name[0],tailm[x.name[1]],x.name[2],x.genes.tolist()[0])).reset_index('index')[0]
with document(title='Results') as doc:
with doc.head:link(rel='stylesheet', href='style.css')
with doc:
for stat,tail in product(stats,tails):
h1('{} ({} tail)'.format(stat,tail))
td(raw(a.loc[(stat,tail)].to_html()))
div(img(src=relpath+stat+tail+'.stat.png'), _class='img')
div(img(src=relpath+stat+tail+'.man.png'), _class='img')
with open(outpath+'results.html', 'w') as f:
f.write(doc.render().replace('<','<').replace('>','>'))
a=pd.read_pickle('/home/arya/storage/Data/Human/Kyrgyz/SFS.df').drop(['i','end'],1).set_index(['stat','tail']).sort_index()
for stat,tail in product(stats,tails):
for i,row in a.loc[(stat,tail)].set_index('index').iterrows():
with document(title='D+') as doc:
with doc.head:link(rel='stylesheet', href='style.css')
with doc:
h1(raw('<a name="{}">{}</a>'.format(i,row.genes)))
for f in ['pca','sfs','freq','daf','genelen']:
div(img(src='../'+relpath+'Healthy.Sick.{}{}.{}.{}.png'.format(stat,tail,i,f)), _class='img')
with open(outpath+'intervals/{}{}.{}.html'.format(stat,tailm[tail],i), 'w') as f:
f.write(doc.render())
In [128]:
print stat,tail,i
In [ ]: