美文网首页便捷工具
将MCScanX文件转化为circos用的link文件

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

作者: 王梓维 | 来源:发表于2023-04-28 13:46 被阅读0次
    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文件

        本文链接:https://www.haomeiwen.com/subject/zshwjdtx.html