ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python中 从gff文件提取指定基因信息

2022-06-07 23:32:15  阅读:301  来源: 互联网

标签:tmp test2 python root PC1 基因 txt gene gff


 

1、测试数据下载:ftp://ftp.ensemblgenomes.org/pub/plants/release-44/gff3/arabidopsis_thaliana/Arabidopsis_thaliana.TAIR10.44.chromosome.1.gff3.gz

 

 

 

2、

[root@PC1 test2]# ls
Arabidopsis_thaliana.TAIR10.44.chromosome.1.gff3.gz
[root@PC1 test2]# gunzip Arabidopsis_thaliana.TAIR10.44.chromosome.1.gff3.gz
[root@PC1 test2]# ls
Arabidopsis_thaliana.TAIR10.44.chromosome.1.gff3
[root@PC1 test2]# mv Arabidopsis_thaliana.TAIR10.44.chromosome.1.gff3 a.txt    ## 测试数据
[root@PC1 test2]# ls
a.txt

 

 

3、

[root@PC1 test2]# ls
a.txt  test.py
[root@PC1 test2]# cat test.py    ## 提取信息脚本

in_file = open("a.txt", "r")
out_file = open("result.txt", "w")

for i in in_file:
    i = i.strip()
    if i.startswith("#"):
        continue
    else:
        tmp = i.split("\t")
        if int(tmp[0]) == 1 and tmp[2] == "gene" and int(tmp[3]) > 100000 and int(tmp[4]) < 500000:
            gene = tmp[8].split(";")[0].split("=")[1]
            final = tmp[0] + "\t" + tmp[3] + "\t" + tmp[4] + "\t" + gene
            out_file.write(final + "\n")
in_file.close()
out_file.close()
[root@PC1 test2]# python test.py     ## 运行程序
[root@PC1 test2]# ls
a.txt  result.txt  test.py
[root@PC1 test2]# head result.txt     ## 查看结果
1       104440  105330  gene:AT1G01250
1       108946  111699  gene:AT1G01260
1       112263  113947  gene:AT1G01280
1       114202  116407  gene:AT1G01290
1       116784  118845  gene:AT1G01300
1       119381  119997  gene:AT1G01305
1       120154  121130  gene:AT1G01310
1       121067  130577  gene:AT1G01320
1       130736  130858  gene:AT1G01335
1       132270  135924  gene:AT1G01340

 

标签:tmp,test2,python,root,PC1,基因,txt,gene,gff
来源: https://www.cnblogs.com/liujiaxin2018/p/16353861.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有