Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Extracting Data from .txt file

by drhicks (Novice)
on Apr 25, 2012 at 22:01 UTC ( #967188=perlquestion: print w/ replies, xml ) Need Help??
drhicks has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I made a simple perl script to determine the codon usage frequencies f +or each amino acid based on data in a text file. So far it works to d +etermine the frequencies, but I have to input codon usage for each am +ino acid manually... I am trying to get it to automatically extract t +he data that I need. I want to extract the interger value for each codon and store it like +so: (example my $UUU = 291490; my $UCU = 244291; etc etc etc). I am f +airly new to programming and am having a hard time getting the data e +xtracted and stored properly. The text file is saved to my desktop and formatted like so: Vitis vinifera [gbpln]: 24140 CDS's (11557387 codons) fields: [triplet] [frequency: per thousand] ([number]) UUU 25.2(291490) UCU 21.1(244291) UAU 17.9(206846) UGU 10.8(125132) UUC 18.6(215288) UCC 12.6(145986) UAC 10.5(121432) UGC 8.2( 94398) UUA 13.5(156031) UCA 18.7(215994) UAA 0.6( 6828) UGA 0.9( 10455) UUG 25.1(289607) UCG 5.6( 64626) UAG 0.6( 6815) UGG 15.6(180435) CUU 22.1(255515) CCU 18.7(216148) CAU 17.9(206688) CGU 6.0( 69669) CUC 13.5(156457) CCC 9.1(105200) CAC 9.1(105740) CGC 4.7( 53766) CUA 11.2(128918) CCA 18.3(211478) CAA 22.2(256139) CGA 6.6( 76515) CUG 12.2(141100) CCG 5.2( 60461) CAG 15.9(184009) CGG 5.2( 59827) AUU 26.1(301597) ACU 17.7(204752) AAU 26.1(301492) AGU 14.1(162715) AUC 15.7(181341) ACC 11.0(127287) AAC 14.6(168187) AGC 10.3(118518) AUA 13.7(158431) ACA 15.5(179134) AAA 29.2(337782) AGA 18.6(214862) AUG 26.1(301968) ACG 4.3( 49960) AAG 33.6(388634) AGG 16.0(185039) GUU 23.3(268788) GCU 23.1(267133) GAU 34.9(403518) GGU 16.8(194580) GUC 10.9(126346) GCC 13.4(155209) GAC 16.1(186142) GGC 10.9(126426) GUA 10.4(120284) GCA 19.8(229251) GAA 32.4(374017) GGA 20.1(231880) GUG 19.6(226898) GCG 5.1( 58533) GAG 32.4(374052) GGG 14.7(169347) Coding GC 44.24% 1st letter GC 50.18% 2nd letter GC 39.88% 3rd letter +GC 42.65% THANKS for any help, Derrick

Comment on Extracting Data from .txt file
Download Code
Re: Extracting Data from .txt file
by trizen (Friar) on Apr 25, 2012 at 22:58 UTC
    my %data; while (<DATA>) { while (/\b([A-Z]{3})\s+\d+(?:\.\d+)?\(\s*(\d+)\)/g) { $data{$1} = $2; } } print $data{UAU}; # prints 206846
Re: Extracting Data from .txt file
by 2teez (Priest) on Apr 25, 2012 at 23:34 UTC

    Like this:

    use warnings; use strict; my %hash_val; while (<>) { while (/\b([[:alpha:]]{3}).+?\(.+?(\d+?)\)/gs) { $hash_val{$1} = $2; } } print $_,'=',$hash_val{$_},$/ foreach keys %hash_val;
Re: Extracting Data from .txt file
by Anonymous Monk on Apr 26, 2012 at 04:26 UTC
    Thanks Guys that was perfect!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (17)
As of 2014-10-23 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (126 votes), past polls