生物::D B::Fasta,无法在 script.pl 行的未定义值上调用方法 "index_file"



我想在perl中重新加载一个预索引文件,该文件以前已被索引如下:

./first_script.pl hg19.fa
use Bio::DB::Fasta;
my $db = Bio::DB::Fasta->new($file_fasta);
...

在另一个脚本中,我想重新加载现有的索引文件。

/script.pl hg19.fa.index输入

#!/usr/bin/perl
use warnings;
use strict;
use Bio::DB::Fasta;
my $fasta_index_file = $ARGV[0];
my $input_file = $ARGV[1];
open(FH,"<$input_file");
my $db->index_file($fasta_index_file);

在描述中,它被称为

 Title   : index_file
Usage   : $db->index_file($filename)
Function: (re)loads a sequence file and indexes sequences offsets in the file
Returns : seq offsets in the file
Args    : filename,
           boolean to force reloading a file

但它返回以下错误:

Can't call method "index_file" on an undefined value at script.pl line

在第二个脚本中,如果我再次使用:

my $db = Bio::DB::Fasta->new($file_fasta);

它立即进入下一步!这是否意味着它已经意识到它的存在?

您没有在第二个脚本中的任何位置定义$db

通常情况下,use strict;会揭示这一点,并且应该是您进行故障排除的第一步。

最新更新