Dear monks,
I am a newbie and am getting stuck! All i want to do is given the two arrays below, i want to concatenate all the elements in @seqs which have the same value in @labels and put each newly formed sequence into a new array with each sequence as a new element. Can someone show me what i'm doing wrong?
my @labels = ('1', '1', '1', '2', '3', '4', '5', '6', '6', '7');
my @seqs = ('a', 'ctgc', 'tggattgactgtg', 'atgcatg' , 'ctgctgcatgtgatg
+actgtg', 'tgatg', 'gtgt', 'gcgccggactatgattgagctagcgtatgctgcatgctgat'
+, 'gggtttttttttttccccccccccc',
'aaaaaagggggg');
# where the $labels[0] .. [2] all correspond to number 1, so $seqs[0]
+.. [2] are concatenated to make actgctggattgactgtg etc.
I have tried the following code but the problem is that if there are t
+hree or more consecutive elements in @labels that have the same value
+, my code only gets the sequences of two in a row, not all of them on
+ce only (meaning that sequences will be redundant).
for (my $i=0; $i< @labels; $i++) {
if ($labels[$i] == $labels[$i+1]) {
# print "$labels[$i] == $labels[$i+1]\n";
push @window_int_seqs, "$seqs[$i]$seqs[$i+1] ";
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.