mirror of
https://github.com/Priyatham-sai-chand/compara-deep-learning.git
synced 2026-10-05 08:11:34 -07:00
Add functionality to write pdf
This commit is contained in:
parent
d66638422f
commit
f3ca3a5870
1 changed files with 62 additions and 15 deletions
|
|
@ -1,38 +1,74 @@
|
|||
import numpy as np
|
||||
import os
|
||||
import json
|
||||
import gc
|
||||
from read_data import read_data_homology
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
from matplotlib.backends.backend_pdf import PdfPages
|
||||
|
||||
a_h,_=read_data_homology("data_homology")
|
||||
a_h,d_h=read_data_homology("data_homology")
|
||||
d_h=list(d_h.keys())
|
||||
|
||||
ndir="processed/synteny_matrices/"
|
||||
nf1="synteny_matrices_global_"
|
||||
nf2="synteny_matrices_local_"
|
||||
nf3="indexes_"
|
||||
nf1="_synteny_matrices_global"
|
||||
nf2="_synteny_matrices_local"
|
||||
nf3="_indexes"
|
||||
|
||||
lsy={}
|
||||
with open("processed/neighbor_genes.json","r") as file:
|
||||
lsy=dict(json.load(file))
|
||||
|
||||
synteny_matrices_global=np.load(ndir+nf1+"11"+".npy")
|
||||
synteny_matrices_local=np.load(ndir+nf2+"11"+".npy")
|
||||
indexes=np.load(ndir+nf3+"11"+".npy")
|
||||
for i in range(len(d_h)):
|
||||
print("{}.{}".format(i+1,d_h[i]))
|
||||
|
||||
df=a_h[0].loc[indexes]
|
||||
while(1):
|
||||
try:
|
||||
ch=int(input("Enter your choice:"))
|
||||
synteny_matrices_global=np.load(ndir+str(d_h[ch-1])+nf1+".npy")
|
||||
synteny_matrices_local=np.load(ndir+str(d_h[ch-1])+nf2+".npy")
|
||||
indexes=np.load(ndir+str(d_h[ch-1])+nf3+".npy")
|
||||
break
|
||||
except:
|
||||
print("Choice invalid or incomplete files!!!!!. Try Another Index.")
|
||||
|
||||
df=a_h[ch-1].loc[indexes]
|
||||
a_h=[]
|
||||
gc.collect()
|
||||
|
||||
inddict={}
|
||||
for i in range(len(indexes)):
|
||||
inddict[indexes[i]]=i
|
||||
|
||||
ng=["Levenshtein Distance","Levenshtein Distance Reverse"]
|
||||
nl=["Local Alignment Score","Local Alignment Score Reverse"]
|
||||
|
||||
print(indexes)
|
||||
while(1):
|
||||
i=int(input("Enter the index"))
|
||||
try:
|
||||
i=int(input("Enter the index:"))
|
||||
except:
|
||||
break
|
||||
if i in inddict:
|
||||
font = {'family': 'sans-serif',
|
||||
'color': 'darkturquoise',
|
||||
'weight': 'heavy',
|
||||
'size': 20,
|
||||
}
|
||||
pdf=PdfPages(str(i)+".pdf")
|
||||
print("Species",df.loc[i].species)
|
||||
print("Homology Species",df.loc[i].homology_species)
|
||||
print("Gene Stable Id:",df.loc[i].gene_stable_id)
|
||||
print("Homology Gene Stable Id:",df.loc[i].homology_gene_stable_id)
|
||||
text="Species:"+df.loc[i].species
|
||||
text+="\n"+"Gene Stable Id:"+df.loc[i].gene_stable_id
|
||||
text+="\n"+"Homology Species:"+df.loc[i].homology_species
|
||||
text+="\n"+"Homology Gene Stable Id:"+df.loc[i].homology_gene_stable_id
|
||||
text+="\n"+"Homology Type:"+df.loc[i].homology_type
|
||||
fp=plt.figure(figsize=(10,10))
|
||||
fp.text(0.5,0.5,text,ha="center",fontdict=font)
|
||||
pdf.savefig()
|
||||
plt.close()
|
||||
print("Global aligned matrix:")
|
||||
|
||||
g1=df.loc[i].gene_stable_id
|
||||
|
|
@ -56,19 +92,30 @@ while(1):
|
|||
sl=synteny_matrices_local[loc]
|
||||
for m in range(sg.shape[-1]):
|
||||
matrix=sg[:,:,m]
|
||||
print(matrix)
|
||||
hmap=sns.heatmap(matrix,xticklabels=y, yticklabels=x,annot=True)
|
||||
print(matrix)
|
||||
fig,ax=plt.subplots(figsize=(8,8))
|
||||
ax.set_xlabel(str(df.loc[i].homology_species),fontsize=10)
|
||||
ax.set_ylabel(str(df.loc[i].species),fontsize=10)
|
||||
hmap=sns.heatmap(matrix,xticklabels=y, yticklabels=x,annot=True,ax=ax,linewidths=.5,cmap="YlGnBu",annot_kws={"size": 10})
|
||||
hmap.figure.subplots_adjust(left=0.33,bottom=0.33,right=0.79,top=0.79)
|
||||
ax.set_title(ng[m])
|
||||
#plt.text(1,0.5,text,size=10)
|
||||
pdf.savefig()
|
||||
plt.show()
|
||||
|
||||
print("Local Alignment Matrix")
|
||||
for m in range(sg.shape[-1]):
|
||||
matrix=sl[:,:,m]
|
||||
print(matrix)
|
||||
hmap=sns.heatmap(matrix,xticklabels=y, yticklabels=x,annot=True)
|
||||
fig,ax=plt.subplots(figsize=(8,8))
|
||||
ax.set_xlabel(df.loc[i].homology_species)
|
||||
ax.set_ylabel(df.loc[i].species)
|
||||
hmap=sns.heatmap(matrix,xticklabels=y, yticklabels=x,annot=True,ax=ax,linewidths=.5,cmap="YlGnBu",annot_kws={"size": 10})
|
||||
hmap.figure.subplots_adjust(left=0.27,bottom=0.29,right=0.92)
|
||||
ax.set_title(nl[m])
|
||||
pdf.savefig()
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
pdf.close()
|
||||
else:
|
||||
print("Index not found")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue