Solved

no error but it closes on .pl run

Posted on 2007-03-17
4
158 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
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 300 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 200 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
String Substitution 4 65
SIMPLE Perl Regex 1 144
git fat pull happens nothing in centos 6.3 python 2.6.6 33 194
create a gui in perl 3 45
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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

16 Experts available now in Live!

Get 1:1 Help Now