peing has asked for the wisdom of the Perl Monks concerning the following question:

output of Jpred is “--------HHHHHH-----HHHHHHHH------” (H stands for helix), write a perl script to count the number of residues in the helices. How do I do this? This is my first time using perl

Replies are listed 'Best First'.
Re: counting protein residues
by huck (Prior) on Mar 19, 2017 at 06:04 UTC
Re: counting protein residues
by AnomalousMonk (Archbishop) on Mar 19, 2017 at 06:27 UTC

    This looks a lot like homework. If it is thought to be so and you have not been forthright in saying so, the quantity and quality of help offered may suffer. If you're new to Perl, maybe look at perlintro. (Update: There's also chromatic's free e-book download Modern Perl — highly recommended.)

    Also, please understand that this is PerlMonks, not BioMonks. What's a "residue"? Could you give a Wikipedia link to a discussion of this topic? I assume it's possible to figure out the "number of residues in the helices" just by looking at the "--------HHHHHH-----HHHHHHHH------" string and knowing the number and context of each H; how about some info on this relationship?


    Give a man a fish:  <%-{-{-{-<

Re: counting protein residues
by duyet (Friar) on Mar 19, 2017 at 07:52 UTC

    Like other monks already mentioned, you need to give more info to get proper responses.

    What did you try?

    Don't know what "number of residues in the helices" means, but if you want to count the H's from the string, below is one way to do it:

    my $jpred='--------HHHHHH-----HHHHHHHH------'; print ( $jpred=~ tr/H/H/ ); Output: 14
Re: counting protein residues
by bart (Canon) on Mar 19, 2017 at 10:29 UTC
    tr/// can be used to count the number of occurrences of characters in some set of characters in a string.

    As this is most likely homework, I'm not saying anything more.