Question: (Closed) perl progrmme error for blast tab limited out put Parsing
0
gravatar for akhilvbioinfo
3.3 years ago by
akhilvbioinfo130
India, chennai
akhilvbioinfo130 wrote:

use warnings;

print "Enter Your BLAST result file name:\t";
chomp($blast = <STDIN>);     # BLAST result file name
print "\n";

print "Enter Your Gene list file name:\t";
chomp($database = <STDIN>);  #  file name
print "\n";

open IN,"$blast" or die "Can not open file $blast: $!";

@ids = ();
@seq_start = ();
@seq_end = ();

while(<IN>){

@feilds = split("\t",$_);
push(@ids,$feilds[0]);
push(@seq_start,$feilds[6]);
push(@seq_end,$feilds[7]);
}
close IN;

open OUT,">Result.fasta" or die "Can not open file $database: $!";


for($i=0;$i<=$#ids;$i++){

($sequence)    = &block($ids[$i]);

($idline,$sequence) = split("\n",$sequence);

    if($seq_start[$i] <= 70){
    $pos_Start = 0;
    }
    else{
    $pos_Start = $seq_start[$i]-70;
    }
    
    $pos_end = $seq_end[$i]+70;
    if($pos_end >= length($sequence)){
    $pos_end = length($sequence);
    }    
    
$seqlen = $pos_end - $pos_Start;

$Nucleotides = substr($sequence,$pos_Start,$seqlen);

$Nucleotides =~ s/(.{1,60})/$1\n/gs;

print OUT "$idline\n";
print OUT "$Nucleotides\n";    
}
print "\nExtraction Completed...";

sub block{

$id1 =shift;
print "$id1\n";
$start = ();

open IN3,"$database" or die "Can not open file $database: $!";

$blockseq = "";
while(<IN3>){

    if (($_ =~ /^>/)&&($start)){
    
    last;
    }
    
    if (($_ !~ /^>/)&&($start)){
    
    chomp;
    $blockseq .= $_;
    }
    
    if (/^>$id1/){
    
    $start = $.;print "$.\n";#-1;
    $blockseq .= $_;
    }
}
close IN3;

return($blockseq);
}<STDIN>;

 

I got following errors while running the above code

Use of uninitialized value $seq_start[1] in numeric le (<=) at Blast_Extractor1.pl line 35.

Use of uninitialized value $seq_end[1] in addition (+) at Blast_Extractor1.pl line 42.

Use of uninitialized value in numeric ge (>=) at Blast_Extractor1.pl line 43.

Use of uninitialized value $pos_end in subtraction (-) at Blast_Extractor1.pl line 47.

Use of uninitialized value $sequence in substr at Blast_Extractor1.pl line 49.

Use of uninitialized value $idline in concatenation (.) or string at Blast_Extractor1.pl line 53.

blast perl • 942 views
ADD COMMENTlink modified 3.3 years ago by Michael Dondrup45k • written 3.3 years ago by akhilvbioinfo130
GCA_001188035.1_1       GCA_001188035.1_1       100.00  159     0       0       1       159     1       159     8e-113   324

GCA_001188035.1_1       GCF_000878595.1_1595    100.00  159     0       0       1       159     853     1011    2e-104   327

GCA_001188035.1_1       GCA_001267965.1_78      100.00  159     0       0       1       159     853     1011    2e-104   327

GCA_001188035.1_1       GCF_000568495.1_4683    100.00  159     0       0       1       159     853     1011    2e-104   327

GCA_001188035.1_2       GCF_000568495.1_4684    100.00  137     0       0       1       137     1       137     8e-97    281

GCA_001188035.1_2       GCA_001188035.1_2       100.00  137     0       0       1       137     1       137     8e-97    281

this is my blast out put

ADD REPLYlink written 3.3 years ago by akhilvbioinfo130

Hello akhilvbioinfo!

We believe that this post does not fit the main topic of this site.

This is a pure Perl question.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink written 3.3 years ago by RamRS20k
1
gravatar for Michael Dondrup
3.3 years ago by
Bergen, Norway
Michael Dondrup45k wrote:

These are not errors but warnings, more often then not they are caused but a non-defensive programming style. The following mistakes were made in the above code:

  • it exists: you wrote a blast parser yourself while there are libraries 
  • you did not use strict;
  • good code handles blank lines and comments, this one doesn't, most likely the reason for all warnings
  • you do not chomp
  • you use a error prone for loop where foreach could be applied instead of $#ids

  • you silently assume that each line has at least 7 entries but you never verify that, so you are pushing undef's onto an array
  • you do not check if these entries are numeric
ADD COMMENTlink modified 3.3 years ago • written 3.3 years ago by Michael Dondrup45k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 818 users visited in the last hour