• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

no error but it closes on .pl run

I need to troubleshoot the pl script below.

It takes the data entry fine until the last input, but it just close after then like below.  No error are showing.  It just closes it by itself.  What would be the cause?

thx much

To enter number N of species
5
Enter the distance (2,1)
3
Enter the distance (3,1)
2
Enter the distance (3,2)
3
Enter the distance (4,1)
4
Enter the distance (4,2)
5
Enter the distance (4,3)
3
Enter the distance (5,1)
4
Enter the distance (5,2)
5
Enter the distance (5,3)
3
Enter the distance (5,4)
3


******************************** pl script *********************************
#!/usr/bin/perl -w

# D. G. M

sub inputfile

# Dated come from a file  ($matrixfilename)

        {
        my($matfilename)=$_[0];
        my ($i,$j);
        open MAT,$matfilename or die "The file $matfilename was not found!\n";

# Determination of the number of species

        $LINE=<MAT>;
        chomp $LINE;
        @element=split / /,$LINE;
        $n=$#element+1;

   if ($n<3){
   die "To build a phylogenetic tree, minimum 3 species are needed!\n"
   }

# Initialization of the matrix of the distances

        for ($i=0;$i<=$n;$i++)
          {
          for ($j=0;$j<=$n;$j++)
             {
             $dist[$i][$j]=1000;
             }
          }

# Entry of the data

        for ($i=2;$i<=$n;$i++){
        $dist[$i][1]=$element[$i-1];
        }

        for ($j=2;$j<=$n;$j++){
        $LINE=<MAT>;
        @element=split / /,$LINE;
          for ($i=$j+1;$i<=$n;$i++){
          $dist[$i][$j]=$element[$i-1];
          }
        }
        return @dist;
}

# ---------------------------------------------------------

sub inputmatrix

# Data entered manually

{
        my ($i,$j);

        print "To enter number N of species\n";
        $n=<STDIN>;
        chop $n;

   if ($n<3){
   die "To build a phylogenetic tree, minimum 3 species are needed!\n"
   }

#  Initialization of the matrix of the distances  

        for ($i=0;$i<=$n;$i++)
          {
          for ($j=0;$j<=$n;$j++)
             {
             $dist[$i][$j]=1000;
             }
          }

# Entry of the data

        for ($i=2;$i<=$n;$i++)
          {
          for ($j=1;$j<=$i-1;$j++)
             {
             print "Enter the distance ($i,$j)\n";
             $dist[$i][$j]=<STDIN>;
             chop $dist[$i][$j];
             }
          }

# Rem: lines $i=0 et $j=0 are without utility ("neutralisee")

        return @dist;
}

# ---------------------------------------------------------

sub newmatrix
{
    my ($i,$j);
    mini(@dist);

    print "The species are grouped $q and $p ";


    for ($i=2;$i<=$n;$i++)
       {
       for ($j=1;$j<=$i-1;$j++)
           {
           if ($i==$p || $j==$p)
               {
               $dist[$i][$j]=1000;
               }
           elsif ($i!=$q && $i!=$p && $j!=$q && $j!=$p)
               {
               $dist[$i][$j]=$dist[$i][$j];
               }
           elsif ($i==$q && $j<$q)
               {
                $dist[$i][$j]=(($clu[$q])*$dist[$q][$j]+($clu[$p])*$dist[$p][$j])/($clu[$q]+$clu[$p]);
               }
           elsif ($j==$q && $i>$q && $i<$p)
               {
                $dist[$i][$j]=(($clu[$q])*$dist[$i][$q]+($clu[$p])*$dist[$p][$i])/($clu[$q]+$clu[$p]);
               }
           elsif ($j==$q && $i>$p)
               {
                $dist[$i][$j]=(($clu[$q])*$dist[$i][$q]+($clu[$p])*$dist[$i][$p])/($clu[$q]+$clu[$p]);
               }
           else
               {
               print "Bug!i=$i,j=$j,p=$p,q=$q\n";
               }
           }
       }

    $clu[$q]=$clu[$q]+$clu[$p];

    $clustr[$q]=join(",","($clustr[$q]","$clustr[$p])");
    print "\nNew Tree => $clustr[$q]  => distance=$min\n\n";

        return @dist;
}

#---------------------------------------------------------

sub mini
{

# Determination of the distance minimum

   $min=1000;
   for ($i=2;$i<=$n;$i++)
       {
       for ($j=1;$j<=$i-1;$j++)
           {
            if($min>$dist[$i][$j])
               {
               $min=$dist[$i][$j];
               $p=$i;
               $q=$j;
               }
           }
       }
    print "The distance min is $min  => ";
}

#----------------------------------------------------------

sub showmatrix

# Posting of the matrices

{
  my ($i,$j,$l);
  print "\n";

  for($l=1;$l<=$n;$l++){
  $cond[$l]=0;
  $cond[$l]=0;
  }

  $k=$k+1;

  if ($k>1){

    $kk=$k-1;
    $pp[$kk]=$p;

    for($l=1;$l<=$kk;$l++){
      for ($j=1;$j<=$n;$j++){
        if ($j==$pp[$l]){
         $cond[$j]=1;
        }
     }
    }

    for($l=1;$l<=$kk;$l++){
      for ($i=1;$i<=$n;$i++){
        if ($i==$pp[$l]){
        $cond[$i]=1;
        }
      }
    }
  }


   for ($j=1;$j<=$n;$j++){
   if ($cond[$j]==0){
      for ($i=1;$i<=$n;$i++){
      if ($cond[$i]==0){
         if ($dist[$i][$j]!=1000){
         printf "%10.2f",$dist[$i][$j];}
         else{
           print "         -";
         }
      }
      }
        print "\n";
   }
   }

        print "\n";
}

#----------------------------------------------------------

# main

my ($i);

if (scalar @ARGV==1){
   ($matrixfilename) = $ARGV[0];
   inputfile($matrixfilename);
   }
   else{
     if (scalar @ARGV==0){
     inputmatrix();
     }
     else{
     die "A number of invalid arguments!\n"
     }
   }


print "Matrix of distances in using method UPGMA.\n\n";

print "There is $n species\n\n...";

   $k=0;

# Posting of the initial matrix

   print "\n--------------------------------------------\n";
   print "Initial matrix:";
   print "\n--------------------------------------------\n";
   $p=1001;
   showmatrix (@dist);

# Initialization of the clusters & the cluster_string

for ($i=1;$i<=$n;$i++)
   {
   $clu[$i]=1;
   $clustr[$i]=$i;
   }

# Calculation and posting of the new matrices

for ($i=1;$i<=$n-1;$i++)
   {
   newmatrix(@dist);
   print "\n--------------------------------------------\n";
   print "New matrix No $i:";
   print "\n--------------------------------------------\n";
   showmatrix (@dist);
   }
0
ethanjohnsons
Asked:
ethanjohnsons
  • 2
2 Solutions
 
ozoCommented:
When I run it, I get

To enter number N of species
5
Enter the distance (2,1)
3
Enter the distance (3,1)
2
Enter the distance (3,2)
3
Enter the distance (4,1)
4
Enter the distance (4,2)
5
Enter the distance (4,3)
3
Enter the distance (5,1)
4
Enter the distance (5,2)
5
Enter the distance (5,3)
3
Enter the distance (5,4)
3
Matrix of distances in using method UPGMA.

There is 5 species

...
--------------------------------------------
Initial matrix:
--------------------------------------------

         -      3.00      2.00      4.00      4.00
         -         -      3.00      5.00      5.00
         -         -         -      3.00      3.00
         -         -         -         -      3.00
         -         -         -         -         -

The distance min is 2  => The species are grouped 1 and 3
New Tree => (1,3)  => distance=2


--------------------------------------------
New matrix No 1:
--------------------------------------------

         -      3.00      3.50      3.50
         -         -      5.00      5.00
         -         -         -      3.00
         -         -         -         -

The distance min is 3  => The species are grouped 1 and 2
New Tree => ((1,3),2)  => distance=3


--------------------------------------------
New matrix No 2:
--------------------------------------------

         -      4.00      4.00
         -         -      3.00
         -         -         -

The distance min is 3  => The species are grouped 4 and 5
New Tree => (4,5)  => distance=3


--------------------------------------------
New matrix No 3:
--------------------------------------------

         -      4.00
         -         -

The distance min is 4  => The species are grouped 1 and 4
New Tree => (((1,3),2),(4,5))  => distance=4


--------------------------------------------
New matrix No 4:
--------------------------------------------

         -


What did you want to happen when you run it?
0
 
mjcoyneCommented:
I get the same output as ozo...
0
 
ethanjohnsonsAuthor Commented:
that is odd..
I will try it with other inputs... again.
0
 
ethanjohnsonsAuthor Commented:
yes, I got it.

thx much
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now