Biotech > FAQ > BioPerl FAQ (Frequently Asked Questions)

I would like to make my own custom fasta header ...

To see other biotech frequently asked questions, please visit http://biotech.fyicenter.com/faq/

(Continued from previous question...)

I would like to make my own custom fasta header - how do I do this?

You want to use the method preferred_id_type(). Here's some example code:

use Bio::SeqIO;
 
my $seqin = Bio::SeqIO->new(-file => $file,
                            -format => 'genbank');
 
my $seqout = Bio::SeqIO->new(-fh => \*STDOUT,
                            -format => 'fasta');
 
# From Bio::SeqIO::fasta
$seqout->preferred_id_type('display');
 
my $count = 1;
 
while (my $seq = $seqin->next_seq) {
    # override the regular display_id with your own
    $seq->display_id('foo'.$count);
    $seqout->write_seq($seq);
    $count++;
}

You can pass one of the following values to preferred_id_type: "accession", "accession.version", "display", "primary". The description line is automatically appended to the preferred id type but this can also be set, like so:

$seq->desc($some_string);

(Continued on next question...)

Other Frequently Asked Questions