def generateTErecurencematrixbaseonLISTdistanceForOneChr(repository,endofthefile,achr,windowsize): dumpmatname=repository+achr+endofthefile+"dumpmat.dump" if op.exists(dumpmatname): print("===> Matrice deja existante") thematrix=pickle.load(open(dumpmatname,"rb")) else: print("===>Constitution de la matrice") filename=repository+achr+endofthefile setlist,sizelist=generatedoublelistofset(filename,windowsize) L=len(setlist) Lset=windowsize #juste for speed writing print(L) thematrix=np.zeros((L,L)) i=0 j=0 print("====>Creation de la matrice") print(thematrix.shape) while i<L: print(i) while j<L: if j>i: val=distancebetweenlist(setlist[i],setlist[j]) thematrix[i,j]=val thematrix[j,i]=val j+=1 j=0 i+=1 print("====>Dumping de la matrice") pickle.dump(thematrix,open(dumpmatname,"wb")) #other option of dump but with bigger file print("===> Afichage de la matrice") manipname=repository+achr+endofthefile+"recurenceplot.png" print(thematrix.shape) #print(np.where(thematrix<0)) utils.showamatwithcolorcode(np.add(thematrix,1),manipname,"hot_r") #jet<bwr return thematrix
def generateTErecurencematrixHicComparableForOneChr(repository,endofthefile,achr,resolution,chrsizepath,species): dumpmatname=repository+achr+endofthefile+"dumpmatHiCbin.dump" densityname=repository+achr+endofthefile if op.exists(dumpmatname+".npy"): print("===> Matrice deja existante") thematrix=np.load(open(dumpmatname+".npy","rb")) else: print("===>Constitution de la matrice") filename=repository+achr+endofthefile print("resolution:",resolution) sizedict=utils.loadchrsizedict(chrsizepath,resolution) #find the size of the list of list base on distance sizeList=findsizeforHicListofList(sizedict,utils.dictchr[species],achr) print("taille de la liste:",sizeList) setlist=generateHicListofpattern(filename,sizeList,resolution) transformHiClistofpatterninDensity(setlist,"LTR/Gypsy",densityname+"Gypsy") transformHiClistofpatterninDensity(setlist,"LINE/CR1",densityname+"CR1") transformHiClistofpatterninDensity(setlist,"DNA/P",densityname+"DNAP") transformHiClistofpatterninDensity(setlist,"RC/Helitron",densityname+"helitron") print("taille de la setlist",len(setlist)) L=sizeList #in theory len(setlist)==sizeList #Lset=windowsize #juste for speed writing print("==>Taille de la matrice:",L) thematrix=np.zeros((L,L)) i=0 j=0 while i<L: print(i) while j<L: if j>=i: val=distancebetweenunequallist3(setlist[i],setlist[j]) thematrix[i,j]=val thematrix[j,i]=val j+=1 j=0 i+=1 print("====>Dumping de la matrice") #pickle.dump(thematrix,open(dumpmatname,"wb")) #other option of dump but with bigger file #toto={}#just to be un matlab savemat format #toto['mat']=thematrix #scpio.savemat(repository+achr+endofthefile+"TErecurencematrix.mat",toto) np.save(dumpmatname, thematrix) """cormat=np.corrcoef(thematrix) v,e=giveeigenvalueandvectorvalue(cormat,10) utils.savematrixasfilelist3(e[:,0],repository+achr+"Corrv1") utils.savematrixasfilelist3(e[:,1],repository+achr+"Corrv2") utils.savematrixasfilelist3(e[:,2],repository+achr+"Corrv3") utils.savematrixasfilelist3(e[:,3],repository+achr+"Corrv4")""" print("===> Afichage de la matrice") manipname=repository+achr+endofthefile+"recurenceplot.png" print(thematrix.shape) #print(np.where(thematrix<0)) utils.showamatwithcolorcode(thematrix,manipname,"bwr") #jet<bwr return thematrix
def fastop(repository,endofthefile,achr,resolution,chrsizepath,species): dumpmatname=repository+achr+endofthefile+"dumpmatHiCbin.dump" thematrix=np.load(open(dumpmatname+".npy","rb")) cormat=np.corrcoef(thematrix) where_are_NaNs =np.isnan(cormat) cormat[where_are_NaNs] = 0 where_are_NaNs =np.isinf(cormat) cormat[where_are_NaNs] = 0 """v,e=giveeigenvalueandvectorvalue(cormat,10) utils.savematrixasfilelist3(e[:,0],repository+achr+"Corrv1") utils.savematrixasfilelist3(e[:,1],repository+achr+"Corrv2") utils.savematrixasfilelist3(e[:,2],repository+achr+"Corrv3") utils.savematrixasfilelist3(e[:,3],repository+achr+"Corrv4")""" print("===> Afichage de la matrice") manipname=repository+achr+endofthefile+"Corrrecurenceplot.png" print(thematrix.shape) #print(np.where(thematrix<0)) utils.showamatwithcolorcode(cormat,manipname,"bwr") #jet<bwr
def generateTErecurencematrixbaseonSETdistanceForOneChr(repository,endofthefile,achr,windowsize): dumpmatname=repository+achr+endofthefile+"dumpmat.dump" if op.exists(dumpmatname): print("===> Matrice deja existante") #thematrix=scpio.loadmat(dumpmatname)['mat'] thematrix=pickle.load(open(dumpmatname,"rb")) else: print("===>Constitution de la matrice") filename=repository+achr+endofthefile setlist,sizelist=generatejumplistofset(filename,windowsize) L=len(setlist) Lset=windowsize #juste for speed writing print(L) thematrix=np.zeros((L,L)) i=0 j=0 print("====>Creation de la matrice") print(thematrix.shape) while i<L: while j<L: if j>i: commonL=len(setlist[i].intersection(setlist[j])) Li=sizelist[i] Lj=sizelist[j] val=commonL-max((Li-Lj),(Lj-Li)) thematrix[i,j]=val thematrix[j,i]=val j+=1 j=0 i+=1 print("====>Dumping de la matrice") #matlabdict={}#just to be un matlab savemat format #matlabdict['mat']=thematrix #not need sparse: not so many 0 #scpio.savemat(dumpmatname,matlabdict) pickle.dump(thematrix,open(dumpmatname,"wb")) #other option of dump but with bigger file print("===> Afichage de la matrice") manipname=repository+achr+endofthefile+"recurenceplot.png" print(thematrix.shape) print(np.where(thematrix<0)) utils.showamatwithcolorcode(np.add(thematrix,1),manipname,"bwr") #jet<bwr return thematrix