| 1 | package Bio::MUST::Core::Seq; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Nucleotide or protein sequence | ||||||||||||||||||||||||||||
| 3 | # CONTRIBUTOR: Catherine COLSON <ccolson@doct.uliege.be> | ||||||||||||||||||||||||||||
| 4 | # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||||||||||||||||||||
| 5 | # CONTRIBUTOR: Valerian LUPO <valerian.lupo@uliege.be> | ||||||||||||||||||||||||||||
| 6 | 18 | $Bio::MUST::Core::Seq::VERSION = '0.252040'; | |||||||||||||||||||||||||||
| 7 | 18 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 18 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 18 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # use Smart::Comments '###'; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 18 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 18 | ▶ | use feature qw(say); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 18 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 18 | ▶ | use Bio::MUST::Core::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 18 | ▶ | use Bio::MUST::Core::Constants qw(:seqtypes :seqids :gaps); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 18 | ▶ | use aliased 'Bio::MUST::Core::SeqId'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 18 | has 'seq_id' => ( | |||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||
| 24 | isa => 'Bio::MUST::Core::SeqId', | ||||||||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||||||||
| 26 | coerce => 1, | ||||||||||||||||||||||||||||
| 27 | handles => qr{.*}xms, # expose all SeqId methods (and attributes) | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 18 | has 'seq' => ( | |||||||||||||||||||||||||||
| 32 | traits => ['String'], | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => 'Bio::MUST::Core::Types::Seq', | ||||||||||||||||||||||||||||
| 35 | default => q{}, # can be empty | ||||||||||||||||||||||||||||
| 36 | coerce => 1, | ||||||||||||||||||||||||||||
| 37 | writer => '_set_seq', | ||||||||||||||||||||||||||||
| 38 | handles => { | ||||||||||||||||||||||||||||
| 39 | seq_len => 'length', | ||||||||||||||||||||||||||||
| 40 | append_seq => 'append', | ||||||||||||||||||||||||||||
| 41 | replace_seq => 'replace', | ||||||||||||||||||||||||||||
| 42 | edit_seq => 'substr', | ||||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # TODO: check whether this could be done by some Moose extension | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 402 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 402 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 402 | return $self->new( | |||||||||||||||||||||||||||
| 54 | seq_id => $self->full_id, seq => $self->seq | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # boolean assertions | ||||||||||||||||||||||||||||
| 60 | # TODO: optimize these assertions via caching | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 699 | ▶ | sub is_protein { | ||||||||||||||||||||||||||
|
Subroutine
is_protein: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 699 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 699 | ▶ | return 1 if $self->seq =~ $PROTLIKE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 209 | return 0; # at least 1 non-nt char | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 11 | ▶ | sub is_rna { | ||||||||||||||||||||||||||
|
Subroutine
is_rna: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 11 | ▶ | return 1 if $self->seq =~ $RNALIKE && (not $self->is_protein); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->seq =~ /$Bio::MUST::Core::Seq::RNALIKE/ and not $self->is_protein
MC/DC100%2/2
$self->seq =~ /$Bio::MUST::Core::Seq::RNALIKE/ and not $self->is_protein
$self->seq =~ /$Bio::MUST::Core::Seq::RNALIKE/
not $self->is_protein
Truth table100%3/3
A and not(B)
A= $self->seq =~ /$Bio::MUST::Core::Seq::RNALIKE/B= not $self->is_protein
| |||||||||||||||||||||||||||||
| 73 | 9 | return 0; # at least 1 'U' | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8609 | ▶ | sub is_aligned { | ||||||||||||||||||||||||||
|
Subroutine
is_aligned: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 8609 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 8609 | ▶ | return 1 if $self->seq =~ $GAP; # at least 1 gap-like char | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 8413 | return 0; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 36 | ▶ | sub is_subseq_of { | ||||||||||||||||||||||||||
|
Subroutine
is_subseq_of: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 36 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 36 | my $seq2 = shift; # can be a mere string | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 36 | $self = $self->raw_str; | |||||||||||||||||||||||||||
| 89 | 36 | ▶ | $seq2 = $seq2->isa('Bio::MUST::Core::Seq') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | ? $seq2->raw_str : _strip_gaps($seq2); | ||||||||||||||||||||||||||||
| 91 | 36 | ▶ | return 1 if $seq2 =~ m/$self/xmsi; # case-insensitive comparison | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 16 | return 0; # only here because expensive! | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 36 | ▶ | sub is_superseq_of { | ||||||||||||||||||||||||||
|
Subroutine
is_superseq_of: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 36 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 36 | my $seq2 = shift; # can be a mere string | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 36 | $self = $self->raw_str; | |||||||||||||||||||||||||||
| 101 | 36 | ▶ | $seq2 = $seq2->isa('Bio::MUST::Core::Seq') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | ? $seq2->raw_str : _strip_gaps($seq2); | ||||||||||||||||||||||||||||
| 103 | 36 | ▶ | return 1 if $self =~ m/$seq2/xmsi; # case-insensitive comparison | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 16 | return 0; # only here because expensive! | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 11 | ▶ | sub first_site { | ||||||||||||||||||||||||||
|
Subroutine
first_site: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 11 | my ($leading_gaps) = $self->seq =~ m{ \A ($GAP+) }xms; | |||||||||||||||||||||||||||
| 112 | 11 | ▶ | return length $leading_gaps // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
length $leading_gaps // 0
MC/DC100%1/1
length $leading_gaps // 0
length $leading_gaps
Truth table100%2/2
A
A= length $leading_gaps
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | ▶ | sub uc { ## no critic (ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||
|
Subroutine
uc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 5 | $self->_set_seq( uc $self->seq ); | |||||||||||||||||||||||||||
| 120 | 5 | return $self; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub uc_seq { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
uc_seq: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | carp '[BMC] Warning: Method uc_seq is deprecated; use uc instead!'; | |||||||||||||||||||||||||||
| 125 | 0 | return shift->uc(@_); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 5 | ▶ | sub recode { | ||||||||||||||||||||||||||
|
Subroutine
recode: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | 5 | my $base_for = shift; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 5 | my @states = $self->all_states; | |||||||||||||||||||||||||||
| 134 | 5 | my @rec_states; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 5 | for my $state (@states) { | |||||||||||||||||||||||||||
| 137 | 700 | ▶ | my $rec_state = $base_for->{$state} // $FRAMESHIFT; | ||||||||||||||||||||||||||
|
Condition33%1/3
$base_for->{$state} // $Bio::MUST::Core::Seq::FRAMESHIFT
MC/DC0%0/2
$base_for->{$state} // $Bio::MUST::Core::Seq::FRAMESHIFT
$base_for->{$state}
$Bio::MUST::Core::Seq::FRAMESHIFT
Truth table33%1/3
A // B
A= $base_for->{$state}B= $Bio::MUST::Core::Seq::FRAMESHIFT
| |||||||||||||||||||||||||||||
| 138 | 700 | push @rec_states, $rec_state; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 5 | my $new_seq = join q{}, @rec_states; | |||||||||||||||||||||||||||
| 142 | 5 | $self->_set_seq($new_seq); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | return $self; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub recode_seq { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
recode_seq: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | carp '[BMC] Warning: Method recode_seq is deprecated; use recode instead!'; | |||||||||||||||||||||||||||
| 149 | 0 | return shift->recode(@_); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # gap cleaning methods | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 38 | ▶ | sub degap { | ||||||||||||||||||||||||||
|
Subroutine
degap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 38 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 38 | $self->_set_seq($self->raw_str); | |||||||||||||||||||||||||||
| 159 | 38 | return $self; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 71 | ▶ | sub gapify { | ||||||||||||||||||||||||||
|
Subroutine
gapify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 71 | my $self = shift; | |||||||||||||||||||||||||||
| 165 | 71 | ▶ | my $char = shift // '*'; # defaults to gap | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "*"
MC/DC100%1/1
shift() // "*"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 71 | my $regex = $PROTMISS; # defaults to protein seq | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # in case of DNA ensure correct 'missification' (if applicable) | ||||||||||||||||||||||||||||
| 170 | 71 | ▶ | unless ($self->is_protein) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 8 | $regex = $DNAMISS; | |||||||||||||||||||||||||||
| 172 | 8 | ▶ | $char = 'N' if $char =~ $DNAMISS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 71 | ( my $seq = $self->seq ) =~ s{$regex}{$char}xmsg; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # alternative versions developed due to a design error in Ali::store_phylip | ||||||||||||||||||||||||||||
| 178 | # They are now commented because less general and not critical anymore. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # alt vers 1: hard-coding $char (if possible) gives a 250% boost | ||||||||||||||||||||||||||||
| 181 | # my $seq = $self->seq; | ||||||||||||||||||||||||||||
| 182 | # if ($self->is_protein) { | ||||||||||||||||||||||||||||
| 183 | # if ($char eq '*') { | ||||||||||||||||||||||||||||
| 184 | # $seq =~ s{$PROTMISS}{*}xmsg; | ||||||||||||||||||||||||||||
| 185 | # } | ||||||||||||||||||||||||||||
| 186 | # elsif ($char eq 'X') { | ||||||||||||||||||||||||||||
| 187 | # $seq =~ s{$PROTMISS}{X}xmsg; | ||||||||||||||||||||||||||||
| 188 | # } | ||||||||||||||||||||||||||||
| 189 | # else { | ||||||||||||||||||||||||||||
| 190 | # $seq =~ s{$PROTMISS}{$char}xmsg; | ||||||||||||||||||||||||||||
| 191 | # } | ||||||||||||||||||||||||||||
| 192 | # } | ||||||||||||||||||||||||||||
| 193 | # else { | ||||||||||||||||||||||||||||
| 194 | # if ($char eq '*') { | ||||||||||||||||||||||||||||
| 195 | # $seq =~ s{$DNAMISS}{*}xmsg; | ||||||||||||||||||||||||||||
| 196 | # } | ||||||||||||||||||||||||||||
| 197 | # elsif ($char eq 'X') { | ||||||||||||||||||||||||||||
| 198 | # $seq =~ s{$DNAMISS}{N}xmsg; | ||||||||||||||||||||||||||||
| 199 | # } | ||||||||||||||||||||||||||||
| 200 | # else { | ||||||||||||||||||||||||||||
| 201 | # $seq =~ s{$DNAMISS}{$char}xmsg; | ||||||||||||||||||||||||||||
| 202 | # } | ||||||||||||||||||||||||||||
| 203 | # } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # alt vers 2: hard-coded tr/// for 900% boost with s/// fall-back | ||||||||||||||||||||||||||||
| 206 | # Note: $PROTMISS and $DNAMISS regexes in Constants.pm are ignored! | ||||||||||||||||||||||||||||
| 207 | # my $seq = $self->seq; | ||||||||||||||||||||||||||||
| 208 | # if ($self->is_protein) { | ||||||||||||||||||||||||||||
| 209 | # if ($char eq '*') { | ||||||||||||||||||||||||||||
| 210 | # $seq =~ tr{?XxBJOUZbjouz}{*}; | ||||||||||||||||||||||||||||
| 211 | # } | ||||||||||||||||||||||||||||
| 212 | # elsif ($char eq 'X') { | ||||||||||||||||||||||||||||
| 213 | # $seq =~ tr{?XxBJOUZbjouz}{X}; | ||||||||||||||||||||||||||||
| 214 | # } | ||||||||||||||||||||||||||||
| 215 | # else { | ||||||||||||||||||||||||||||
| 216 | # $seq =~ s{[?XxBJOUZbjouz]}{$char}xmsg; | ||||||||||||||||||||||||||||
| 217 | # } | ||||||||||||||||||||||||||||
| 218 | # } | ||||||||||||||||||||||||||||
| 219 | # else { | ||||||||||||||||||||||||||||
| 220 | # if ($char eq '*') { | ||||||||||||||||||||||||||||
| 221 | # $seq =~ tr{?XxNnBDHKMRSVWYbdhkmrsvwy}{*}; | ||||||||||||||||||||||||||||
| 222 | # } | ||||||||||||||||||||||||||||
| 223 | # elsif ($char eq 'X') { | ||||||||||||||||||||||||||||
| 224 | # $seq =~ tr{?XxNnBDHKMRSVWYbdhkmrsvwy}{N}; | ||||||||||||||||||||||||||||
| 225 | # } | ||||||||||||||||||||||||||||
| 226 | # else { | ||||||||||||||||||||||||||||
| 227 | # $seq =~ s{[?XxNnBDHKMRSVWYbdhkmrsvwy]}{$char}xmsg; | ||||||||||||||||||||||||||||
| 228 | # } | ||||||||||||||||||||||||||||
| 229 | # } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 71 | $self->_set_seq($seq); | |||||||||||||||||||||||||||
| 232 | 71 | return $self; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 3069 | ▶ | sub spacify { | ||||||||||||||||||||||||||
|
Subroutine
spacify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 237 | 3069 | my $self = shift; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 3069 | my $seq = $self->seq; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # uniformize runs of [*-space] having at least one 'true' space | ||||||||||||||||||||||||||||
| 242 | # Note: we cannot use replace_seq because of the g flag | ||||||||||||||||||||||||||||
| 243 | 3069 | $seq =~ s{ ( $GAP+ \ + ) }{ ' ' x length($1) }xmseg; | |||||||||||||||||||||||||||
| 244 | 3069 | $seq =~ s{ ( \ + $GAP+ ) }{ ' ' x length($1) }xmseg; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # Note: two simpler regexes are muuuuuch faster than one complicated regex! | ||||||||||||||||||||||||||||
| 247 | # $seq =~ s{ ( $GAP* \ + $GAP* ) }{ ' ' x length($1) }xmseg; | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 3069 | $self->_set_seq($seq); | |||||||||||||||||||||||||||
| 250 | 3069 | return $self; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 3068 | ▶ | sub trim { | ||||||||||||||||||||||||||
|
Subroutine
trim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 255 | 3068 | my $self = shift; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 3068 | $self->replace_seq( qr{ $GAP+\z }xms, q{} ); | |||||||||||||||||||||||||||
| 258 | 3068 | return $self; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 3068 | ▶ | sub pad_to { | ||||||||||||||||||||||||||
|
Subroutine
pad_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 263 | 3068 | my $self = shift; | |||||||||||||||||||||||||||
| 264 | 3068 | my $bound = shift; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 3068 | $self->append_seq( q{ } x ($bound - $self->seq_len) ); | |||||||||||||||||||||||||||
| 267 | 3068 | return $self; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 3 | ▶ | sub clear_new_tag { | ||||||||||||||||||||||||||
|
Subroutine
clear_new_tag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 272 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 3 | (my $full_id = $self->full_id) =~ s{$NEW_TAG\z}{}xms; | |||||||||||||||||||||||||||
| 275 | 3 | $self->set_seq_id( SeqId->new( full_id => $full_id ) ); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 3 | return $self; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # site-wise methods (0-numbered) | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 4203 | ▶ | sub all_states { | ||||||||||||||||||||||||||
|
Subroutine
all_states: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 284 | 4203 | my $self = shift; | |||||||||||||||||||||||||||
| 285 | 4203 | return split //, $self->seq; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 2002847 | ▶ | sub state_at { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
state_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 2002847 | return shift->edit_seq(@_, 1); | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub delete_site { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
delete_site: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | $self->edit_seq(@_, 1, q{}); | |||||||||||||||||||||||||||
| 298 | 0 | return $self; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 40 | ▶ | sub is_missing { | ||||||||||||||||||||||||||
|
Subroutine
is_missing: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 303 | 40 | my $self = shift; | |||||||||||||||||||||||||||
| 304 | 40 | my $site = shift; | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 40 | my $state = $self->state_at($site); | |||||||||||||||||||||||||||
| 307 | 40 | ▶ | return 1 if $state =~ $PROTMISS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 38 | ▶ | return 1 if $state =~ $DNAMISS && (not $self->is_protein); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$state =~ /$Bio::MUST::Core::Seq::DNAMISS/ and not $self->is_protein
MC/DC100%2/2
$state =~ /$Bio::MUST::Core::Seq::DNAMISS/ and not $self->is_protein
$state =~ /$Bio::MUST::Core::Seq::DNAMISS/
not $self->is_protein
Truth table100%3/3
A and not(B)
A= $state =~ /$Bio::MUST::Core::Seq::DNAMISS/B= not $self->is_protein
| |||||||||||||||||||||||||||||
| 309 | 37 | return 0; # X (or N depending on seq type) | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 139 | ▶ | sub is_gap { | ||||||||||||||||||||||||||
|
Subroutine
is_gap: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 314 | 139 | my $self = shift; | |||||||||||||||||||||||||||
| 315 | 139 | my $site = shift; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 139 | ▶ | return 1 if $self->state_at($site) =~ $GAP; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 109 | return 0; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # global methods | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 88 | ▶ | around qw(purity reverse_complemented_seq codons) => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 325 | 88 | my $method = shift; | |||||||||||||||||||||||||||
| 326 | 88 | my $self = shift; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # Note: we return an explicit undef to emulate other accessor behavior | ||||||||||||||||||||||||||||
| 329 | 88 | ▶ | if ($self->is_protein) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | 42 | carp '[BMC] Warning: sequence looks like a protein; returning undef!'; | |||||||||||||||||||||||||||
| 331 | 42 | return undef; ## no critic (ProhibitExplicitReturnUndef) | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 46 | return $self->$method(@_); | |||||||||||||||||||||||||||
| 335 | 18 | }; | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 407 | ▶ | sub nomiss_seq_len { | ||||||||||||||||||||||||||
|
Subroutine
nomiss_seq_len: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 339 | 407 | my $self = shift; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 407 | ▶ | my $regex = $self->is_protein ? $PROTMISS : $DNAMISS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 407 | (my $raw_str = $self->raw_str) =~ s/$regex//xmsg; | |||||||||||||||||||||||||||
| 343 | # TODO: decide how to handle ambiguous nucleotides | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 407 | return length $raw_str; | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub purity { | ||||||||||||||||||||||||||
|
Subroutine
purity: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | (my $pure_seq = $self->seq) =~ s/$NONPUREDNA//xmsg; | |||||||||||||||||||||||||||
| 353 | 0 | my $purity = 1.0 * length($pure_seq) / $self->seq_len; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | return $purity; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 17 | ▶ | sub reverse_complemented_seq { | ||||||||||||||||||||||||||
|
Subroutine
reverse_complemented_seq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 360 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | # reverse complement and preserve case | ||||||||||||||||||||||||||||
| 363 | # Note: RNA always becomes DNA | ||||||||||||||||||||||||||||
| 364 | 17 | my $new_seq = scalar reverse $self->seq; | |||||||||||||||||||||||||||
| 365 | 17 | $new_seq =~ tr/ATUGCYRSWKMBDHVN/TAACGRYSWMKVHDBN/; | |||||||||||||||||||||||||||
| 366 | 17 | $new_seq =~ tr/atugcyrswkmbdhvn/taacgryswmkvhdbn/; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 17 | return $self->new( seq_id => $self->full_id, seq => $new_seq ); | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 1 | ▶ | sub spliced_seq { | ||||||||||||||||||||||||||
|
Subroutine
spliced_seq: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 373 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 374 | 1 | my $blocks = shift; | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 1 | my $new_seq; | |||||||||||||||||||||||||||
| 377 | 1 | my $seq = $self->seq; | |||||||||||||||||||||||||||
| 378 | 1 | for my $block ( @{$blocks} ) { | |||||||||||||||||||||||||||
| 379 | 8 | my ($start, $end) = @{$block}; | |||||||||||||||||||||||||||
| 380 | 8 | $new_seq .= substr $seq, $start - 1, $end - $start + 1; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 1 | return $self->new( seq_id => $self->full_id, seq => $new_seq ); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 564 | ▶ | sub raw_str { | ||||||||||||||||||||||||||
|
Subroutine
raw_str: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 388 | 564 | my $self = shift; | |||||||||||||||||||||||||||
| 389 | 564 | return _strip_gaps($self->seq); | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub raw_seq { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
raw_seq: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 393 | 0 | carp '[BMC] Warning: Method raw_seq is deprecated; use raw_str instead!'; | |||||||||||||||||||||||||||
| 394 | 0 | return shift->raw_str(@_); | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 113 | ▶ | sub wrapped_str { | ||||||||||||||||||||||||||
|
Subroutine
wrapped_str: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 399 | 113 | my $self = shift; | |||||||||||||||||||||||||||
| 400 | 113 | ▶ | my $chunk = shift // 60; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // 60
MC/DC0%0/1
shift() // 60
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 113 | ▶ | my $nowrap = $chunk < 0 ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 113 | my $width = $self->seq_len; | |||||||||||||||||||||||||||
| 404 | 113 | ▶ | $chunk = $width if $nowrap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 113 | my $str; | |||||||||||||||||||||||||||
| 407 | 113 | ▶ | for (my $site = 0; $site < $width; $site += $chunk) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 7533 | $str .= $self->edit_seq($site, $chunk) . "\n"; | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 113 | return $str; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 29 | ▶ | sub codons { | ||||||||||||||||||||||||||
|
Subroutine
codons: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 416 | 29 | my $self = shift; | |||||||||||||||||||||||||||
| 417 | 29 | ▶ | my $frame = shift // 1; # defaults to frame +1 | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | # get specified DNA strand | ||||||||||||||||||||||||||||
| 420 | 29 | ▶ | my $dna = $frame < 0 ? $self->reverse_complemented_seq->seq : $self->seq; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 29 | $dna =~ tr/Uu/Tt/; # ensure DNA | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | # split strand into codons beginning at specified frame | ||||||||||||||||||||||||||||
| 424 | # ... and discard incomplete codons | ||||||||||||||||||||||||||||
| 425 | 29 | my @codons; | |||||||||||||||||||||||||||
| 426 | 29 | ▶ | for (my $i = (abs $frame) - 1; $i < length $dna; $i += 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 2035 | my $codon = substr $dna, $i, 3; | |||||||||||||||||||||||||||
| 428 | 2035 | ▶ | push @codons, $codon if length $codon == 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 29 | return \@codons; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | # private subs | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 600 | ▶ | sub _strip_gaps { | ||||||||||||||||||||||||||
|
Subroutine
_strip_gaps: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 438 | 600 | my $seq = shift; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 600 | $seq =~ s/$GAP+//xmsg; | |||||||||||||||||||||||||||
| 441 | 600 | return $seq; # strip all gaps | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 18 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 445 | 18 | 1; | |||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | __END__ | ||||||||||||||||||||||||||||