将MCScanX文件转化为circos用的link文件

import pandas as pd
gffname = "D:/circos/MLA.final/h1_h1.gff"
####MCScanX用的gff
collinearity = "D:/circos/MLA.final/h1_h1_20.collinearity"
####MCScanX产生的collinerity文件


gff =  pd.read_csv(gffname,sep='\t',header=None)


print(gff)





with open(collinearity,'r') as r:
    lines=r.readlines()

tmp_collinearity = collinearity + '.tmp'
with open(tmp_collinearity,'w') as w:
    for l in lines:
       if '#' not in l:
            w.write(l)

coll = pd.read_csv(tmp_collinearity,sep='\t',header=None)

print(coll)




fileresult = collinearity + '.link'
f = open(fileresult , "w")



for index,row in coll.iterrows():
    gene1 = gff.loc[gff[1]==row[1]][[0,2,3]]
    gene1_str = ""
    for i in [0,2,3]:
        if i != 3:
            gene1_str += gene1[i].to_string(header=False, index=False).strip() + "\t"
        else:
            gene1_str += gene1[i].to_string(header=False, index=False).strip()
 
    gene2 = gff.loc[gff[1]==row[2]][[0,2,3]]
    gene2_str = ""
    for i in [0,2,3]:
        if i != 3:
            gene2_str += gene2[i].to_string(header=False, index=False).strip() + "\t"
        else:
            gene2_str += gene2[i].to_string(header=False, index=False).strip()
    
    if index < 2:
        print(gene1_str + "\t" + gene2_str +"\n" )
        
    f.write(gene1_str + "\t" + gene2_str +"\n")

你可能感兴趣的:(将MCScanX文件转化为circos用的link文件)