Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Could you provide perhaps a single line or maybe even 2 or 3 of the input file?

I modified your code a bit for brevity(untested). I am not all that familiar with microbiology(been 35 years since high school biology). I suspect there are CPAN modules that will handle problems like this. Do a search for like this one at bio:: and see if there might be something you can use if that is an option for you.

Hope that is in some way helpful...

#!/usr/bin/perl use strict; use warnings; print "Select the region where you want to find CpG Island\n"; my ($a,$t,$c,$g,$cg,$total); print "1. Region 1-200\n"; print "2. Region 2-202\n"; print "3. Region 3-203\n"; my $choice =<STDIN>; chomp($choice); my $file = 'd:\perl\1.txt'; if ( $choice == 1 ) { region(0); } elsif ( $choice == 2 ) { region(1); } elsif ( $choice == 3) { region(2); } sub region { my $start = shift; open(INPUT, $file) or die ("File not found"); foreach(my $line = <INPUT>) { my $a = substr($line,$start,200) =~ tr/A//; my $t = substr($line,$start,200) =~ tr/T//; my $g = substr($line,$start,200) =~ tr/G//; my $c = substr($line,$start,200) =~ tr/C//; my $cg = substr($line,$start,200) =~ tr/ CG //; my $total = substr($line,$start,200) =~ tr/ATGC//; } } my $CpG = ($cg)/$total*100; print"Count of A = $a\n"; print"Count of T = $t\n"; print"Count of G = $g\n"; print"Count of C = $c\n"; print"CG = $cg\n"; print"total count of ATGC = $total\n"; print"CpG percentage = $CpG\n"; if ($CpG>=60) { print"CpG present"; } else { print"CpG absent"; }
Update: moved printing back outside the sub. What I get for messing with code at this hour of the morning...
...the majority is always wrong, and always the last to know about it...
Insanity: Doing the same thing over and over again and expecting different results...

In reply to Re^15: how to access elements in perl by wjw
in thread how to access elements in perl by grewal7634

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (8)
    As of 2014-09-18 15:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (116 votes), past polls