Sorry 'nall, but that is a ludicrous suggestion.

On a file of around 1GB of randomly generated DNA data:

C:\test>dir randDNA.txt 10/06/2012 01:13 1,036,000,000 randDNA.txt C:\test>head randDNA.txt ATAGTAAGGGACCTCAGCGAGTGTCATAAATATAAGTTGTCGAGAGGTAACGATAGACGCCAATCACTTT +TA GCATCCAGGGGGTCAGTGTCCTAGCGACGTGGAACAACGACTACGCTTCGTAGGTCTCACCGTATAGATG +CC CGGGAGGCCTGCAAAGGAGTGAAGGGTAACGCCTGAACCCTTTGGCCTATCTACGTCGAGATTTCTACCG +GA GCGGAGATCTCCCCCCGGATTTCGTCAAATTCTGGAAATAAGTGTAGCAACCGAACGGTATAGCCAGATA +AT GCTCGAGCACACGCGGACGGTCTCAGAAACTAATTTTCTTAAGCTGGAACAGGCAACCAAAGATTTTAGA +TT ATCGGACGTAGCCAGAAGTGCGGATTTACAGCAACGCCTTTCTCAAAAGTTGCCGTCCCGCGGCACTAAT +AC ACCGATATGAAGGCGCTGAAACGATTATGTGTAGTGACGTGCCTTTCAGCGGCTATGGACGCTATCCCCG +CA GTCATGAGTCCAATTTGGGGTTAGCTGAAATAACCTGCTGTCCCCTAAAATTGTCGCATTCAAGCAGGGT +GG CGGGTACACATGCTAGCATCCGGACGCTATAAGGGCTCCCTTAGTAACATTTCCACTTTCTTGATATTTG +TG GGTGCGTTTAACGACGTCATTACTATGAGAGTCGGTATAGCCATCACATAATGACTCGAGCTTACGTCCT +AC

This short script reads that into a single scalar and searches it for a single short sequence and prints out the 15000+ offsets where it is found in just over eleven seconds:

#! perl -slw use strict; use Time::HiRes qw[ time ]; my $start = time(); local $/; my $DNA = <>; $DNA =~ tr[\n][]d; my $seek = 'AGAGAGAA'; my $p = 0; printf "%s found at position %d\n", $seek, $p while $p = 1+index $DNA, $seek, $p; printf STDERR "Took %.3f seconds\n", time() - $start; __END__ C:\test>DNAsearch1 randDNA.txt | wc -l Took 11.281 seconds 15313

This does the same thing using your 100 bytes-at-a-time method:

#! perl -slw use strict; use Time::HiRes qw[ time ]; my $seek = 'AGAGAGAA'; my $start = time(); my $file = shift; open DNA, '<', $file or die $!; my $size = -s( *DNA ); for my $o ( 1 .. $size - 100 ) { read( DNA, my $DNA, 100 ); $DNA =~ tr[\n][]d; my $p =0; printf "%s found at position %d\n", $seek, $p while $p = 1+index $DNA, $seek, $p; seek( DNA, $o, 0 ); } printf "Took %.3f seconds\n", time() - $start; __END__ [ 1:32:07.24] C:\test>DNAsearch2 randDNA.txt | wc -l 1441865 [ 4:12:28.90] C:\test>

It has been running for 30+ minutes now and I don't expect it to finish anytime soon, so I'll leave it running and report back tomorrow.

Updated above: Over 2 1/2 hours and 1.4 million hits instead of 15,000.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


In reply to Re^2: How to store large strings? by BrowserUk
in thread How to store large strings? by Anonymous Monk

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, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.