Closed Thread
Results 1 to 7 of 7

Thread: help

  1. #1
    lichy is offline Newbie
    Join Date
    Jun 2007
    Posts
    17
    Rep Power
    0

    help

    i need help.

    for example, my input is AAXXXAAXXXAAXX

    so i want to count the number of times the AA actually appear in total. that will be 3 times. how to write a program like this?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    double-post, see below.........
    Last edited by KevinADC; 09-03-2007 at 10:51 PM.

  4. #3
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    Really mate, this is too simple, next time post some code you have tried.

    two ways:

    Code:
    $input = 'AAXXXAAXXXAAXXAXA';
    $count = $input =~ s/(AA)/$1/g;
    print $count;
    
    $input = 'AAXXXAAXXXAAXXAXXA';
    $count = () = $input =~ /AA/g;
    print $count;
    but what is if the input has three or more 'A's in a row? For example:

    AAXXXAAXXXAAXXAXAAAXXAAAAAXXAA

  5. #4
    lichy is offline Newbie
    Join Date
    Jun 2007
    Posts
    17
    Rep Power
    0
    as for that, i still have to verify with my teacher in school. to see what he gonna say about that.

    btw thanks for helping.

    input : AAXXXXAAXXXACXXXACXXX

    i would like to count the times AA and AC occurred separately.

    i try using your method. but the output is not what i want.
    and i try using "if" statement. it's still the same output which is not what i expected.

    this is the code for "if" statement.

    if($seq =~ AA)
    {
    $countAA = $seq =~ s/(AA)/$1/g;

    print "\nNumbers of AA pairs occurred: $countAA";
    }

    if($seq =~ AC)
    {
    $countAC = $seq =~ s/(AC)/$1/g;

    print "\nNumbers of AC pairs occurred: $countAC";
    }

  6. #5
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    the "if" conditions are not necessary:

    Code:
    $seq = 'AAXXXXAAXXXACXXXACXXX';
    $countAA = $seq =~ s/(AA)/$1/g;
    print "\nNumbers of AA pairs occurred: $countAA";
    $countAC = $seq =~ s/(AC)/$1/g;
    print "\nNumbers of AC pairs occurred: $countAC";

    both substrings (AA and AC) are counted twice, so the code works as expected.

    From now on if you post questions I will not reply unless i see the code you have been writing and trying. That is my personal policy for helping students.

  7. #6
    lichy is offline Newbie
    Join Date
    Jun 2007
    Posts
    17
    Rep Power
    0
    ok noted.

    btw instead of putting

    $count = $seq =~ s/(AA)/$1/g;
    print $count;

    can i put

    $count = $seq =~ s/($codon)/$1/g;
    print $count;

    as for the $codon, it's a input for the user to type in.

  8. #7
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    try it and see what happens. This is the kind of thing that is easy to run a test on and see what the results are.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts