Newbie question on Bio::SeqIO

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Newbie question on Bio::SeqIO

JayPea
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
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

Joshua Udall-3
Use this bash command to see which libraries are loading in perl.
Ideally, you would make sure the fink library is represented in the list.
A quick fix would be to simply use a 'lib' statement at the beginning of
your script to source your Bioperl path.

perl -e 'for (@INC) { printf "%d %s\n", $i++, $_}'

Josh



On 1/26/11 3:05 PM, "JayPea" <[hidden email]> 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-tp30768204p3076820
>4.html
>Sent from the Perl - Bioperl-L mailing list archive at Nabble.com.
>
>_______________________________________________
>Bioperl-l mailing list
>[hidden email]
>http://lists.open-bio.org/mailman/listinfo/bioperl-l


_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

Florent Angly
In reply to this post by JayPea
Hi James,
This should get you started: http://www.bioperl.org/wiki/HOWTO:SeqIO
Best,
Florent

On 26/01/11 17:05, JayPea 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

_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

Adam Sjøgren
In reply to this post by JayPea
On Wed, 26 Jan 2011 14:05:08 -0800 (PST), JayPea wrote:

> #!/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);

Try replacing that line by these two:

 my $seq=$seqio_obj->next_seq;
 my $output=$seq->subseq(1,20);

> print "$output\n";

 See "perldoc Bio::SeqIO" :-)


Also: Never forget to start your scripts with "use strict; use
warnings;" - a great way to avoid typos and stuff.


  Best regards,

    Adam

--
 "Här kommer rädslan, gamle vän                               Adam Sjøgren
  När alla fjärilar i magen vaknar upp                   [hidden email]
  Viskar välkommen hem"

_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

Fields, Christopher J
Also, FASTQ parsing only works correctly if you are using BioPerl 1.6.1.  Not sure what version fink currently has.

chris

On Jan 26, 2011, at 4:30 PM, Adam Sjøgren wrote:

> On Wed, 26 Jan 2011 14:05:08 -0800 (PST), JayPea wrote:
>
>> #!/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);
>
> Try replacing that line by these two:
>
> my $seq=$seqio_obj->next_seq;
> my $output=$seq->subseq(1,20);
>
>> print "$output\n";
>
> See "perldoc Bio::SeqIO" :-)
>
>
> Also: Never forget to start your scripts with "use strict; use
> warnings;" - a great way to avoid typos and stuff.
>
>
>  Best regards,
>
>    Adam
>
> --
> "Här kommer rädslan, gamle vän                               Adam Sjøgren
>  När alla fjärilar i magen vaknar upp                   [hidden email]
>  Viskar välkommen hem"
>
> _______________________________________________
> Bioperl-l mailing list
> [hidden email]
> http://lists.open-bio.org/mailman/listinfo/bioperl-l


_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

JayPea
In reply to this post by JayPea
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 <[hidden email]> 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
> [hidden email]
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
>
>
> --
> Yifei Huang
> Department of Biology
> McMaster University


_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

Roy Chaudhuri-3
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<[hidden email]>
>> 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 [hidden email]
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>
>>
>>
>> -- Yifei Huang Department of Biology McMaster University
>
>
> _______________________________________________ Bioperl-l mailing
> list [hidden email]
> http://lists.open-bio.org/mailman/listinfo/bioperl-l

_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on Bio::SeqIO

JayPea
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<[hidden email]>
>>> 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 [hidden email]
>>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>>
>>>
>>>
>>> -- Yifei Huang Department of Biology McMaster University
>>
>>
>> _______________________________________________ Bioperl-l mailing
>> list [hidden email]
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>


_______________________________________________
Bioperl-l mailing list
[hidden email]
http://lists.open-bio.org/mailman/listinfo/bioperl-l