Coordinate/Utils.pm

filter: Statementstmt 66.1% 43 / 65 Branchbran 31.2% 5 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.8% 8 / 9 Podpod 100% 2 / 2 totaltotal 62.1% 59 / 95 CC 11 SCAR 27.5
CC
11
Cov
59%
from_seq_to_alignmentpos
42.0
from_align
6.2
BEGIN
1.0
CRAP 15.6
« Coordinate/GeneMapper.pm ↑ Summary Coordinate/Collection.pm »
1 package Bio::Coordinate::Utils;
2 2 our $AUTHORITY = 'cpan:BIOPERLML';
3 2 $Bio::Coordinate::Utils::VERSION = '1.007001';
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Bio::Location::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Bio::Coordinate::Pair;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Coordinate::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use parent qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Additional methods to create Bio::Coordinate objects.
13 # AUTHOR: Heikki Lehvaslaiho <heikki@bioperl.org>
14 # AUTHOR: Jason Stajich <jason@bioperl.org>
15 # OWNER: Heikki Lehvaslaiho
16 # OWNER: Jason Stajich
17 # LICENSE: Perl_5
18  
19  
20  
21  
22 1 ▶sub from_align {
Subroutine from_align: called CC=6 SCAR=18.2
Pod documented
23 1 my ($self, $aln, $ref ) = @_;
24  
25 1 ▶ $aln->isa('Bio::Align::AlignI') ||
Branch: 1 branch
BranchTrueFalseTotal
$aln->isa("Bio::Align::AlignI") or $self->throw('Not a Bio::Align::AlignI object but [' . ref($aln) . ']') 1 0 1
26 $self->throw('Not a Bio::Align::AlignI object but ['. ref($aln). ']');
27  
28 # default reference sequence to the first sequence
29 1 ▶ $ref ||= 1;
Condition50%1/2
$ref ||= 1
l!l
01
MC/DC0%0/1
$ref ||= 1
$ref
Truth table50%1/2
A
A= $ref
Aresult
11
00
30  
31 1 my $collection = Bio::Coordinate::Collection->new(-return_match=>1);
32  
33 # this works only for pairs, so split the MSA
34 # take the ref
35 #foreach remaining seq in aln, do:
36 1 $aln->map_chars('\.','-');
37 1 my $cs = $aln->gap_line;
38 1 my $seq1 = $aln->get_seq_by_pos(1);
39 1 my $seq2 = $aln->get_seq_by_pos(2);
40 1 ▶ while ( $cs =~ /([^\-]+)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cs =~ /([^\-]+)/g) 2 1 3
41 # alignment coordinates
42 2 my $lenmatch = length($1);
43 2 my $start = pos($cs) - $lenmatch +1;
44 2 my $end = $start + $lenmatch -1;
45 2 my $match1 = Bio::Location::Simple->new
46 (-seq_id => $seq1->id,
47 -start => $seq1->location_from_column($start)->start,
48 -end => $seq1->location_from_column($end)->start,
49 -strand => $seq1->strand );
50  
51 2 my $match2 = Bio::Location::Simple->new
52 (-seq_id => $seq2->id,
53 -start => $seq2->location_from_column($start)->start,
54 -end => $seq2->location_from_column($end)->start,
55 -strand => $seq2->strand );
56  
57 2 my $pair = Bio::Coordinate::Pair->new
58 (-in => $match1,
59 -out => $match2
60 );
61 2 ▶ unless( $pair->test ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pair->test) 0 2 2
62 0 $self->warn(join("",
63 "pair align did not pass test ($start..$end):\n",
64 "\tm1=",$match1->to_FTstring(), " len=",
65 $match1->length,
66 " m2=", $match2->to_FTstring()," len=",
67 $match2->length,"\n"));
68 }
69 2 $collection->add_mapper($pair);
70 }
71 1 ▶ return ($collection->each_mapper)[0] if $collection->mapper_count == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $collection->mapper_count == 1 0 1 1
72 1 return $collection;
73  
74 }
75  
76  
77 0 ▶sub from_seq_to_alignmentpos {
Subroutine from_seq_to_alignmentpos: not called CC=6 SCAR=37.4
Pod documented
78 0 my ($self, $aln ) = @_;
79  
80 0 ▶ $aln->isa('Bio::Align::AlignI') ||
Branch: 1 branch
BranchTrueFalseTotal
$aln->isa("Bio::Align::AlignI") or $self->throw('Not a Bio::Align::AlignI object but [' . ref($aln) . ']') 0 0 0
81 $self->throw('Not a Bio::Align::AlignI object but ['. ref($aln). ']');
82  
83 # default reference sequence to the first sequence
84 0 my @mappers;
85 0 $aln->map_chars('\.','-');
86 0 for my $seq ( $aln->each_seq ) {
87 0 my $collection = Bio::Coordinate::Collection->new(-return_match=>1);
88 0 my $cs = $seq->seq();
89 # do we change this over to use index and substr for speed?
90 0 ▶ while ( $cs =~ /([^\-]+)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cs =~ /([^\-]+)/g) 0 0 0
91 # alignment coordinates
92 0 my $lenmatch = length($1);
93 0 my $start = pos($cs) - $lenmatch +1;
94 0 my $end = $start + $lenmatch -1;
95  
96 0 my $match1 = Bio::Location::Simple->new
97 (-seq_id => $seq->id,
98 -start => $seq->location_from_column($start)->start,
99 -end => $seq->location_from_column($end)->start,
100 -strand => $seq->strand );
101  
102 0 my $match2 = Bio::Location::Simple->new
103 (-seq_id => 'alignment',
104 -start => $start,
105 -end => $end,
106 -strand => 0 );
107  
108 0 my $pair = Bio::Coordinate::Pair->new
109 (-in => $match1,
110 -out => $match2
111 );
112 0 ▶ unless ( $pair->test ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pair->test) 0 0 0
113 0 $self->warn(join("",
114 "pair align did not pass test ($start..$end):\n",
115 "\tm1=",$match1->to_FTstring(), " len=",
116 $match1->length,
117 " m2=", $match2->to_FTstring()," len=",
118 $match2->length,"\n"));
119 }
120 0 $collection->add_mapper($pair);
121 }
122 0 ▶ if( $collection->mapper_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($collection->mapper_count == 1) { } 0 0 0
123 0 push @mappers, ($collection->each_mapper)[0];
124 } else {
125 0 push @mappers, $collection;
126 }
127 }
128 0 return @mappers;
129 }
130  
131 2 1;
132  
133 __END__
« Coordinate/GeneMapper.pm ↑ Summary Coordinate/Collection.pm »