Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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,
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.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
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array and counting
by bart (Canon) on Oct 04, 2004 at 10:49 UTC | |
|
Re: array and counting
by si_lence (Deacon) on Oct 04, 2004 at 12:29 UTC |