open(DNA,"<$filename") or croak("Cannot open $filename:$!\n"); FASTAKEY: for my $g (@fastarray){ print "\$g is: $g\n"; if (@{$sets{$g}}){ print "This \$g, $g, has a set.\n"; $buffer = ''; my $skip = 0; my $i = 0; $position = 0; $num = (@{$sets{$g}}); LINE: while ($newline = ) { if ($skip == 1) { unless ($newline =~ /^>/) { next LINE; } if ($newline =~ /^>/) { $skip = 0; goto NOSKIP; } } else { # If new fasta header, NOSKIP: if($newline =~ /^>/) { print "....We've hit a newline, which is: $newline"; if ($buffer eq '') { chomp $newline; print "We are in the 'if buffer eq' loop.\n"; print "..\$g is: $g, and \$newline is $newline\n"; if ($newline ne $g) { $skip = 1; next LINE; } if ($newline eq $g) { $header = $newline; $g = $header; $skip = 0; print "Gathering sequence data from sequence $g\n"; next LINE; } # closes if buffer eq '' } else { # ($buffer ne '') FINISH: print "......At FINISH, \$num is: $num, and \$i is: $i\n"; if ($i == $num) { print "in FINISH, \$i is: $i, and \$num is $num. They should be equal\n"; $position = 0; $skip = 1; seek(DNA,(0-length($buffer)),1); $len = 0; $buffer = ''; next FASTAKEY; } else { print "in FINISH, \$i is: $i, and \$num is $num. They should not be equal\n"; print "\$i is: $i, \$HoA{$g}[$i][0] is: $HoA{$g}[$i][0], \$HoA{$g}[$i][1] is: $HoA{$g}[$i][1], \$position is: $position and length(\$buffer) is: ".length($buffer)."\n"; if ($HoA{$g}[$i][0] >= ($position + length($buffer))) {print "The position of \$lowest is past the end of the buffer! How did that happen?!\n";} if ($HoA{$g}[$i][1] < $position) {print "The position of \$highest is below that of \$position! How did this happen?!\n";} if ($HoA{$g}[$i][1] >= ($position + length($buffer))) { $match{$g}[$i] = uc(substr($buffer, ($HoA{$g}[$i][0] - $position))); } else { $match{$g}[$i] = uc(substr($buffer, ($HoA{$g}[$i][0] - $position), $HoA{$g}[$i][2])); } $i++; goto FINISH; # close uncommented else } #closes else ($buffer ne '' ) } # closes if newline } # closes else statement } chomp $newline; $buffer .= $newline; $len = length($newline); if (($position + $span) < $HoA{$g}[$i][0] && length($buffer) > $span) { # Reset the position counter # (will be accurate after you reset the buffer, next) $position += $span; # Reset the buffer # Discard the first $max worth of data in the buffer $buffer = substr($buffer, $span); } unless (length($buffer) >= $HoA{$g}[$i][2] && $position <= $HoA{$g}[$i][0] && (length($buffer) + $position) >= $HoA{$g}[$i][1]) { next LINE; } if ($i < $num) { $match{$g}[$i] = uc(substr($buffer, ($HoA{$g}[$i][0] - $position), $HoA{$g}[$i][2])); $i++; } if ($i == $num) { seek(DNA,(0-length($buffer)),1); $buffer = ''; $position = 0; $skip = 1; $len = 0; next FASTAKEY; } else { if ($position + $len < $HoA{$g}[$i][0]) { # Reset the position counter # (will be accurate after you reset the buffer, next) $position += $len; # Reset the buffer # Discard the first $max worth of data in the buffer $buffer = substr($buffer, $len); } $len = 0; next LINE; } # closes LINE } } # closes FASTAKEY } close(DNA) or croak("Cannot close $filename:$!\n"); print "Finished gathering all the sequences, now moving on.\n";