BioPerl Tutorial: Writing sequence to FASTA file with BioPerl SeqIO (Bio::SeqIO) module

bioperl tutorialContinuing 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");

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.

bioseqio module 2

After executing you will see a file named example.fasta being created, holding the information of obj_seq object.

bioperl programming 3

I will be showcasing how to read sequence with BioPerl modules in next article. Hope you could use Bio::SeqIO module easily now.

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


  1. […] 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 […]

Speak Your Mind