| 1 | package Bio::MUST::Apps::FortyTwo::RunProcessor; | ||||||||||
| 2 | # ABSTRACT: Internal class for forty-two tool | ||||||||||
| 3 | 1 | $Bio::MUST::Apps::FortyTwo::RunProcessor::VERSION = '0.262780'; | |||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use feature qw(say); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Smart::Comments; # logging always enabled here | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use List::AllUtils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Path::Class qw(dir file); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use Parallel::Batch; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use Bio::MUST::Core; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use Bio::MUST::Drivers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use aliased 'Bio::MUST::Apps::FortyTwo::AliProcessor'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 1 | with 'Bio::MUST::Apps::Roles::RunProcable', | |||||||||
| 23 | 'Bio::MUST::Core::Roles::Taxable'; | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 1 | has 'run_mode' => ( | |||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | isa => 'Str', | ||||||||||
| 29 | default => 'phylogenomic', | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 1 | has '+out_suffix' => ( | |||||||||
| 33 | default => '-42', | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 1 | has 'query_orgs' => ( | |||||||||
| 38 | traits => ['Array'], | ||||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | isa => 'ArrayRef[Str]', | ||||||||||
| 41 | required => 1, | ||||||||||
| 42 | handles => { | ||||||||||
| 43 | 'count_query_orgs' => 'count', | ||||||||||
| 44 | 'all_query_orgs' => 'elements', | ||||||||||
| 45 | }, | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | # blast_args | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | 1 | has 'ref_brh' => ( | |||||||||
| 53 | is => 'ro', | ||||||||||
| 54 | isa => 'Str', | ||||||||||
| 55 | default => 'on', | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | 1 | has 'ref_bank_dir' => ( | |||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | isa => 'Str', | ||||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | 1 | has 'ref_org_mapper' => ( | |||||||||
| 64 | is => 'ro', | ||||||||||
| 65 | isa => 'Bio::MUST::Core::IdMapper', | ||||||||||
| 66 | coerce => 1, | ||||||||||
| 67 | handles => { | ||||||||||
| 68 | ref_bank_for => 'abbr_id_for', | ||||||||||
| 69 | }, | ||||||||||
| 70 | ); | ||||||||||
| 71 | |||||||||||
| 72 | has 'ref_orgs' => ( | ||||||||||
| 73 | traits => ['Array'], | ||||||||||
| 74 | is => 'ro', | ||||||||||
| 75 | isa => 'ArrayRef[Str]', | ||||||||||
| 76 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 77 | 1 | handles => { | |||||||||
| 78 | 'count_ref_orgs' => 'count', | ||||||||||
| 79 | 'all_ref_orgs' => 'elements', | ||||||||||
| 80 | }, | ||||||||||
| 81 | ); | ||||||||||
| 82 | |||||||||||
| 83 | 1 | has 'ref_org_mul' => ( | |||||||||
| 84 | is => 'ro', | ||||||||||
| 85 | isa => 'Num', | ||||||||||
| 86 | default => 1.0, | ||||||||||
| 87 | ); | ||||||||||
| 88 | |||||||||||
| 89 | 1 | has 'ref_score_mul' => ( | |||||||||
| 90 | is => 'ro', | ||||||||||
| 91 | isa => 'Num', | ||||||||||
| 92 | default => 1.0, | ||||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | 1 | has 'tol_check' => ( | |||||||||
| 97 | is => 'ro', | ||||||||||
| 98 | isa => 'Str', | ||||||||||
| 99 | default => 'off', | ||||||||||
| 100 | ); | ||||||||||
| 101 | |||||||||||
| 102 | 1 | has 'tol_bank_dir' => ( | |||||||||
| 103 | is => 'ro', | ||||||||||
| 104 | isa => 'Str', | ||||||||||
| 105 | ); | ||||||||||
| 106 | |||||||||||
| 107 | 1 | has 'tol_bank' => ( | |||||||||
| 108 | is => 'ro', | ||||||||||
| 109 | isa => 'Str', | ||||||||||
| 110 | ); | ||||||||||
| 111 | |||||||||||
| 112 | 1 | has 'tol_blastdb' => ( | |||||||||
| 113 | is => 'ro', | ||||||||||
| 114 | isa => 'Maybe[Bio::MUST::Drivers::Blast::Database]', | ||||||||||
| 115 | init_arg => undef, | ||||||||||
| 116 | lazy => 1, | ||||||||||
| 117 | builder => '_build_tol_blastdb', | ||||||||||
| 118 | ); | ||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | # trim_homologues | ||||||||||
| 122 | |||||||||||
| 123 | # trim_max_shift | ||||||||||
| 124 | |||||||||||
| 125 | # trim_extra_margin | ||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | 1 | has 'merge_orthologues' => ( | |||||||||
| 129 | is => 'ro', | ||||||||||
| 130 | isa => 'Str', | ||||||||||
| 131 | default => 'off', | ||||||||||
| 132 | ); | ||||||||||
| 133 | |||||||||||
| 134 | 1 | has 'merge_min_ident' => ( | |||||||||
| 135 | is => 'ro', | ||||||||||
| 136 | isa => 'Num', | ||||||||||
| 137 | default => 0.9, | ||||||||||
| 138 | ); | ||||||||||
| 139 | |||||||||||
| 140 | 1 | has 'merge_min_len' => ( | |||||||||
| 141 | is => 'ro', | ||||||||||
| 142 | isa => 'Num', | ||||||||||
| 143 | default => 40, | ||||||||||
| 144 | ); | ||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | 1 | has 'aligner_mode' => ( | |||||||||
| 148 | is => 'ro', | ||||||||||
| 149 | isa => 'Str', | ||||||||||
| 150 | default => 'blast', | ||||||||||
| 151 | ); | ||||||||||
| 152 | |||||||||||
| 153 | 1 | has 'ali_skip_self' => ( | |||||||||
| 154 | is => 'ro', | ||||||||||
| 155 | isa => 'Str', | ||||||||||
| 156 | default => 'off', | ||||||||||
| 157 | ); | ||||||||||
| 158 | |||||||||||
| 159 | 1 | has 'ali_cover_mul' => ( | |||||||||
| 160 | is => 'ro', | ||||||||||
| 161 | isa => 'Num', | ||||||||||
| 162 | default => 1.1, | ||||||||||
| 163 | ); | ||||||||||
| 164 | |||||||||||
| 165 | 1 | has 'ali_keep_lengthened_seqs' => ( | |||||||||
| 166 | is => 'ro', | ||||||||||
| 167 | isa => 'Str', | ||||||||||
| 168 | default => 'on', | ||||||||||
| 169 | ); | ||||||||||
| 170 | |||||||||||
| 171 | 1 | has 'ali_keep_old_new_tags' => ( | |||||||||
| 172 | is => 'ro', | ||||||||||
| 173 | isa => 'Str', | ||||||||||
| 174 | default => 'off', | ||||||||||
| 175 | ); | ||||||||||
| 176 | |||||||||||
| 177 | |||||||||||
| 178 | 1 | has 'tax_reports' => ( | |||||||||
| 179 | is => 'ro', | ||||||||||
| 180 | isa => 'Str', | ||||||||||
| 181 | default => 'on', | ||||||||||
| 182 | ); | ||||||||||
| 183 | |||||||||||
| 184 | # tax_dir | ||||||||||
| 185 | |||||||||||
| 186 | 1 | has 'tax_min_hits' => ( | |||||||||
| 187 | is => 'ro', | ||||||||||
| 188 | isa => 'Num', | ||||||||||
| 189 | default => 1, | ||||||||||
| 190 | ); | ||||||||||
| 191 | |||||||||||
| 192 | 1 | has 'tax_max_hits' => ( | |||||||||
| 193 | is => 'ro', | ||||||||||
| 194 | isa => 'Num', | ||||||||||
| 195 | default => 10000, | ||||||||||
| 196 | ); | ||||||||||
| 197 | |||||||||||
| 198 | 1 | has 'tax_min_ident' => ( | |||||||||
| 199 | is => 'ro', | ||||||||||
| 200 | isa => 'Num', | ||||||||||
| 201 | default => 0, | ||||||||||
| 202 | ); | ||||||||||
| 203 | |||||||||||
| 204 | 1 | has 'tax_min_len' => ( | |||||||||
| 205 | is => 'ro', | ||||||||||
| 206 | isa => 'Num', | ||||||||||
| 207 | default => 0, | ||||||||||
| 208 | ); | ||||||||||
| 209 | |||||||||||
| 210 | 1 | has 'tax_min_score' => ( | |||||||||
| 211 | is => 'ro', | ||||||||||
| 212 | isa => 'Num', | ||||||||||
| 213 | default => 0, | ||||||||||
| 214 | ); | ||||||||||
| 215 | |||||||||||
| 216 | 1 | has 'tax_score_mul' => ( | |||||||||
| 217 | is => 'ro', | ||||||||||
| 218 | isa => 'Num', | ||||||||||
| 219 | default => 0, | ||||||||||
| 220 | ); | ||||||||||
| 221 | |||||||||||
| 222 | |||||||||||
| 223 | # bank_dir | ||||||||||
| 224 | |||||||||||
| 225 | # orgs | ||||||||||
| 226 | |||||||||||
| 227 | # infiles | ||||||||||
| 228 | |||||||||||
| 229 | # debug_mode | ||||||||||
| 230 | |||||||||||
| 231 | # threads | ||||||||||
| 232 | |||||||||||
| 233 | 1 | has '_ref_blastdb_by_org' => ( | |||||||||
| 234 | traits => ['Hash'], | ||||||||||
| 235 | is => 'ro', | ||||||||||
| 236 | isa => 'HashRef[Bio::MUST::Drivers::Blast::Database]', | ||||||||||
| 237 | init_arg => undef, | ||||||||||
| 238 | lazy => 1, | ||||||||||
| 239 | builder => '_build_ref_blastdb_by_org', | ||||||||||
| 240 | handles => { | ||||||||||
| 241 | ref_blastdb_for => 'get', | ||||||||||
| 242 | }, | ||||||||||
| 243 | ); | ||||||||||
| 244 | |||||||||||
| 245 | |||||||||||
| 246 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||
| 247 | |||||||||||
| 248 | 0 | ▶ | sub _build_ref_blastdb_by_org { | ||||||||
|
Subroutine
_build_ref_blastdb_by_org: not called CC=2 SCAR=17.9
| |||||||||||
| 249 | 0 | my $self = shift; | |||||||||
| 250 | |||||||||||
| 251 | # tie probably useless here but ensuring reproducible logs | ||||||||||
| 252 | 0 | tie my %ref_blastdb_for, 'Tie::IxHash'; | |||||||||
| 253 | |||||||||||
| 254 | 0 | for my $ref_org ($self->all_ref_orgs) { | |||||||||
| 255 | 0 | $ref_blastdb_for{$ref_org} = Bio::MUST::Drivers::Blast::Database->new( | |||||||||
| 256 | file => file( | ||||||||||
| 257 | $self->ref_bank_dir, | ||||||||||
| 258 | $self->ref_bank_for($ref_org) | ||||||||||
| 259 | ) | ||||||||||
| 260 | ); | ||||||||||
| 261 | } | ||||||||||
| 262 | |||||||||||
| 263 | 0 | return \%ref_blastdb_for; | |||||||||
| 264 | } | ||||||||||
| 265 | |||||||||||
| 266 | |||||||||||
| 267 | 0 | ▶ | sub _build_tol_blastdb { | ||||||||
|
Subroutine
_build_tol_blastdb: not called CC=2 SCAR=17.9
| |||||||||||
| 268 | 0 | my $self = shift; | |||||||||
| 269 | |||||||||||
| 270 | 0 | ▶ | return if $self->tol_check eq 'off'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 271 | |||||||||||
| 272 | 0 | my $tolfile = file( $self->tol_bank_dir, $self->tol_bank ); | |||||||||
| 273 | 0 | #### [RUN] TOL bank in use: $tolfile->stringify | |||||||||
| 274 | 0 | return Bio::MUST::Drivers::Blast::Database->new( file => $tolfile ); | |||||||||
| 275 | } | ||||||||||
| 276 | |||||||||||
| 277 | ## use critic | ||||||||||
| 278 | |||||||||||
| 279 | |||||||||||
| 280 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||
| 281 | 0 | my $self = shift; | |||||||||
| 282 | |||||||||||
| 283 | 0 | ▶ | unless ($self->ref_brh eq 'off') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 284 | 0 | ▶ | croak '[RUN] Error: ref_bank_dir missing from config file; aborting!' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 285 | unless $self->ref_bank_dir; | ||||||||||
| 286 | |||||||||||
| 287 | 0 | ▶ | croak '[RUN] Error: ref_org_mapper missing from config file; aborting!' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 288 | unless $self->ref_org_mapper; | ||||||||||
| 289 | |||||||||||
| 290 | croak '[RUN] Error: BLAST databases missing from ref_org_mapper;' | ||||||||||
| 291 | . ' aborting!' | ||||||||||
| 292 | 0 | ▶ | if List::AllUtils::any { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 293 | 0 | !defined $self->ref_bank_for($_) | |||||||||
| 294 | 0 | ▶ | } $self->all_ref_orgs | ||||||||
|
Branch: 1 branch
| |||||||||||
| 295 | ; | ||||||||||
| 296 | } | ||||||||||
| 297 | |||||||||||
| 298 | # TODO: revise this but not sure this is really needed | ||||||||||
| 299 | |||||||||||
| 300 | # if ($self->aligner eq 'off' && $self->run_mode eq 'phylogenomic') { | ||||||||||
| 301 | # croak 'Error: cannot disable aligner with nucleotide banks; aborting!' | ||||||||||
| 302 | # if List::AllUtils::any { | ||||||||||
| 303 | # $_->{bank_type} eq 'nucl' | ||||||||||
| 304 | # } $self->all_orgs | ||||||||||
| 305 | # ; | ||||||||||
| 306 | # } | ||||||||||
| 307 | # | ||||||||||
| 308 | # if ($self->aligner =~ m/exonerate|exoblast/xms) { | ||||||||||
| 309 | # croak 'Error: cannot use exonerate with protein banks; aborting!' | ||||||||||
| 310 | # if List::AllUtils::any { | ||||||||||
| 311 | # $_->{bank_type} eq 'prot' | ||||||||||
| 312 | # } $self->all_orgs | ||||||||||
| 313 | # ; | ||||||||||
| 314 | # } | ||||||||||
| 315 | |||||||||||
| 316 | # build optional output dir | ||||||||||
| 317 | 0 | ▶ | if ($self->out_dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 318 | 0 | my $dir = dir($self->out_dir)->relative; | |||||||||
| 319 | 0 | $dir->mkpath(); | |||||||||
| 320 | } | ||||||||||
| 321 | |||||||||||
| 322 | 0 | ▶ | if ($self->threads > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 323 | 0 | ### [RUN] Multithreading is on: $self->threads | |||||||||
| 324 | 0 | ### [RUN] Logging data will be mixed-up! | |||||||||
| 325 | } | ||||||||||
| 326 | |||||||||||
| 327 | # spawn Taxonomy only once (especially useful for multithreading) | ||||||||||
| 328 | 0 | $self->tax; | |||||||||
| 329 | |||||||||||
| 330 | # create job queue | ||||||||||
| 331 | my $batch = Parallel::Batch->new( { | ||||||||||
| 332 | maxprocs => $self->threads, | ||||||||||
| 333 | jobs => [ $self->all_infiles ], | ||||||||||
| 334 | 0 | ▶ | code => sub { # closure (providing $self) | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 335 | 0 | my $infile = shift; | |||||||||
| 336 | 0 | ### [RUN] Processing ALI: $infile | |||||||||
| 337 | 0 | return AliProcessor->new( | |||||||||
| 338 | run_proc => $self, | ||||||||||
| 339 | ali => $infile, | ||||||||||
| 340 | ); | ||||||||||
| 341 | }, | ||||||||||
| 342 | 0 | } ); | |||||||||
| 343 | |||||||||||
| 344 | # launch jobs | ||||||||||
| 345 | 0 | $batch->run(); | |||||||||
| 346 | |||||||||||
| 347 | 0 | return; | |||||||||
| 348 | } | ||||||||||
| 349 | |||||||||||
| 350 | |||||||||||
| 351 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 352 | 1 | 1; | |||||||||
| 353 | |||||||||||
| 354 | __END__ | ||||||||||