This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can I Get An All Uppercase Dna Sequence From Bio::Seq Without Uc?

I've got a lot of perl code that expects DNA sequences to be uppercase strings. I want to use Bio::SeqIO for reading them in, but Bio::Seq method seq() returns a lowercase string. uc doesn't really take all that long, but it would be nice if I didn't have to use it since I'm reading in whole chromosomes here.

perl bioperl

2 answers

It retains the case that went in:

e.g

keith@tao:~$ cat convert.pl

#!/usr/bin/perl

use strict;
use warnings;

use Bio::SeqIO;

my $iformat = shift;
my $oformat = shift;

$iformat ||= 'fasta';
$oformat ||= 'fasta';

my $seqi = Bio::SeqIO->new(-fh     => \*STDIN,
                           -format => $iformat);
my $seqo = Bio::SeqIO->new(-fh     => \*STDOUT,
                           -format => $oformat);

while (my $seq = $seqi->next_seq) {
    $seqo->write_seq($seq);
}

keith@tao:~$ cat foo.fasta 
>foo
AGTCGACGTAGTCACGTGTCA

keith@tao:~$ convert.pl < foo.fasta
>foo
AGTCGACGTAGTCACGTGTCA

keith@tao:~$ cat bar.fasta 
>bar
agtcgacgtagtcacgtgtca

keith@tao:~$ converter.pl < bar.fasta
>bar
agtcgacgtagtcacgtgtca

The design principle of Bio::Seq objects is that the case of the sequence should not matter. If it does, you have to code it yourself.

Log in to answer this question.