Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Reading in Qual File Using Bio::SeqIO

by biohisham (Priest)
on Jul 01, 2010 at 22:13 UTC ( #847642=note: print w/replies, xml ) Need Help??

in reply to Reading in Qual File Using Bio::SeqIO

This qual format is similar to FastA but it has its own module interfaces at 'Bio::Seq::PrimaryQual' and Bio::SeqIO::qual, you are mixing between Bio::SeqIO and the others since Bio::SeqIO is the general wrapper for many other packages that intelligently handle many different formats each having their own peculiarities. It is still flexibly possible to interchange methods under such a generalized wrapper btw with some significant differences (read 'potential for things to go wrong!')...

However BioPerl can gift you valuable hints were you adhering to and observing the mantra of:

use strict; use warnings;
at the top of your program and declaring your variable accordingly, this can save you needless tail-chasing.

$qual_obj->seq is better written as $qual_obj->qual
use strict; use warnings; use Bio::SeqIO::qual; my $file = "Qual.txt"; my $qual_obj = Bio::SeqIO::qual->new(-file =>"<$file",-format=>'qual', +); my %qual_hash ; while(my $qual = $qual_obj->_next_qual){ $qual_hash{$qual->id}= $qual->qual(); } use Data::Dumper; print Dumper(\%qual_hash);
The above code's $qual_obj can still be initialized directly through Bio::SeqIO:
use strict; use warnings; use Bio::SeqIO; my $file = "Qual.txt"; my $qual_obj = Bio::SeqIO->new(-file =>"<$file",-format=>'qual',);

You can also read this file in as a FastA file since it has the '>' record identifier, however, each qual record would not be indexed in an array as is the case in the above example since reading the file as a FastA would slurp in all qual values into a single string that is treated as a protein sequence by BioPerl.

#THIS DOESN'T READ THE FILE RIGHT.. my $file = "Qual.txt"; my $qual_obj = Bio::SeqIO->new(-file =>"<$file",-format=>'fasta',); my %seq_hash = (); while(my $seq= $qual_obj->next_seq){ $seq_hash{$seq->id} = $seq->seq; } use Data::Dumper; print Dumper(\%seq_hash);
Kudos for providing examples of code and input :)...

Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

Replies are listed 'Best First'.
Re^2: Reading in Qual File Using Bio::SeqIO
by twaddlac (Novice) on Jul 02, 2010 at 18:43 UTC
    Thank you very much @biohisham!! Reading in the qual like a fasta works like a charm!! :-)
Re^2: Reading in Qual File Using Bio::SeqIO
by twaddlac (Novice) on Jul 06, 2010 at 19:09 UTC

    Well I have unfortunately encountered another error. I read the qual file in like a fastA file and put it into a hash and I can't write it like a qual file for some reason.. is there some sort of parsing that I have to do that the BioPerl modules won't do for me?

    --------------------- WARNING --------------------- MSG: seq doesn't validate, mismatch is 4040404040404040404040404040404 +040404040404040404040404040404040404040393737373737373737373737373737 +373737373535353535353030302828283030323235373737373737373737373737373 +737373737373737373737373737373535353737343232323232323230161515152427 +2626131313232313131317212121212119211618171918 --------------------------------------------------- ------------- EXCEPTION: Bio::Root::Exception ------------- MSG: Attempting to set the sequence to [404040404040404040404040404040 +404040404040404040404040404040404040404039373737373737373737373737373 +737373737353535353535303030282828303032323537373737373737373737373737 +373737373737373737373737373737353535373734323232323232323016151515242 +72626131313232313131317212121212119211618171918] which does not look +healthy STACK: Error::throw STACK: Bio::Root::Root::throw /usr/lib/perl5/site_perl/5.8.8/Bio/Root/ STACK: Bio::PrimarySeq::seq /usr/lib/perl5/site_perl/5.8.8/Bio/Primary STACK: Bio::PrimarySeq::new /usr/lib/perl5/site_perl/5.8.8/Bio/Primary STACK: Bio::Seq::new /usr/lib/perl5/site_perl/5.8.8/Bio/ STACK:

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://847642]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-02-21 07:50 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (308 votes). Check out past polls.