如題愤炸,目的是從fasta文件中批量提取特定的基因序列.
實現辦法有幾種:
- perl腳本:
CSDN博主「little^raccoon」的原創(chuàng)文章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博主「冷月状答、無聲」的原創(chuàng)文章:根據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]
這個小工具誕生之初就是為了解決最基本的序列提取等操作,隨著作者的不斷完善根悼,現在已經是一個小有名氣的多功能生信軟件彤叉,兼具繪圖等功能,各類教程可以看作者發(fā)布的使用說明棉胀。
- 在線云平臺
以聯川生物的云平臺為例,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). ?