heidi has asked for the wisdom of the Perl Monks concerning the following question:

dear all, i have a text file:
A G C T G G G G A C T T T A G C
i also have a number file with a same length of text file:
34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 67
my problem is : the corresponding number for each alphabet should be above 10. but, when there is repetition of alphabet which is 3 or more, the last alphabet (last alphabet in the repeat, example 'G') is less than 10, which should be chopped off from the string in alphabet file and also in number file. in some cases the repeats may not have less than 10 (like last alphabet in repeat 'T'). it can be left as it is. how do i solve this problem.? plz help.

Replies are listed 'Best First'.
Re: finding position
by GrandFather (Saint) on Oct 09, 2008 at 04:24 UTC

    If you want to keep the pairings for future manipulation then you might like:

    use strict; use warnings; my @pairs = map {[$_]} split ' ', 'A G C T G G G G A C T T T A G C'; my @nums = split ' ', '34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 67' +; push @{$pairs[$_]}, $nums[$_] for 0 .. $#pairs; print "$_->[0]: $_->[1], " for grep $_->[1] >= 10, @pairs;

    Prints:

    A: 34, G: 23, C: 43, T: 45, G: 34, G: 43, G: 45, A: 45, C: 43, T: 12, +T: 34, T: 32, A: 56, G: 43, C: 67,

    Perl reduces RSI - it saves typing
Re: finding position
by ikegami (Patriarch) on Oct 09, 2008 at 04:11 UTC
    use strict; use warnings; my @alphas = split ' ', 'A G C T G G G G A C T T T A G C'; my @nums = split ' ', '34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 6 +7'; my @keep = grep $nums[$_]>=10, 0..$#nums; print( join( ' ', @alphas[ @keep ] ), "\n" ); print( join( ' ', @nums [ @keep ] ), "\n" );
    A G C T G G G A C T T T A G C 34 23 43 45 34 43 45 45 43 12 34 32 56 43 67
      but in this case it chops all the numbers less than 10.. i want it to chop only where there are repeats in the alphabets !!!

        Then just peek back.

        use strict; use warnings; my @alphas = split ' ', 'A G C T G G G G A C T T T A G C'; my @nums = split ' ', '34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 6 +7'; my @keep = grep { $_ < 1 || $nums[$_] >= 10 || $alphas[$_-1] ne $alphas[$_-0] } 0..$#nums; print( join( ' ', @alphas[ @keep ] ), "\n" ); print( join( ' ', @nums [ @keep ] ), "\n" );