Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have a script which extracts equal length DNA-sequences at user-specified positions from a genome and then calculates the frequency at which each letter (A/G/C/T) occurred at each position.

The user-specific positions can also come with a frequency - how many times that point was seen.

If this frequency is ignored (i.e. position-weighted analysis), the script runs at a satisfactory speed. However, it is when the frequencies are taken into consideration that it is considerably slow.

My approach for this has been:

if ($mode eq "Position") { push (@data, $string); } elsif ($mode eq "Freq") { push (@data, $string) for (1..$F[2]); } my %freq; for my $i (1..@data) { $freq{$1}[$-[0]] += 1/@data while $data[$i-1] =~ /(.)/g; }

Which is evidently inefficient and quite literal - i.e. add that sequence X(freq) number of times into the array.

Is there a better way to do weighted frequency calculations and if so, how?

EDIT: The sequences can range from 30 to 250 characters. Weighting occurs at an average of 26, but with a range of 5-3565 for one particular sample. In any given run, around 200,000 unique positions exist within the input data.


In reply to Weighted frequency of characters in an array of strings by K_Edw

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found