1
# $Id: Utils.pm,v 1.4 2003/12/19 03:00:09 jason Exp $
3
# BioPerl module for Bio::Coordinate::Utils
5
# Cared for by Heikki Lehvaslaiho <heikki@ebi.ac.uk>
7
# Copyright Heikki Lehvaslaiho
9
# You may distribute this module under the same terms as perl itself
11
# POD documentation - main docs before the code
15
Bio::Coordinate::Utils - Additional methods to create Bio::Coordinate objects
19
use Bio::Coordinate::Utils;
20
# get a Bio::Align::AlignI compliant object, $aln, somehow
21
# it could be a Bio::SimpleAlign
23
$mapper = Bio::Coordinate::Utils->from_align($aln, 1);
27
This class is a holder of methods that work on or create
28
Bio::Coordinate::MapperI- compliant objects. . These methods are not
29
part of the Bio::Coordinate::MapperI interface and should in general
30
not be essential to the primary function of sequence objects. If you
31
are thinking of adding essential functions, it might be better to
32
create your own sequence class. See L<Bio::PrimarySeqI>,
33
L<Bio::PrimarySeq>, and L<Bio::Seq> for more.
39
User feedback is an integral part of the evolution of this and other
40
Bioperl modules. Send your comments and suggestions preferably to one
41
of the Bioperl mailing lists. Your participation is much appreciated.
43
bioperl-l@bioperl.org - General discussion
44
http://bio.perl.org/MailList.html - About the mailing lists
48
Report bugs to the Bioperl bug tracking system to help us keep track
49
the bugs and their resolution. Bug reports can be submitted via email
52
bioperl-bugs@bio.perl.org
53
http://bugzilla.bioperl.org/
55
=head1 AUTHOR - Heikki Lehvaslaiho
57
Email: heikki@ebi.ac.uk
60
EMBL Outstation, European Bioinformatics Institute
61
Wellcome Trust Genome Campus, Hinxton
62
Cambs. CB10 1SD, United Kingdom
66
The rest of the documentation details each of the object
67
methods. Internal methods are usually preceded with a _
72
# Let the code begin...
75
package Bio::Coordinate::Utils;
78
use Bio::Location::Simple;
79
use Bio::Coordinate::Pair;
80
use Bio::Coordinate::Collection;
84
@ISA = qw(Bio::Root::Root);
85
# new inherited from Root
90
Usage : $mapper = Bio::Coordinate::Utils->from_align($aln, 1);
92
Create a mapper out of an alignment.
93
The mapper will return a value only when both ends of
94
the input range find a match.
96
Note: This implementation works only on pairwise alignments
97
and is not yet well tested!
99
Returns : A Bio::Coordinate::MapperI
100
Args : Bio::Align::AlignI object
101
Id for the reference sequence, optional
106
my ($self, $aln, $ref ) = @_;
108
$aln->isa('Bio::Align::AlignI') ||
109
$self->throw('Not a Bio::Align::AlignI object but ['. ref($self). ']');
111
# default reference sequence to the first sequence
114
my $collection = Bio::Coordinate::Collection->new(-return_match=>1);
116
# this works only for pairs, so split the MSA
118
#foreach remaining seq in aln, do:
120
my $cs = $aln->gap_line;
121
my $seq1 = $aln->get_seq_by_pos(1);
122
my $seq2 = $aln->get_seq_by_pos(2);
124
while ( $cs =~ /([^-]+)/g) {
126
# alignment coordinates
127
my $start = pos($cs) - length($1) + 1;
128
my $end = $start + length($1)-1;
130
my $match1 = Bio::Location::Simple->new
131
(-seq_id => $seq1->id,
132
-start => $seq1->location_from_column($start)->start,
133
-end => $seq1->location_from_column($end)->start,
134
-strand => $seq1->strand );
136
my $match2 = Bio::Location::Simple->new
137
(-seq_id => $seq2->id,
138
-start => $seq2->location_from_column($start)->start,
139
-end => $seq2->location_from_column($end)->start,
140
-strand => $seq2->strand );
142
my $pair = Bio::Coordinate::Pair->new
146
$collection->add_mapper($pair);
149
return ($collection->each_mapper)[0] if $collection->mapper_count == 1;