Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

no error but it closes on .pl run

Posted on 2007-03-17
4
Medium Priority
?
181 Views
Last Modified: 2010-03-05
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
Comment
Question by:ethanjohnsons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1200 total points
ID: 18742546
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
 
LVL 17

Assisted Solution

by:mjcoyne
mjcoyne earned 800 total points
ID: 18743007
I get the same output as ozo...
0
 

Author Comment

by:ethanjohnsons
ID: 18743188
that is odd..
I will try it with other inputs... again.
0
 

Author Comment

by:ethanjohnsons
ID: 18771372
yes, I got it.

thx much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

609 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