Hi heavenfeel,
The following is a demonstration using the MCE::Loop module. What is nice about MCE is the ability to process a file containing multiple records. The record separator for a fastq file is "\n@" which anchors @ at the start of the line. MCE detects "\n" at the start of the record separator.
MCE is a chunking engine allowing a worker to receive several records at a time. The effect is a reduction in the number of trips to and from the MCE-manager process.
The logic below allows one to search multiple patterns. Simply change the patterns to suite your needs. Perhaps, this can read patterns stored in a file. Anyway, this is a small MCE demonstration. The MCE->print statement prints the entire record to STDOUT.
use strict;
use warnings;
use MCE::Loop;
my @patterns = ( "biopattern1", "biopattern2", "biopattern3" );
my $search = join('|', @patterns);
my $regex = qr/$search/;
open my $fh, "gunzip -c in.fastq.gz |" or die "open error: $!";
MCE::Loop->init(
max_workers => 4,
chunk_size => 50,
RS => "\n@"
);
MCE::Loop->run( sub {
my ( $mce, $chunk_ref, $chunk_id ) = @_;
for my $i ( 0 .. $#{ $chunk_ref } ) {
if ( $chunk_ref->[$i] =~ /$regex/ ) {
MCE->print( $chunk_ref->[$i] );
}
}
}, $fh );
MCE::Loop->finish();
close $fh;
Kind regards,
Mario
-
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.