http://www.perlmonks.org?node_id=1091054

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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);