Bio-SeqAlignment-Components-SeqMapping
view release on metacpan or search on metacpan
lib/Bio/SeqAlignment/Components/SeqMapping/Dataflow/Linear.pm view on Meta::CPAN
package Bio::SeqAlignment::Components::SeqMapping::Dataflow::Linear;
$Bio::SeqAlignment::Components::SeqMapping::Dataflow::Linear::VERSION = '0.03';
use strict;
use warnings;
use Moose::Role;
use Carp;
use MCE;
use MCE::Candy;
use namespace::autoclean;
requires 'seq_align'; ## the method that does (pseudo)alignment mapping & reductions
requires 'cleanup';
sub sim_seq_search {
my ( $self, $workload, %args ) = @_;
croak 'expect an array(ref) as workload' unless ref $workload eq 'ARRAY';
my $max_workers = $args{max_workers}
// 1; # set default value if not defined
my $chunk_size = $args{chunk_size} // 1; # set default value if not defined
my $cleanup = $args{cleanup} // 1; # set default value if not defined
my @results;
if ( $max_workers == 1 ) {
foreach my $chunk ( @{$workload} ) {
my $reduced_metric = $self->seq_align($chunk);
push @results, $reduced_metric->@*; ## append to the results
$self->cleanup($reduced_metric) if $cleanup;
}
return \@results;
}
else {
my $mce = MCE->new(
max_workers => $max_workers,
chunk_size => $chunk_size,
gather => MCE::Candy::out_iter_array( \@results ),
posix_exit => 1,
user_func => sub {
my ( $mce, $chunk_ref, $chunk_id ) = @_;
my @chunk_results;
foreach my $chunk ( @{$chunk_ref} ) {
my $reduced_metric = $self->seq_align($chunk);
push @chunk_results, $reduced_metric->@*;
$self->cleanup($reduced_metric) if $cleanup;
}
$mce->gather( $chunk_id, @chunk_results );
}
);
$mce->process($workload);
$mce->shutdown();
}
return \@results;
}
1;
=head1 NAME
Bio::SeqAlignment::Components::SeqMapping::Dataflow::Linear - A role to implement a linear dataflow for a non-generic sequence mapper.
=head1 VERSION
version 0.03
=head1 DESCRIPTION
This role provides a linear dataflow for sequence mapping. By that we
( run in 1.444 second using v1.01-cache-2.11-cpan-39bf76dae61 )