Help: Count special words

A

Amy Lee

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
 
T

Tad J McClellan

Amy Lee said:
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
 
T

Todd

Tad said:
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
 
T

Todd

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
 
J

Jürgen Exner

Todd said:
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
 
T

Todd

split() the strings into individual characters, then see "perldoc -q
intersection".

I know it will work, but it'll be very very slow, it seems that we
need to wrap a c code using XSUB.

-Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top