lib/Bio/MUST/Apps/FortyTwo/OrgProcessor.pm

filter: Statementstmt 21.2% 77 / 363 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 70 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 70.9% 22 / 31 Podpod 0.0% 0 / 1 totaltotal 15.3% 99 / 644 CC 107 SCAR 63.6
CC
107
Cov
13%
_fetch_tax_line_for_transcript
1260.0
_build_aligned_seqs
992.0
_build_orthologous_seqs
132.0
CRAP 577.1
↑ Summary lib/Bio/MUST/Apps/Roles/OrgProcable.pm »
1 package Bio::MUST::Apps::FortyTwo::OrgProcessor;
2 # ABSTRACT: Internal class for forty-two tool
3 1 $Bio::MUST::Apps::FortyTwo::OrgProcessor::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 -ENV;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use List::AllUtils qw(each_array pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Path::Class qw(file);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Tie::IxHash;
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::Core::Constants qw(:gaps :ncbi);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Bio::MUST::Core::Utils qw(:filenames);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Bio::MUST::Drivers;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use aliased 'Bio::MUST::Core::Ali';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use aliased 'Bio::MUST::Core::Ali::Temporary';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use aliased 'Bio::MUST::Core::IdList';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use aliased 'Bio::MUST::Core::Seq';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use aliased 'Bio::MUST::Core::SeqId';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use aliased 'Bio::MUST::Core::SeqMask';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use aliased 'Bio::MUST::Drivers::Cap3';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use aliased 'Bio::MUST::Apps::Debrief42::TaxReport::NewSeq';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 with 'Bio::MUST::Apps::Roles::OrgProcable';
32  
33  
34 # org
35  
36 # banks
37  
38 # code
39  
40  
41 1 has 'ali_proc' => (
42 is => 'ro',
43 isa => 'Bio::MUST::Apps::FortyTwo::AliProcessor',
44 required => 1,
45 );
46  
47  
48 1 has 'tax_filter' => (
49 is => 'ro',
50 isa => 'Maybe[ArrayRef[Str]]',
51 );
52  
53  
54 1 has '_tax_filter' => (
55 is => 'ro',
56 isa => 'Maybe[Bio::MUST::Core::Taxonomy::Filter]',
57 init_arg => undef,
58 writer => '_set_tax_filter',
59 handles => [ qw(is_allowed) ],
60 );
61  
62  
63 has $_ . '_seqs' => (
64 is => 'ro',
65 isa => 'Bio::MUST::Core::Ali::Temporary',
66 init_arg => undef,
67 lazy => 1,
68 builder => '_build_' . $_ . '_seqs',
69 1 ) for qw(homologous orthologous);
70  
71  
72 1 has 'aligned_seqs' => (
73 is => 'ro',
74 isa => 'Bio::MUST::Core::Ali',
75 init_arg => undef,
76 lazy => 1,
77 builder => '_build_aligned_seqs',
78 );
79  
80  
81 has '_' . $_ . '_para_scores' => (
82 traits => ['Hash'],
83 is => 'ro',
84 isa => 'HashRef[Num]',
85 init_arg => undef,
86 lazy => 1,
87 builder => '_build_' . $_ . '_scores',
88 handles => {
89 $_ . '_score_for' => 'get',
90 },
91 1 ) for qw(para tol);
92  
93  
94 has '_count_for' => (
95 is => 'ro',
96 isa => 'HashRef[HashRef[Num]]',
97 init_arg => undef,
98 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 1 );
100  
101  
102 ## no critic (ProhibitUnusedPrivateSubroutines)
103  
104 0 ▶sub _build_homologous_seqs {
Subroutine _build_homologous_seqs: not called CC=7 SCAR=40.3
105 0 my $self = shift;
106  
107 ##### [ORG] Searching for homologues...
108  
109 0 my $ap = $self->ali_proc;
110 0 my $rp = $ap->run_proc;
111  
112 0 ▶ my $args = $rp->blast_args_for('homologues') // {};
Condition0%0/2
$rp->blast_args_for("homologues") // {}
l!l
00
MC/DC0%0/1
$rp->blast_args_for("homologues") // {}
$rp->blast_args_for("homologues")
Truth table0%0/2
A
A= $rp->blast_args_for("homologues")
Aresult
11
00
113 0 $args->{-outfmt} = 6;
114 $args->{-max_target_seqs} = 10000
115 0 ▶ unless defined $args->{-max_target_seqs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"-max_target_seqs"} 0 0 0
116  
117 0 my @seqs;
118 0 for my $bank ($self->all_banks) {
119  
120 ###### [ORG] Processing BANK: $bank
121 0 my $query_seqs = $ap->query_seqs;
122 0 my $file = file( $rp->bank_dir, $bank );
123 0 my $blastdb = Bio::MUST::Drivers::Blast::Database->new( file => $file );
124 0 ▶ $args->{-db_gencode} = $self->code # if TBLASTN
Branch: 1 branch
BranchTrueFalseTotal
if $query_seqs->type eq "prot" and $blastdb->type eq "nucl" 0 0 0
Condition0%0/3
$query_seqs->type eq "prot" and $blastdb->type eq "nucl"
!ll&&!rl&&r
000
MC/DC0%0/2
$query_seqs->type eq "prot" and $blastdb->type eq "nucl"
$query_seqs->type eq "prot" $blastdb->type eq "nucl"
Truth table0%0/3
A and B
A= $query_seqs->type eq "prot"B= $blastdb->type eq "nucl"
ABresult
0X0
100
111
125 if $query_seqs->type eq 'prot' && $blastdb->type eq 'nucl';
126 0 my $parser = $blastdb->blast($query_seqs, $args);
127 ###### [ORG] TBLASTN (or BLASTP/N): $bank . q{ } . $parser->filename
128  
129 # tie might help making 42 completely deterministic
130 0 tie my %mask_for, 'Tie::IxHash';
131 0 my %strand_for;
132  
133 # collect hit ids, masks and strands covered by queries
134 0 $self->_collect_hsps(
135 parser => $parser,
136 mask_for => \%mask_for,
137 strand_for => \%strand_for,
138 );
139 0 ▶ $parser->remove unless $rp->debug_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $rp->debug_mode 0 0 0
140  
141 # fetch (and optionally trim) hits to their max range
142 0 my @hits = $self->_fetch_and_trim_hits(
143 blastdb => $blastdb,
144 mask_for => \%mask_for,
145 strand_for => \%strand_for,
146 );
147 ######## [DEBUG] hits: display( map { $_->full_id . ' => ' . $_->seq } @hits )
148  
149 # add seqs from current bank to homologous seqs
150 0 push @seqs, @hits;
151 }
152  
153 # build BLAST query file from homologous seqs
154 0 return Temporary->new( seqs => \@seqs );
155 }
156  
157  
158 0 ▶sub _build_orthologous_seqs {
Subroutine _build_orthologous_seqs: not called CC=11 SCAR=48.8
159 0 my $self = shift;
160  
161 0 my $ap = $self->ali_proc;
162 0 my $rp = $ap->run_proc;
163  
164 0 my $seqs;
165  
166 0 ▶ unless ($rp->ref_brh eq 'off') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->ref_brh eq 'off') { } 0 0 0
167 ##### [ORG] Identifying orthologues among homologues...
168  
169 0 ▶ my $args = $rp->blast_args_for('orthologues') // {};
Condition0%0/2
$rp->blast_args_for("orthologues") // {}
l!l
00
MC/DC0%0/1
$rp->blast_args_for("orthologues") // {}
$rp->blast_args_for("orthologues")
Truth table0%0/2
A
A= $rp->blast_args_for("orthologues")
Aresult
11
00
170 0 $args->{-outfmt} = 6;
171 0 $args->{-max_target_seqs} = 1;
172  
173 # tie might help making 42 completely deterministic
174 0 tie my %count_for, 'Tie::IxHash';
175 0 for my $ref_org ($ap->all_ref_orgs) {
176  
177 0 my $homologous_seqs = $self->homologous_seqs;
178 0 my $blastdb = $rp->ref_blastdb_for($ref_org);
179 0 ▶ $args->{-query_gencode} = $self->code # if BLASTX
Branch: 1 branch
BranchTrueFalseTotal
if $homologous_seqs->type eq "nucl" and $blastdb->type eq "prot" 0 0 0
Condition0%0/3
$homologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
!ll&&!rl&&r
000
MC/DC0%0/2
$homologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
$homologous_seqs->type eq "nucl" $blastdb->type eq "prot"
Truth table0%0/3
A and B
A= $homologous_seqs->type eq "nucl"B= $blastdb->type eq "prot"
ABresult
0X0
100
111
180 if $homologous_seqs->type eq 'nucl' && $blastdb->type eq 'prot';
181 0 my $parser = $blastdb->blast($homologous_seqs, $args);
182 ##### [ORG] BLASTX (or BLASTP/N): $ref_org . q{ } . $parser->filename
183  
184 0 my $best_hits = $ap->best_hits_for($ref_org);
185 0 ▶ while (my $hsp = $parser->next_query) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hsp = $parser->next_query) 0 0 0
186 0 my $candidate = $homologous_seqs->long_id_for( $hsp->query_id );
187 0 my $in_best_hits = $best_hits->is_listed( $hsp->hit_id );
188 ######## [DEBUG]: $candidate . ( $in_best_hits && ' [=BRH=]' )
189 0 ▶ $count_for{$candidate}++ if $in_best_hits;
Branch: 1 branch
BranchTrueFalseTotal
if $in_best_hits 0 0 0
190 }
191 0 ▶ $parser->remove unless $rp->debug_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $rp->debug_mode 0 0 0
192 }
193  
194 ######## [DEBUG] BRH counts: display( pairmap { "$a => $b" } %count_for )
195  
196 # keep only homologues that are orthologous for all effective ref_orgs
197 0 my $ref_org_n = $ap->count_ref_orgs;
198 my $orthologues = IdList->new(
199 0 ids => [ grep { $count_for{$_} == $ref_org_n } keys %count_for ]
200 );
201 0 $seqs = $orthologues->filtered_ali( $self->homologous_seqs );
202 }
203  
204 else {
205 ##### [ORG] Skipping orthology assessment!
206 0 $seqs = $self->homologous_seqs->seqs;
207 }
208  
209 # optionally merge orthologues before aligning
210 # Note: this is always disabled in metagenomic mode
211 0 ▶ unless ($rp->run_mode eq 'metagenomic') { # TODO: warn user?
Branch: 1 branch
BranchTrueFalseTotal
unless ($rp->run_mode eq "metagenomic") 0 0 0
212 0 ▶ if ($rp->merge_orthologues eq 'on') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->merge_orthologues eq "on") 0 0 0
213 ##### [ORG] pre-merge orthologues: display( map { $_->full_id } $seqs->all_seq_ids )
214 0 $self->_compress_seqs($seqs);
215 }
216 }
217  
218 # build BLAST query file from orthologous seqs
219 0 return Temporary->new( seqs => $seqs );
220 }
221  
222  
223 0 ▶sub _build_para_scores {
Subroutine _build_para_scores: not called CC=7 SCAR=40.3
224 0 my $self = shift;
225  
226 0 my $ap = $self->ali_proc;
227 0 my $rp = $ap->run_proc;
228  
229 # ignore if no .para file in use
230 0 my $blastdb = $ap->para_blastdb;
231 0 ▶ return unless $blastdb;
Branch: 1 branch
BranchTrueFalseTotal
unless $blastdb 0 0 0
232  
233 0 ▶ my $args = $rp->blast_args_for('templates') // {};
Condition0%0/2
$rp->blast_args_for("templates") // {}
l!l
00
MC/DC0%0/1
$rp->blast_args_for("templates") // {}
$rp->blast_args_for("templates")
Truth table0%0/2
A
A= $rp->blast_args_for("templates")
Aresult
11
00
234 0 $args->{-outfmt} = 6;
235 0 $args->{-max_target_seqs} = 1;
236  
237 0 my $orthologous_seqs = $self->orthologous_seqs;
238 0 ▶ $args->{-query_gencode} = $self->code # if BLASTX
Branch: 1 branch
BranchTrueFalseTotal
if $orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot" 0 0 0
Condition0%0/3
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
!ll&&!rl&&r
000
MC/DC0%0/2
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
$orthologous_seqs->type eq "nucl" $blastdb->type eq "prot"
Truth table0%0/3
A and B
A= $orthologous_seqs->type eq "nucl"B= $blastdb->type eq "prot"
ABresult
0X0
100
111
239 if $orthologous_seqs->type eq 'nucl' && $blastdb->type eq 'prot';
240 0 my $parser = $blastdb->blast($orthologous_seqs, $args);
241 ##### [ORG] BLASTX (or BLASTP/N): 'PARA ' . $parser->filename
242  
243 0 my %para_score_for;
244 0 ▶ while (my $hsp = $parser->next_query) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hsp = $parser->next_query) 0 0 0
245 0 my $transcript_acc = $orthologous_seqs->long_id_for( $hsp->query_id );
246 0 my $hit_id = $blastdb->long_id_for( $hsp->hit_id );
247 0 my $score = $hsp->bit_score;
248 ######## [DEBUG] orthologue: $transcript_acc
249 ######## [DEBUG] PARA hit: $hit_id
250 ######## [DEBUG] score: $score
251 0 $para_score_for{$transcript_acc} = $score;
252 }
253 0 ▶ $parser->remove unless $rp->debug_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $rp->debug_mode 0 0 0
254  
255 0 return \%para_score_for;
256 }
257  
258  
259 0 ▶sub _build_tol_scores {
Subroutine _build_tol_scores: not called CC=11 SCAR=48.8
260 0 my $self = shift;
261  
262 0 my $ap = $self->ali_proc;
263 0 my $rp = $ap->run_proc;
264  
265 # ignore if no tol_check in use
266 0 my $blastdb = $rp->tol_blastdb;
267 0 ▶ return unless $blastdb;
Branch: 1 branch
BranchTrueFalseTotal
unless $blastdb 0 0 0
268  
269 0 ▶ my $args = $rp->blast_args_for('templates') // {};
Condition0%0/2
$rp->blast_args_for("templates") // {}
l!l
00
MC/DC0%0/1
$rp->blast_args_for("templates") // {}
$rp->blast_args_for("templates")
Truth table0%0/2
A
A= $rp->blast_args_for("templates")
Aresult
11
00
270 0 $args->{-outfmt} = 5;
271 0 $args->{-max_target_seqs} = 250;
272  
273 0 my $orthologous_seqs = $self->orthologous_seqs;
274 0 ▶ $args->{-query_gencode} = $self->code # if BLASTX
Branch: 1 branch
BranchTrueFalseTotal
if $orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot" 0 0 0
Condition0%0/3
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
!ll&&!rl&&r
000
MC/DC0%0/2
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
$orthologous_seqs->type eq "nucl" $blastdb->type eq "prot"
Truth table0%0/3
A and B
A= $orthologous_seqs->type eq "nucl"B= $blastdb->type eq "prot"
ABresult
0X0
100
111
275 if $orthologous_seqs->type eq 'nucl' && $blastdb->type eq 'prot';
276 0 my $parser = $blastdb->blast($orthologous_seqs, $args);
277 ##### [ORG] XML BLASTX (or BLASTP/N): 'TOL ' . $parser->filename
278  
279 # abort if no hit
280 0 my $bo = $parser->blast_output;
281 0 ▶ return unless $bo;
Branch: 1 branch
BranchTrueFalseTotal
unless $bo 0 0 0
282  
283 0 my %tol_score_for;
284  
285 ORTHOLOGUE:
286 0 for my $orthologue ($bo->all_iterations) {
287 0 ▶ next ORTHOLOGUE unless $orthologue->count_hits;
Branch: 1 branch
BranchTrueFalseTotal
unless $orthologue->count_hits 0 0 0
288 # Note: this should never happen...
289  
290 0 my $query_def = $orthologue->query_def;
291 0 my $transcript_acc = $orthologous_seqs->long_id_for($query_def);
292 ######## [DEBUG] orthologue: $transcript_acc
293  
294 TOL_HIT:
295 0 for my $hit ($orthologue->all_hits) {
296  
297 # check taxonomy of hit: skip SELF-like hits
298 0 my $hit_id = SeqId->new( full_id => $hit->id );
299 ######## [DEBUG] TOL hit: $hit_id->full_id
300 0 ▶ next TOL_HIT if $self->is_allowed($hit_id);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_allowed($hit_id) 0 0 0
301  
302 # fetch score for first non-SELF-like hit
303 0 my $score = $hit->get_hsp(0)->bit_score;
304 ######## [DEBUG] score: $score
305 0 $tol_score_for{$transcript_acc} = $score;
306 0 next ORTHOLOGUE;
307 }
308 }
309 0 ▶ $parser->remove unless $rp->debug_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $rp->debug_mode 0 0 0
310  
311 0 return \%tol_score_for;
312 }
313  
314  
315 0 ▶sub _build_aligned_seqs { ## no critic (ProhibitExcessComplexity)
Subroutine _build_aligned_seqs: not called CC=31 SCAR=69.0
316 0 my $self = shift;
317  
318 ##### [ORG] Aligning orthologues...
319  
320 0 my $ap = $self->ali_proc;
321 0 my $rp = $ap->run_proc;
322  
323 0 ▶ my $args = $rp->blast_args_for('templates') // {};
Condition0%0/2
$rp->blast_args_for("templates") // {}
l!l
00
MC/DC0%0/1
$rp->blast_args_for("templates") // {}
$rp->blast_args_for("templates")
Truth table0%0/2
A
A= $rp->blast_args_for("templates")
Aresult
11
00
324 0 $args->{-outfmt} = 5;
325 0 $args->{-max_target_seqs} = $rp->tax_max_hits * 2;
326  
327 0 my $orthologous_seqs = $self->orthologous_seqs;
328 0 my $blastdb = $ap->blastdb;
329 0 ▶ $args->{-query_gencode} = $self->code # if BLASTX
Branch: 1 branch
BranchTrueFalseTotal
if $orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot" 0 0 0
Condition0%0/3
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
!ll&&!rl&&r
000
MC/DC0%0/2
$orthologous_seqs->type eq "nucl" and $blastdb->type eq "prot"
$orthologous_seqs->type eq "nucl" $blastdb->type eq "prot"
Truth table0%0/3
A and B
A= $orthologous_seqs->type eq "nucl"B= $blastdb->type eq "prot"
ABresult
0X0
100
111
330 if $orthologous_seqs->type eq 'nucl' && $blastdb->type eq 'prot';
331 0 my $parser = $blastdb->blast($orthologous_seqs, $args);
332 ##### [ORG] XML BLASTX (or BLASTP/N): $parser->filename
333  
334 0 my $aligned_seqs = Ali->new();
335  
336 # abort if no hit
337 0 my $bo = $parser->blast_output;
338 0 ▶ return $aligned_seqs unless $bo;
Branch: 1 branch
BranchTrueFalseTotal
unless $bo 0 0 0
339  
340 ORTHOLOGUE:
341 0 for my $orthologue ($bo->all_iterations) {
342 0 ▶ unless ($orthologue->count_hits) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($orthologue->count_hits) 0 0 0
343 ###### [ORG] skipped orthologue due to lack of significant template
344 0 next ORTHOLOGUE;
345 } # TODO: investigate why this should happen at all...
346  
347 # fetch tax_line from orthologue
348 # Note: .para check is also done in this sub (hence the next below)
349 0 my $tax_line = $self->_fetch_tax_line_for_transcript($orthologue);
350 0 ▶ next ORTHOLOGUE unless $tax_line;
Branch: 1 branch
BranchTrueFalseTotal
unless $tax_line 0 0 0
351  
352 # extract contam_org and transcript_id from tax_line...
353 0 my $contam_org = $tax_line->contam_org;
354 0 my $transcript_id = $tax_line->seq_id . '%s'; # chunk placeholder
355 0 ▶ $transcript_id .= "...$contam_org" if $contam_org;
Branch: 1 branch
BranchTrueFalseTotal
if $contam_org 0 0 0
356 0 $transcript_id .= '#NEW#';
357  
358 # ... and use it "as is" to store tax_line in tax_report (no chunk tag)
359 0 my $tax_line_id = sprintf $transcript_id, q{};
360 0 $ap->set_tax_line( $tax_line_id => $tax_line );
361  
362 # extract transcript_seq from tax_line
363 0 my $transcript_seq = Seq->new(
364 seq_id => $tax_line_id, # same id without alignment
365 seq => $tax_line->seq
366 );
367  
368 # skip both orthologue alignment and integration if metagenomic mode
369 0 ▶ next ORTHOLOGUE if $rp->run_mode eq 'metagenomic';
Branch: 1 branch
BranchTrueFalseTotal
if $rp->run_mode eq "metagenomic" 0 0 0
370  
371 # optionally add transcript_seq as is (without alignment)
372 0 ▶ if ($rp->aligner_mode eq 'off') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->aligner_mode eq "off") 0 0 0
373  
374 ####### [ORG] Adding: $transcript_seq->full_id
375  
376 0 $aligned_seqs->add_seq($transcript_seq);
377 0 next ORTHOLOGUE;
378 }
379  
380 # build a template_seq list as long as query coverage improves
381 # exonerate will try to use the longest template for alignment
382 # while BLAST will use each hit in turn (possibly as a fall-back)
383 0 my @templates;
384 my @template_seqs;
385 0 my $best_coverage = 0;
386  
387 TEMPLATE:
388 0 for my $template ($orthologue->all_hits) {
389  
390 # fetch template full_id
391 0 ▶ my $template_id = SeqId->new(
Condition0%0/3
$blastdb->long_id_for($template->def) // $blastdb->long_id_for($template->id)
l!l&&r!l&&!r
000
MC/DC0%0/2
$blastdb->long_id_for($template->def) // $blastdb->long_id_for($template->id)
$blastdb->long_id_for($template->def) $blastdb->long_id_for($template->id)
Truth table0%0/3
A // B
A= $blastdb->long_id_for($template->def)B= $blastdb->long_id_for($template->id)
ABresult
1X1
011
000
392 full_id => $blastdb->long_id_for( $template->def )
393 // $blastdb->long_id_for( $template->id )
394 ); # workaround to accommodate change in BLAST XML report
395  
396 # optionally skip template if from same org as the orthologue
397 0 ▶ if ($rp->ali_skip_self eq 'on') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->ali_skip_self eq "on") 0 0 0
398 0 ▶ if ($template_id->full_org eq $transcript_seq->full_org) {
Branch: 1 branch
BranchTrueFalseTotal
if ($template_id->full_org eq $transcript_seq->full_org) 0 0 0
399 ###### [ORG] skipped same-org template due to ali_skip_self
400 0 next TEMPLATE;
401 }
402 }
403  
404 # compute query coverage by template HSPs
405 0 my $mask = SeqMask->empty_mask( $orthologue->query_len );
406 $mask->mark_block($_->query_start, $_->query_end)
407 0 for $template->all_hsps;
408 0 my $coverage = $mask->coverage;
409  
410 0 ▶ last TEMPLATE if $coverage
Branch: 1 branch
BranchTrueFalseTotal
if $coverage < $best_coverage * $rp->ali_cover_mul 0 0 0
411 < $best_coverage * $rp->ali_cover_mul;
412 0 $best_coverage = $coverage;
413  
414 ######## [DEBUG] template: $template_id->full_id
415 ######## [DEBUG] coverage: sprintf '%.2f', $coverage
416  
417 # fetch and cache aligned template seq from Ali
418 # Note: we emulate a fast get_seq_with_id using Ali lookup
419 0 push @templates, $template;
420 0 push @template_seqs, $ap->ali->get_seq(
421 $ap->lookup->index_for( $template_id->full_id )
422 );
423 }
424  
425 # Note: as we (optionally) skip templates, we may run out of templates
426 0 ▶ unless (@templates) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@templates) 0 0 0
427 ###### [ORG] skipped orthologue due to lack of suitable template
428 0 next ORTHOLOGUE;
429 }
430  
431 # flag tracking exonerate failure (for exoblast mode)
432 0 my $failure;
433  
434 0 ▶ if ($rp->aligner_mode =~ m/exonerate|exoblast/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->aligner_mode =~ /exonerate|exoblast/msx) 0 0 0
435  
436 # use longest template for exonerate alignment
437 0 my $template_seq = $template_seqs[-1];
438  
439 # align transcript on template protein and get its translation
440 # Note: in exonerate the translated dna_seq is called 'target_seq'
441 0 my $exo = Bio::MUST::Drivers::Exonerate::Aligned->new(
442 dna_seq => $transcript_seq,
443 pep_seq => $template_seq->clone->degap,
444 code => $self->code,
445 );
446  
447 # get new_seq from exonerate report
448 # build new_id from transcript_id and exonerate model used
449 0 my $new_id = sprintf $transcript_id, '.E.' . $exo->model;
450 0 my $new_seq = $exo->target_seq;
451 0 $new_seq->set_seq_id($new_id);
452  
453 ####### [ORG] Adding: $new_seq->full_id
454  
455 0 ▶ unless ($new_seq->seq_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_seq->seq_len) { } 0 0 0
456 0 ▶ my $fate = $rp->aligner_mode eq 'exoblast'
Branch: 1 branch
BranchTrueFalseTotal
$rp->aligner_mode eq 'exoblast' ? : 0 0 0
457 ? 'will retry with BLAST' : 'discarded'
458 ;
459 ####### [ORG] exonerate failure: $fate
460 0 $failure = 1;
461 }
462  
463 else {
464 # align new_seq on template_seq using subject_seq as a guide
465 0 $aligned_seqs->add_seq(
466 $ap->integrator->align(
467 new_seq => $new_seq,
468 subject => $exo->query_seq,
469 template => $template_seq,
470 start => $exo->query_start,
471 )
472 );
473  
474 ######## [DEBUG] aligned with exonerate model: $exo->model
475 }
476 }
477  
478 0 ▶ if ( ($rp->aligner_mode eq 'blast')
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->aligner_mode eq "blast" or $rp->aligner_mode eq "exoblast" and $failure) 0 0 0
Condition0%0/6
$rp->aligner_mode eq "blast" or $rp->aligner_mode eq "exoblast" and $failure
l!l&&r!l&&!r
000
$rp->aligner_mode eq "exoblast" and $failure
!ll&&!rl&&r
000
MC/DC0%0/3
$rp->aligner_mode eq "blast" or $rp->aligner_mode eq "exoblast" and $failure
$rp->aligner_mode eq "blast" $rp->aligner_mode eq "exoblast" $failure
Truth table0%0/4
A or B and C
A= $rp->aligner_mode eq "blast"B= $rp->aligner_mode eq "exoblast"C= $failure
ABCresult
1XX1
0111
00X0
0100
479 || ($rp->aligner_mode eq 'exoblast' && $failure) ) {
480  
481 TEMPLATE:
482 0 for my $template (@templates) {
483  
484 # use each template in turn for BLAST alignment
485 0 my $template_seq = shift @template_seqs;
486 0 ▶ last TEMPLATE unless $template_seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $template_seq 0 0 0
487  
488 HSP:
489 0 for my $hsp ($template->all_hsps) {
490  
491 # build HSP id from transcript_id and template/HSP ranks
492 0 my $hsp_id = sprintf $transcript_id,
493 '.H' . $template->num . '.' . $hsp->num;
494  
495 # build HSP seq from BLASTX report
496 0 (my $hsp_seq = $hsp->qseq) =~ s{\*}{$FRAMESHIFT}xmsg;
497 0 my $new_seq = Seq->new(
498 seq_id => $hsp_id,
499 seq => $hsp_seq
500 );
501  
502 # fetch aligned template seq from HSP (= subject)
503 0 my $subject_seq = Seq->new(
504 seq_id => $template_seq->seq_id,
505 seq => $hsp->hseq
506 );
507  
508 # reverse complement seqs if template on reverse in BLASTN
509 0 ▶ if ($ap->query_seqs->type eq 'nucl'
Branch: 1 branch
BranchTrueFalseTotal
if ($ap->query_seqs->type eq "nucl" and $blastdb->type eq "nucl" and $hsp->hit_strand == -1) 0 0 0
Condition0%0/6
$ap->query_seqs->type eq "nucl" and $blastdb->type eq "nucl" and $hsp->hit_strand == -1
!ll&&!rl&&r
000
$ap->query_seqs->type eq "nucl" and $blastdb->type eq "nucl"
!ll&&!rl&&r
000
MC/DC0%0/3
$ap->query_seqs->type eq "nucl" and $blastdb->type eq "nucl" and $hsp->hit_strand == -1
$ap->query_seqs->type eq "nucl" $blastdb->type eq "nucl" $hsp->hit_strand == -1
Truth table0%0/4
A and B and C
A= $ap->query_seqs->type eq "nucl"B= $blastdb->type eq "nucl"C= $hsp->hit_strand == -1
ABCresult
0XX0
10X0
1100
1111
510 && $blastdb->type eq 'nucl'
511 && $hsp->hit_strand == -1) {
512 0 $new_seq = $new_seq->reverse_complemented_seq;
513 0 $subject_seq = $subject_seq->reverse_complemented_seq;
514 }
515  
516 ####### [ORG] Adding: $new_seq->full_id
517  
518 # align new_seq on template_seq using subject_seq as a guide
519 $aligned_seqs->add_seq(
520 0 $ap->integrator->align(
521 new_seq => $new_seq,
522 subject => $subject_seq,
523 template => $template_seq,
524 start => $hsp->hit_start,
525 )
526 );
527  
528 ######## [DEBUG] aligned with BLAST
529 }
530 }
531 }
532 }
533  
534 0 ▶ $parser->remove unless $rp->debug_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $rp->debug_mode 0 0 0
535  
536 0 return $aligned_seqs;
537 }
538  
539 ## use critic
540  
541  
542 0 ▶sub _compress_seqs {
Subroutine _compress_seqs: not called CC=6 SCAR=37.4
543 0 my $self = shift;
544 0 my $ali = shift;
545  
546 0 my $rp = $self->ali_proc->run_proc;
547  
548 # first fetch all seqs...
549 # ... then clear existing seqs
550 0 my @seqs2cap = $ali->all_seqs;
551 0 $ali->_set_seqs( [] );
552  
553 # proceed only if at least one seq
554 0 ▶ return unless @seqs2cap;
Branch: 1 branch
BranchTrueFalseTotal
unless @seqs2cap 0 0 0
555  
556 # Note: this might seem sub-optimal in case of singletons
557 # but we follow as closely as possible the logic of compress-db.pl
558  
559 # proceed only if at least two seqs
560 # otherwise add lone seq
561 0 ▶ if (@seqs2cap < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@seqs2cap < 2) 0 0 0
562 0 $ali->add_seq( shift @seqs2cap );
563 0 return;
564 }
565  
566 # TODO: add debugging comments?
567  
568 # try to cap seqs
569 0 my $cap = Cap3->new(
570 seqs => \@seqs2cap,
571 cap3_args => {
572 -p => $rp->merge_min_ident * 100.0, # CAP3 expects percents
573 -o => $rp->merge_min_len,
574 },
575 );
576  
577 # add singlet seqs
578 0 my @singlets = $cap->all_singlets;
579 0 $ali->add_seq($_) for @singlets;
580  
581 # proceed only if contigs of seqs
582 0 my @contigs = $cap->all_contigs;
583 0 ▶ return unless @contigs;
Branch: 1 branch
BranchTrueFalseTotal
unless @contigs 0 0 0
584  
585 0 for my $contig (@contigs) {
586 0 my @ids = map { $_->full_id }
587 0 @{ $cap->seq_ids_for( $contig->full_id ) };
588 0 my $contig_id = shift(@ids) . ':::+' . @ids;
589 0 my $contig_seq = $contig->seq;
590  
591 # add contig seq
592 0 $ali->add_seq(
593 Seq->new( seq_id => $contig_id, seq => $contig_seq )
594 );
595 }
596  
597 # Note: we do not need to return anything as we modified $ali in place
598 0 return;
599 }
600  
601  
602 0 ▶sub _fetch_tax_line_for_transcript {
Subroutine _fetch_tax_line_for_transcript: not called CC=35 SCAR=71.4
603 0 my $self = shift;
604 0 my $orthologue = shift;
605  
606 0 my $ap = $self->ali_proc;
607 0 my $rp = $ap->run_proc;
608  
609 # fetch transcript accession (= query id) from BLAST report
610 0 my $query_def = $orthologue->query_def;
611 0 my $transcript_acc = $self->orthologous_seqs->long_id_for($query_def);
612  
613 # extract range and strand (if any) from transcript accession...
614 # Note: this mostly makes sense for genomic contigs/scaffolds
615 # ... and extract potential tail '+N' (if orthologues have been merged)
616 # Note: this looks convoluted but it has to work in many different setups
617 # depending on the value of trim_homologues and merge_orthologues:
618 # - off/off: acc
619 # - off/on: acc:::+N
620 # - on /off: acc:::start:::end:::strand
621 # - on /on: acc:::start:::end:::strand:::+N
622 0 my @fields = split /:::/xms, $transcript_acc;
623 0 my ($strip_acc, $start, $end, $strand, $more) = @fields;
624 0 ▶ ($more, $start) = ($start, undef)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $end and defined $start and $start =~ /\A \+\d+ \z/msx 0 0 0
Condition0%0/6
not defined $end and defined $start and $start =~ /\A \+\d+ \z/msx
!ll&&!rl&&r
000
not defined $end and defined $start
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $end and defined $start and $start =~ /\A \+\d+ \z/msx
not defined $end defined $start $start =~ /\A \+\d+ \z/msx
Truth table0%0/4
not(A) and B and C
A= not defined $endB= defined $startC= $start =~ /\A \+\d+ \z/msx
ABCresult
0XX0
10X0
1100
1111
625 if !defined $end && defined $start && $start =~ m/\A \+\d+ \z/xms;
626  
627 # set acc to transcript accession
628 0 my ($first_chunk) = $strip_acc =~ m/^(\S+)/xms;
629 0 my @parts = split /\|/xms, $first_chunk;
630 0 my $acc = pop @parts;
631 ###### [ORG] orthologous transcript: $acc
632  
633 # fetch score for best template
634 0 my $temp_score = $orthologue->get_hit(0)->get_hsp(0)->bit_score;
635  
636 # check again for paralogy if .para file in use
637 0 ▶ if ($ap->para_blastdb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ap->para_blastdb) 0 0 0
638 0 ▶ my $para_score = $self->para_score_for($transcript_acc) // 0;
Condition0%0/2
$self->para_score_for($transcript_acc) // 0
l!l
00
MC/DC0%0/1
$self->para_score_for($transcript_acc) // 0
$self->para_score_for($transcript_acc)
Truth table0%0/2
A
A= $self->para_score_for($transcript_acc)
Aresult
11
00
639 0 ▶ if ($para_score > $temp_score) {
Branch: 1 branch
BranchTrueFalseTotal
if ($para_score > $temp_score) 0 0 0
640 ###### [ORG] rejected for PARA[logy]: "$para_score > $temp_score"
641 0 return;
642 }
643 }
644  
645 # check for contamination if tol_check in use
646 0 ▶ if ($rp->tol_blastdb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->tol_blastdb) 0 0 0
647 0 ▶ my $tol_score = $self->tol_score_for($transcript_acc) // 0;
Condition0%0/2
$self->tol_score_for($transcript_acc) // 0
l!l
00
MC/DC0%0/1
$self->tol_score_for($transcript_acc) // 0
$self->tol_score_for($transcript_acc)
Truth table0%0/2
A
A= $self->tol_score_for($transcript_acc)
Aresult
11
00
648 0 ▶ if ($tol_score > $temp_score) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tol_score > $temp_score) 0 0 0
649 ###### [ORG] rejected due to TOL check: "$tol_score > $temp_score"
650 0 return;
651 }
652 }
653  
654 # prebuild SeqId list for all templates
655 # this is needed for family affiliation (first only)
656 # ... and for assessing template taxonomy (all)
657 0 my $blastdb = $self->ali_proc->blastdb;
658 0 my @templates = $orthologue->all_hits;
659 0 ▶ my @template_ids = map { SeqId->new(
Condition0%0/3
$blastdb->long_id_for($_->def) // $blastdb->long_id_for($_->id)
l!l&&r!l&&!r
000
MC/DC0%0/2
$blastdb->long_id_for($_->def) // $blastdb->long_id_for($_->id)
$blastdb->long_id_for($_->def) $blastdb->long_id_for($_->id)
Truth table0%0/3
A // B
A= $blastdb->long_id_for($_->def)B= $blastdb->long_id_for($_->id)
ABresult
1X1
011
000
660 full_id => $blastdb->long_id_for( $_->def )
661 // $blastdb->long_id_for( $_->id )
662 ) } @templates; # workaround to accommodate change in BLAST XML report
663  
664 # set family to first template family (if any)
665 0 ▶ my $family = $template_ids[0]->family // q{};
Condition0%0/2
$template_ids[0]->family // ""
l!l
00
MC/DC0%0/1
$template_ids[0]->family // ""
$template_ids[0]->family
Truth table0%0/2
A
A= $template_ids[0]->family
Aresult
11
00
666 0 ▶ $family .= '-' if $family;
Branch: 1 branch
BranchTrueFalseTotal
if $family 0 0 0
667  
668 # set org to current (bank) org
669 0 my $org = $self->org;
670 0 my $contam_org = q{};
671  
672 # setup tax_report data
673 0 my $common_tax;
674 my $lca;
675 0 my $lineage;
676 0 my $tag = q{};
677 0 my $top_score = 0;
678 0 my $rel_n = 0;
679 0 my $mean_len;
680 my $mean_ident;
681  
682 # optionally analyze template taxonomy
683 # ... to build tax_reports of additions
684 # ... to tag potential contaminations
685 0 ▶ if ( $rp->tax_reports eq 'on' || $self->_tax_filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->tax_reports eq "on" or $self->_tax_filter) 0 0 0
Condition0%0/3
$rp->tax_reports eq "on" or $self->_tax_filter
l!l&&r!l&&!r
000
MC/DC0%0/2
$rp->tax_reports eq "on" or $self->_tax_filter
$rp->tax_reports eq "on" $self->_tax_filter
Truth table0%0/3
A or B
A= $rp->tax_reports eq "on"B= $self->_tax_filter
ABresult
1X1
011
000
686 0 my @relatives;
687 0 my $best_score = 0;
688 0 my $sum_len = 0;
689 0 my $sum_ident = 0;
690  
691 0 my $tax = $rp->tax;
692 0 my $ea = each_array @templates, @template_ids;
693  
694 # accumulate relatives for LCA inference
695 # Note: three logical modes can be distinguished.
696 # These should be implemented in the config file.
697 # 1. best-hit
698 # - tax_max_hits: 1
699 # - filter on tax_min_score or tax_min_len / tax_min_ident
700 # 2. classic LCA
701 # - tax_max_hits: to be specified
702 # - filter on tax_min_score or tax_min_len / tax_min_ident
703 # 3. MEGAN-like LCA
704 # - tax_max_hits: should be ignored
705 # - filter on tax_min_score / tax_score_mul
706 # however all criteria can be simultaneously activated
707  
708 REL:
709 0 ▶ while ( my ($template, $template_id) = $ea->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$ea()) 0 0 0
710  
711 # accumulate at most tax_max_hits relatives for LCA inference
712 0 ▶ last REL if @relatives >= $rp->tax_max_hits;
Branch: 1 branch
BranchTrueFalseTotal
if @relatives >= $rp->tax_max_hits 0 0 0
713  
714 # ensure that match to template is good enough...
715 # by default all these thresholds are disabled
716 0 my $hsp = $template->get_hsp(0);
717  
718 # ... MEGAN-like mode (and top_score needed for one-on-one)
719 0 my $score = $hsp->bit_score;
720 0 $top_score = List::AllUtils::max($top_score, $score);
721 # Note: we do not use last due to non-monotonic score decrease
722  
723 # no need to accumulate relatives if no NCBI Taxonomy is available
724 0 ▶ last REL unless $tax;
Branch: 1 branch
BranchTrueFalseTotal
unless $tax 0 0 0
725  
726 0 ▶ next REL if $score < $rp->tax_min_score;
Branch: 1 branch
BranchTrueFalseTotal
if $score < $rp->tax_min_score 0 0 0
727 0 ▶ next REL if $score < $rp->tax_score_mul * $best_score;
Branch: 1 branch
BranchTrueFalseTotal
if $score < $rp->tax_score_mul * $best_score 0 0 0
728  
729 # ... classic or best-hit mode
730 0 my $len = $hsp->align_len;
731 0 ▶ next REL if $len < $rp->tax_min_len;
Branch: 1 branch
BranchTrueFalseTotal
if $len < $rp->tax_min_len 0 0 0
732 0 my $ident = $hsp->identity / $len;
733 0 ▶ next REL if $ident < $rp->tax_min_ident;
Branch: 1 branch
BranchTrueFalseTotal
if $ident < $rp->tax_min_ident 0 0 0
734  
735 # try to determine taxonomy of template
736 # if possible add template to list of relatives...
737 # ... and set best_score for MEGAN-like mode
738 0 my @taxonomy = $tax->fetch_lineage($template_id);
739 0 ▶ if (@taxonomy) {
Branch: 1 branch
BranchTrueFalseTotal
if (@taxonomy) 0 0 0
740 # Note: contrary to ref_score_mul the best_score never changes
741 0 ▶ $best_score ||= $score;
Condition0%0/3
$best_score ||= $score
l!l&&r!l&&!r
000
MC/DC0%0/2
$best_score ||= $score
$best_score $score
Truth table0%0/3
A ||= B
A= $best_scoreB= $score
ABresult
1X1
011
000
742 0 $sum_len += $len;
743 0 $sum_ident += $ident;
744 0 push @relatives, \@taxonomy;
745 ######## [DEBUG] hit: $template_id->full_id
746 ######## [DEBUG] length: $len
747 ######## [DEBUG] identity: sprintf '%.2f', $ident
748 ######## [DEBUG] lineage: join '; ', @taxonomy
749 }
750 }
751  
752 ######## [DEBUG] relatives: display( map { join '; ', @$_ } @relatives )
753  
754 0 ▶ if (@relatives < $rp->tax_min_hits) {
Branch: 1 branch
BranchTrueFalseTotal
if (@relatives < $rp->tax_min_hits) { } 0 0 0
755 ###### [ORG] tagged as unclassified due to lack of relatives
756 0 $common_tax = [ 'unclassified sequences' ];
757 0 ▶ if ($self->_tax_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_tax_filter) 0 0 0
758 0 $tag = 'u#';
759 }
760 }
761  
762 else {
763 # infer LCA from all relatives...
764 0 $common_tax = $tax->compute_lca(@relatives);
765 0 $lineage = join '; ', @{$common_tax};
766 ######## [DEBUG] LCA lineage: $lineage
767 0 $lca = $common_tax->[-1];
768 ###### [ORG] affiliated to: $lca
769  
770 0 ▶ if ($rp->tax_reports eq 'on') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp->tax_reports eq "on") 0 0 0
771 0 $rel_n = @relatives;
772 0 $mean_len = sprintf '%.2f', $sum_len / $rel_n;
773 0 $mean_ident = sprintf '%.2f', $sum_ident / $rel_n;
774 }
775  
776 # optionally tag potential contamination based on LCA
777 # Note: LCAs are used "as is" because is_allowed handles them
778 # Note: tol_check 'on' disables positive taxonomic filtering
779 0 ▶ if ($self->_tax_filter && $rp->tol_check eq 'off') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_tax_filter and $rp->tol_check eq "off") 0 0 0
Condition0%0/3
$self->_tax_filter and $rp->tol_check eq "off"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_tax_filter and $rp->tol_check eq "off"
$self->_tax_filter $rp->tol_check eq "off"
Truth table0%0/3
A and B
A= $self->_tax_filterB= $rp->tol_check eq "off"
ABresult
0X0
100
111
780 ######## [DEBUG] pass tax_filter: $self->is_allowed($common_tax)
781 0 ▶ unless ( $self->is_allowed($common_tax) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_allowed($common_tax)) 0 0 0
782 ###### [ORG] tagged as contaminated
783 0 $tag = 'c#';
784 $contam_org = join '_',
785 0 ▶ map { $_ // () } SeqId->parse_ncbi_name($lca);
Condition0%0/3
$_ // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ // ()
$_ ()
Truth table0%0/3
A // B
A= $_B= ()
ABresult
1X1
011
000
786 } # delete undef species/strains
787 }
788 }
789 }
790  
791 # check for multiple orthologues derived from the same transcript
792 # Note: this mostly makes sense for genomic contigs/scaffolds
793 0 my $acc_u = $acc;
794 0 my $count = ++$self->_count_for->{$org}{$acc};
795 0 ▶ if ($count > 1) { # direct access to private attr
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 1) 0 0 0
796 0 carp "[ORG] Note: more than one orthologue extracted from $acc;"
797 . " appending .$count to accession.";
798 0 $acc_u .= ".$count";
799 }
800  
801 # add potential accession tail '+N' (if orthologues have been merged)
802 0 ▶ $acc_u .= $more if $more;
Branch: 1 branch
BranchTrueFalseTotal
if $more 0 0 0
803  
804 # fetch orthologous transcript and give it nearly complete full_id
805 0 my $transcript_seq
806 = $self->orthologous_seqs->get_seq_with_id($transcript_acc)->seq;
807 0 ▶ my $transcript_id
Branch: 1 branch
BranchTrueFalseTotal
$org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::PKEYONLY/ || $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::GCAONLY/ ? : 0 0 0
Condition0%0/3
$org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::PKEYONLY/ or $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::GCAONLY/
l!l&&r!l&&!r
000
MC/DC0%0/2
$org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::PKEYONLY/ or $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::GCAONLY/
$org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::PKEYONLY/ $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::GCAONLY/
Truth table0%0/3
A or B
A= $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::PKEYONLY/B= $org =~ /$Bio::MUST::Apps::FortyTwo::OrgProcessor::GCAONLY/
ABresult
1X1
011
000
808 = $org =~ $PKEYONLY || $org =~ $GCAONLY ? $org . '|' . $acc_u
809 : $family . $tag . $org . '@' . $acc_u
810 ;
811  
812 # build tax_report line for transcript
813 0 my $tax_line = NewSeq->new(
814 seq_id => $transcript_id,
815 contam_org => $contam_org,
816 top_score => $top_score,
817 rel_n => $rel_n,
818 mean_len => $mean_len,
819 mean_ident => $mean_ident,
820 lca => $lca,
821 lineage => $lineage,
822 acc => $acc, # Note: not $acc_u here!
823 start => $start,
824 end => $end,
825 strand => $strand,
826 seq => $transcript_seq,
827 );
828  
829 0 return $tax_line;
830 }
831  
832  
833 0 ▶sub BUILD {
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
834 0 my $self = shift;
835  
836 0 my $ap = $self->ali_proc;
837 0 my $rp = $ap->run_proc;
838  
839 # optionally build _tax_filter from tax_filter (specs) and tax attrs
840 # Note: cannot use builder/coercion because of the need for a tax object
841 0 ▶ if ($self->tax_filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tax_filter) 0 0 0
842 0 my $tax = $rp->tax;
843 0 ▶ $self->_set_tax_filter( $tax->tax_filter( $self->tax_filter ) )
Branch: 1 branch
BranchTrueFalseTotal
if $tax 0 0 0
844 if $tax; # warning already issued at this stage
845 }
846  
847 ##### [ORG] homologues: display( $self->homologous_seqs->all_long_ids )
848 0 ▶ return unless $self->homologous_seqs->all_long_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->homologous_seqs->all_long_ids 0 0 0
849  
850 ##### [ORG] orthologues: display( $self->orthologous_seqs->all_long_ids )
851 0 ▶ return unless $self->orthologous_seqs->all_long_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->orthologous_seqs->all_long_ids 0 0 0
852  
853 ##### [ORG] aligned: display( map { $_->full_id } $self->aligned_seqs->all_seq_ids )
854 0 ▶ return unless $self->aligned_seqs->all_seq_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->aligned_seqs->all_seq_ids 0 0 0
855  
856 ##### [ORG] Adding aligned seqs to file...
857 0 $ap->ali->add_seq( $self->aligned_seqs->all_seqs );
858  
859 0 return;
860 }
861  
862  
863 1 __PACKAGE__->meta->make_immutable;
864 1 1;
865  
866 __END__
↑ Summary lib/Bio/MUST/Apps/Roles/OrgProcable.pm »