Skip to content

Commit

Permalink
Merge pull request #1677 from Clinical-Genomics/smncopy_sample_2
Browse files Browse the repository at this point in the history
Smncopy sample 2
  • Loading branch information
henrikstranneheim authored Sep 17, 2020
2 parents 2289d4e + 9cf85fa commit 2a725e1
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [9.0.1]
- Use sample_id in smncopynumber caller instead of file_name_prefix

## [9.0.0]
- Moved annotationof CADD and SPIDEX to vcfanno´s toml config
- Removed CADD and SPIDEX annotations from Rankvariants recipe, CLI and parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/MIP/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Readonly our %ANALYSIS => (
);

## Set MIP version
Readonly our $MIP_VERSION => q{v9.0.0};
Readonly our $MIP_VERSION => q{v9.0.1};

## Cli
Readonly our $MOOSEX_APP_SCEEN_WIDTH => 160;
Expand Down
75 changes: 72 additions & 3 deletions lib/MIP/Recipes/Analysis/Smncopynumbercaller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ use autodie qw{ :all };
use Readonly;

## MIPs lib/
use MIP::Constants qw{ $GENOME_VERSION $LOG_NAME $NEWLINE $UNDERSCORE };
use MIP::Constants
qw{ $GENOME_VERSION $LOG_NAME $NEWLINE $SINGLE_QUOTE $SPACE $UNDERSCORE };

BEGIN {

require Exporter;
use base qw{ Exporter };

# Set the version for version checking
our $VERSION = 1.02;
our $VERSION = 1.03;

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{ analysis_smncopynumbercaller };
Expand Down Expand Up @@ -117,6 +118,7 @@ sub analysis_smncopynumbercaller {

use MIP::Get::File qw{ get_io_files };
use MIP::Get::Parameter qw{get_recipe_attributes get_recipe_resources };
use MIP::Language::Perl qw{ perl_base };
use MIP::Program::Gnu::Coreutils qw{ gnu_echo };
use MIP::Parse::File qw{ parse_io_outfiles };
use MIP::Processmanagement::Processes qw{ submit_recipe };
Expand Down Expand Up @@ -146,6 +148,7 @@ sub analysis_smncopynumbercaller {
);

my @infile_paths;
my %sample_file_prefix;
SAMPLE_ID:
foreach my $sample_id ( @{ $active_parameter_href->{sample_ids} } ) {

Expand All @@ -159,9 +162,11 @@ sub analysis_smncopynumbercaller {
stream => q{in},
}
);
my $file_name_prefix = $sample_io{in}{file_name_prefix};
my $file_path_prefix = $sample_io{in}{file_path_prefix};
my $file_suffix = $sample_io{in}{file_suffix};
push @infile_paths, $file_path_prefix . $file_suffix;
$sample_file_prefix{$sample_id} = $file_name_prefix;
}

my %io = parse_io_outfiles(
Expand Down Expand Up @@ -204,7 +209,7 @@ sub analysis_smncopynumbercaller {

say {$filehandle} q{## } . $recipe_name;

## Create manifest file
## Create manifest file
my $manifest_file_path = catfile( $outdir_path_prefix, q{manifest.txt} );

gnu_echo(
Expand All @@ -230,6 +235,14 @@ sub analysis_smncopynumbercaller {
);
say {$filehandle} $NEWLINE;

_use_sample_id_in_output(
{
filehandle => $filehandle,
outfile_path => $outfile_path,
sample_file_prefix_href => \%sample_file_prefix,
}
);

## Close filehandleS
close $filehandle or $log->logcroak(q{Could not close filehandle});

Expand Down Expand Up @@ -274,4 +287,60 @@ sub analysis_smncopynumbercaller {
return 1;
}

sub _use_sample_id_in_output {

## Function : Rename file_name_prefix to sample_id for sample column
## Returns :
## Arguments: $filehandle => Filehandle to write to
## : $outfile_path => Outfile path to use for search and replace
## : $sample_file_prefix_href => Map of file_name_prefix and sample_id

my ($arg_href) = @_;

## Flatten argument(s)
my $filehandle;
my $outfile_path;
my $sample_file_prefix_href;

my $tmpl = {
filehandle => {
required => 1,
store => \$filehandle,
},
outfile_path => {
defined => 1,
required => 1,
store => \$outfile_path,
strict_type => 1,
},
sample_file_prefix_href => {
default => {},
defined => 1,
required => 1,
store => \$sample_file_prefix_href,
strict_type => 1,
},
};

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

while ( my ( $sample_id, $file_name_prefix ) = each %{$sample_file_prefix_href} ) {

my @perl_commands = perl_base(
{
command_line => 1,
inplace => 1,
print => 1,
}
);
push @perl_commands,
(
$SINGLE_QUOTE, qq{s/$file_name_prefix/$sample_id/g},
$SINGLE_QUOTE, $outfile_path
);
say {$filehandle} join $SPACE, @perl_commands;
}
return;
}

1;

0 comments on commit 2a725e1

Please sign in to comment.