[Bioperl-l] Bio::DB::Fasta problem

Jason Stajich jason.stajich at gmail.com
Tue Dec 7 20:55:38 UTC 2010


use strict at the top of your script would have also helped catch this.


> Scott Cain December 7, 2010 12:08 PM:
>
> Hi Maxim,
>
> I think you have a scope problem.  If you declare the variable $db
> inside of the if block, it ceases to exist when exiting the block.
> Put the "my $db;" before the if block so that it will continue to
> exist.
>
> Scott
>
>
> On Tue, Dec 7, 2010 at 3:00 PM, Maxim<deeepersound at googlemail.com>  wrote:
>> Hi,
>>
>> I'm using Bio::DB::Fasta to retrieve sequences. This works like a charm
>> (super fast!!!), for example like in the script below, where bed-files are
>> taken as input.
>>
>> My problem: as soon as the initialization of the fasta directory index is
>> called from within an if-statement, I get an error like:
>>
>> Can't call method "get_Seq_by_id" on an undefined value at
>> extract_bed_bio_db_fasta_test.pl line 20,<INP>  line 134.
>>
>>
>> The script is as simple as this, the error comes up when I use the full
>> script (including the 2 out-commented lines):
>>
>> use Bio::Perl;
>> use Bio::DB::Fasta;
>>
>> $bedFileName=@ARGV[0];
>> $genome = @ARGV[1];
>> #if ($genome eq "mm9") {
>> my $db      = Bio::DB::Fasta->new('/Users/Computing/BIODBFASTA/mm9_masked');
>> #}
>>
>> open (INP, "$bedFileName");
>> foreach (<INP>)
>> {
>> @words = split /\s+/, $_; ### 0-chr 1-start 2-end
>> $chr = @words[0];$chr =~s/\s+//g;
>> $start = @words[1];$start =~s/\s+//g;
>> $end = @words[2];$end =~s/\s+//g;
>>    $fast_name = $chr . "_" . $start . "_" . $end;
>> my $obj     = $db->get_Seq_by_id($chr);
>> $subseq  = $obj->subseq($start =>  $end);
>> print ">", "$fast_name\n";
>> print "$subseq\n";
>> }
>>
>> What is the problem when initializing from within the if-statement?
>>
>> I really appreciate all kind of advice, I guess the reason is rather simple,
>> but I do not get it.
>> Regards
>> Maxim
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>
>
>
>
> ------------------------------------------------------------------------
>
> Maxim December 7, 2010 12:00 PM:
>
> Hi,
>
> I'm using Bio::DB::Fasta to retrieve sequences. This works like a charm
> (super fast!!!), for example like in the script below, where bed-files are
> taken as input.
>
> My problem: as soon as the initialization of the fasta directory index is
> called from within an if-statement, I get an error like:
>
> Can't call method "get_Seq_by_id" on an undefined value at
> extract_bed_bio_db_fasta_test.pl line 20,<INP>  line 134.
>
>
> The script is as simple as this, the error comes up when I use the full
> script (including the 2 out-commented lines):
>
> use Bio::Perl;
> use Bio::DB::Fasta;
>
> $bedFileName=@ARGV[0];
> $genome = @ARGV[1];
> #if ($genome eq "mm9") {
> my $db      = Bio::DB::Fasta->new('/Users/Computing/BIODBFASTA/mm9_masked');
> #}
>
> open (INP, "$bedFileName");
> foreach (<INP>)
> {
> @words = split /\s+/, $_; ### 0-chr 1-start 2-end
> $chr = @words[0];$chr =~s/\s+//g;
> $start = @words[1];$start =~s/\s+//g;
> $end = @words[2];$end =~s/\s+//g;
>     $fast_name = $chr . "_" . $start . "_" . $end;
> my $obj     = $db->get_Seq_by_id($chr);
> $subseq  = $obj->subseq($start =>  $end);
> print ">", "$fast_name\n";
> print "$subseq\n";
> }
>
> What is the problem when initializing from within the if-statement?
>
> I really appreciate all kind of advice, I guess the reason is rather simple,
> but I do not get it.
> Regards
> Maxim
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l

-- 
Jason Stajich





More information about the Bioperl-l mailing list