Skip to content

Commit

Permalink
Merge eb02906 into 70866c4
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstranneheim committed Dec 29, 2020
2 parents 70866c4 + eb02906 commit 14e0088
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 218 deletions.
199 changes: 0 additions & 199 deletions lib/MIP/Get/File.pm
Expand Up @@ -14,7 +14,6 @@ use warnings qw{ FATAL utf8 };

## CPANM
use Readonly;
use List::MoreUtils qw{ any };

## MIPs lib/
use MIP::Constants qw{ $COMMA $DOT $LOG_NAME $PIPE $SPACE };
Expand All @@ -27,7 +26,6 @@ BEGIN {
our @EXPORT_OK = qw{
get_io_files
get_merged_infile_prefix
get_path_entries
};
}

Expand Down Expand Up @@ -249,203 +247,6 @@ sub get_merged_infile_prefix {
return $file_info_href->{$sample_id}{merged_infile};
}

sub get_path_entries {

## Function : Collects all recipes outfile path(s) created by MIP as Path->value located in %sample_info.
## Returns :
## Arguments : $paths_ref => Holds the collected paths {REF}
## : $sample_info_href => Info on samples and case hash {REF}

my ($arg_href) = @_;

## Flatten argument(s)
my $paths_ref;
my $sample_info_href;

my $tmpl = {
paths_ref => {
default => [],
defined => 1,
required => 1,
store => \$paths_ref,
strict_type => 1,
},
sample_info_href => {
default => {},
defined => 1,
required => 1,
store => \$sample_info_href,
strict_type => 1,
},
};

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

## Copy hash to enable recursive removal of keys
my %info = %{$sample_info_href};

## Temporary array for collecting outdirectories within the same recipe
my @outdirectories;

## Temporary array for collecting outfile within the same recipe
my @outfiles;

KEY_VALUE_PAIR:
while ( my ( $key, $value ) = each %info ) {

if ( ref $value eq q{HASH} ) {

get_path_entries(
{
paths_ref => $paths_ref,
sample_info_href => $value,
}
);
}
else {

## Required for first dry-run
next KEY_VALUE_PAIR if ( not $value );

## Check if key is "path" and adds value to @paths_ref if true.
_check_and_add_to_array(
{
key => $key,
paths_ref => $paths_ref,
value => $value,
}
);

## Check if key is "outdirectory" or "outfile" and adds joined value to @paths_ref if true.
_collect_outfile(
{
key => $key,
paths_ref => $paths_ref,
outdirectories_ref => \@outdirectories,
outfiles_ref => \@outfiles,
value => $value,
}
);

delete $info{$value};
}
}
return;
}

sub _check_and_add_to_array {

## Function : Check if Key name is "path" and adds to @paths_ref if true.
## Returns :
## Arguments : $keyName => Hash key
## : $paths_ref => Holds the collected paths {REF}
## : $value => Hash value

my ($arg_href) = @_;

## Flatten argument(s)
my $key;
my $paths_ref;
my $value;

my $tmpl = {
key => { defined => 1, required => 1, store => \$key, strict_type => 1, },
paths_ref => {
default => [],
defined => 1,
required => 1,
store => \$paths_ref,
strict_type => 1,
},
value => { required => 1, store => \$value, },
};

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

return if ( $key ne q{path} );

## Do not add same path twice
if ( not any { $_ eq $value } @{$paths_ref} ) {

push @{$paths_ref}, $value;
}
return;
}

sub _collect_outfile {

## Function : Check if Key name is "outdirectory" or "outfile" and adds to @paths_ref if true.
## Returns :
## Arguments : $key => Hash key
## : $outdirectories_ref => Holds temporary outdirectory path(s) {Optional, REF}
## : $outfiles_ref => Holds temporary outdirectory path(s) {Optional, REF}
## : $value => Hash value
## : $paths_ref => Holds the collected paths {REF}

my ($arg_href) = @_;

## Flatten argument(s)
my $key;
my $outdirectories_ref;
my $outfiles_ref;
my $paths_ref;
my $value;

my $tmpl = {
paths_ref => {
default => [],
defined => 1,
required => 1,
store => \$paths_ref,
strict_type => 1,
},
outdirectories_ref => {
default => [],
defined => 1,
required => 1,
store => \$outdirectories_ref,
strict_type => 1,
},
outfiles_ref => {
default => [],
defined => 1,
required => 1,
store => \$outfiles_ref,
strict_type => 1,
},
value => { defined => 1, required => 1, store => \$value, },
key => { defined => 1, store => \$key, required => 1, strict_type => 1, },
};

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

if ( $key eq q{outdirectory} ) {

push @{$outdirectories_ref}, $value;
}
if ( $key eq q{outfile} ) {

push @{$outfiles_ref}, $value;
}

## Both outdirectory and outfile have been collected, time to join
if ( @{$outdirectories_ref} && @{$outfiles_ref} ) {

my $path = catfile( $outdirectories_ref->[0], $outfiles_ref->[0] );

## Do not add same path twice
if ( not any { $_ eq $path } @{$paths_ref} ) {

push @{$paths_ref}, catfile( $outdirectories_ref->[0], $outfiles_ref->[0] );

## Restart
@{$outdirectories_ref} = ();
@{$outfiles_ref} = ();
}
}
return;
}

sub _inherit_upstream_io_files {

## Function : Switch upstream out to recipe in - i.e. inherit from upstream
Expand Down
22 changes: 8 additions & 14 deletions lib/MIP/Recipes/Analysis/Analysisrunstatus.pm
Expand Up @@ -112,10 +112,10 @@ sub analysis_analysisrunstatus {

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

use MIP::Get::File qw{ get_path_entries };
use MIP::Get::Parameter qw{ get_recipe_resources };
use MIP::Language::Shell qw{ check_mip_process_paths };
use MIP::Processmanagement::Processes qw{ submit_recipe };
use MIP::Sample_info qw{ get_path_entries };
use MIP::Script::Setup_script qw{ setup_script };

Readonly my $FINAL_VCFS_RECIPE => q{endvariantannotationblock};
Expand Down Expand Up @@ -355,19 +355,13 @@ sub _check_string_within_file {
say {$filehandle} $TAB . q?STATUS="1"?;

## Echo FAILED
say {$filehandle} $TAB
. q?echo "String match status=FAILED for file: ?
. $file
. q?" >&2?;
say {$filehandle} $TAB . q?echo "String match status=FAILED for file: ? . $file . q?" >&2?;

## Infile is clean
say {$filehandle} q?else?;

## Echo PASSED
say {$filehandle} $TAB
. q?echo "String match status=PASSED for file: ?
. $file
. q?" >&2?;
say {$filehandle} $TAB . q?echo "String match status=PASSED for file: ? . $file . q?" >&2?;
say {$filehandle} q?fi?, $NEWLINE;
}
return;
Expand Down Expand Up @@ -431,11 +425,11 @@ sub _check_vcf_header_and_keys {
next MODE if ( not defined $vcf_file_path );

$vcf_file_path = remove_file_path_suffix(
{
file_path => $vcf_file_path,
file_suffixes_ref => [qw{ .gz}],
}
);
{
file_path => $vcf_file_path,
file_suffixes_ref => [qw{ .gz}],
}
);

print {$filehandle} q?perl -MTest::Harness -e ' ?;

Expand Down

0 comments on commit 14e0088

Please sign in to comment.