如题,目的是从fasta文件中批量提取特定的基因序列.
实现办法有几种:
- perl脚本:
CSDN博主「little^raccoon」的原创文章perl实现根据序列ID从提取fasta文件序列
原文链接:https://blog.csdn.net/weixin_40099163/article/details/109635328usage: perl thisScript.pl query.fa gene.lst outfile
query.fa 基因组或其他需要从中提取的fasta格式文件
gene.lst 需要提取的基因或染色体名字,有无>均可
outfile 输出文件
#!/bin/perl
#unless(@ARGV==3){
# die "usage: $0 <input.fa> <lst> <output.fas>\n";
#}
$file=shift;
$lst=shift;
$out=shift;
open FILE,$file;
open LST,$lst;
open OUT,">".$out;
while(<FILE>){
chomp;
my $line=$_;
if($line=~/^>/){
my @line=split /[ |\t]/,$line;
our $name=$line[0];
#print "$name\n";
}
else{
$seq_hash{$name}.=$line;
}
}
while(<LST>){
chomp;
my $line=$_;
if($line=~/^>/){
$ID=$line;
if(exists $seq_hash{$ID}){
print OUT "$ID\n$seq_hash{$ID}\n";
}
else{
print OUT "error1: ".$ID." no found.\n";
}
}
else{
my $ID=">".$line;
if(exists $seq_hash{$ID}){
print OUT "$ID\n$seq_hash{$ID}\n";
}
else{
print OUT "error2: ".$ID." no found.\n";
}
}
}
- python
采用click模块添加命令行参数。**
CSDN博主「冷月、无声」的原创文章:根据ID从FASTA文件中批量提取序列【Python脚本】
原文链接:https://blog.csdn.net/weixin_42358077/article/details/87985833
# -*- coding: utf-8 -*-
"""
@author: gyw
@Date: Wed Feb 27 09:19:54 2019
@E-mail: willgyw@126.com
@Description: This program can extract sequences
from a fasta file, according to a
given id list.
"""
import click
@click.command()
@click.option('-f', '--fastafile', help='Input a fasta file', required=True)
@click.option('-i', '--idfile', help='Input an idlist', required=True)
@click.option('-o', '--outfile', help='Input the name of result file', default='result.fa')
def main(fastafile, idfile, outfile):
"""
Extract seqences from a fasta file
according to a id list.
"""
idfile = open(idfile, 'r')
resultfile = open(outfile, 'w')
for id in idfile:
qid = id.strip()
flag = 0
with open(fastafile,'r') as ffile:
for line in ffile:
line = line.strip()
if line.startswith('>'):
name = line.replace('>','').split()[0]
if name == qid:
flag = 1
resultfile.write(line + '\n')
else:
flag = 0
else:
if flag == 0:
pass
else:
resultfile.write(line + '\n')
resultfile.close()
if __name__ == '__main__':
main()
- TBtool software[1]
这个小工具诞生之初就是为了解决最基本的序列提取等操作,随着作者的不断完善,现在已经是一个小有名气的多功能生信软件,兼具绘图等功能,各类教程可以看作者发布的使用说明。
- 在线云平台
以联川生物的云平台为例,https://www.omicstudio.cn/tool/77,可以参看微信公众号推文使用说明,免费在线小工具:fasta序列提取
只要思想不滑坡,办法总比困难多。
-
Chen C , Chen H , Y Zhang, et al. TBtools: An Integrative Toolkit Developed for Interactive Analyses of Big Biological Data[J]. Molecular Plant, 2020, 13(8). ↩
网友评论