Hi all, I'm using perl for some basic file manipulation for a bioinformatics project.
TLDR: the index in my for loop isn't incrementing. :(
My intent for this program would be to supply it with a .fasta file of genome sequences (its in base pair form, with a header, and they are labeled with a unique accession number which is functionally an id number) and a feature table (.txt). My goal is to trim the complete genome sequences to only the part that corresponds to a certain gene (for me it is rbcL). Luckily, the annotations for where to trim are in the feature table file in the format of a start and end, both stated as a simple value which is the character count in the file at that start/end (example line: rbcL 65478 24534). Before I can even begin to trim the sequences however, I need to search the .fasta file (represented below by the array @arraybl) for the correct accession number (in the list @GBlist), and start from that spot. I can gather all the accession numbers easily, and I have a subroutine that will splice the full file into just the entry that I am working with at that moment, but the counter ($lineIndex) in the for loop (c-style) I am using is not progressing from 0. I don't reset it anywhere, and I believe its format is correct within the for loop header. I am posting the code below (just the loops in question).
for (my $annoIndex = 0; $annoIndex <= $#gbList; $annoIndex++) { my $currGB = $gbList[$annoIndex]; $startmark = 0; print "Current GB is $currGB\n"; for (my $lineIndex = 0; $lineIndex <= $#arraybl; $lineIndex++){ print "Line index is: $lineIndex\n"; my $lineinfile = $arraybl[$lineIndex]; print "line is: $lineinfile\n"; if (index($lineinfile, $currGB) != -1 || $lineinfile =~ m/$cur +rGB/){ $startmark = $lineIndex+1; my @chunk = GetEntryLines($startmark); print "$currGB has been matched!\n"; #print "Chunk Length is $#chunk\n"; #-----------get rbcL & stuff------------ last; } else { next; } } }
GetEntryLines is the subroutine that splices the whole array (the file as lines) into the individual entry. The above loops are the only instances of $lineIndex in the code. Your help is so much appreciated!
In reply to Index isn't progressing in C-style for loop by ItsGinny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |