Solved

undefined value error

Posted on 2004-10-02
4
282 Views
Last Modified: 2008-03-17
my test.cgi can be excuted at command mode with "perl test.cgi", however it has some error called "sequence method cannot be called for undefined value error" happened at one line (indicated by ***** in the code )calling one method of another module. Before that line, everything is ok.

The code for test.cgi is following (followed by the code of module DNAalign.pm):

Can anybody help me figure out the problem?

thanks,

#!/usr/bin/perl

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use warnings;
use diagnostics;
use File::Basename;
use DNAalign;
use fastream;
use DNAseq;

my $query = new CGI;
my ($defaultfolder,$project)=split(/&/,$ENV{'QUERY_STRING'});
print "Content-type: text/html\n\n";

print "<html><head><title>Perl CGI Example # 2";
print "</title></head><body><h1>";
print "Alignment Result </h1><p>";
print "<pre>";


my $strk="/srv/www/httmp/$defaultfolder/$project/chromat_dir";
chdir($strk);
my $upload_filehandle = $query->upload("alignFile");
open UPLOADFILE, ">/srv/www/httmp/$defaultfolder/$project/chromat_dir/secondFile";
while ( <$upload_filehandle> )
{
   print UPLOADFILE;
}
close UPLOADFILE;
my $pfile1="$project.fasta.screen.contigs.qual";
open(INPUT2, "<","$project.fasta.screen.contigs.qual" )
or die "Could not open the file for reading: $!\n";
my @logData2 = <INPUT2>;
close(INPUT2);

my $size=@logData2;

my @arr3=();
for(my $i=1;$i<$size;$i++){
  chomp $logData2[$i];
  my @brr3=split(/ /,$logData2[$i]);
  push(@arr3,@brr3);
}
my $pfile="secondFile";
my $str="/srv/www/httmp/$defaultfolder/$project/chromat_dir";
chdir($str);
my $seq1=fastream->new("$project.fasta.screen.contigs");
my $seq2=fastream->new("secondFile");

my $test1=$seq1->next_seq();
print "$test1";
my $test2=$seq2->next_seq();
print "$test2";

my ($result1,$result2);
($result1,$result2) = DNAalign::align($test1,$test2);

*****my $str1=$result1->sequence();
my $str2=$result2->sequence();

my @arrStr1=split(//,$str1);
my @arrStr2=split(//,$str2);
my $siz=@arrStr1;
my $count=0;
for(my $c1=0;$c1<(int $siz/30)+1;$c1++){
  my $start=$c1*30+1;
  my $stop=$c1*30+30;
  my $str="$start"."-"."$stop"." ";
  print "$str";
  my $l=11-(length $str);
  for(my $len=0;$len<$l;$len++){
     print " ";
  }

 for(my $c2=0;$c2<30;$c2++){
    if($arrStr1[30*$c1+$c2] eq $arrStr2[30*$c1+$c2]){
      print "<font color=\"green\">$arrStr1[30*$c1+$c2]</font>";
          print "  ";
    }else{
      print "<font color=\"red\">$arrStr1[30*$c1+$c2]</font>";
          print "  ";
    }
  }      
  print "\n";
  my $str3="alignment  ";
  print "<font color=\"orange\">$str3</font>";
  for(my $c2=0;$c2<30;$c2++){
    if($arrStr1[30*$c1+$c2] eq $arrStr2[30*$c1+$c2]){
      print "<font color=\"green\">$arrStr2[30*$c1+$c2]</font>";
          print "  ";
    }else{
      print "<font color=\"red\">$arrStr2[30*$c1+$c2]</font>";
          print "  ";
    }
  }
  print "\n";
 
  my $str4="confidence ";
  print "<font color=\"orange\">$str4</font>";
  for(my $c2=0;$c2<30;$c2++){
    if($arrStr1[30*$c1+$c2] ne "-"){
      print "<font color=\"blue\">$arr3[$count]</font>";
        print " ";
        if((int $arr3[$count])<10){print " ";}
        $count++;
    }else{
      print "   ";
    }
  }
  print "\n";  
  print "\n";
}


print "</pre>";
print "</p>";

print "</body></html>";


____________________
code for DNAalign.pm


# Keith Anthony Boroevich -- 24.11.2003

package DNAalign;
use strict;
use Carp;
use diagnostics;
use File::Temp 'tempfile', 'tempdir';
use fastream;

my $tdir = tempdir('DNAalignXXXXX', TMPDIR => 1, CLEANUP => 1);

BEGIN { }

sub align {
    my $seq1 = shift;
    my $seq2 = shift;
    my %options = (
               ALGORITHM => 'lagan',
               FILENAME => undef,
               STYLE => undef,
               );
    %options = (%options, @_) if @_;

    # --- align sequences --- #
    my @aseq;
    if    (uc($options{ALGORITHM}) eq 'LAGAN')   { @aseq = lagan($seq1,$seq2); }
    elsif (uc($options{ALGORITHM}) eq 'CLUSTAL') { croak "Clustal not yet supported.\n"; return ($seq1,$seq2); }
    # elsif other formats
    else { croak "Unknown Algorithm: ",$options{ALGORITHM},".\n"; return ($seq1,$seq2); }

    #--- output file if requested ---#
    if (defined($options{FILENAME})) {
      open OFILE, ">$options{FILENAME}";
      if ((uc($options{STYLE}) eq 'FASTA')||(! $options{STYLE})) {
          foreach my $aseq (@aseq) { print OFILE "$aseq"; }
      } elsif (uc($options{STYLE}) eq 'CLUSTAL') {
          print OFILE clustal_format(@aseq);
      }
      close OFILE;
    }
    return (@aseq);
}


sub lagan {
    my $seq1 = shift;
    my $seq2 = shift;

    # --- create sequence files --- #
    my ($ofh1,$ofile1) = tempfile( TEMPLATE => 'kabXXXXX', SUFFIX => '.fas', UNLINK => 1, DIR => $tdir);
    print $ofh1 "$seq1";
    system("/data/software/RepeatMasker/current/RepeatMasker -qq -int -nocut $ofile1 > /dev/null");
    my ($ofh2,$ofile2) = tempfile( TEMPLATE => 'kabXXXXX', SUFFIX => '.fas', UNLINK => 1, DIR => $tdir);
    print $ofh2 "$seq2";
    system("/data/software/RepeatMasker/current/RepeatMasker -qq -int -nocut $ofile2 > /dev/null");

    # --- align sequences --- #
    my ($ifh, $ifile) = tempfile( TEMPLATE => 'kabXXXXX', SUFFIX => '.fas', UNLINK => 1, DIR => $tdir);
    close($ifh);
    #print `/data/software/lagan/current/lagan.pl $ofile1 $ofile2 -mfa > $ifile`; # With lagan reporting
    system("/data/software/lagan/current/lagan.pl $ofile1 $ofile2 -mfa > $ifile 2> /dev/null");
    my $istream = fastream->new($ifile);
    my @seqs;
    while (my $seq = $istream->next_seq()) { push @seqs, $seq; }
    return @seqs;

}

sub clustal_format {
    my @seqs = @_;
    my $count = $#seqs;
    my $minlength = $seqs[0]->length();
    foreach (@seqs) {
      $minlength = $_->length() if $_->length() < $minlength;
    }
    my $cf = "CLUSTAL X (1.8) multiple sequence alignment\n\n";
    for (my $i = 0; $i < $minlength; $i+=50) {
      foreach (@seqs) {
          $cf .= $_->id().' '.$_->subseq($i,50)."\n";
      }
      $cf .= "\n";
    }
    return $cf;
}

END { }

1;

0
Comment
Question by:jingks03
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12210452
What is fastream?
0
 

Accepted Solution

by:
stefzodiak earned 250 total points
ID: 12213855
Your returning an array from your function DNAlign::align
whereas your trying to put the return values into two scalars.

so, check that the values are defined before passing them
back. On top of that, before you call the object result1 to
invoke the method 'sequence', you should also 'bless' the
variable the appropiate class (which i dont see in the source
you have provided).

hope this helps.
Stef

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question