Prev: OLE with outlook
Next: Data cleaning issue involving bad wide characters in what ought to be ascii data
From: Amy Lee on 26 Nov 2008 21:54 Hello, Here's my data. Chr01 621 A A/G A Chr01 752 C C/G C Chr01 969 T C/T T Chr01 1220 A/G G G Chr01 1246 A/C C C Chr01 1263 A/G A/G A .... ... And as you see I wanna clean up the lines which the 3rd, 4th and 5th column has the same letter. For example, A A/G A, this line has the same letter A. So what I'm going is to count letters with A/T/G/C. However, I didn't grasp the point to solving this problem. So my problem is what kinds of function(tr?) or something else could help me fix this? Best Regards, Amy
From: Tad J McClellan on 27 Nov 2008 00:15 Amy Lee <openlinuxsource(a)gmail.com> wrote: > I wanna clean up the lines which the 3rd, 4th and 5th > column has the same letter. ----------------------------------- #!/usr/bin/perl use warnings; use strict; while ( <DATA> ) { chomp; print "$_ has 3 A's\n" if tr/A// >= 3; print "$_ has 3 T's\n" if tr/T// >= 3; print "$_ has 3 G's\n" if tr/G// >= 3; print "$_ has 3 C's\n" if tr/C// >= 3; } __DATA__ Chr01 621 A A/G A Chr01 752 C C/G C Chr01 969 T C/T T Chr01 1220 A/G G G Chr01 1246 A/C C C Chr01 1263 A/G A/G A ----------------------------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
From: Todd on 27 Nov 2008 06:43 Tad J McClellan wrote: > Amy Lee <openlinuxsource(a)gmail.com> wrote: > > > I wanna clean up the lines which the 3rd, 4th and 5th > > column has the same letter. > > while ( <DATA> ) { > chomp; > print "$_ has 3 A's\n" if tr/A// >= 3; To make question less boring and pure and to be interested, I'll present a new question as: give 2 strings, how to judge whether they have common character? or the next question, give 3/4/... strings, what to do? -Todd
From: Todd on 27 Nov 2008 06:56 I got a solution for this: > give 2 strings, how to judge whether they have common >perl -e '"$ARGV[0]\0$ARGV[1]"=~/(\S).*?\0.*?\1/ ? print "true" : print "false"' aaaaaaabcccccccccc eebff true /xueweizhong:~/perl/misc (1 jobs) >perl -e '"$ARGV[0]\0$ARGV[1]"=~/(\S).*?\0.*?\1/ ? print "true" : print "false"' aaaaaaabcccccccccc eeff false Following this, we can write 3 strings solution naturally, but not for any number of strings problem. -Todd
From: J�rgen Exner on 27 Nov 2008 11:04 Todd <xueweizhong(a)gmail.com> wrote: >To make question less boring and pure and to be interested, I'll >present a new question as: > > give 2 strings, how to judge whether they have common > character? > > or the next question, give 3/4/... strings, what to do? Yawwwwnnnnn split() the strings into individual characters, then see "perldoc -q intersection". jue
|
Next
|
Last
Pages: 1 2 Prev: OLE with outlook Next: Data cleaning issue involving bad wide characters in what ought to be ascii data |