Skip to content

Commit

Permalink
Merge pull request #1820 from Clinical-Genomics/feature/rename_star_f…
Browse files Browse the repository at this point in the history
…usion_out

feat(star_fusion): rename outfile
  • Loading branch information
jemten committed Mar 1, 2021
2 parents f3ecff6 + 0e84958 commit 9a4246c
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 52 deletions.
2 changes: 1 addition & 1 deletion definitions/rd_rna_parameters.yaml
Expand Up @@ -397,7 +397,7 @@ star_fusion:
- mip
data_type: SCALAR
default: 1
file_tag: _fusion
file_tag: _starfusion
outfile_suffix: ".tsv"
program_executables:
- gtf_file_to_feature_seqs.pl
Expand Down
35 changes: 35 additions & 0 deletions lib/MIP/File_info.pm
Expand Up @@ -33,6 +33,7 @@ BEGIN {
get_io_files
get_is_sample_files_compressed
get_merged_infile_prefix
get_sample_fastq_file_lanes
get_sample_file_attribute
get_sampling_fastq_files
parse_file_compression_features
Expand Down Expand Up @@ -685,6 +686,40 @@ sub get_sample_file_attribute {
return $stored_attribute;
}

sub get_sample_fastq_file_lanes {

## Function : Get sample fastq file lanes
## Returns :
## Arguments: $file_info_href => File info hash {REF}
## : $sample_id => Sample id

my ($arg_href) = @_;

## Flatten argument(s)
my $file_info_href;
my $sample_id;

my $tmpl = {
file_info_href => {
default => {},
defined => 1,
required => 1,
store => \$file_info_href,
strict_type => 1,
},
sample_id => {
defined => 1,
required => 1,
store => \$sample_id,
strict_type => 1,
},
};

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

return @{ $file_info_href->{$sample_id}{lanes} };
}

sub get_sampling_fastq_files {

## Function : Get sample fastq files. Either single-end, paired-end or interleaved
Expand Down
39 changes: 22 additions & 17 deletions lib/MIP/Recipes/Analysis/Arriba.pm
Expand Up @@ -132,7 +132,8 @@ sub analysis_arriba {

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

use MIP::File_info qw{ get_io_files get_sample_file_attribute parse_io_outfiles };
use MIP::File_info
qw{ get_io_files get_sample_fastq_file_lanes get_sample_file_attribute parse_io_outfiles };
use MIP::Program::Gnu::Coreutils qw{ gnu_rm gnu_tee };
use MIP::Processmanagement::Processes qw{ submit_recipe };
use MIP::Program::Arriba qw{ arriba draw_fusions };
Expand Down Expand Up @@ -165,7 +166,6 @@ sub analysis_arriba {
);
my @infile_paths = @{ $io{in}{file_paths} };

## Build outfile_paths
my %recipe = parse_recipe_prerequisites(
{
active_parameter_href => $active_parameter_href,
Expand All @@ -174,29 +174,34 @@ sub analysis_arriba {
}
);

my $outsample_directory =
catdir( $active_parameter_href->{outdata_dir}, $sample_id, $recipe_name );
my $lanes_id = join $EMPTY_STR, @{ $file_info_href->{$sample_id}{lanes} };
my $outfile_tag = $file_info_href->{$sample_id}{$recipe_name}{file_tag};
my $outfile_suffix = $recipe{outfile_suffix};
my $outfile_path_prefix = catfile( $outsample_directory,
$sample_id . $UNDERSCORE . q{lanes} . $UNDERSCORE . $lanes_id . $outfile_tag );

## Join infile lanes
my $lanes_id = join $EMPTY_STR,
get_sample_fastq_file_lanes(
{
file_info_href => $file_info_href,
sample_id => $sample_id,
}
);
%io = (
%io,
parse_io_outfiles(
{
chain_id => $recipe{job_id_chain},
chain_id => $recipe{job_id_chain},
file_info_href => $file_info_href,
file_name_prefixes_ref =>
[ $sample_id . $UNDERSCORE . q{lanes} . $UNDERSCORE . $lanes_id ],
id => $sample_id,
file_info_href => $file_info_href,
file_paths_ref => [ $outfile_path_prefix . $outfile_suffix ],
outdata_dir => $active_parameter_href->{outdata_dir},
parameter_href => $parameter_href,
recipe_name => $recipe_name,
}
)
);
my $outfile_name = ${ $io{out}{file_names} }[0];
my $outfile_path = $io{out}{file_path};
my $outdir_path = $io{out}{dir_path};
my $outfile_name = ${ $io{out}{file_names} }[0];
my $outfile_path = $io{out}{file_path};
my $outfile_path_prefix = $io{out}{file_path_prefix};
my $outfile_suffix = $io{out}{file_suffix};

my $use_sample_id_as_display_name =
$active_parameter_href->{arriba_use_sample_id_as_display_name};
Expand Down Expand Up @@ -394,8 +399,8 @@ sub analysis_arriba {
);
if ( $sample_display_name and not $use_sample_id_as_display_name ) {

$report_path = catfile( $outsample_directory,
$sample_display_name . $UNDERSCORE . q{arriba_fusions.pdf} );
$report_path =
catfile( $outdir_path, $sample_display_name . $UNDERSCORE . q{arriba_fusions.pdf} );
}
draw_fusions(
{
Expand Down
33 changes: 19 additions & 14 deletions lib/MIP/Recipes/Analysis/Star_aln.pm
Expand Up @@ -126,7 +126,8 @@ sub analysis_star_aln {

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

use MIP::File_info qw{ get_io_files get_sample_file_attribute parse_io_outfiles };
use MIP::File_info
qw{ get_io_files get_sample_fastq_file_lanes get_sample_file_attribute parse_io_outfiles };
use MIP::Program::Gnu::Coreutils qw{ gnu_mv gnu_rm };
use MIP::Program::Samtools qw{ samtools_index };
use MIP::Program::Star qw{ star_aln };
Expand Down Expand Up @@ -165,29 +166,33 @@ sub analysis_star_aln {
}
);

my $outsample_directory =
catdir( $active_parameter_href->{outdata_dir}, $sample_id, $recipe_name );
my $lanes_id = join $EMPTY_STR, @{ $file_info_href->{$sample_id}{lanes} };
my $outfile_tag = $file_info_href->{$sample_id}{$recipe_name}{file_tag};
my $outfile_suffix = $recipe{outfile_suffix};
my $outfile_path_prefix = catfile( $outsample_directory,
$sample_id . $UNDERSCORE . q{lanes} . $UNDERSCORE . $lanes_id . $outfile_tag );

## Join infile lanes
my $lanes_id = join $EMPTY_STR,
get_sample_fastq_file_lanes(
{
file_info_href => $file_info_href,
sample_id => $sample_id,
}
);
%io = (
%io,
parse_io_outfiles(
{
chain_id => $recipe{job_id_chain},
chain_id => $recipe{job_id_chain},
file_info_href => $file_info_href,
file_name_prefixes_ref =>
[ $sample_id . $UNDERSCORE . q{lanes} . $UNDERSCORE . $lanes_id ],
id => $sample_id,
file_info_href => $file_info_href,
file_paths_ref => [ $outfile_path_prefix . $outfile_suffix ],
outdata_dir => $active_parameter_href->{outdata_dir},
parameter_href => $parameter_href,
recipe_name => $recipe_name,
}
)
);
my $outfile_name = ${ $io{out}{file_names} }[0];
my $outfile_path = $io{out}{file_path};
my $outfile_name = ${ $io{out}{file_names} }[0];
my $outfile_path = $io{out}{file_path};
my $outfile_path_prefix = $io{out}{file_path_prefix};
my $outfile_suffix = $io{out}{file_suffix};

## Filehandles
# Create anonymous filehandle
Expand Down
60 changes: 48 additions & 12 deletions lib/MIP/Recipes/Analysis/Star_fusion.pm
Expand Up @@ -16,7 +16,7 @@ use autodie qw{ :all };
use Readonly;

## MIPs lib/
use MIP::Constants qw{ $ASTERISK $LOG_NAME $NEWLINE $UNDERSCORE };
use MIP::Constants qw{ $ASTERISK $EMPTY_STR $LOG_NAME $NEWLINE $UNDERSCORE };

BEGIN {

Expand Down Expand Up @@ -127,8 +127,8 @@ sub analysis_star_fusion {
check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

use MIP::File::Format::Star_fusion qw{ create_star_fusion_sample_file };
use MIP::File_info qw{ get_io_files parse_io_outfiles };
use MIP::Program::Gnu::Coreutils qw{ gnu_cp };
use MIP::File_info qw{ get_io_files parse_io_outfiles get_sample_fastq_file_lanes };
use MIP::Program::Gnu::Coreutils qw{ gnu_mv gnu_rm };
use MIP::Program::Star_fusion qw{ star_fusion };
use MIP::Processmanagement::Processes qw{ submit_recipe };
use MIP::Recipe qw{ parse_recipe_prerequisites };
Expand Down Expand Up @@ -165,23 +165,33 @@ sub analysis_star_fusion {
recipe_name => $recipe_name,
}
);
my $outdir_path = catdir( $active_parameter_href->{outdata_dir}, $sample_id, $recipe_name );
my $outsample_name = $STAR_FUSION_PREFIX . $recipe{outfile_suffix};
my @file_paths = catfile( $outdir_path, $outsample_name );

## Join infile lanes
my $lanes_id = join $EMPTY_STR,
get_sample_fastq_file_lanes(
{
file_info_href => $file_info_href,
sample_id => $sample_id,
}
);
%io = (
%io,
parse_io_outfiles(
{
chain_id => $recipe{job_id_chain},
chain_id => $recipe{job_id_chain},
file_info_href => $file_info_href,
file_name_prefixes_ref =>
[ $sample_id . $UNDERSCORE . q{lanes} . $UNDERSCORE . $lanes_id ],
id => $sample_id,
file_info_href => $file_info_href,
file_paths_ref => \@file_paths,
outdata_dir => $active_parameter_href->{outdata_dir},
parameter_href => $parameter_href,
recipe_name => $recipe_name,
}
)
);
my $outdir_path = $io{out}{dir_path};
my $outfile_path = $io{out}{file_path};
my $outfile_suffix = $io{out}{file_suffix};

## Filehandles
# Create anonymous filehandle
Expand Down Expand Up @@ -236,14 +246,40 @@ sub analysis_star_fusion {
);
say {$filehandle} $NEWLINE;

## Close filehandleS
say {$filehandle} q{## Rename outfile};
my $star_fusion_outfile_path = catfile( $outdir_path, $STAR_FUSION_PREFIX . $outfile_suffix );
gnu_mv(
{
filehandle => $filehandle,
infile_path => $star_fusion_outfile_path,
outfile_path => $outfile_path,
}
);
say {$filehandle} $NEWLINE;

say {$filehandle} q{## Remove intermediary files};
FILE_TAG:
foreach my $file_tag (qw{ _STARgenome _STARpass1 }) {

gnu_rm(
{
filehandle => $filehandle,
force => 1,
infile_path => catdir( $outdir_path, $file_tag ),
recursive => 1,
}
);
print {$filehandle} $NEWLINE;
}

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

if ( $recipe{mode} == 1 ) {
## Collect QC metadata info for later use
set_recipe_outfile_in_sample_info(
{
path => $file_paths[0],
path => $outfile_path,
recipe_name => $recipe_name,
sample_id => $sample_id,
sample_info_href => $sample_info_href,
Expand All @@ -254,7 +290,7 @@ sub analysis_star_fusion {
{
format => q{meta},
id => $sample_id,
path => $file_paths[0],
path => $outfile_path,
recipe_name => $recipe_name,
sample_info_href => $sample_info_href,
}
Expand Down
18 changes: 10 additions & 8 deletions t/analysis_star_fusion.t
Expand Up @@ -62,18 +62,20 @@ my %active_parameter = test_mip_hashes(
$active_parameter{$recipe_name} = 1;
$active_parameter{recipe_core_number}{$recipe_name} = 1;
$active_parameter{recipe_time}{$recipe_name} = 1;
$active_parameter{star_fusion_genome_lib_dir} = q{a_dir};
$active_parameter{star_fusion_reference_genome} = q{a_reference_genome};
my $sample_id = $active_parameter{sample_ids}[0];
$active_parameter{star_fusion_genome_lib_dir} = q{a_dir};
$active_parameter{star_fusion_reference_genome} = q{a_reference_genome};

my %file_info = test_mip_hashes(
{
mip_hash_name => q{file_info},
recipe_name => $recipe_name,
}
);

$file_info{star_fusion_reference_genome} = [qw{ _star_fusion_genome_dir }];
@{ $file_info{$sample_id}{lanes} } = ( 1, 2 );
$file_info{$sample_id}{$recipe_name}{file_tag} = q{starfusion};

my %job_id;
my %parameter = test_mip_hashes(
{
Expand All @@ -84,11 +86,11 @@ my %parameter = test_mip_hashes(

test_add_io_for_recipe(
{
file_info_href => \%file_info,
id => $sample_id,
parameter_href => \%parameter,
recipe_name => $recipe_name,
step => q{bam},
file_info_href => \%file_info,
id => $sample_id,
parameter_href => \%parameter,
recipe_name => $recipe_name,
step => q{bam},
}
);

Expand Down

0 comments on commit 9a4246c

Please sign in to comment.