Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^8: how to access elements in perl

by grewal7634 (Novice)
on May 08, 2014 at 10:36 UTC ( #1085438=note: print w/ replies, xml ) Need Help??


in reply to Re^7: how to access elements in perl
in thread how to access elements in perl

I am using this code given below which you send me. I want to add some more things so that i can count GC% in 0-200, 1-201, 2-202.... upto 1000 or more and if GC% in any region is more than 50% then to take output as: "GC% in more than 50% in this ... region". How can i do this.

#! perl -slw use strict; my $dna = do{ local $/; <DATA> }; $dna =~ tr[ +\n][]d; my %counts; ++$counts{ substr $dna, $_, 1 } for 0 .. 199; for + my $offset ( 0 .. length( $dna )-200 ) { printf "range: %d .. %d A:% +d C:%d G:%d T:%d\n", $offset, $offset+1 +99, @counts{ qw[ A C G T ] } +; --$counts{ substr $dna, $offset, 1 }; ++$counts{ substr $dna, $offs +et+200, 1 }; } __DATA__ TGCCATCGCGCCAGGAGGGAAGACCAGTTGCTCTGGGTAAATCAG +CCGTGAGCGTATCTGTCCCTCTTAT +AATTAGGAGTTTAAACTCTACGATGTTACC ATCCTTGAATC +AGGTATATACCGCACTGAAACATCGTCGGCTTTGGGCTCATTCGCTACCCTGTCGCTGA +TATGCGAT +CTATTCTACATATGCGGGGCCA CCCAATGTCGATTGTCATGAGGAGGGGGTCATAACGACTCACTATA +GGACCAGCACGTCCGGTTGCGCTG +AGTAAAATAGAGCTACAAAAGACACAGTAC TCCAAGATGTAA +AGGGGAAGACGGGACCTGGGTCGGGGGCGCAACTTCACTGAGCTTTTAACCTTGCGCG +CATGCGAGA +GCCTTTCCGCTTAGGAAATGC TGTAAGATCAAGTGGTAGGACTATTGAGAGGTCTTACCTTGCCGCAG +CAACGTGGACGGCGACCGGATAA +TTTAAGGCCGACATTCAATATAGAATGTCA GGGAGCAGAACTG +TATCCCAAATGCTAGTTGTAGGTGTACGAGCGCACCTGGGGACCTATCGCTCCGACG +GGGTCTGCGT +AGCCCATACATCCTGCCAGC ACTGGGGCTATTGAACGGTCAATCCGTAATGTACTCGCTGAATGCTCA +GGGATTCCTTAATCTTTGAGCA +CGCGGCTTCTCTCACTTTTCTCACGTCAAC CCTGACTCATAACG +GAGTTCGGCAGTCCCGGAACGGCTTATAGAAGCAATGCCTGAGTAGATAGCGTCAG +GGATCGGCCCT +ACGTCGAGTCCAGTACGCC ATTGGATGGAGGTCTCAGCCGTCGGTGGAGTGCGGCTCCACCCCCACAT +GAACGAGGTTGTTCCTGACCA +CCCCTGAAACTGTGAGAACCATTGTGTCGA AACCAAGAGGCTTGC +GTCGCGCTATAGGTCGATTGCCCCCTAGTTTCCCTATATTGAACGTGTTTCCATT +AAAGACTCTCGG +TAAATCTCACGTATTGCA
Produces:
C:\test>junk77 range: 0 .. 199 A:46 C:51 G:47 T:56 range: 1 .. 200 A:4 +6 C:52 G:47 T:55 range: 2 .. 201 A:46 C:53 G:46 T:55 range: 3 .. 202 +A:46 C:53 G:46 T:55 range: 4 .. 203 A:47 C:52 G:46 T:55 range: 5 .. 2 +04 A:47 C:52 G:46 T:55 range: 6 .. 205 A:47 C:52 G:46 T:55 range: 7 . +. 206 A:47 C:51 G:47 T:55 range: 8 .. 207 A:47 C:51 G:46 T:56 range: +9 .. 208 A:47 C:51 G:46 T:56 range: 10 .. 209 A:47 C:51 G:46 T:56 ran +ge: 11 .. 210 A:48 C:50 G:46 T:56 range: 12 .. 211 A:48 C:49 G:46 T:5 +7 range: 13 .. 212 A:47 C:49 G:46 T:58 range: 14 .. 213 A:47 C:49 G:4 +6 T:58 range: 15 .. 214 A:47 C:49 G:45 T:59 range: 16 .. 215 A:46 C:5 +0 G:45 T:59 range: 17 .. 216 A:47 C:50 G:44 T:59 ...


Comment on Re^8: how to access elements in perl
Select or Download Code
Replies are listed 'Best First'.
Re^9: how to access elements in perl
by BrowserUk (Pope) on May 08, 2014 at 10:43 UTC
    How can i do this.

    Change something; run the code, see how the output changes. Repeat.

    You say you are learning Perl. You won't learn anything until you start trying things for yourself.

    I gave you code to get you started, because that's the hardest part. Now you need to start trying things for yourself.

    When you have a specific problem you cannot solve, I'll help you. But I won't do it for you.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Ok i will try. Thanks.
      There is also one another problem, when i execute the above code it gives output starting from 289 - 489.. but not from 0 - 199.
        it gives output starting from 289 - 489.. but not from 0 - 199.

        Hm. If you look at the output I posted above, my code outputs the counts for 0 - 199, 1 - 200, 2 - 201, ...

        So what did you change? (Post your current version of the code and don't forget the <code></code> tags.)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085438]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2015-07-07 20:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls