-1

I am trying to download the sequence file from the gene bank database using perl but it shows error. I don't have any guide to correct my program.

Can any one help me with this? The error is in line 6 (use Bio::DB::GenBank;)

File accnumber.txt is on my desktop and I am running the program from desktop itself. I am using CentOS.

#!usr/bin/perl -w

use strict;
use warnings;

use Bio::DB::GenBank;

open (INPUT_FILE, 'accnumber.txt');
open (OUTPUT_FILE, 'sequence_dwnl.fa');

while()
{
    chomp;
    my $line = $_;
    my @acc_no = split(",", $line);
    my $counter = 0;

    while ($acc_no[$counter])
    {
        $acc_no[$counter] =~ s/\s//g;

        if ($acc_no[$counter] =~ /^$/)
        {
            exit;
        }

        my $db_obj = Bio::DB::GenBank->new;
        my $seq_obj = $db_obj->get_Seq_by_acc($acc_no[$counter]);
        my $sequence1 = $seq_obj->seq;

        print OUTPUT_FILE ">"."$acc_no[$counter]","\n";
        print OUTPUT_FILE $sequence1,"\n";
        print "Sequence Downloaded:", "\t", $acc_no[$counter], "\n";

        $counter++;
    }
}

close OUTPUT_FILE;
close INPUT_FILE;

These are errors I get:

Bareword "Bio::DB::GenBank" not allowed while "strict subs" in use at db.pl line 6.
Bareword "new" not allowed while "strict subs" in use at db.pl line 27.
Bareword "seq" not allowed while "strict subs" in use at db.pl line 29.
Execution of db.pl aborted due to compilation errors.
Toto
  • 89,455
  • 62
  • 89
  • 125
  • `open (OUTPUT_FILE, 'sequence_dwnl.fa');` should be `open (OUTPUT_FILE, '>', 'sequence_dwnl.fa');` , but that doesn't seem related to the problem you're defining. – kjprice Mar 27 '13 at 17:29
  • 3
    Also, what is the error you're getting? – kjprice Mar 27 '13 at 17:30
  • 2
    Your first line should be: `#!/usr/bin/perl -w` – imran Mar 27 '13 at 17:41
  • Your first line should be `#!/usr/bin/perl -w` Also you have `>` all over your script. Replace that with '>' Let us know what other errors you see when you run the script. – imran Mar 27 '13 at 17:54
  • 1
    `use warnings;` is generally encouraged over `-w` these days. http://stackoverflow.com/questions/221919/should-i-turn-on-perl-warnings-with-the-command-line-switch-or-pragma – Jim Davis Mar 27 '13 at 20:49
  • I actually tried to install `Bio::Perl` module and debug the script for you, but even after fixing things that have been mentioned here, the script still has serious issues. For example, it will run in an infinite loop without producing any meaningful output. That said, since you still get the "bareword" errors, I'm suspicious that you haven't fixed the `>` issues. And the fact that you get them on line 6 makes me suspicious that you are actually running the **same** code as above. – Alois Mahdal Mar 30 '13 at 12:06
  • To sum up, please **do** cooperate with us and apply fixes mentioned here. And **if** the **original** issue persists, update the question with new version of code. Also reply to the suggestions so that we know you tried it and whether it helped or not. Otherwise we can't help you since most of us do not have crystal balls. This way you are only frustrating those who want to help you, earning downvotes and risking that the question will be closed. – Alois Mahdal Mar 30 '13 at 12:16

2 Answers2

1

Since line you mention loads external Perl module Bio::DB::GenBank from CPAN, first thing that came to my mind: Is the module installed on your system?

Try running command cpan Bio::DB::GenBank as root (e.g. by prepending it with sudo). This should not hurt even if the module is installed, in that case it will check CPAN for updates.

Alois Mahdal
  • 10,763
  • 7
  • 51
  • 69
  • i'm getting this error while i change my script "Bareword "Bio::DB::GenBank" not allowed while "strict subs" in use at db.pl line 6. Bareword "new" not allowed while "strict subs" in use at db.pl line 27. Bareword "seq" not allowed while "strict subs" in use at db.pl line 29. Execution of db.pl aborted due to compilation errors." – Manoj kumar K Mar 28 '13 at 02:33
  • @ManojkumarK Alois fixed up your code in the original post. Use that and try again. On a side note, I don't think it is right to fix the code in the original post, that is what answers are supposed to do. – imran Mar 28 '13 at 14:27
  • @imran I was thinking about that, but as long as you fix only code that is obviously not part of the question, I guess it should be OK. OTOH I don't find it very helpful if everybody starts to "answer" problems that are caused only by bad markup... – Alois Mahdal Mar 29 '13 at 07:50
  • @ManojkumarK sounds strange so far. Please make sure you use the last version of the code, line 27 does not have keyword "new" in that. Also make sure you fix the "#!" line as suggested (I cannot do that in the OP due to 6 char limit) – Alois Mahdal Mar 29 '13 at 07:55
  • @AloisMahdal The errors he is getting about bareword new and bareword seq are directly related to the `>` issue. – imran Mar 29 '13 at 13:56
  • @imran It seems you're right, reverting the code part. I thought that was result of translation to MD and back but should have thought twice... :) It's still confusing that the first error is reported at line 6, though. – Alois Mahdal Mar 29 '13 at 15:21
  • @AloisMahdal yes, the error for line 6 is odd. I would like to see what error he gets with the updated code. – imran Mar 29 '13 at 17:00
  • Bareword "Bio::DB::GenBank" not allowed while "strict subs" in use at db.pl line 6. Bareword "new" not allowed while "strict subs" in use at db.pl line 27. Bareword "seq" not allowed while "strict subs" in use at db.pl line 29. Execution of db.pl aborted due to compilation errors. this is my error – Manoj kumar K Mar 30 '13 at 04:17
  • @ManojkumarK you did replace the `>` with `>`? what editor are you using to edit the script? If you did make this change, I feel your editor is implicitly converting the script to be HTML friendly. – imran Apr 01 '13 at 04:41
-2

In addition to the above answer,

Please use die function to check whether the files are opened.

open (INPUT_FILE, 'accnumber.txt');
open (OUTPUT_FILE, 'sequence_dwnl.fa');

Like this:

open (my $input_file, '<', 'accnumber.txt') or die "Could not open because $!\n";
open (my $output_file, '<', 'sequence_dwnl.fa') or die "Could not open because $!\n";

Also, please specify the purpose of opening each file with these operators:

  1. < to open file in read only mode.
  2. > to overwrite the file content.
  3. >> to append the file content.

Also please check whether you have Bio::DB::GenBank module installed or not.

You can do that by running this in command line:

perldoc -l Bio::DB::GenBank or perl -MBio::DB::GenBank -e 1

Joel Berger
  • 20,180
  • 5
  • 49
  • 104
Krishnachandra Sharma
  • 1,332
  • 2
  • 20
  • 42
  • Krishnachandra, you have been here long enough, and I have voted on you enough times. Please start using a modern Perl style. We are tying to remove examples of bareword handles and two arg opens, not add them! `open (my $input_handle, '<', 'accnumber.txt') or die "Could not open because $!\n";` – Joel Berger Mar 27 '13 at 21:18