我Bioperl
用来寻找GOterms
基因。我检索一个html
文件,将其转换为文本,去掉所有多余的空格和换行符,并尝试遍历生成的数组。
但是,我不断收到访问数组中未初始化值的错误。我进行了许多检查以确保数组不为空并且我不会越界。我怎样才能摆脱这个错误?
我以更易读的格式重新发布了代码。谢谢您的帮助。
它似乎成功地从 html 中解析出正确的数据,所以我不知道出了什么问题。
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use HTML::TreeBuilder;
use HTML::FormatText;
my $URL = get("http://amigo.geneontology.org/amigo/term/GO:0000001");
my $Format = HTML::FormatText->new;
my $TreeBuilder = HTML::TreeBuilder->new;
$TreeBuilder->parse($URL);
my $Parsed = $Format->format($TreeBuilder);
print "$Parsed";
my @parsed = split( /[ ]{2,}|(\n+)|(\r+)/, $Parsed );
if ( @parsed == 1 ) { return; }
my %termhash;
my $count = 0;
while ( $count < @parsed ) {
if ( defined $parsed[$count] && $parsed[$count] eq 'Name' ) {
my $count2 = $count;
while ( ( $parsed[$count2] ne 'Feedback' ) && ( $count2 < @parsed ) ) {
$count2++;
}
$count2--;
@parsed = @parsed[ $count .. $count2 ]; # Gets the slice of the array needed
last;
}
$count++;
}
if ( @parsed <= 1 ) { return; }
print "\n";
print @parsed;
$count = 0;
while ( $count < @parsed ) {
if ( $parsed[$count] eq 'Name' ) {
while ( $parsed[$count] ne 'Ontology' && ( $count < @parsed )) {
$termhash{'Name'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'Ontology' ) {
while ( $parsed[$count] ne 'Synonyms' && ( $count < @parsed )) {
$termhash{'Category'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'Synonyms' ) {
while ( $parsed[$count] ne 'Definition' && ( $count < @parsed )) {
$termhash{'Aliases'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'Definition' ) {
while ( $parsed[$count] ne 'Comment' && ( $count < @parsed )) {
$termhash{'Definition'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'Comment' ) {
while ( $parsed[$count] ne 'History' && ( $count < @parsed )) {
$termhash{'Comment'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'History' ) {
while ( $parsed[$count] ne 'Subset' && ( $count < @parsed )) {
$termhash{'Version'} .= $parsed[$count];
$count++;
}
}
if ( $parsed[$count] eq 'Subset' ) {
while ( ( $parsed[$count] ne 'Community' ) && ( $count < @parsed ) ) {
$count++;
}
}
if ( $parsed[$count] eq 'Community' ) {
while ( ( $parsed[$count] ne 'Related' ) && ( $count < @parsed ) ) {
$count++;
}
}
if ( $parsed[$count] eq 'Related' ) {
for ( $count < @parsed ) {
$termhash{'Definition references'} .= $parsed[$count];
$count++;
}
}
}
if ( $termhash{'Definition'} =~ m/OBSOLETE/ ) { $termhash{'Is obsolete'} = 1 }
else { $termhash{'Is obsolete'} = 0 }
#print %termhash;
主要的错误信息是:
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 23 行的字符串 ne 中使用未初始化的值 $parsed[127]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 35 行的打印中使用未初始化的值 $parsed[1]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 42 行的字符串 ne 中使用未初始化的值 $parsed[1]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 41 行的连接 (.) 或字符串中使用未初始化的值 $parsed[1]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 48 行的字符串 ne 中使用未初始化的值 $parsed[17]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 47 行的连接 (.) 或字符串中使用未初始化的值 $parsed[17]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 54 行的字符串 ne 中使用未初始化的值 $parsed[29]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 53 行的连接 (.) 或字符串中使用未初始化的值 $parsed[29]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 60 行的字符串 ne 中使用未初始化的值 $parsed[41]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 59 行的连接 (.) 或字符串中使用未初始化的值 $parsed[41]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 66 行的字符串 ne 中使用未初始化的值 $parsed[79]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 65 行的连接 (.) 或字符串中使用未初始化的值 $parsed[79]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 72 行的字符串 ne 中使用未初始化的值 $parsed[83]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 71 行的连接 (.) 或字符串中使用未初始化的值 $parsed[83]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 77 行的字符串 ne 中使用未初始化的值 $parsed[95]。
在 /home/adur/workspace/BI7643/ParseGOhtml.pl 第 82 行的字符串 ne 中使用未初始化的值 $parsed[107]。