From 66ecbe86d3f8536482d914dde079ecff10329f60 Mon Sep 17 00:00:00 2001 From: Marina Gourtovaia Date: Tue, 5 Jun 2018 11:43:48 +0100 Subject: [PATCH] remove unused code, including vestiges of decoding with BamIndexDecoder.jar; use standard samtools command accessor --- lib/npg_qc/autoqc/checks/upstream_tags.pm | 147 +++++++++------------- 1 file changed, 56 insertions(+), 91 deletions(-) diff --git a/lib/npg_qc/autoqc/checks/upstream_tags.pm b/lib/npg_qc/autoqc/checks/upstream_tags.pm index b10e44993..f6d088f25 100644 --- a/lib/npg_qc/autoqc/checks/upstream_tags.pm +++ b/lib/npg_qc/autoqc/checks/upstream_tags.pm @@ -6,10 +6,9 @@ use Carp; use English qw(-no_match_vars); use Fatal qw(open close); use File::Basename; -use File::Spec::Functions qw(catfile catdir); -use List::MoreUtils qw { any }; +use File::Spec::Functions qw(catfile); +use List::MoreUtils qw(any); use Readonly; -use FindBin qw($Bin); use npg_tracking::Schema; use npg_qc::autoqc::checks::tag_metrics; @@ -23,10 +22,8 @@ with qw(npg_tracking::data::reference::find our $VERSION = '0'; -Readonly::Scalar my $SAMTOOLS_NAME => q[samtools]; Readonly::Scalar my $EXT => q[bam]; Readonly::Scalar my $BARCODE_FILENAME => q[sanger168.tags]; -Readonly::Scalar my $BID_JAR_NAME => q[BamIndexDecoder.jar]; Readonly::Scalar my $NUM_BACK_RUNS => 5; Readonly::Scalar my $MAX_MISMATCHES_DEFAULT => 1; Readonly::Scalar my $MAX_NO_CALLS_DEFAULT => 0; @@ -44,8 +41,6 @@ Readonly::Scalar my $ID_INSTRUMENT_POS => 2; Readonly::Scalar my $INSTRUMENT_NAME_POS => 3; Readonly::Scalar my $SLOT_POS => 4; -Readonly::Scalar my $DEFAULT_JAVA_XMX => q{-Xmx1000m}; - has '+file_type' => (default => $EXT,); ##################################################################################################### @@ -142,7 +137,7 @@ has 'num_back_runs' => ( isa => 'NpgTrackingNonNegativeInt', ); ############################################################### -# max_mismatches: BamIndexDecoder parameter +# max_mismatches: index decoder parameter ############################################################### has 'max_mismatches' => ( isa => 'NpgTrackingNonNegativeInt', is => 'rw', @@ -150,7 +145,7 @@ has 'max_mismatches' => ( isa => 'NpgTrackingNonNegativeInt', ); ############################################################### -# max_no_calls: BamIndexDecoder parameter +# max_no_calls: index decoder parameter ############################################################### has 'max_no_calls' => ( isa => 'NpgTrackingNonNegativeInt', is => 'rw', @@ -169,7 +164,7 @@ sub _build_total_tag0_reads { my $self = shift; my $total_reads = 0; - for my $read_count (values %{$self->tag0_BamIndexDecoder_metrics->result->reads_pf_count}) { + for my $read_count (values %{$self->tag0_metrics->result->reads_pf_count}) { $total_reads += $read_count; } @@ -189,8 +184,8 @@ sub _build_total_tag0_perfect_matches_reads { my $total_reads = 0; my $phix_tag_indices = $self->_run_info_data->{runs_info}->[0]->{phix_tagidx}; - my $pmc = $self->tag0_BamIndexDecoder_metrics->result->perfect_matches_pf_count; - for my $perfect_matches_tagidx (keys %{$self->tag0_BamIndexDecoder_metrics->result->perfect_matches_pf_count}) { + my $pmc = $self->tag0_metrics->result->perfect_matches_pf_count; + for my $perfect_matches_tagidx (keys %{$self->tag0_metrics->result->perfect_matches_pf_count}) { next if($phix_tag_indices->{$perfect_matches_tagidx}); $total_reads += $pmc->{$perfect_matches_tagidx}; } @@ -290,7 +285,7 @@ sub _build_tag0_index_length { ## no critic (ProhibitTwoArgOpen ErrorHandling::RequireCheckingReturnValueOfEval my $index_length = 0; my $bfile = $self->tag0_bam_file; - my $command = q[/bin/bash -c "set -o pipefail && ] . $self->samtools . qq[ view $bfile" ]; + my $command = q[/bin/bash -c "set -o pipefail && ] . $self->samtools_cmd . qq[ view $bfile" ]; open my $ph, q(-|), $command or croak qq[Cannot fork '$command', error $ERRNO]; while (my $line = <$ph>) { if($line =~ /\t(BC|RT):Z:(\S+)/smx) { @@ -368,12 +363,6 @@ has 'db_lookup' => ( isa => 'Bool', default => 1, ); -has 'bid_jar_path' => ( is => 'ro', - isa => 'NpgCommonResolvedPathJarFile', - coerce => 1, - default => $BID_JAR_NAME, - ); - has 'run_rows' => ( isa => 'ArrayRef', is => 'ro', lazy_build => 1, @@ -412,49 +401,22 @@ sub _build__run_info_data { return $rid; } -has 'java_xmx_flag' => ( is => 'ro', - isa => 'Str', - default => $DEFAULT_JAVA_XMX, - ); - -has 'maskflags_name' => ( is => 'ro', - isa => 'NpgCommonResolvedPathExecutable', - coerce => 1, - default => 'bammaskflags', - ); - -has 'maskflags_cmd' => ( is => 'ro', - isa => 'Str', - lazy_build => 1, - ); -sub _build_maskflags_cmd { - my $self = shift; - return $self->maskflags_name . q[ maskneg=107]; -} - -## no critic qw(NamingConventions::Capitalization NamingConventions::ProhibitMixedCaseSubs) -has 'BamIndexDecoder_cmd' => ( isa => 'Str', - is => 'ro', - required => 0, - lazy_build => 1, - ); -sub _build_BamIndexDecoder_cmd { +has 'index_decoder_cmd' => ( isa => 'Str', + is => 'ro', + required => 0, + lazy_build => 1, + ); +sub _build_index_decoder_cmd { my $self = shift; -# my $bid_cmd_template = q[java %s -jar %s COMPRESSION_LEVEL=0 INPUT=%s OUTPUT=/dev/null BARCODE_FILE=%s METRICS_FILE=%s MAX_MISMATCHES=%d MAX_NO_CALLS=%d VALIDATION_STRINGENCY=LENIENT]; -# -# my $bid_cmd = sprintf $bid_cmd_template, -# $self->java_xmx_flag, -# $self->bid_jar_path, - my $bid_cmd_template = q[bambi decode --compression-level 0 --output /dev/null --barcode-file %s --metrics-file %s --max-mismatches %d --max-no-calls %d %s]; my $bid_cmd = sprintf $bid_cmd_template, - $self->barcode_filename, - $self->metrics_output_file, - $self->max_mismatches, - $self->max_no_calls, - $self->tag0_bam_file; + $self->barcode_filename, + $self->metrics_output_file, + $self->max_mismatches, + $self->max_no_calls, + $self->tag0_bam_file; $bid_cmd .= q[ > /dev/null 2>&1]; # all useful output goes to metrics_file @@ -462,22 +424,22 @@ sub _build_BamIndexDecoder_cmd { } ################################################################################## -# tag0_BamIndexDecoder_metrics: tag metrics check object - created with the output -# from a BamIndexDecoder run on the tag#0 bam file +# tag0_metrics: tag metrics check object - created with the output +# from a index decoder run on the tag#0 bam file ################################################################################## -has 'tag0_BamIndexDecoder_metrics' => ( isa => 'Object', - is => 'ro', - lazy_build => 1, - ); -sub _build_tag0_BamIndexDecoder_metrics { +has 'tag0_metrics' => ( isa => 'Object', + is => 'ro', + lazy_build => 1, + ); +sub _build_tag0_metrics { my ($self) = @_; - my $bid_cmd = $self->BamIndexDecoder_cmd; + my $bid_cmd = $self->index_decoder_cmd; - system($bid_cmd) == 0 or croak qq[Failed to execute BamIndexDecoder command: $bid_cmd]; + system($bid_cmd) == 0 or croak qq[Failed to execute index decoder command: $bid_cmd]; ############################################################# - # Read BamIndexDecoder output into a tag_metrics check object + # Read index decoder output into a tag_metrics check object # for easier manipulation of values ############################################################# my $tmc=npg_qc::autoqc::checks::tag_metrics->new( @@ -488,10 +450,9 @@ sub _build_tag0_BamIndexDecoder_metrics { return $tmc; } -## use critic ############################################################################################# -# _tmc_tag_indexes: maps tag sequences to tag indices for tag set used in BamIndexDecoder run +# _tmc_tag_indexes: maps tag sequences to tag indices for tag set used in index decoder run ############################################################################################# has '_tmc_tag_indexes' => ( isa => 'HashRef', is => 'ro', @@ -500,7 +461,7 @@ has '_tmc_tag_indexes' => ( isa => 'HashRef', sub _build__tmc_tag_indexes { my ($self) = @_; # tag_seq -> tag_idx map for sanger168 tag set - return { reverse %{$self->tag0_BamIndexDecoder_metrics->result->tags} }; + return { reverse %{$self->tag0_metrics->result->tags} }; } ## no critic qw(BuiltinFunctions::ProhibitReverseSortBlock) @@ -515,7 +476,7 @@ sub _build_unexpected_tags { my ($self) = @_; my @ret = (); - my $bid_metrics = $self->tag0_BamIndexDecoder_metrics; + my $bid_metrics = $self->tag0_metrics; my $tti = $self->_tmc_tag_indexes; my $tag_seq_runs = $self->_run_info_data->{tag_seq_runs}; @@ -550,30 +511,12 @@ sub _build_prev_runs { for my $i (0..($self->num_back_runs - 1)) { my $tti = $self->_tmc_tag_indexes; - push @ret, _generate_run_info_row($run_info_list->[$i], $self->composition->get_component(0)->position, $self->tag0_BamIndexDecoder_metrics, $tti); + push @ret, _generate_run_info_row($run_info_list->[$i], $self->composition->get_component(0)->position, $self->tag0_metrics, $tti); } return \@ret; } -######################################################################################## -# you can override the executable name. May be useful for variants like "samtools_irods" -######################################################################################## -has 'samtools_name' => ( is => 'ro', - isa => 'Str', - default => $SAMTOOLS_NAME, - ); - -has 'samtools' => ( is => 'ro', - isa => 'NpgCommonResolvedPathExecutable', - lazy_build => 1, - coerce => 1, - ); -sub _build_samtools { - my ($self) = @_; - return $self->samtools_name; -} - override 'can_run' => sub { my $self = shift; @@ -848,8 +791,30 @@ npg_qc::autoqc::checks::upstream_tags =over +=item Moose + =item namespace::autoclean +=item Carp + +=item English + +=item Fatal + +=item File::Basename + +=item File::Spec::Functions + +=item List::MoreUtils + +=item Readonly + +=item npg_tracking::Schema + +=item npg_tracking::data::reference::find + +=item npg_common::roles::software_location + =back =head1 AUTHOR @@ -858,7 +823,7 @@ Kevin Lewis, kl2 =head1 LICENSE AND COPYRIGHT -Copyright (C) 2016 GRL +Copyright (C) 2018 GRL This file is part of NPG.