Syntactic Confectionery Delight PerlMonks

### Comment on

 Need Help??

hey i have a code (given below) which counts A,T,G,C and GC,and GC percentage in between 0-200, 1-201, 2-202 regions. But i have to count a lenghty sequence upto 10,000 basepairs, so this would be very lenghty and less efficient. What modification can i do in this code so that it can automateically count upto 10,000 bases.

```#!/usr/bin/perl

use warnings;my\$seq;my\$file;my\$line;my\$len;my@seq;

print "Select the region where you want to find CpG Island\n";

print  "1. Region 1-200\n";

print  "2. Region 2-202\n";

print  "3. Region 3-203\n";

\$choice =<STDIN>;

chomp(\$choice);

if(\$choice == 1){

&region1;

}

if(\$choice == 2){

&region2;

}

if(\$choice == 3){

&region3;

}

sub region1 {

\$file = 'd:\perl\1.txt';

open(INPUT, \$file) or die ("File not found");

foreach(\$line = <INPUT>){

\$a = substr(\$line,0,200) =~tr/A//;

\$t = substr(\$line,0,200) =~tr/T//;

\$g = substr(\$line,0,200) =~tr/G//;

\$c = substr(\$line,0,200) =~tr/C//;

\$cg = substr(\$line,0,200) =~tr/ CG //;

\$total = substr(\$line,0,200) =~tr/ATGC//;

}

\$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";}

}

sub region2 {

\$file = 'd:\perl\1.txt';

open(INPUT, \$file) or die ("File not found");

foreach(\$line = <INPUT>){

\$a = substr(\$line,1,201) =~tr/A//;

\$t = substr(\$line,1,201) =~tr/T//;

\$g = substr(\$line,1,201) =~tr/G//;

\$c = substr(\$line,1,201) =~tr/C//;

\$total = substr(\$line,1,201) =~tr/ATGC//;

}

\$CpG = (\$g+\$c)/\$total*100;
regarding perl,So i need your help for the same.

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"total count of ATGC = \$total\n";

print"CpG percentage = \$CpG\n";

if (\$CpG>=60){

print"CpG present";}

else{ print"CpG absent";}

}

sub region3 {

\$file = 'd:\perl\1.txt';

open(INPUT, \$file) or die ("File not found");

foreach(\$line = <INPUT>){

\$a = substr(\$line,2,203) =~tr/A//;

\$t = substr(\$line,2,203) =~tr/T//;

\$g = substr(\$line,2,203) =~tr/G//;

\$c = substr(\$line,2,203) =~tr/C//;

\$total = substr(\$line,2,203) =~tr/ATGC//;

}

\$CpG = (\$g+\$c)/\$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"total count of ATGC = \$total\n";

print"CpG percentage = \$CpG\n";

if (\$CpG>=60){

print"CpG present";}

else{ print"CpG absent";}

}
[download]```

In reply to Re^14: how to access elements in perl by grewal7634
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!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• 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
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-04-26 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (94 votes). Check out past polls.

Notices?