Dearest Monks, I have been playing around with the same code for over a day and I still don't understand where I'm falling down. I'm trying to pull out a certain sequence based on certain conditions and then print to a file the results. Unfortunately, what ends up printing to file is multiple matches of the same sequence. I have done a few tests and have commented out what happens when I print out the sequence at different stages in my code. I have tried googling,using books,pure determination, and I'm still confused... Please can you help?

my ($value, $col, $col2, $l_o_b, $left, $matchedID, $diff_three_prime, + $diff_five_prime, $sequence); open (EXONS_five, '>fasta_exons_five'); open (EXONS_three, '>fasta_exons_three'); my $i = 0; foreach my $match(@exonic_matches) { $value = $exon_ID[$i]; $col = $exon_left{$value}; $col2 = $exon_right{$value}; my @three_prime_ss = split(",", $col); my @five_prime_ss = split(",", $col2); my @reverse_three = reverse(@three_prime_ss); my @reverse_five = reverse(@five_prime_ss); if ($strands{$value} =~ m/\+/) { $diff_three_prime = $LBP[$i] - $three_prime_ss[$exons2{$value} - 1 +]; $diff_five_prime = $LBP[$i] - $five_prime_ss[$exons2{$value} - 1]; + $matchedID = $ID{$LBP[$i]}; if ($diff_three_prime !~ m/\-/ && $diff_three_prime <= 3) { $BP{$LBP[$i]} =~ s/\[[ACTG]\]/$alt[$i]/i; $l_o_b = 20; ##$right_of_boundary = 3; $l_o_b = $l_o_b + $diff_three_prime; $left = 51 - $l_o_b; $sequence = substr($BP{$LBP[$i]}, $left, 23); ## print $sequence, "\n"; ## POINT ONE: prints out correct sequence for condition ## } elsif ($diff_five_prime =~ m/\-/ && $diff_five_prime >= -3) { $BP{$LBP[$i]} =~ s/\[[ACTG]\]/$alt[$i]/i; $l_o_b = 3; ##$right_of_boundary = 6; $l_o_b = $l_o_b + $diff_five_prime; $left = 51 - $l_o_b; $sequence = substr( $BP{$LBP[$i]}, $left, 9); ## print $sequence, "\n"; ## POINT TWO: prints out what I want for this condition plus some repe +ats ## } } ## print $sequence, "\n"; ## POINT THREE: prints out multiple sequences of the above ## my $seq_length = length($sequence); if ($seq_length == 9) { print EXONS_five (">" . "$match_exon{$matchedID}" . "\n", lc($sequ +ence),"\n"); } else { print EXONS_three (">" . "$match_exon{$matchedID}" . "\n", lc($seq +uence),"\n"); } $i++; } close (EXONS_five); close (EXONS_three);

In reply to looping foreach error 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.