Continuing my BioPerl Tutorial series, in this article we will see how to use BioPerl modules, especially SeqIO module. If you are looking for BioPerl Introduction and Usage, click here; to install BioPerl on Windows you can see this BioPerl tutorial and to write your first BioPerl script, click here.
Bio::SeqIO is most widely used BioPerl module. This is because this module is used for reading and writing sequences from files as well as databases.
About Bio::SeqIO
SeqIO stands for Sequence Input Output. We can read as well as write sequences using Bio::SeqIO module in all BioPerl supported files and databases.
NOTE: BioPerl is case sensitive and ensure to write BioPerl code in same manner.
To learn how to write and execute BioPerl programs, click here.
We will be including this BioPerl module same way as we did for Bio::Seq (Click here to know more about it)
use Bio::SeqIO;
Creating Bio::SeqIO object
Now, we will create a Bio::SeqIO object. The same way we created Bio::Seq object using new().
I will be naming the object as $obj_seqio. To know more about creating objects using BioPerl modules you can view this BioPerl Tutorial.
$obj_seqio = Bio::SeqIO-> new(-file => ">example.fasta",-format => "fasta");
Here –file and –format are arguments. To learn about arguments and syntax of new() click here.
> symbol tells Perl that we will be writing to file called “example”.
–format tells that the format of file to be created is fasta format.
Writing to file using Bio::SeqIO
Now, let’s combine previous and this example where we stored a sequence in Bio::Seq Object.
use Bio::SeqIO;
use Bio::Seq;
$obj_seq = Bio::Seq->new(-seq => "atgcatgc",-desc => "SeqIO example",-display_id => "#888", -alphabet => "dna" );
$obj_seqio = Bio::SeqIO-> new(-file => ">example.fasta",-format => "fasta");
$obj_seqio->write_seq($obj_seq);
In last we are using write_seq() method to write to FASTA file.
The complete BioPerl code will be like this:
Now, you will be running the Perl code on command prompt.
After executing you will see a file named example.fasta being created, holding the information of obj_seq object.
I will be showcasing how to read sequence with BioPerl modules in next article. Hope you could use Bio::SeqIO module easily now.





















