python20

作者: rong酱 | 来源:发表于2021-12-15 09:38 被阅读0次
    # coding=UTF-8
    # -*- coding: utf-8 -*-
    
    import os
    import sys
    
    inputfile=sys.argv[1]
    outputfile=sys.argv[2]
    
    ensdict={}
    with open('geneName.txt','r') as ens:
        ensli=ens.readlines()
        for enslin in ensli:
            enslincon=enslin.strip().split("\t")
            genekey1=enslincon[0]
            genekey2=enslincon[1]
            genename=enslincon[2]
            if genekey1 not in ensdict.keys():
                ensdict[genekey1]=genename
            if genekey2 not in ensdict.keys():
                ensdict[genekey2]=genename
    
    newtxt=open(outputfile,"w")
    with open(inputfile,'r') as enr:
        enrli=enr.readlines()
        newtxt.write("GO_class"+"\t"+"GO ID"+"\t"+"GO_term"+"t"+"Hit_number"+"\t"+"Background number"+"\t"+"P-Value"+"\t"+"Q-Value"+"\t"+"Gene ID"+"\n")
        enricon=""  
        for enrlin in enrli[1:]:
            enrlincon=enrlin.strip().split("\t")
            enricon=str(enrlincon[0])+"\t"+str(enrlincon[1])+"\t"+str(enrlincon[2])+"\t"+str(enrlincon[3])+"\t"+str(enrlincon[4])+"\t"+str(enrlincon[5])+"\t"+str(enrlincon[6])+"\t"
            genecon=enrlincon[7]
            genecontent=enrlincon[7].strip().split(",")
            congene=""
            for genecontenti in genecontent:
                genename=ensdict[genecontenti]
                congene=congene+genename+","
            enricon=enricon+congene+"\n"
            newtxt.write(str(enricon))
    

    相关文章

      网友评论

          本文标题:python20

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