in reply to Re: Get Fasta file with Protein Sequences given a file with Genbank Ids using Perl
in thread Get Fasta file with Protein Sequences given a file with Genbank Ids using Perl

hello 1nickt and kevbot,

I'm trying this code:
use strict; use warnings; use Bio::DB::GenBank; use File::Slurp; my @lines = read_file('sec.txt'); chomp @lines; print "@lines\n"; foreach my $id (@lines) { my $gb=Bio::DB::GenBank; my $seq = $gb->get_Seq_by_id($id); write_sequence( ">>roar.fa", 'fasta', $seq ); }
Everything seem logic but I get this Error: Bareword "Bio::DB::GenBank" not allowed while "strict subs" in use at .... line 15.

I have absolutely no idea how to fix it ....

Replies are listed 'Best First'.
Re^3: Get Fasta file with Protein Sequences given a file with Genbank Ids using Perl
by AnomalousMonk (Archbishop) on Mar 21, 2016 at 05:20 UTC

    Line 15 of the code
        my $gb=Bio::DB::GenBank;
    should be
        my $gb = new Bio::DB::GenBank;
    (indirect object notation), or better yet
        my $gb = Bio::DB::GenBank->new;
    or
        my $gb = Bio::DB::GenBank->new();
    which avoid the syntactic ambiguities of indirect object notation.


    Give a man a fish:  <%-{-{-{-<

      thanks! but after fixing that I get this: Undefined subroutine &main::write_sequence called at .... line 20.

        Do you have a sub called write_sequence in your main package? No. So you can't call it!

        Perhaps your object has a method of that name?

        Edit: Find where you copy-pasted write_sequence from and refer to the docs for that module. You'll need to use the module in your program. I leave it to you to figure out which module it is. Hint: it's not ... LOL, just saw you figured it out. Nice!


        The way forward always starts with a minimal test.
        You have not written a subroutine for write_sequence and the Bio::DB::Genbank module does not provide this method. It's likely that you want to add this to your code:
        use Bio::Perl;
        as the Bio::Perl module does provide a write_sequence method. I recommend that you carefully read the documentation for Bio::DB::Genbank and Bio::Perl.

        I haven't read the Bio::DB::GenBank documentation (please feel free to do so ;-), but I suspect that write_sequence is a method of that class and so maybe needs to be called something like
            $gb->write_sequence( ">>roar.fa", 'fasta', $seq );


        Give a man a fish:  <%-{-{-{-<

Re^3: Get Fasta file with Protein Sequences given a file with Genbank Ids using Perl
by 1nickt (Canon) on Mar 21, 2016 at 05:27 UTC

    Sure you do.

    If something stops working, go back and look at what worked. Your OP had:

    my $gb=new Bio::DB::GenBank;
    Now this is actually deprecated syntax and should be written as:
    my $gb = Bio::DB::GenBank->new();
    ... but either style shows the point: you need to call the new() method to get an instance of the class Bio::DB::GenBank, aka, an object, and store it in $gb. Your existing code just assigns the bareword 'Bio::DB::GenBank' to $gb -- or tries to, but barewords are not allowed in your script because you're sensibly using strict. This is a great example of why to use strict: it tells you exactly what the problem is and where to find it.

    Also, don't use File::Slurp, it's broken. Use File::Slurper or Path::Tiny.

    Hope this helps!


    The way forward always starts with a minimal test.
Re^3: Get Fasta file with Protein Sequences given a file with Genbank Ids using Perl
by kevbot (Vicar) on Mar 21, 2016 at 05:26 UTC
    Change this:
    my $gb=Bio::DB::GenBank;
    to this:
    my $gb = new Bio::DB::GenBank;
    and see if that gets things working for you.