python 在管道中将GTF转换为GFF转换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在管道中将GTF转换为GFF转换相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python
# Slightly adapted from http://blog.nextgenetics.net/?e=27

import sys

def main():
    for line in sys.stdin.xreadlines():
      #skip comment lines that start with the '#' character
      if line[0] != '#':
        #split line into columns by tab
        data = line.strip().split('\t')

        #parse the transcript/gene ID. I suck at using regex, so I usually just do a series of splits.
        transcriptID = data[-1].split('transcript_id')[-1].split(';')[0].strip()[1:-1]
        geneID = data[-1].split('gene_id')[-1].split(';')[0].strip()[1:-1]

        #replace the last column with a GFF formatted attributes columns
        #I added a GID attribute just to conserve all the GTF data
        data[-1] = "ID=" + transcriptID + ";GID=" + geneID

        #print out this new GFF line
        print '\t'.join(data)


if __name__ == '__main__':
    main()

以上是关于python 在管道中将GTF转换为GFF转换的主要内容,如果未能解决你的问题,请参考以下文章

基因组注释文件(二) gff 和 gtf文件格式说明

基因组注释文件(GTF/GFF)格式介绍

gff/gtf格式

探索gff/gtf格式

读取gff/gtf文件的内容

在mongodb聚合管道中将毫秒转换为日期以进行分组?