2019-06-10 09:37:49 -07:00
|
|
|
import pandas as pd
|
|
|
|
|
import numpy as np
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import progressbar
|
|
|
|
|
import json
|
|
|
|
|
from read_data import read_data_homology
|
|
|
|
|
from read_get_gene_seq import read_gene_sequences
|
|
|
|
|
from create_synteny_matrix import synteny_matrix
|
2019-06-17 03:17:47 -07:00
|
|
|
from access_data_rest import update_rest
|
2019-06-10 09:37:49 -07:00
|
|
|
|
2019-06-12 01:25:02 -07:00
|
|
|
if not os.path.isdir("processed/synteny_matrices"):
|
2019-06-10 09:37:49 -07:00
|
|
|
os.mkdir("processed/synteny_matrices")
|
|
|
|
|
|
|
|
|
|
arg=sys.argv
|
|
|
|
|
arg=arg[1:]
|
|
|
|
|
|
2019-06-12 01:25:02 -07:00
|
|
|
nos=int(arg[0])
|
2019-06-10 09:37:49 -07:00
|
|
|
|
|
|
|
|
lsy={}
|
|
|
|
|
a_h,d_h=read_data_homology("data_homology")
|
2019-06-12 01:25:02 -07:00
|
|
|
print(d_h)
|
|
|
|
|
d_h=list(d_h.keys())
|
2019-06-10 09:37:49 -07:00
|
|
|
print("Homology Data Read")
|
2019-06-12 01:25:02 -07:00
|
|
|
for i in range(len(a_h)):
|
|
|
|
|
df=a_h[i]
|
|
|
|
|
random_indexes=np.random.permutation(len(df))
|
|
|
|
|
random_indexes=random_indexes[:nos]
|
|
|
|
|
df=df.loc[random_indexes]
|
|
|
|
|
assert(len(df)==nos)
|
|
|
|
|
a_h[i]=df
|
|
|
|
|
|
2019-06-17 03:17:47 -07:00
|
|
|
print("Data Selected")
|
|
|
|
|
|
2019-06-10 09:37:49 -07:00
|
|
|
with open("processed/neighbor_genes.json","r") as file:
|
|
|
|
|
lsy=dict(json.load(file))
|
|
|
|
|
print(len(lsy))
|
|
|
|
|
print("Neighbor Genes Loaded")
|
2019-06-12 01:25:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
gene_sequences=read_gene_sequences(a_h,lsy,"geneseq","gene_sequences")
|
2019-06-10 09:37:49 -07:00
|
|
|
print("Gene Sequences Loaded")
|
|
|
|
|
|
2019-06-17 03:17:47 -07:00
|
|
|
print("Going to update not found sequences:")
|
|
|
|
|
gene_sequences=update_rest(gene_sequences)
|
2019-06-10 09:37:49 -07:00
|
|
|
|
|
|
|
|
n=3
|
|
|
|
|
ndir="processed/synteny_matrices/"
|
|
|
|
|
nf1="synteny_matrices_global"
|
|
|
|
|
nf2="synteny_matrices_local"
|
|
|
|
|
nf3="indexes"
|
2019-06-12 01:25:02 -07:00
|
|
|
for i in range(len(a_h)):
|
|
|
|
|
df=a_h[i]
|
2019-06-17 03:17:47 -07:00
|
|
|
print(len(df))
|
2019-06-12 01:25:02 -07:00
|
|
|
synteny_matrices_global,synteny_matrices_local,indexes=synteny_matrix(gene_sequences,df,lsy,n,0)
|
|
|
|
|
np.save(ndir+str(d_h[i])+"_"+nf1,synteny_matrices_global)
|
|
|
|
|
np.save(ndir+str(d_h[i])+"_"+nf2,synteny_matrices_local)
|
|
|
|
|
np.save(ndir+str(d_h[i])+"_"+nf3,indexes)
|
2019-06-17 03:17:47 -07:00
|
|
|
print(len(indexes))
|
2019-06-10 09:37:49 -07:00
|
|
|
print("Synteny Matrices Created Successfully :)")
|