Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Regular expressions across multiple lines

by marioroy (Prior)
on Apr 24, 2016 at 23:12 UTC ( [id://1161406]=note: print w/replies, xml ) Need Help??


in reply to Re: Regular expressions across multiple lines
in thread Regular expressions across multiple lines

The following is a parallel demonstration when extra performance is desired for very large sequences. Otherwise, the serial demonstration is faster.

use strict; use warnings; use BioUtil::Seq; use constant { HDR => 0, SEQ => 1 }; use MCE::Flow; use MCE::Shared; mce_open my $out_fh, '>', \*STDOUT or die "open error: $!\n"; # From the documentation: # # FastaReader returns an anonymous subroutine, when called, returns # a fasta record which is a reference of an array containing the fasta # header and sequence. By default, spaces and \r?\n are trimmed from # the sequence. # mce_flow { max_workers => 4, chunk_size => 1, input_data => FastaReader("input_file.fasta") }, sub { my ( $mce, $chunk_ref, $chunk_id ) = @_; my $fa = $chunk_ref->[0]; # my $fa = $_; # same thing for chunk_size => 1 # therefore, the 2 lines above may be omitted # print ">$fa->[HDR]\n$fa->[SEQ]\n"; my $name = ( split(/ /, $fa->[HDR], 2) )[0]; my $output; while ( $fa->[SEQ] =~ /(?<=(.....))abc(.{10})def(?=(.....))/g ) { $output .= "$name: $1, $2, $3\n"; } print $out_fh $output if length($output); };

Regards, Mario.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-26 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found