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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If the files are very large, you don't want to load the whole file into memory. A more efficient solution would be to only read the last (10 + epsilon) characters of the file (the epsilon "fudge factor" is just in case there is a \r or \r\n within the last 10 characters.

Here is some code I came up with to do this search efficiently:

my $tail_length = 10; sub contains_polytail { my $file = shift; open my $fh, "<$file" or die "Couldn't open $file: $!"; ## only read the last 10 + 2 bytes seek $fh, -( $tail_length + 2), 2; my $tail = do { local $/; <$fh> }; ## ignore newlines and ^M's $tail =~ s/[\r\n]//g; return ($tail =~ /[AN]{$tail_length}$/); } print contains_polytail('test.dna') ? "yes\n" : "no\n";
Important note: this won't tell you the entire polyA tail, just whether there is one. The polyA tail might be 600 characters, it might be 15. If you need the entire tail's contents, you either have to keep reading backwards through the file, or else simply slurp the entire file into memory and use one of the other solutions in this thread. But now you only need to slurp the entire file if you know it contains a polyA tail.


In reply to Re: BioInformatics - polyA tail search by blokhead
in thread BioInformatics - polyA tail search by MiamiGenome

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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2023-03-24 10:27 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.