WonkoTheSane has asked for the wisdom of the Perl Monks concerning the following question:
I store the results from the blast search in a file blast.out. After running my script and therby also blasting. This file is not empty, but something is wrong in this file too because only the results from one of the blasted sequences are stored, not all of them as one would have expected.Can't call method "next_hit" on an undefined value at read_blast_stats +.pl line 150, <GEN2> line 253 (#1) (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an undefined value. Som +ething like this will reproduce the error: $BADREF = undef; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "next_hit" on an undefined value at read_blast_s +tats.pl line 150, <GEN2> line 253. at read_blast_stats.pl line 150
# Creates BioPerl input sequence stream. my $in_seq = Bio::SeqIO->new(-file => "<$input_file", -format => $se +q_format ); # Extracting sequences from stream. print("- reading and translating sequences...\n"); my $seq_counter = 0; my $unique_count = 0; my @translated_seqs; while (my $seq = $in_seq->next_seq()) { $seq_counter++; print("-\tsequences read: $seq_counter\r"); my $temp_seq; # Translates sequence and stores the translated sequences if they +do not # contain any stop codons. # Reading frames 1, 2 and 3. $temp_seq = $seq->translate(); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); $temp_seq = $seq->translate(-frame => 1); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); $temp_seq = $seq->translate(-frame => 2); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); # Creates the reverse complement sequence. my $rc_seq = $seq->revcom(); # Reading frames -1, -2, and -3 $temp_seq = $rc_seq->translate(); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); $temp_seq = $rc_seq->translate(-frame => 1); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); $temp_seq = $rc_seq->translate(-frame => 2); $temp_seq->display_id("test_id-$unique_count"); $unique_count++; push(@translated_seqs, $temp_seq) unless ($temp_seq->seq() =~ /\*+ +/); } # Blasting... my @params = (-program => 'blastp', -database => '/share/raid1/databas +e/ftp.ncbi.nih.gov/blast/db/20090602/nr', -expectation => '200000', - +Word => '2', -Matrix => 'PAM30', -Gapcost => '9.1', -FilterString => +'F', _READMETHOD => 'blasttable' , -m => '8', -outfile => 'blast.out' +); my $blaster = Bio::Tools::Run::StandAloneBlast->new(@params); my $blast_report = $blaster->blastall(@translated_seqs); # Parsing results my $result = $blast_report->next_result(); my $hit = $result->next_hit();
# This code is inserted instead of # the Blasting and parsing part of the original code. # Creating blast.in open(OUTPUT_FILE, "> blast.in") or die "Could not create the output fi +le \"blast.in\"\n"; # Writing blast.in sequence file in FASTA format foreach(@translated_seqs){ print OUTPUT_FILE (">".$_->id()."\n".$_->seq()."\n");} # Performing blast `blastall -i "blast_beta.in" -d /share/raid1/database/ftp.ncbi.nih.gov +/blast/db/20090602/nr -p blastp -e 200000 -W 2 -M PAM30 -G 9.1 -F F - +m 8 -o "blast.out"`; # Creating SearchIO my $blast_report = Bio::SearchIO->new(-format => "blasttable", -file +=> "blast.out"); # Testing SearchIO for data. my $result = $blast_report->next_result(); my $hit = $result->next_hit(); print("Number of hits: ".$hit->length()."\n");
|
|---|