Help: Count special words

Discussion in 'Perl Misc' started by Amy Lee, Nov 27, 2008.

  1. Amy Lee

    Amy Lee Guest

    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
     
    Amy Lee, Nov 27, 2008
    #1
    1. Advertising

  2. Amy Lee <> 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/"
     
    Tad J McClellan, Nov 27, 2008
    #2
    1. Advertising

  3. Amy Lee

    Todd Guest

    Tad J McClellan wrote:
    > Amy Lee <> 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
     
    Todd, Nov 27, 2008
    #3
  4. Amy Lee

    Todd Guest

    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
     
    Todd, Nov 27, 2008
    #4
  5. Todd <> 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
     
    Jürgen Exner, Nov 27, 2008
    #5
  6. Amy Lee

    Todd Guest


    > 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
     
    Todd, Nov 28, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Strøiman
    Replies:
    1
    Views:
    2,092
    Peter Strøiman
    Aug 23, 2005
  2. Richard Heathfield
    Replies:
    7
    Views:
    365
    Barry Schwarz
    Oct 5, 2003
  3. utab

    Words Words

    utab, Feb 16, 2006, in forum: C++
    Replies:
    6
    Views:
    429
    Daniel T.
    Feb 16, 2006
  4. BerlinBrown
    Replies:
    6
    Views:
    4,507
  5. Lasse Edsvik

    replace words with bold words

    Lasse Edsvik, Oct 5, 2003, in forum: ASP General
    Replies:
    9
    Views:
    240
Loading...

Share This Page