Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amend _alignment_command() to allow creation and interrogation of def… #542

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 56 additions & 20 deletions lib/npg_pipeline/function/seq_alignment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ Readonly::Array my @RNA_ANALYSES => qw{tophat2 star hisat2};
Readonly::Scalar my $PFC_MARKDUP_OPT_DIST => q{2500}; # distance in pixels for optical duplicate detection on patterned flowcells
Readonly::Scalar my $NON_PFC_MARKDUP_OPT_DIST => q{100}; # distance in pixels for optical duplicate detection on non-patterned flowcells

Readonly::Scalar my $MARKDUP_DEFAULT => q{biobambam};
Readonly::Scalar our $GENERATE_MODE_DEFAULT => 0;
Readonly::Scalar our $GENERATE_MODE_NOWRITE => 1;
Readonly::Scalar our $GENERATE_MODE_DRY_RUN => 2;

=head2 p4_params

P4 parameters generated (per data product)

=cut

has 'p4_params' => ( isa => 'HashRef',
is => 'ro',
required => 0,
default => sub {return {};},
);

around 'markdup_method' => sub {
my $orig = shift;
my $self = shift;
Expand Down Expand Up @@ -126,18 +143,31 @@ has '_do_gbs_plex_analysis' => ( isa => 'Bool',
);

sub generate {
my ($self, $pipeline_name, $dry_run) = @_;
my ($self, $pipeline_name, $mode) = @_;

$mode //= $GENERATE_MODE_DEFAULT;
my @definitions = ();

for my $dp (@{$self->products->{data_products}}) {
my $ref = {};
$ref->{'memory'} = $MEMORY;
my $subsets = [];
$ref->{'command'} = $self->_alignment_command($dp, $ref, $subsets, $dry_run);
$self->_save_compositions($dp, $subsets);
if (!$dry_run) {
push @definitions, $self->_create_definition($ref, $dp);
my $file_name_root = $dp->file_name_root;
my $ac_results = $self->_alignment_command($dp);
$ac_results->{'ref'}->{'command'} //= q[]; #??
$ac_results->{'ref'}->{'memory'} //= $MEMORY;
$ac_results->{'subsets'} ||= [];
$self->p4_params->{$file_name_root} = $ac_results->{'p4_params'}->{'contents'};

push @definitions, $self->_create_definition($ac_results->{'ref'}, $dp);

if($mode != $GENERATE_MODE_NOWRITE) {

# write p4 parameters to file
my $param_vals_fname = join q{/}, $self->_p4_stage2_params_path, $file_name_root.q{_p4s2_pv_in.json};
write_file($ac_results->{'p4_params'}->{'filename'}, encode_json($ac_results->{'p4_params'}->{'contents'}));

$self->_save_compositions($dp, $ac_results->{'subsets'});
}
elsif($mode == $GENERATE_MODE_DRY_RUN) {
$self->_save_compositions($dp, $ac_results->{'subsets'});
}
}

Expand All @@ -151,8 +181,8 @@ sub generate_compositions {
# Pipeline name is always passed by the calling function.
# If we want to use an extra flag, it should be passed
# as a second argument to generate().
my $dry_run = 1;
$self->generate($pipeline_name, $dry_run);
my $mode = $GENERATE_MODE_DRY_RUN;
$self->generate($pipeline_name, $mode);
return [npg_pipeline::function::definition->new(
created_by => __PACKAGE__,
created_on => $self->timestamp(),
Expand Down Expand Up @@ -191,7 +221,10 @@ sub _create_definition {
}

sub _alignment_command { ## no critic (Subroutines::ProhibitExcessComplexity)
my ( $self, $dp, $ref, $subsets, $dry_run) = @_;
my ( $self, $dp) = @_;

my $subsets = [];
my $ref = {};

########################################################
# derive base parameters from supplied data_product (dp)
Expand Down Expand Up @@ -599,15 +632,9 @@ sub _alignment_command { ## no critic (Subroutines::ProhibitExcessComplexity)
if($nchs) {
push @{$subsets}, 'human';
}
##############################################
return if $dry_run; # Early return, we only need a list of subsets
##############################################

# write p4 parameters to file
my $param_vals_fname = join q{/}, $self->_p4_stage2_params_path(q[POSITION]),
$name_root.q{_p4s2_pv_in.json};
write_file($param_vals_fname, encode_json(
{ assign => [ $p4_param_vals ], assign_local => $p4_local_assignments, ops => $p4_ops }));
# generate p4 parameters file name
my $param_vals_fname = join q{/}, $self->_p4_stage2_params_path, $name_root.q{_p4s2_pv_in.json};

####################
# log run parameters
Expand Down Expand Up @@ -636,7 +663,7 @@ sub _alignment_command { ## no critic (Subroutines::ProhibitExcessComplexity)

my $num_threads_expression = q[npg_pipeline_job_env_to_threads --num_threads ] . $self->_num_cpus->[0];
my $id = $self->_job_id();
return join q( ),
$ref->{'command'} = join q( ),
q(bash -c '),
q(mkdir -p), $working_dir, q{;},
q(cd), $working_dir,
Expand Down Expand Up @@ -687,6 +714,15 @@ sub _alignment_command { ## no critic (Subroutines::ProhibitExcessComplexity)
),

q(');

return {
ref => $ref,
subsets => $subsets,
p4_params => {
filename => $param_vals_fname,
contents => {assign => [ $p4_param_vals ], assign_local => $p4_local_assignments, ops => $p4_ops}
}
};
}

sub _qc_command {##no critic (Subroutines::ProhibitManyArgs)
Expand Down