line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Coordinate::Utils; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:BIOPERLML'; |
3
|
|
|
|
|
|
|
$Bio::Coordinate::Utils::VERSION = '1.007001'; |
4
|
1
|
|
|
1
|
|
3604
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
28
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
7
|
1
|
|
|
1
|
|
4
|
use Bio::Location::Simple; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
8
|
1
|
|
|
1
|
|
3
|
use Bio::Coordinate::Pair; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
15
|
|
9
|
1
|
|
|
1
|
|
5
|
use Bio::Coordinate::Collection; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
10
|
1
|
|
|
1
|
|
3
|
use parent qw(Bio::Root::Root); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Additional methods to create Bio::Coordinate objects. |
13
|
|
|
|
|
|
|
# AUTHOR: Heikki Lehvaslaiho |
14
|
|
|
|
|
|
|
# AUTHOR: Jason Stajich |
15
|
|
|
|
|
|
|
# OWNER: Heikki Lehvaslaiho |
16
|
|
|
|
|
|
|
# OWNER: Jason Stajich |
17
|
|
|
|
|
|
|
# LICENSE: Perl_5 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub from_align { |
23
|
1
|
|
|
1
|
1
|
4209
|
my ($self, $aln, $ref ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
14
|
$aln->isa('Bio::Align::AlignI') || |
26
|
|
|
|
|
|
|
$self->throw('Not a Bio::Align::AlignI object but ['. ref($aln). ']'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# default reference sequence to the first sequence |
29
|
1
|
|
50
|
|
|
5
|
$ref ||= 1; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
7
|
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
|
|
|
|
|
6
|
$aln->map_chars('\.','-'); |
37
|
1
|
|
|
|
|
203
|
my $cs = $aln->gap_line; |
38
|
1
|
|
|
|
|
188
|
my $seq1 = $aln->get_seq_by_pos(1); |
39
|
1
|
|
|
|
|
49
|
my $seq2 = $aln->get_seq_by_pos(2); |
40
|
1
|
|
|
|
|
29
|
while ( $cs =~ /([^\-]+)/g) { |
41
|
|
|
|
|
|
|
# alignment coordinates |
42
|
2
|
|
|
|
|
5
|
my $lenmatch = length($1); |
43
|
2
|
|
|
|
|
3
|
my $start = pos($cs) - $lenmatch +1; |
44
|
2
|
|
|
|
|
8
|
my $end = $start + $lenmatch -1; |
45
|
2
|
|
|
|
|
8
|
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
|
|
|
|
|
971
|
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
|
|
|
|
|
944
|
my $pair = Bio::Coordinate::Pair->new |
58
|
|
|
|
|
|
|
(-in => $match1, |
59
|
|
|
|
|
|
|
-out => $match2 |
60
|
|
|
|
|
|
|
); |
61
|
2
|
50
|
|
|
|
6
|
unless( $pair->test ) { |
62
|
0
|
|
|
|
|
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
|
|
|
|
|
23
|
$collection->add_mapper($pair); |
70
|
|
|
|
|
|
|
} |
71
|
1
|
50
|
|
|
|
4
|
return ($collection->each_mapper)[0] if $collection->mapper_count == 1; |
72
|
1
|
|
|
|
|
3
|
return $collection; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub from_seq_to_alignmentpos { |
78
|
0
|
|
|
0
|
1
|
|
my ($self, $aln ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$aln->isa('Bio::Align::AlignI') || |
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) { |
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
|
0
|
|
|
|
|
unless ( $pair->test ) { |
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
|
0
|
|
|
|
|
if( $collection->mapper_count == 1) { |
123
|
0
|
|
|
|
|
|
push @mappers, ($collection->each_mapper)[0]; |
124
|
|
|
|
|
|
|
} else { |
125
|
0
|
|
|
|
|
|
push @mappers, $collection; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
return @mappers; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |