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()
    
    
  • 相关阅读:
    spring filter and interceptor
    spring 与 swagger 2 的整合
    spring 异步操作
    图片延迟加载 jquery,lazyload.js 调用的demo
    一、Spring的第一个课时
    线程的基本了解
    HTTPS/HTTP监听常见问题
    Leetcode 118 杨辉三角
    HashSet的源码解释
    HashMap源码理解
  • 原文地址:https://www.cnblogs.com/jessepeng/p/13205633.html
Copyright © 2011-2022 走看看