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()
    
    
  • 相关阅读:
    排序sort (一)
    c++实现二叉树笔记(模板实现)(三)
    树(二叉树)的建立和遍历算法(二)
    IO流之字节流
    计算机基础知识
    计算机启动过程
    2020软考报名计划表
    2020软件工程作业02
    初来乍到 20200904
    关于考研
  • 原文地址:https://www.cnblogs.com/jessepeng/p/13205633.html
Copyright © 2011-2022 走看看