lib/Bio/MUST/Apps/SlaveAligner/Local.pm

filter: Statementstmt 41.6% 35 / 84 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 2 totaltotal 38.1% 45 / 118 CC 12 SCAR 33.1
CC
12
Cov
34%
align
56.0
make_indels
42.0
__ANON__
2.0
CRAP 27.3
« lib/Bio/MUST/Apps/FortyTwo/AliProcessor.pm ↑ Summary lib/Bio/MUST/Apps/Leel/OrgProcessor.pm »
1 package Bio::MUST::Apps::SlaveAligner::Local;
2 # ABSTRACT: Internal class for slave-aligner
3 1 $Bio::MUST::Apps::SlaveAligner::Local::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 switch);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use experimental qw(smartmatch); # to suppress warnings about 'when'
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Smart::Comments -ENV;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use List::AllUtils qw(max);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Sort::Naturally;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Bio::MUST::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use aliased 'Bio::MUST::Core::Seq';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 # _delayed_indels is a hash (site) of hashes (new_seq id)
21 # storing the number of insertions caused by each new_seq at each
22 # pos (as if each new_seq was added on its own to the Ali)
23  
24 1 has 'ali' => (
25 is => 'ro',
26 isa => 'Bio::MUST::Core::Ali',
27 required => 1,
28 );
29  
30  
31 has '_delayed_indels' => (
32 traits => ['Hash'],
33 is => 'ro',
34 isa => 'HashRef[HashRef[Num]]',
35 init_arg => undef,
36 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 1 handles => {
38 all_sites => 'keys',
39 indels_at => 'get',
40 },
41 );
42  
43  
44 0 ▶sub align { ## no critic (RequireArgUnpacking)
Subroutine align: not called CC=7 SCAR=40.3
Pod undocumented
45 0 my $self = shift;
46 0 my %args = @_;
47  
48 my (
49 $query, # new_seq as aligned in BLAST report
50 $sbjct, # template as aligned in BLAST report
51 $tmplt, # template as aligned in Ali
52 $splcd,
53 $start # pairwise alignment start in template
54 0 ) = @args{ qw(new_seq subject template cds_seq start) };
55  
56 # determine mode (prot/nucl) based on absence/presence of a DNA seq
57 # setup multiplier according to mode
58 0 ▶ my $mul = defined $splcd ? 3 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $splcd ? : 0 0 0
59  
60 # align query left-end on template
61 0 ▶ for (my $u = 0; $u < $start; $u++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u < $start) 0 0 0
62 0 ▶ $start++ if $tmplt->is_gap($u);
Branch: 1 branch
BranchTrueFalseTotal
if $tmplt->is_gap($u) 0 0 0
63 }
64 0 my $aligned_seq = q{ } x ( ($start-1) * $mul );
65  
66 # TODO: check whether $start can be set to hit_start-1 before the loop
67  
68 # setup loop
69 0 my $t = $start-1; # pos within template in Ali
70 0 my $q = 0; # pos within new_seq in BLAST report
71 0 my $s = 0; # pos within template in BLAST report
72 0 my $len = $query->seq_len;
73  
74 # loop through new_seq positions
75 0 ▶ while ($q < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q < $len) 0 0 0
76  
77 # encode gap configuration for easy dispatching
78 0 my $case
79 = $tmplt->is_gap($t)
80 . $query->is_gap($q)
81 . $sbjct->is_gap($s)
82 ;
83  
84 # examine 6 possible cases (t* q* s* and tL q* s* do not exist)
85 0 given ($case) {
86 0 when (/100|110/xms) { # case 1: t* qL sL
87 # case 2: t* q* sL
88 0 $aligned_seq .= '*' x $mul;
89 0 $t++;
90 }
91 0 when (/101|000/xms) { # case 3: t* qL s*
92 # case 4: tL qL sL
93 0 ▶ $aligned_seq .= $mul == 1 ? $query->state_at($q)
Branch: 1 branch
BranchTrueFalseTotal
$mul == 1 ? : 0 0 0
94 : $splcd->edit_seq($q * $mul, $mul);
95 0 $t++;
96 0 $q++;
97 0 $s++;
98 }
99 0 when (/010/xms) { # case 5: tL q* sL
100 0 $aligned_seq .= '*' x $mul;
101 0 $t++;
102 0 $q++;
103 0 $s++;
104 }
105 0 when (/001/xms) { # case 6: tL qL s*
106 0 ▶ $aligned_seq .= $mul == 1 ? $query->state_at($q)
Branch: 1 branch
BranchTrueFalseTotal
$mul == 1 ? : 0 0 0
107 : $splcd->edit_seq($q * $mul, $mul);
108 0 $self->_delayed_indels->{$t}{ $query->full_id } += $mul;
109 0 $q++;
110 0 $s++;
111 }
112 }
113 }
114  
115 0 return Seq->new(
116 seq_id => $query->full_id,
117 seq => $aligned_seq
118 );
119 }
120  
121  
122 # TODO: ensure that new seqs are in Ali
123  
124 0 ▶sub make_indels {
Subroutine make_indels: not called CC=6 SCAR=37.4
Pod undocumented
125 0 my $self = shift;
126  
127 # process delayed indels (from left to right)
128 0 my $offset = 0;
129 0 my @sites = sort { $a <=> $b } $self->all_sites;
130  
131 0 for my $site (@sites) {
132  
133 # get length of longest indel at site
134 0 my %indel_by = %{ $self->indels_at($site) };
135 0 my $max_indel = max values %indel_by;
136  
137 # insert indels at site into all seqs
138  
139 SEQ:
140 0 for my $seq ( $self->ali->all_seqs ) {
141  
142 # reduce indel length if seq has indels at the same site
143 0 ▶ my $indel = $max_indel - ( $indel_by{ $seq->full_id } // 0 );
Condition0%0/2
$indel_by{$seq->full_id} // 0
l!l
00
MC/DC0%0/1
$indel_by{$seq->full_id} // 0
$indel_by{$seq->full_id}
Truth table0%0/2
A
A= $indel_by{$seq->full_id}
Aresult
11
00
144  
145 # skip seq if indel reduced to zero
146 0 ▶ next SEQ if $indel == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $indel == 0 0 0 0
147  
148 # skip seq if indel farther than seq end
149 # TODO: check boundary
150 0 ▶ next SEQ if $site + $offset > $seq->seq_len - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $site + $offset > $seq->seq_len - 1 0 0 0
151  
152 # splice seq to insert required number of gaps
153 0 $seq->edit_seq($site + $offset, 0, '*' x $indel);
154 }
155  
156 # account for indel in subsequent computations
157 0 $offset += $max_indel;
158 }
159  
160 0 return;
161 }
162  
163  
164 1 __PACKAGE__->meta->make_immutable;
165 1 1;
166  
167 __END__
« lib/Bio/MUST/Apps/FortyTwo/AliProcessor.pm ↑ Summary lib/Bio/MUST/Apps/Leel/OrgProcessor.pm »