從fasta文件中批量提取特定序列

如題,目的是從fasta文件中批量提取特定的基因序列.
實現(xiàn)辦法有幾種:

  1. perl腳本:
    CSDN博主「little^raccoon」的原創(chuàng)文章perl實現(xiàn)根據(jù)序列ID從提取fasta文件序列
    原文鏈接:https://blog.csdn.net/weixin_40099163/article/details/109635328

    usage: 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";
        }
    }
}
  1. python
    采用click模塊添加命令行參數(shù)。**
    CSDN博主「冷月、無聲」的原創(chuàng)文章:根據(jù)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()
  1. TBtool software[1]
    這個小工具誕生之初就是為了解決最基本的序列提取等操作,隨著作者的不斷完善,現(xiàn)在已經(jīng)是一個小有名氣的多功能生信軟件,兼具繪圖等功能,各類教程可以看作者發(fā)布的使用說明。
  1. 在線云平臺
    以聯(lián)川生物的云平臺為例,https://www.omicstudio.cn/tool/77,可以參看微信公眾號推文使用說明,免費在線小工具:fasta序列提取

只要思想不滑坡,辦法總比困難多。


  1. 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). ?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容