BioPerl Tutorial: Reading sequence from FASTA file with BioPerl SeqIO (Bio::SeqIO) module

bioperl tutorialIn last article of this BioPerl Tutorial series, I showed how to write sequence information into FASTA file. In this article, we will see how to read sequence from FASTA files using Bio::SeqIO module.

 

NOTE: To install BioPerl or for knowing about coding in BioPerl, BioPerl modules see index of this BioPerl Tutorial series.

 

Reading Information using Bio::SeqIO module

To read the file, we need to create an object. We will be reading content from file we created in previous article, example.fasta

The syntax is as following:

$objr_seqio= Bio::SeqIO->new(-file=> "example.fasta",-format=>"fasta");

The only difference between reading and writing sequences is > character. If you remember, > character denoted writing the sequence information to a file.

 Retrieving Information with next_seq() method:

Now as we have read information from the file, we need to store it to seq object.
The code will be:

$obj_seq = $objr_seqio->next_seq;

Next_seq() method will parse the sequences in the file sequentially, starting with first sequence in case you have just opened file.

$obj_seq object created is the same sequence objects we creating in our first program and holds the information about the sequence.

 Printing the sequence:

Once we have got access of a sequence, we need to either use if further or print it. We will be printing the sequence using print command (same as first program).

The syntax will be:

print $obj_seq->seq:

The complete code will be:

use Bio::SeqIO;
$objr_seqio= Bio::SeqIO->new(-file=> "example.fasta",-format=>"fasta");
$obj_seq = $objr_seqio->next_seq;
print $obj_seq->seq;

The screenshot for code will be:

 seq seqio 1

The output will be the sequence getting printed:

 bioperl programming 2

I hope you enjoying this BioPerl Tutorial too. In case, you have some difficult regarding BioPerl modules, feel free to post comments or write to me.

In next article, we will be querying GenBank database to retrieve sequences.

About Brij

Bhrat Brij is a SEO expert, Internet Marketer, Affiliate Marketer and Bioinformatician. My short bio or have a look on my Google Profile

Speak Your Mind

*