in reply to finding position

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

Replies are listed 'Best First'.
Re^2: finding position
by heidi (Sexton) on Oct 09, 2008 at 06:43 UTC
    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" );
        thanks for the program... but then, i m not able to remove the duplicate values even after nulling the array... where should i do it? my input file is:
        read.txt >s1 A G C T G G G G A C T T T A G C >s2 A G C T G G G G A C T T T A G C >s3 A G C T G G G G A C T T T A G C and num.txt is >s1 34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 >s2 34 23 43 45 34 43 45 7 45 43 12 34 32 56 43 >s3 34 23 43 45 34 43 45 7 45 43 12 34 32 56 43
        i have just given the same values as example. my program follows:
        #!/usr/bin/perl open(FH1,"read.txt"); open(FH2,"num.txt"); @arr1=<FH1>; @arr2=<FH2>; $joi1=join('',@arr1); $joi2=join('',@arr2); @new=split('>',$joi1); @numbers=split('>',$joi2); foreach(@new){ ($seq_id,$seq)=split(/\n/,$_); push(@alp,split('',$seq)); push(@seqid,$seq_id); } foreach(@numbers){ ($num_id,$numb)=split(/\n/,$_); push(@num,split(' ',$numb)); push(@numid,$num_id) } #my @alp=split(' ','A G G G G T C A A A T C'); #my @num=split(' ','23 34 54 23 2 43 54 56 23 5 76 34'); my @keep= grep {$_ < 1 || $num[$_]>=10 || $alp[$_-1] ne $alp[$_-0]} 0. +.$#num; foreach(@seqid){ print "$_\n"; print (join(' ',@alp[@keep]),"\n"); } foreach(@numid){ print "$_\n"; print (join(' ',@num[@keep]),"\n"); }