zoukankan      html  css  js  c++  java
  • 【数据处理】python将GO注释结果整理为WEGO文件

    通常,比对NR库后为m8格式,通过NR和GO数据库对应关系文件,写代码整理为Gene——>GO文件,如下:
    image.png
    这里是一对一的关系,要转换为WEGO格式文件,即一对多关系,如下:
    image.png
    用python脚本处理代码示例如下:

    #! /usr/bin/env python
    import optargs
    import os
    import sys
    
    usage='''
        tidy go annotation file to wego file
    '''
    
    option = optparse.OptionParser(usage)
    option.add_option('','--infile',help='* annot file',default='')
    option.add_option('','--outfile',help='* outfile',default='')
    
    (opts,args) = option.parse_args()
    infile = opts.infile
    outfile = opts.outfile
    
    def main():
        acc2go = {}
        res = open(outfile,'w')
        for line in open(infile,'r'):
            line = line.strip().split('	')
            if len(line) < 2: continue
            accession = line[0]
            go = line[1]
            acc2go.setdefault(accession, set()).add(go)
    
        for acc,goi in acc2go.items():
            res.write("%s	%s
    "%(acc, "	".join(goi)))
        res.close()
    
    if __name__ == '__main__':
        if len(sys.argv) < 2:
            os.system("python %s -h"%(sys.args[0]))
            sys.exit(1)
        else:
            main()
    
    
  • 相关阅读:
    静态代码块执行顺序
    静态代码块
    方法的定义(实例与静态)
    变量的声明(实例与静态)
    static关键字
    封装2
    线程1
    数组元素的查找——二分法查找
    docker介绍、安装及要素讲解
    渗透测试基础
  • 原文地址:https://www.cnblogs.com/jessepeng/p/13205633.html
Copyright © 2011-2022 走看看