Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, my program below was working perfectly fine until i tried to run it using a shell script. this highlighted 2 problems in the code but i just can't see them. the lines containing errors are:
if( ($counter > $pos_end) && ($orf_counter < @orf_array_pos) )
and
if( ($counter >= $pos_start) && ($counter <= $pos_end) )
All the variable sin these two lines are declared so i can't see the problem.

If it helps the program reads in strings of DNA and prints to an output file the bits that don't overlap. $counter reads along one string, and $orf_counter counts the position in the second file. $pos_start and $pos_end just refer to the start and stop positions of matches. Hope someone can spot the mistake!

#! /usr/local/bin/perl -w use strict; my($num_of_params,$line,$key,$name); my @keys; my %orf_hash_pos; $num_of_params = @ARGV; if($num_of_params < 3) { die ("\n Not enough params have been entered!!!!\n"); } open (ORF_POS, $ARGV[0]) or die "unable to open file"; open (FASTA, $ARGV[1]) or die "unable to open file"; open (OUTFILE, ">$ARGV[2]"); foreach $line (<ORF_POS>) { if(! ($line =~ /(\d+)\s+(\d+)\s+(\d+)/)) { print "CHECK YOR FILE .... continue \n"; next; } if($2 <= $3) { $orf_hash_pos{$2} = $3; } else { $orf_hash_pos{$3} = $2; } } @keys = sort { $a <=> $b } ( keys %orf_hash_pos ); #--------------- step 2 --------------------------- my $counter=0; my $orf_counter=0; my $new_pos; my $pos_start=0; my $pos_end=0; my $found_new=0; my @lines; my @dna; my @orf_array_pos; my $base; my $dna; my $orf_names; @lines = <FASTA>; chomp @lines; $dna = join( '', @lines); @dna = split( '', $dna); foreach $key (@keys) { push @orf_array_pos , $key; push @orf_array_pos , $orf_hash_pos{$key}; } $pos_start = $orf_array_pos[$orf_counter]; $pos_end = $orf_array_pos[$orf_counter+1]; $found_new=0; foreach $base (@dna) { if( ($counter > $pos_end) && ($orf_counter < @orf_array_pos) ) { $orf_counter += 2; $new_pos = $orf_array_pos[$orf_counter]; if($new_pos < $pos_end) { $pos_start = $pos_end; } else { $pos_start = $new_pos; } $pos_end = $orf_array_pos[$orf_counter+1]; } if( ($counter >= $pos_start) && ($counter <= $pos_end) ) { $found_new=0; } else { if($found_new==0) { $orf_names = $orf_counter + 1; $found_new=1; print "\n\n> dORF$orf_names \n"; print OUTFILE "\n\n> dORF$orf_names \n"; } print $base; print OUTFILE $base; } $counter++; } print "\n";

Edit by tye

Replies are listed 'Best First'.
Re: a little bit tricky...
by dsb (Chaplain) on May 21, 2002 at 16:11 UTC
    Hey, 2 things. What are the errors? What is the command you are using to call the script?

    Gonna be hard to help without this information.




    Amel
    This is my cool %SIG
      the errors are just on the two lines i specified, something to do with the >= symbols. In the shell script i am just using the command
      perl ./file.name arg1 arg2
      this works perfect from a shell script on its own, but not when the command is embedded between other commands in the shell script.