|
| 1 | +package npg_tracking::data::primer_panel::find; |
| 2 | + |
| 3 | +use strict; |
| 4 | +use warnings; |
| 5 | +use Moose::Role; |
| 6 | +use Carp; |
| 7 | +use Readonly; |
| 8 | +use File::Spec::Functions qw(catdir); |
| 9 | + |
| 10 | +use npg_tracking::util::abs_path qw(abs_path); |
| 11 | + |
| 12 | +with qw/ npg_tracking::data::reference::find |
| 13 | + npg_tracking::data::common /; |
| 14 | + |
| 15 | +our $VERSION = '0'; |
| 16 | + |
| 17 | +Readonly::Scalar our $FORM => q[default]; |
| 18 | + |
| 19 | +has 'primer_panel' => ( isa => q{Maybe[Str]}, |
| 20 | + is => q{ro}, |
| 21 | + lazy => 1, |
| 22 | + builder => '_build_primer_panel', |
| 23 | + documentation => 'The primer panel optionally including version',); |
| 24 | + |
| 25 | +sub _build_primer_panel { |
| 26 | + my $self = shift; |
| 27 | + return $self->lims->gbs_plex_name; |
| 28 | +} |
| 29 | + |
| 30 | +has 'primer_panel_name' => ( isa => q{Maybe[Str]}, |
| 31 | + is => q{ro}, |
| 32 | + lazy => 1, |
| 33 | + builder => '_build_primer_panel_name', |
| 34 | + documentation => 'The primer panel name',); |
| 35 | + |
| 36 | +sub _build_primer_panel_name { |
| 37 | + my $self = shift; |
| 38 | + my $name; |
| 39 | + if($self->primer_panel) { |
| 40 | + my @n = split /\//smx, $self->primer_panel; |
| 41 | + $name = $n[0]; |
| 42 | + } |
| 43 | + return $name; |
| 44 | +} |
| 45 | + |
| 46 | +has 'primer_panel_version' => ( isa => q{Maybe[Str]}, |
| 47 | + is => q{ro}, |
| 48 | + lazy => 1, |
| 49 | + builder => '_build_primer_panel_version', |
| 50 | + documentation => 'The primer panel version',); |
| 51 | + |
| 52 | +sub _build_primer_panel_version { |
| 53 | + my $self = shift; |
| 54 | + my $version; |
| 55 | + if ($self->primer_panel =~ m{[/] \s* (\w+) \s* $}smx) { |
| 56 | + $version = $1; |
| 57 | + } |
| 58 | + return (defined $version) ? $version : $FORM; |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +has 'primer_panel_path'=> ( isa => q{Maybe[Str]}, |
| 63 | + is => q{ro}, |
| 64 | + lazy => 1, |
| 65 | + builder => q{_build_primer_panel_path}, |
| 66 | + documentation => q{Path to the primer panel folder},); |
| 67 | + |
| 68 | +sub _build_primer_panel_path { |
| 69 | + my ( $self ) = @_; |
| 70 | + |
| 71 | + my $primer_panel_name = $self->primer_panel_name; |
| 72 | + if ($primer_panel_name) { |
| 73 | + # trim all white space around the name and replace spaces with underscores |
| 74 | + $primer_panel_name =~ s/\A(\s)+//smx; |
| 75 | + $primer_panel_name =~ s/(\s)+\z//smx; |
| 76 | + $primer_panel_name =~ s/ /_/gsm; |
| 77 | + } |
| 78 | + else { |
| 79 | + $self->messages->push('Primer panel name not available.'); |
| 80 | + return; |
| 81 | + } |
| 82 | + |
| 83 | + my ($organism, $strain) = |
| 84 | + $self->parse_reference_genome($self->lims->reference_genome); |
| 85 | + |
| 86 | + my $path = catdir |
| 87 | + ($self->primer_panel_repository, $primer_panel_name, |
| 88 | + $self->primer_panel_version, $organism, $strain); |
| 89 | + |
| 90 | + if (!-d $path) { |
| 91 | + $self->messages->push('Primer panel directory ' . $path . ' does not exist'); |
| 92 | + return; |
| 93 | + } |
| 94 | + return abs_path($path); |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +has 'primer_panel_bed_file' => |
| 99 | + (isa => q{Maybe[Str]}, |
| 100 | + is => q{ro}, |
| 101 | + lazy => 1, |
| 102 | + builder => q{_build_primer_panel_bed_file}, |
| 103 | + documentation => 'Full path to primer panel bed file', |
| 104 | + ); |
| 105 | + |
| 106 | +sub _build_primer_panel_bed_file { |
| 107 | + my $self = shift; |
| 108 | + return $self->find_file($self->primer_panel_path, q[], 'bed'); |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +1; |
| 113 | +__END__ |
| 114 | +
|
| 115 | +=head1 NAME |
| 116 | +
|
| 117 | +npg_tracking::data::primer_panel::find |
| 118 | +
|
| 119 | +=head1 VERSION |
| 120 | +
|
| 121 | +=head1 SYNOPSIS |
| 122 | +
|
| 123 | + package MyPackage; |
| 124 | + use Moose; |
| 125 | + with qw{npg_tracking::data::primer_panel::find}; |
| 126 | +
|
| 127 | +=head1 DESCRIPTION |
| 128 | +
|
| 129 | +A Moose role for finding the location of primer panel related files. |
| 130 | +
|
| 131 | +=head1 SUBROUTINES/METHODS |
| 132 | +
|
| 133 | +=head2 primer_panel_name |
| 134 | +
|
| 135 | +Note gbs_plex_name is an alias for primer_panel. |
| 136 | +
|
| 137 | +=head2 primer_panel_path |
| 138 | +
|
| 139 | +=head2 primer_panel_bed_file |
| 140 | +
|
| 141 | +=head1 DIAGNOSTICS |
| 142 | +
|
| 143 | +=head1 CONFIGURATION AND ENVIRONMENT |
| 144 | +
|
| 145 | +=head1 DEPENDENCIES |
| 146 | +
|
| 147 | +=over |
| 148 | +
|
| 149 | +=item Moose::Role |
| 150 | +
|
| 151 | +=item Carp |
| 152 | +
|
| 153 | +=item Readonly |
| 154 | +
|
| 155 | +=item File::Spec::Functions |
| 156 | +
|
| 157 | +=item npg_tracking::util::abs_path |
| 158 | +
|
| 159 | +=item npg_tracking::data::reference::find |
| 160 | +
|
| 161 | +=back |
| 162 | +
|
| 163 | +=head1 INCOMPATIBILITIES |
| 164 | +
|
| 165 | +=head1 BUGS AND LIMITATIONS |
| 166 | +
|
| 167 | +=head1 AUTHOR |
| 168 | +
|
| 169 | +=head1 LICENSE AND COPYRIGHT |
| 170 | +
|
| 171 | +Copyright (C) 2020 GRL |
| 172 | +
|
| 173 | +This program is free software: you can redistribute it and/or modify |
| 174 | +it under the terms of the GNU General Public License as published by |
| 175 | +the Free Software Foundation, either version 3 of the License, or |
| 176 | +(at your option) any later version. |
| 177 | +
|
| 178 | +This program is distributed in the hope that it will be useful, |
| 179 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 180 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 181 | +GNU General Public License for more details. |
| 182 | +
|
| 183 | +You should have received a copy of the GNU General Public License |
| 184 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 185 | +
|
0 commit comments