Dear all, I am trying to write a fairly simple script that takes a pathway, and writes out all the possible pairs and the 'steps' between the pairs, ie. 1 means that they are beside each other in the pathway and 2 means that there is another unit between them. However my output for the 'steps' is incorrect, the second time I go through everything is +1 (compare desired and current output). Any help is appreciated. thanks.

input

PA5098 PA5100 PA5092 PA3175

desired output

PA5098 PA5100 1 PA5098 PA5092 2 PA5098 PA3175 3 PA5100 PA5092 1 PA5100 PA3175 2 PA5092 PA3175 1

current output

PA5098 PA5100 1 PA5098 PA5092 2 PA5098 PA3175 3 PA5100 PA5092 2 PA5100 PA3175 3 PA5092 PA3175 3

code

############# open pathways output list with PA01 locus IDs my $in=$ARGV[1] || "pathways.col"; open (IN,$in) or die "cannot open $in\n"; ## my $out="$in.$org.stepSize.tab"; open(OUT,">",$out); # my %HoCplx2ID; my %HoPwyPair;my %HoPairs; while (my $lines=<IN>){ next if ($lines =~/^#/); next if ($lines =~/^UNIQUE-ID/); chomp $lines; my @cols=split(/\t/,$lines); my $cmplxID=$cols[0]; my $cmplxNm=$cols[1]; my @restCols=@cols[2..$#cols]; my @cycIDs=grep(/^GCXG-/, @restCols); @cycIDs=grep($_ ne '',@cycIDs); my $pwySize=scalar(@cycIDs); push (@{$HoCplx2ID{$cmplxID}},@cycIDs); } close(IN); ########### my %HoP; foreach my $pwy (keys %HoCplx2ID){ my @genes=@{$HoCplx2ID{$pwy}}; my $numbGenes=scalar(@genes); for (my $i=0;$i<$numbGenes;$i++){ for (my $j=1;$j<$numbGenes;$j++){ my $pair=join +("-",$HoCycID2Loc{$genes[$i]},$HoCycID2Loc{$genes[$j]}); my $rev_pair=join("-",$HoCycID2Loc{$genes[$j]} +,$HoCycID2Loc{$genes[$i]}); if (($genes[$i] ne $genes[$j]) && (!exists($Ho +P{$rev_pair}))){ print OUT join("\t",$HoCycID2Loc{$gene +s[$i]},$HoCycID2Loc{$genes[$i+1]},$j)."\n"; $HoP{$pair}=1; } } } }

In reply to problem with loop by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.