Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report