Solved

undefined value error

Posted on 2004-10-02
4
279 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now