[Bioperl-l] Newbie question on Bio::SeqIO

James Platt plattj at Cardiff.ac.uk
Thu Jan 27 17:06:20 UTC 2011


Thanks Roy,

I am definitely a newbie to bioperl. 

James


On 27 Jan 2011, at 13:20, Roy Chaudhuri wrote:

> Hi James,
> 
> It's important to not confuse sequence objects with sequence strings. If you try to print out a sequence object, you will get something like Bio::PrimarySeq=HASH(0x9c8e20). But you can call methods like revcom on sequence objects - if you try to do that with a sequence string you get an error.
> 
> The subseq method:
> $seq_obj->subseq(160,180)
> returns a plain text string of the sequence. If you want a sequence object that you can call additional methods on, you need to use a different method, called trunc, which returns a sequence object:
> $seq_obj->trunc(160,180)
> 
> To get a sequence string from a sequence object, use the seq method:
> $seq_obj->seq
> 
> So to get the reverse complement of your subsequence as a string you would do:
> my $trunc=$seq_obj->trunc(160,180);
> my $revcom=$trunc->revcom;
> my $rev_output=$revcom->seq;
> 
> Or you can combine them all into one line:
> my $rev_output=$seq_obj->trunc(160,180)->revcom->seq;
> 
> Hope this helps.
> Roy.
> 
> On 27/01/2011 13:02, James Platt wrote:
>> I tried this already I got a different error:
>> 
>> Unrecognized character \xE2 in column 21 at ./biotester.pl line 18.
>> 
>> I then copied your script in and it worked, then I had my script and
>> that identical and mine still didn't work. Not sure why it was
>> happening.
>> 
>> So I  have my sequence now and I'm trying to reverese complement it:
>> 
>> $output1 = $seq_obj->subseq(160,180); print "$output1\n";
>> $rev_output1 = revcom( $output1 ); print "$rev_output1\n";
>> 
>> I get this output:
>> 
>> ATTATAAAAAACTTTTAATTT Bio::PrimarySeq=HASH(0x9c8e20)
>> 
>> I also try it in an object orientated manner:
>> 
>> $rev_output1 = $output1->revcom;
>> 
>> ATTATAAAAAACTTTTAATTT Can't locate object method "revcom" via package
>> "ATTATAAAAAACTTTTAATTT" (perhaps you forgot to load
>> "ATTATAAAAAACTTTTAATTT"?) at biotester.pl line 24,<GEN0>  line 1.
>> 
>> I've been following instructions at
>> http://www.bioperl.org/wiki/HOWTO:Beginners
>> 
>> Thanks again!
>> 
>> James
>> 
>> 
>> On 26 Jan 2011, at 22:15, Yifei Huang wrote:
>> 
>>> subseq is not a member function in SeqIO class. You need to use
>>> next_seq function in SeqIO class to read a sequence and then fetch
>>> a subsequence, which might be something like this.
>>> 
>>> 
>>> #!/usr/bin/perl use Bio::Perl; use Bio::SeqIO;
>>> 
>>> 
>>> my $seqio_obj = Bio::SeqIO->new(-file =>  "dna.fa", -format =>
>>> 'Fasta'); my $seq_obj = $seqio_obj->next_seq(); my $output =
>>> $seq_obj->subseq(1,20); print "$output\n";
>>> 
>>> On Wed, Jan 26, 2011 at 5:05 PM, JayPea<plattj at cardiff.ac.uk>
>>> wrote:
>>> 
>>> Hi all.
>>> 
>>> I recently installed bioperl on my mac (OSX 10.6.6) using fink. And
>>> have been playing around trying to get some really simple things to
>>> work. SO what I'm trying to do is just grab 20bases of the fasta
>>> file then print them out.
>>> 
>>> This is my script:
>>> 
>>> #!/usr/bin/perl use Bio::Perl; use Bio::SeqIO;
>>> 
>>> 
>>> my $seqio_obj = Bio::SeqIO->new(-file =>  "dna.fa", -format =>
>>> 'Fasta'); my $output = $seqio_obj->subseq(1,20); print
>>> "$output\n";
>>> 
>>> fasta file:
>>> 
>>>> chr1 D_discoideum_Ax4_May_2005 4923596 bp DDB0232428
>>> NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
>>> NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNTATAGTTACTATTGTAAATC
>>> GATAGATAACTTAATTTCATTAATATTATACATAGTAACATTATAAAAAACTTTTAATTT
>>> TTATTTGGGAATTTCAAATTGCTCATTTGGGAAAATTTTTAACTAAGAAAAAATTCAAAA
>>> 
>>> I get this error:
>>> 
>>> Can't locate object method "subseq" via package "Bio::SeqIO::fasta"
>>> at ./biotester.pl line 16.
>>> 
>>> Thanks for any help!
>>> 
>>> James -- View this message in context:
>>> http://old.nabble.com/Newbie-question-on-Bio%3A%3ASeqIO-tp30768204p30768204.html
>>> 
>>> 
> Sent from the Perl - Bioperl-L mailing list archive at Nabble.com.
>>> 
>>> _______________________________________________ Bioperl-l mailing
>>> list Bioperl-l at lists.open-bio.org
>>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>> 
>>> 
>>> 
>>> -- Yifei Huang Department of Biology McMaster University
>> 
>> 
>> _______________________________________________ Bioperl-l mailing
>> list Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
> 





More information about the Bioperl-l mailing list