Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: how to access elements in perl

by grewal7634 (Novice)
on May 27, 2014 at 11:21 UTC ( #1087513=note: print w/ replies, xml ) Need Help??


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

Hey i have done following modifications in above code, but i need some more help from you to modify it a little bit.

#! perl -slw use strict; my $dna = do{ local $/; <DATA> }; $dna =~ tr[\n][]d; my$len = length $dna; my %counts; ++$counts{ substr $dna, $_, 1 } for 0 ..199; # output.txt file will be created in which all of your results will be + stored. You can change the name of file as your wish. open(PAGE,">output.txt") || die"Can't open Outfile\n"; for my $offset ( 0 .. length( $dna )-200 ) { if ((($counts{'G'}+$counts{'C'})/(200)*100) > 40) { printf PAGE "range: %d .. %d A:%d C:%d G:%d T:%d G+C:%d GC%%:%d E +:%d R:%.1f\n", $offset, $offset+199, @counts{ qw[ A C G T ] }, $coun +ts{'G'}+$counts{'C'}, ($counts{'G'}+$counts{'C'})/(200)*100, ($len)*5 +/100, (($counts{'G'}+$counts{'C'})/(200)*100)/(($len)*5/100)*100; } --$counts{ substr $dna, $offset, 1 }; ++$counts{ substr $dna, $offset+200, 1 }; } print "The length of entire DNA sequence is = $len\n"; __DATA__ GATCTAAATGCTAGCTAGCTAGCTAGCTGGAATCCTCAATAGCTCAATCGATTCAATGCGCGCGTATAAG GGTAAGCGGTCCGCTACGATCCATCACATTCCACAATTAAAATTACCAAAATCGCATTCAAGGTCTCACA TAAAGAGTGCAGCTGCATCGATTGTAAATGCATAGATACATCATTAAATCTACAACACAGTTGACAAGAA CGTCAAAACCGTATTGTTTCAAAACTAAGGTCAAAAAAACCAAGCAGCATTTTGTTTTTGAAAATATACC CAAATATGTGCTAGCTACGACAAATAGCAATGTATTTATCCATAGCGATCGCGGACCTAACTTTCGCAAA AAATGCCAAGCCTAACCCAGACAAGACTCTCGCAATGAAATCGGAAAACAATAGCACTATGATGTATATT TCGTTCAGTTTTTGGTGAAAGAGCTCGAAGGTTTCATTAACGATAATCGCAAGGGCTAGCGAGCCTTTGG AAGCTGTCCTGTGACACGTTGACAATTCAATATATTACACTACATATTTTTACATATTATTTATATAATA TATAAGCATCGATGCAGCGAATCGTTCTTATTTCAATATGTACGAGTGTTTTGCGATACAAAATATCCCA ACGAGCACATTTCAGGGCATTTTATGAGACCGATCTGACGAGTCTGACGCTCGCAAAAGGCTTTTATGTT AAATGCAAATAAAAGATCGAGCAGTCTGACGTATACATGGAATTGCCTTCATTGCAAGAAAACAAATTTT CTCTAAACTGTCCTAACTGGCTGACTGATTGGTTAATAAACGCACAGAGTTAGAAAGCTGACACTTGAAC TTTAAGCAGCAGCGAGCAGCGTAATTTATATGATGAGGTCATGGAAATTTTACCGACATGTATGGTAAAT ACAAATTGTTTGGTAGTTCCGGTGCGCCTAAGACGCGTAGATTATCCGATCGGCTCTAAACTTATTTTCG +
output: range: 0 .. 199 A:69 C:47 G:35 T:49 G+C:82 GC%:41 E:49 R:83.7 range: 1 .. 200 A:69 C:47 G:34 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 2 .. 201 A:68 C:47 G:34 T:51 G+C:81 GC%:40 E:49 R:82.7 range: 3 .. 202 A:68 C:47 G:35 T:50 G+C:82 GC%:41 E:49 R:83.7 range: 4 .. 203 A:69 C:46 G:35 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 5 .. 204 A:69 C:47 G:35 T:49 G+C:82 GC%:41 E:49 R:83.7 range: 6 .. 205 A:69 C:47 G:35 T:49 G+C:82 GC%:41 E:49 R:83.7 range: 7 .. 206 A:69 C:47 G:35 T:49 G+C:82 GC%:41 E:49 R:83.7 range: 8 .. 207 A:68 C:47 G:36 T:49 G+C:83 GC%:41 E:49 R:84.7 range: 9 .. 208 A:69 C:47 G:36 T:48 G+C:83 GC%:41 E:49 R:84.7 range: 10 .. 209 A:70 C:47 G:35 T:48 G+C:82 GC%:41 E:49 R:83.7 range: 11 .. 210 A:70 C:47 G:35 T:48 G+C:82 GC%:41 E:49 R:83.7 range: 12 .. 211 A:70 C:47 G:36 T:47 G+C:83 GC%:41 E:49 R:84.7 range: 13 .. 212 A:69 C:47 G:36 T:48 G+C:83 GC%:41 E:49 R:84.7 range: 14 .. 213 A:69 C:48 G:35 T:48 G+C:83 GC%:41 E:49 R:84.7 range: 15 .. 214 A:70 C:47 G:35 T:48 G+C:82 GC%:41 E:49 R:83.7 range: 16 .. 215 A:71 C:47 G:35 T:47 G+C:82 GC%:41 E:49 R:83.7 range: 17 .. 216 A:71 C:47 G:35 T:47 G+C:82 GC%:41 E:49 R:83.7 range: 18 .. 217 A:72 C:47 G:34 T:47 G+C:81 GC%:40 E:49 R:82.7 range: 19 .. 218 A:72 C:47 G:34 T:47 G+C:81 GC%:40 E:49 R:82.7 range: 20 .. 219 A:72 C:48 G:34 T:46 G+C:82 GC%:41 E:49 R:83.7 range: 21 .. 220 A:71 C:48 G:35 T:46 G+C:83 GC%:41 E:49 R:84.7 range: 22 .. 221 A:71 C:48 G:34 T:47 G+C:82 GC%:41 E:49 R:83.7 range: 23 .. 222 A:72 C:47 G:34 T:47 G+C:81 GC%:40 E:49 R:82.7 range: 24 .. 223 A:72 C:47 G:34 T:47 G+C:81 GC%:40 E:49 R:82.7 range: 25 .. 224 A:71 C:47 G:34 T:48 G+C:81 GC%:40 E:49 R:82.7 range: 26 .. 225 A:71 C:47 G:34 T:48 G+C:81 GC%:40 E:49 R:82.7 range: 276 .. 475 A:69 C:43 G:38 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 277 .. 476 A:69 C:43 G:38 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 278 .. 477 A:69 C:43 G:38 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 279 .. 478 A:69 C:42 G:39 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 280 .. 479 A:69 C:42 G:39 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 281 .. 480 A:69 C:41 G:40 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 282 .. 481 A:69 C:41 G:40 T:50 G+C:81 GC%:40 E:49 R:82.7 range: 283 .. 482 A:68 C:41 G:41 T:50 G+C:82 GC%:41 E:49 R:83.7 range: 284 .. 483 A:67 C:42 G:41 T:50 G+C:83 GC%:41 E:49 R:84.7 range: 285 .. 484 A:67 C:43 G:41 T:49 G+C:84 GC%:42 E:49 R:85.7 range: 286 .. 485 A:66 C:43 G:41 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 287 .. 486 A:66 C:43 G:41 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 288 .. 487 A:66 C:43 G:40 T:51 G+C:83 GC%:41 E:49 R:84.7 range: 289 .. 488 A:66 C:43 G:41 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 290 .. 489 A:66 C:43 G:41 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 291 .. 490 A:67 C:42 G:41 T:50 G+C:83 GC%:41 E:49 R:84.7 range: 292 .. 491 A:68 C:42 G:41 T:49 G+C:83 GC%:41 E:49 R:84.7 range: 293 .. 492 A:67 C:42 G:42 T:49 G+C:84 GC%:42 E:49 R:85.7 range: 294 .. 493 A:67 C:43 G:41 T:49 G+C:84 GC%:42 E:49 R:85.7 range: 295 .. 494 A:67 C:42 G:41 T:50 G+C:83 GC%:41 E:49 R:84.7 range: 296 .. 495 A:67 C:42 G:42 T:49 G+C:84 GC%:42 E:49 R:85.7 range: 297 .. 496 A:66 C:42 G:42 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 298 .. 497 A:66 C:42 G:42 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 299 .. 498 A:66 C:43 G:41 T:50 G+C:84 GC%:42 E:49 R:85.7 range: 300 .. 499 A:65 C:43 G:41 T:51 G+C:84 GC%:42 E:49 R:85.7 range: 301 .. 500 A:65 C:42 G:42 T:51 G+C:84 GC%:42 E:49 R:85.7 range: 302 .. 501 A:64 C:42 G:42 T:52 G+C:84 GC%:42 E:49 R:85.7 range: 303 .. 502 A:63 C:42 G:43 T:52 G+C:85 GC%:42 E:49 R:86.7 range: 304 .. 503 A:63 C:42 G:43 T:52 G+C:85 GC%:42 E:49 R:86.7 range: 305 .. 504 A:63 C:43 G:43 T:51 G+C:86 GC%:43 E:49 R:87.8 range: 306 .. 505 A:63 C:43 G:43 T:51 G+C:86 GC%:43 E:49 R:87.8 range: 307 .. 506 A:63 C:44 G:42 T:51 G+C:86 GC%:43 E:49 R:87.8 range: 308 .. 507 A:63 C:43 G:43 T:51 G+C:86 GC%:43 E:49 R:87.8 range: 309 .. 508 A:62 C:43 G:43 T:52 G+C:86 GC%:43 E:49 R:87.8 range: 310 .. 509 A:61 C:43 G:43 T:53 G+C:86 GC%:43 E:49 R:87.8 range: 311 .. 510 A:61 C:43 G:44 T:52 G+C:87 GC%:43 E:49 R:88.8 range: 312 .. 511 A:62 C:43 G:43 T:52 G+C:86 GC%:43 E:49 R:87.8 range: 313 .. 512 A:62 C:44 G:43 T:51 G+C:87 GC%:43 E:49 R:88.8 range: 314 .. 513 A:62 C:44 G:43 T:51 G+C:87 GC%:43 E:49 R:88.8 range: 315 .. 514 A:63 C:44 G:43 T:50 G+C:87 GC%:43 E:49 R:88.8 range: 316 .. 515 A:63 C:44 G:43 T:50 G+C:87 GC%:43 E:49 R:88.8 range: 317 .. 516 A:63 C:44 G:43 T:50 G+C:87 GC%:43 E:49 R:88.8 range: 318 .. 517 A:62 C:45 G:43 T:50 G+C:88 GC%:44 E:49 R:89.8 range: 319 .. 518 A:63 C:45 G:43 T:49 G+C:88 GC%:44 E:49 R:89.8 range: 320 .. 519 A:64 C:44 G:43 T:49 G+C:87 GC%:43 E:49 R:88.8 range: 321 .. 520 A:64 C:43 G:43 T:50 G+C:86 GC%:43 E:49 R:87.8 range: 322 .. 521 A:64 C:43 G:43 T:50 G+C:86 GC%:43 E:49 R:87.8 range: 323 .. 522 A:64 C:43 G:43 T:50 G+C:86 GC%:43 E:49 R:87.8 range: 324 .. 523 A:64 C:43 G:43 T:50 G+C:86 GC%:43 E:49 R:87.8 range: 325 .. 524 A:64 C:43 G:42 T:51 G+C:85 GC%:42 E:49 R:86.7 range: 326 .. 525 A:64 C:42 G:42 T:52 G+C:84 GC%:42 E:49 R:85.7 range: 327 .. 526 A:65 C:42 G:41 T:52 G+C:83 GC%:41 E:49 R:84.7 range: 328 .. 527 A:64 C:43 G:41 T:52 G+C:84 GC%:42 E:49 R:85.7 range: 329 .. 528 A:65 C:43 G:41 T:51 G+C:84 GC%:42 E:49 R:85.7 range: 330 .. 529 A:65 C:43 G:41 T:51 G+C:84 GC%:42 E:49 R:85.7 range: 331 .. 530 A:65 C:43 G:40 T:52 G+C:83 GC%:41 E:49 R:84.7 range: 332 .. 531 A:66 C:42 G:40 T:52 G+C:82 GC%:41 E:49 R:83.7 range: 333 .. 532 A:66 C:43 G:39 T:52 G+C:82 GC%:41 E:49 R:83.7 range: 334 .. 533 A:67 C:43 G:38 T:52 G+C:81 GC%:40 E:49 R:82.7 range: 335 .. 534 A:66 C:43 G:38 T:53 G+C:81 GC%:40 E:49 R:82.7 range: 602 .. 801 A:63 C:40 G:41 T:56 G+C:81 GC%:40 E:49 R:82.7 range: 654 .. 853 A:67 C:39 G:42 T:52 G+C:81 GC%:40 E:49 R:82.7 range: 655 .. 854 A:68 C:39 G:42 T:51 G+C:81 GC%:40 E:49 R:82.7 range: 656 .. 855 A:68 C:39 G:42 T:51 G+C:81 GC%:40 E:49 R:82.7 range: 657 .. 856 A:67 C:40 G:42 T:51 G+C:82 GC%:41 E:49 R:83.7 range: 658 .. 857 A:68 C:40 G:41 T:51 G+C:81 GC%:40 E:49 R:82.7 range: 659 .. 858 A:67 C:40 G:42 T:51 G+C:82 GC%:41 E:49 R:83.7 range: 660 .. 859 A:67 C:40 G:42 T:51 G+C:82 GC%:41 E:49 R:83.7 range: 661 .. 860 A:67 C:39 G:43 T:51 G+C:82 GC%:41 E:49 R:83.7 range: 662 .. 861 A:67 C:39 G:42 T:52 G+C:81 GC%:40 E:49 R:82.7 range: 663 .. 862 A:67 C:39 G:42 T:52 G+C:81 GC%:40 E:49 R:82.7 range: 664 .. 863 A:68 C:39 G:42 T:51 G+C:81 GC%:40 E:49 R:82.7 range: 762 .. 961 A:61 C:36 G:45 T:58 G+C:81 GC%:40 E:49 R:82.7 range: 763 .. 962 A:61 C:35 G:46 T:58 G+C:81 GC%:40 E:49 R:82.7 range: 764 .. 963 A:60 C:36 G:46 T:58 G+C:82 GC%:41 E:49 R:83.7 range: 765 .. 964 A:59 C:36 G:46 T:59 G+C:82 GC%:41 E:49 R:83.7 range: 766 .. 965 A:58 C:37 G:46 T:59 G+C:83 GC%:41 E:49 R:84.7 range: 767 .. 966 A:58 C:37 G:46 T:59 G+C:83 GC%:41 E:49 R:84.7 range: 768 .. 967 A:59 C:37 G:46 T:58 G+C:83 GC%:41 E:49 R:84.7 range: 769 .. 968 A:60 C:37 G:46 T:57 G+C:83 GC%:41 E:49 R:84.7 range: 770 .. 969 A:61 C:37 G:46 T:56 G+C:83 GC%:41 E:49 R:84.7 range: 771 .. 970 A:61 C:37 G:46 T:56 G+C:83 GC%:41 E:49 R:84.7 range: 772 .. 971 A:61 C:37 G:46 T:56 G+C:83 GC%:41 E:49 R:84.7 range: 773 .. 972 A:61 C:36 G:46 T:57 G+C:82 GC%:41 E:49 R:83.7 range: 774 .. 973 A:62 C:36 G:46 T:56 G+C:82 GC%:41 E:49 R:83.7 range: 775 .. 974 A:61 C:36 G:46 T:57 G+C:82 GC%:41 E:49 R:83.7 range: 776 .. 975 A:60 C:36 G:46 T:58 G+C:82 GC%:41 E:49 R:83.7 range: 777 .. 976 A:59 C:36 G:46 T:59 G+C:82 GC%:41 E:49 R:83.7 range: 778 .. 977 A:59 C:35 G:46 T:60 G+C:81 GC%:40 E:49 R:82.7 range: 779 .. 978 A:59 C:36 G:46 T:59 G+C:82 GC%:41 E:49 R:83.7 range: 780 .. 979 A:59 C:36 G:46 T:59 G+C:82 GC%:41 E:49 R:83.7

This code prints only those regions that have GC% more than 40%. i want to count GC only when there is G and C present together as GC or as CG, and not when G and C present randomly as CAGTGATC. After this i have to calculate GC%. Secondly i have to take my input from file, not to copy my input data in the script. Please help me to solve this.


Comment on Re^4: how to access elements in perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-29 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (213 votes), past polls