I've got an issue with an exercise in Perl. I would like to scan huge textfiles with Regex. Everything works just fine, but when i've found the Stop Codon at the nested while loop, the first while loop takes over, but it should continue from the last position of the found stop codon. Could someone give me a hint where to look?
I've tried the last statement, but that doesn't work.
use strict;
use warnings;
$|=1;
sub read_Fasta {
my ($filename) = @_;
open (FIN, "<$filename") or die "Bestand $filename niet te openen\n";
my $sequence = "";
while (my $line = <FIN>) {
if ($line =~ /^\s*$/) {
next;
} elsif ($line =~ /^\s*#/) {
next;
} elsif ($line =~ /^>/) {
next;
} else {
$sequence .= $line;
}
}
close (FIN);
$sequence =~ s/\s//g;
return ($sequence);
}
print "Het vinden van ORF's in een organisme.\n\n";
print "Bestanden worden geladen vanuit de locatie C:\\ \n";
print "Voer bestandsnaam (inclusief extensie) in:\n";
my $path = <STDIN>;
chomp ($path);
$path = "C:\\$path";
my $DNA_seq = &read_Fasta($path);
chomp ($DNA_seq);
print "De DNA sequentie is gevonden\n";
print "voer de minimale lengte van de ORF in: \n";
my $minlengte_ORF = <STDIN>;
chomp ($minlengte_ORF);
if ($minlengte_ORF =~ /^[0-9]+$/ && $minlengte_ORF >= 1) {
print "De gevonden ORF's zijn:\n";
while(($DNA_seq =~ (/[ATG]TG/ig))) {
my $startcodon = $&;
my $pos_startcodon = pos($DNA_seq);
$pos_startcodon -= 2;
my $stringvanafstart = $';
while($stringvanafstart =~ (/(TAA)|(TAG)|(TGA)/ig)){
my $stopcodon = $&;
my $lengte_ORF = length ($`);
$lengte_ORF += 3; #vanwege meetellen startcodon.
my $pos_stopcodon = pos ($stringvanafstart);
$pos_stopcodon -= 2;
if($lengte_ORF % 3 == 0){
if($lengte_ORF >= $minlengte_ORF) {
print "de positie van het startcodon $startcodon is $pos_startcodon \n";
print "de positie (vanaf het startcodon) van het stopcodon $stopcodon is $pos_stopcodon \n";
print "de totale lengte van de ORF bedraagt $lengte_ORF basen\n";
#Go back to first while loop, exclude everything till endposition.
}
else{
next;
}
}
else{
next;
}
}
}
}
else{
print "Invoer is onjuist, minimale lengte mag alleen getallen bevatten en/of moet groter zijn dan 0! \n";
}