Dear Monks,

I have an array where each element represents a different sequence, I simply want to divide each sequence in @seq into 3, e.g.gcttctgtc -> , and then seperate into three new categories based on the three positions in the new triplet. For example,

gct tct gtc category I = positions 1 +2, therefore = gc tc gt = gctcgt cat II = positions 2+3, = ct ct tc = ctcttc cat III = positions 3+1, = tg tt cg = tgttcg
This part is fine, where I am struggling is for cat III when there isn't a letter in position 3, I want to take it from the first position of the next sequence. e.g. in the sequences below, if there was no 3rd letter in the last triplet, I want to take the 1st letter from the next sequence (in this case 'a' from 'agtcatgcatgact') and use this in its place.

I hope someone can help my confusion!

# @seq contains the following: gcttctgtc agtcatgcatgact gcgtatcatgactgcatgatatgctgct gactgagcactgtgactgcatg for (my $i=0; $i<@seq; $i++) { my @gene = $seq[$i]; my $s = join ('', @gene); @gene = split ('', $s); print "GENE @gene\n"; # FORMAT TYPE I CODING: POSITIONS 1+2 for (my $i=0; $i<@gene; $i+=3) { push @gene_type1, "$gene[$i]"; push @gene_type1, "$gene[$i+1]"; } # FORMAT TYPE 2 CODING: POSITIONS 2+3 for (my $i=0; $i<@gene; $i+=3) { push @gene_type2, "$gene[$i+1]"; push @gene_type2, "$gene[$i+2]"; } # FORMAT TYPE 3 CODING POSITIONS 3+1 for (my $i=0; $i<@gene; $i+=3) { if ($gene[$i+2] !~ /\s+/) { push @gene_type3, "$gene[$i+2]"; push @gene_type3, "$gene[$i]"; } } push @gene_type1, "\n"; push @gene_type2, "\n"; push @gene_type3, "\n"; }

Updated Steve_p - removed wrapping blank lines in the code.


In reply to array and counting by Anonymous Monk

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.