Sorry about the length of this, but since its all of a piece... well, here goes.
I am having a problem with (i think) the outer loop in this code snippet.
Description
The point of the script is to loop through a file that has been split into a 2D array:
YAL038W 1.1 2.4 4.1 YCL040W 1.1 1.6 1.8 9.11 0.0402128119838095
such that the identifiers (in this case) are yal038w and ycl040w, and the rest are their 'values' (which may be of any length). While there are still digits found by my regexp (i.e. we haven't hit the other identitfier yet) keep trying to match $pathway_name
$m (e.g. 1, 2, 26) to the value after the identifier. If matched, go to the next row of identifier/values. After all rows are done, go to the next pathway number and check.
for($m = 0; $m < scalar(@pathway_name); $m++) # foreach pathway name
+given by an integer
{
print "Pathway is $pathway_name[$m]\n"; # e.g.pathway name is 1
for($j = 0; $j < $rows; $j++) # for each row in my 2-
+D converted input file $file[][]
{
$n = 1;
#print "Gene: $file[$j][0], Value: $file[$j][1]\n";
if($seen{$file[$j][0]}) # if the ind
+exing element has already been seen
{
#print "Seen this Gene: $file[$j][0]\n"; # go on to t
+he next row
}
elsif($file[$j][1]) # if the val
+ue exists
{
$n = 1;
VALUE:while($file[$j][$n] =~ /\b\.+\b/gi) # while the
+re is still a digit there (i.e. not a name
{
#print "Gene: $file[$j][0], Value:$file[$j][$n]\n";
#print "Entering if statement in while block...\n";
if($file[$j][$n] =~ /\b\Q$pathway_name[$m]\E\.\d+/) # if
+matches the combination of pathwayname.digit.digit
{
print OUTPUT "$file[$j][0]\t$pathway_name[$m]\n";
print "Gene: $file[$j][0], Value: $file[$j][$n] printed to o
+utput file\n";
#print "Going to last value.\n";
$seen{$file[$j][0]} = 1; # add
+ the gene to the %seen hash for this pathway
last VALUE;
}
else
{
#print "Gene: $file[$j][0], Value: $file[$j][$n] not matched
+.\n";
$n++; # go
+ on to the next value
}
} # en
+d while
} # en
+d elsif
else
{
print "Skipped gene $file[$j][0]\n"; # g
+o on to the next line
}
} # end
+ while ($j < $row)
undef %seen; # since
+ going on to the next pathway, undefine %seen
}
The Problem
The loop keeps skipping every second $m from the outer for loop. It enters the loop, prints out the pathway name, and then increments $m without apparently checking the if/else statements. For example, in the input line above, it will find 1.1 and 4.1, but not 2.4.
I'm using perl 5.6.1 for i386-linux if that matters, with strict, disgnostics, and warnings turned on.
<edited for cleanup on aisle three>
janitored by ybiC: Balanced <code> tags around longish codeblock, for less vertical scrolling
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.