Skip to content

Commit

Permalink
feat(refactor): Move sub set_recipe_gatk_variantrecalibration
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstranneheim committed Jan 15, 2021
1 parent a5d0614 commit cc6f66a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 76 deletions.
57 changes: 57 additions & 0 deletions lib/MIP/Analysis.pm
Expand Up @@ -41,6 +41,7 @@ BEGIN {
set_rankvariants_ar
set_recipe_bwa_mem
set_recipe_deepvariant
set_recipe_gatk_variantrecalibration
update_prioritize_flag
update_recipe_mode_for_fastq_compatibility
update_recipe_mode_for_pedigree
Expand Down Expand Up @@ -874,6 +875,62 @@ sub set_recipe_deepvariant {
return;
}

sub set_recipe_gatk_variantrecalibration {

## Function : Update which gatk variant recalibration to use depending on number of samples
## Returns :
## Arguments: $analysis_recipe_href => Analysis recipe hash {REF}
## : $sample_ids_ref => Sample ids {REF}
## : $use_cnnscorevariants => Use gatk cnnscorevariants recipe

my ($arg_href) = @_;

## Flatten argument(s)
my $analysis_recipe_href;
my $sample_ids_ref;
my $use_cnnscorevariants;

my $tmpl = {
analysis_recipe_href => {
default => {},
defined => 1,
required => 1,
store => \$analysis_recipe_href,
strict_type => 1,
},
sample_ids_ref => {
default => [],
defined => 1,
required => 1,
store => \$sample_ids_ref,
strict_type => 1,
},
use_cnnscorevariants => {
store => \$use_cnnscorevariants,
strict_type => 1,
},
};

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

use MIP::Recipes::Analysis::Gatk_cnnscorevariants qw{ analysis_gatk_cnnscorevariants };

## Use already set gatk_variantrecalibration recipe
return if ( @{$sample_ids_ref} != 1 );

return if ( not $use_cnnscorevariants );

my $log = Log::Log4perl->get_logger($LOG_NAME);

$log->warn(
q{Switched from VariantRecalibration to CNNScoreVariants for single sample analysis});

## Use new CNN recipe for single samples
$analysis_recipe_href->{gatk_variantrecalibration} = \&analysis_gatk_cnnscorevariants;

return;
}

sub update_prioritize_flag {

## Function : Update prioritize flag depending on analysis run value as some recipes are not applicable for e.g. wes
Expand Down
6 changes: 3 additions & 3 deletions lib/MIP/Recipes/Pipeline/Analyse_rd_dna.pm
Expand Up @@ -434,10 +434,11 @@ sub pipeline_analyse_rd_dna {

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

use MIP::Analysis qw{ set_rankvariants_ar set_recipe_bwa_mem set_recipe_deepvariant };
use MIP::Analysis
qw{ set_rankvariants_ar set_recipe_bwa_mem set_recipe_deepvariant set_recipe_gatk_variantrecalibration };
use MIP::Log::MIP_log4perl qw{ log_display_recipe_for_user };
use MIP::Parse::Reference qw{ parse_references };
use MIP::Set::Analysis qw{ set_recipe_gatk_variantrecalibration set_recipe_on_analysis_type };
use MIP::Set::Analysis qw{ set_recipe_on_analysis_type };

## Recipes
use MIP::Recipes::Analysis::Analysisrunstatus qw{ analysis_analysisrunstatus };
Expand Down Expand Up @@ -651,7 +652,6 @@ sub pipeline_analyse_rd_dna {
set_recipe_gatk_variantrecalibration(
{
analysis_recipe_href => \%analysis_recipe,
log => $log,
sample_ids_ref => $active_parameter_href->{sample_ids},
use_cnnscorevariants => $active_parameter_href->{gatk_cnnscorevariants},
}
Expand Down
62 changes: 0 additions & 62 deletions lib/MIP/Set/Analysis.pm
Expand Up @@ -23,73 +23,11 @@ BEGIN {

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{
set_recipe_gatk_variantrecalibration
set_recipe_on_analysis_type
set_recipe_star_aln
};
}

sub set_recipe_gatk_variantrecalibration {

## Function : Update which gatk variant recalibration to use depending on number of samples
## Returns :
## Arguments: $analysis_recipe_href => Analysis recipe hash {REF}
## : $log => Log object to write to
## : $sample_ids_ref => Sample ids {REF}
## : $use_cnnscorevariants => Use gatk cnnscorevariants recipe

my ($arg_href) = @_;

## Flatten argument(s)
my $analysis_recipe_href;
my $log;
my $sample_ids_ref;
my $use_cnnscorevariants;

my $tmpl = {
analysis_recipe_href => {
default => {},
defined => 1,
required => 1,
store => \$analysis_recipe_href,
strict_type => 1,
},
log => {
defined => 1,
required => 1,
store => \$log,
},
sample_ids_ref => {
default => [],
defined => 1,
required => 1,
store => \$sample_ids_ref,
strict_type => 1,
},
use_cnnscorevariants => {
store => \$use_cnnscorevariants,
strict_type => 1,
},
};

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

use MIP::Recipes::Analysis::Gatk_cnnscorevariants qw{ analysis_gatk_cnnscorevariants };

## Use already set gatk_variantrecalibration recipe
return if ( @{$sample_ids_ref} != 1 );

return if ( not $use_cnnscorevariants );

$log->warn(
q{Switched from VariantRecalibration to CNNScoreVariants for single sample analysis});

## Use new CNN recipe for single samples
$analysis_recipe_href->{gatk_variantrecalibration} = \&analysis_gatk_cnnscorevariants;

return;
}

sub set_recipe_on_analysis_type {

## Function : Set which recipe to use depending on consensus analysis type
Expand Down
19 changes: 8 additions & 11 deletions t/set_recipe_gatk_variantrecalibration.t
Expand Up @@ -16,7 +16,6 @@ use warnings qw{ FATAL utf8 };
## CPANM
use autodie qw { :all };
use Modern::Perl qw{ 2018 };
use Readonly;

## MIPs lib/
use lib catdir( dirname($Bin), q{lib} );
Expand All @@ -30,14 +29,14 @@ BEGIN {
### Check all internal dependency modules and imports
## Modules with import
my %perl_module = (
q{MIP::Set::Analysis} => [qw{ set_recipe_gatk_variantrecalibration }],
q{MIP::Analysis} => [qw{ set_recipe_gatk_variantrecalibration }],
q{MIP::Test::Fixtures} => [qw{ test_log }],
);

test_import( { perl_module_href => \%perl_module, } );
}

use MIP::Set::Analysis qw{ set_recipe_gatk_variantrecalibration };
use MIP::Analysis qw{ set_recipe_gatk_variantrecalibration };
use MIP::Recipes::Analysis::Gatk_cnnscorevariants qw{ analysis_gatk_cnnscorevariants };

diag( q{Test set_recipe_gatk_variantrecalibration from Analysis.pm}
Expand All @@ -48,50 +47,48 @@ diag( q{Test set_recipe_gatk_variantrecalibration from Analysis.pm}
. $SPACE
. $EXECUTABLE_NAME );

my $log = test_log( { no_screen => 1, } );
test_log( { no_screen => 1, } );

## Given more than a single sample
my %analysis_recipe;
my $gatk_cnnscorevariants = 1;
my @sample_ids = qw{ sample_1 sample_2 };

## When setting the gat variantrecalibration recipe to use
set_recipe_gatk_variantrecalibration(
{
analysis_recipe_href => \%analysis_recipe,
log => $log,
sample_ids_ref => \@sample_ids,
use_cnnscorevariants => $gatk_cnnscorevariants,
}
);

## Then skip setting cnnscorevariants recipe in hash
is( $analysis_recipe{gatk_variantrecalibration},
undef, q{Skip when more than single sample} );
is( $analysis_recipe{gatk_variantrecalibration}, undef, q{Skip when more than single sample} );

## Given single sample, when not to use cnnscorevariants
$gatk_cnnscorevariants = 0;
pop @sample_ids;

## When setting the gat variantrecalibration recipe to use
set_recipe_gatk_variantrecalibration(
{
analysis_recipe_href => \%analysis_recipe,
log => $log,
sample_ids_ref => \@sample_ids,
use_cnnscorevariants => $gatk_cnnscorevariants,
}
);

## Then skip setting cnnscorevariants recipe in hash
is( $analysis_recipe{gatk_variantrecalibration},
undef, q{Skip when not using cnnscorevariants} );
is( $analysis_recipe{gatk_variantrecalibration}, undef, q{Skip when not using cnnscorevariants} );

## Given single sample, when turned on cnnscorevariants
$gatk_cnnscorevariants = 1;

## When setting the gat variantrecalibration recipe to use
set_recipe_gatk_variantrecalibration(
{
analysis_recipe_href => \%analysis_recipe,
log => $log,
sample_ids_ref => \@sample_ids,
use_cnnscorevariants => $gatk_cnnscorevariants,
}
Expand Down

0 comments on commit cc6f66a

Please sign in to comment.