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

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.