Get the App
SLTechnology News&Howtos  ›  Development  › 

How to extract the fasta sequence of a specified gene by perl

Shulou Source: shulou.com Published: 2022-06-01 12:59:46 09月18日 Update

The editor will share with you how perl extracts the fasta sequence of a specified gene. I hope you will get something after reading this article. Let's discuss it together.

Easy to use perl script for sequence extraction

Here, introduce a very easy to use sequence extraction perl script, the use is very simple.

The usage is as follows:

Perl / share/work/huangls/piplines/01.script/get_fa_by_id.pl

For example:

Perl / share/work/huangls/piplines/01.script/get_fa_by_id.pl id.txt input.fasta out.fa

Where id.txt is the sequence to be extracted ID,input.fasta is the input sequence file and out.fa is the output sequence file.

The id.txt format is as follows:

TRINITY_DN116733_c6_g37TRINITY_DN116733_c6_g70TRINITY_DN95808_c0_g7TRINITY_DN104586_c1_g2TRINITY_DN108413_c2_g23TRINITY_DN37223_c0_g1TRINITY_DN107955_c0_g8TRINITY_DN117047_c0_g2TRINITY_DN78058_c0_g1

Here is the script code:

Die "perl $0" unless (@ ARGV==3); use Math::BigFloat;use Bio::SeqIO;use Bio::Seq;$in = Bio::SeqIO- > new (- file = > "$ARGV [1]",-format = > 'Fasta'); $out = Bio::SeqIO- > new (- file = > "> $ARGV [2]",-format = >' Fasta'); my%keep;open IN, "$ARGV [0]" or die "$!"; while () {chomp;next if / ^ # /; # next unless / > > / My@tmp=split (/\ tmp /); $keep {$tmp [0]} = 1;} close (IN); my$i=0;while (my$ seq = $in- > next_seq ()) {my ($id,$sequence,$desc) = ($seq- > id,$seq- > seq,$seq- > desc); if (exists $keep {$id}) {$out- > write_seq ($seq);} $in- > close (); $out- > close ()

The script uses the Bio::SeqIO module to process the sequence file, which is concise and efficient. First, it uses hash to store the sequence ID to be extracted, and then uses Bio::SeqIO to traverse the sequence file to determine whether each sequence is the sequence to be extracted. If so, output.

After reading this article, I believe you have a certain understanding of "how to extract the fasta sequence of a specified gene from perl". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Sequences documents scripts genes simplicity articles easy to use output simplicity code done yes more formats modules knowledge industry information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi Shulou Tech Info Redmi Huawei