Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: control DNA file with perl

by polypompholyx (Chaplain)
on Sep 06, 2013 at 08:17 UTC ( #1052671=note: print w/replies, xml ) Need Help??


in reply to control DNA file with perl

Something like the code below works, for some value of 'works'. If there are Us, Ns, spaces, blank lines, or lowercase bases, then it won't, and I would suggest you add some sanity checking.

However, you've not really explained what a position frequency matrix is (I'm taking an informed guess). It would also have been helpful to have seen what code you had already attempted so we could comment on that, rather than having the sneaking suspicion we're doing your homework for you. See How (Not) To Ask A Question

use strict; my @pmf; my $count = 0; while( my $seq = <DATA> ) { $count++; chomp $seq; my @bases = split //, $seq; for my $i ( 0 .. $#bases ) { $pmf[ $i ]{ $bases[$i] }++; } } for my $i ( 0 .. $#pmf ) { printf "%3u: ", $i; for my $base ( qw{ A C G T } ) { printf "$base %3.0f, ", 100 * $pmf[ $i ]{ $base } / $count; } print "\n"; } __DATA__ ATTCATCTCTCGG ATTGTGAGATAGA AAGATGATCGCTC AGATAGATCGCTG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052671]
help
Chatterbox?
[ambrus]: GotToBTru: wait, you tell only the atom totals of what you want? Is that like ordering food in a restaurant by telling only the nutrient amounts you need, or
[ambrus]: like when a medieval scientist supposedly proves his priority inventing something by having previously published an anagram of a thousand letters long summary of the invention?
[choroba]: Progress! Nowadays, you can write a Perl script to generate such an anagram!
[GotToBTru]: i like to order my chemicals a-la-carte ambrus ;)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2016-12-06 13:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.