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

Re: BioInformatics - polyA tail search

by blokhead (Monsignor)
on Sep 02, 2003 at 19:32 UTC ( [id://288400]=note: print w/replies, xml ) Need Help??


in reply to BioInformatics - polyA tail search

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.

blokhead

Replies are listed 'Best First'.
Re: Re: BioInformatics - polyA tail search
by Arbogast (Monk) on Sep 03, 2003 at 00:59 UTC
    I wrote a simple program for something similar once. Seemed like you needed to account for inexact matches, if it was a real world and not an academic problem.

    You might want to look at the CPAN module String::Approx. It aint a speed demon, but it seemed to work.

    http://search.cpan.org/author/JHI/String-Approx-3.20/Approx.pm

    Please forgive if I am wrong, I know a little Perl and even less Genetics.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://288400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-19 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found