| 1 | #Copyright (c) 2010 Joachim Bargsten <code at bargsten dot org>. All rights reserved. | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Bio::Gonzales::Tools::SeqMask; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MouseX::Foreign 'Bio::Root::Root'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | with 'Bio::Gonzales::Role::BioPerl::Constructor'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.062'; # VERSION | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | has seq => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head2 mask | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Title : mask | ||||||||||||||||||||||||||||
| 23 | Usage : $obj->mask(10,40,'Z'); | ||||||||||||||||||||||||||||
| 24 | $obj->mask(10,40); | ||||||||||||||||||||||||||||
| 25 | $obj->mask($bio_location_obj, 'Z'); | ||||||||||||||||||||||||||||
| 26 | $obj->mask($bio_location_obj); | ||||||||||||||||||||||||||||
| 27 | Function: masks a sequence region by replacing the respective part with a | ||||||||||||||||||||||||||||
| 28 | custom character. If the character is omitted, 'X' in case of | ||||||||||||||||||||||||||||
| 29 | protein and 'N' in case of DNA/RNA alphabet is used to mask the | ||||||||||||||||||||||||||||
| 30 | sequence region. | ||||||||||||||||||||||||||||
| 31 | Returns : the object it was invoked on | ||||||||||||||||||||||||||||
| 32 | Args : integer for start position | ||||||||||||||||||||||||||||
| 33 | integer for end position | ||||||||||||||||||||||||||||
| 34 | custom character to use for masking | ||||||||||||||||||||||||||||
| 35 | OR | ||||||||||||||||||||||||||||
| 36 | Bio::LocationI location for sequence region (strand NOT honored) | ||||||||||||||||||||||||||||
| 37 | custom character to use for masking | ||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | our %UNKNOWN_CHAR = ( | |||||||||||||||||||||||||||
| 41 | dna => 'N', | ||||||||||||||||||||||||||||
| 42 | rna => 'N', | ||||||||||||||||||||||||||||
| 43 | protein => 'X', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub mask { | ||||||||||||||||||||||||||||
| 47 | 8 | ▶ | my ( $self, $start, $end, $char ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
mask: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | if ( ref($start) && $start->isa('Bio::LocationI') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $start and $start->isa("Bio::LocationI")
MC/DC50%1/2
ref $start and $start->isa("Bio::LocationI")
ref $start
$start->isa("Bio::LocationI")
Truth table66%2/3
A and B
A= ref $startB= $start->isa("Bio::LocationI")
| |||||||||||||||||||||||||||||
| 50 | 2 | my $loc = $start; | |||||||||||||||||||||||||||
| 51 | 2 | $char = $end; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | for my $subloc ( $loc->each_Location() ) { | |||||||||||||||||||||||||||
| 54 | 2 | $self->mask( $subloc->start, $subloc->end, $char ); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 6 | ▶ | $char = $UNKNOWN_CHAR{ lc( $self->seq->alphabet ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | unless ($char); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | $self->seq->subseq( | |||||||||||||||||||||||||||
| 61 | -start => $start, | ||||||||||||||||||||||||||||
| 62 | -end => $end, | ||||||||||||||||||||||||||||
| 63 | -replace_with => $char x ( $end - $start + 1 ), | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | return $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub trunc_masked_ends { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ( $self, $char ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
trunc_masked_ends: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $char = $UNKNOWN_CHAR{ lc( $self->seq->alphabet ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | unless ($char); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $seq = $self->seq->seq; | |||||||||||||||||||||||||||
| 77 | 0 | $seq =~ s/^$char+//; | |||||||||||||||||||||||||||
| 78 | 0 | $seq =~ s/$char+$//; | |||||||||||||||||||||||||||
| 79 | 0 | $self->seq->seq($seq); | |||||||||||||||||||||||||||
| 80 | 0 | return $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||||||||||