Solved

# no error but it closes on .pl run

Posted on 2007-03-17
175 Views
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);

# 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
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
• 2

LVL 84

Accepted Solution

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

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

Author Comment

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

Author Comment

ID: 18771372
yes, I got it.

thx much
0

## Featured Post

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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
###### Suggested Courses
Course of the Month3 days, 16 hours left to enroll