2 # bioperl module for Bio::Coordinate::Chain
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
8 # Copyright Heikki Lehvaslaiho
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Coordinate::Chain - Mapping locations through a chain of coordinate mappers
20 # create Bio::Coordinate::Pairs, or any MapperIs, somehow
23 # add them into a Chain
24 $collection = Bio::Coordinate::Chain->new;
25 $collection->add_mapper($pair1);
26 $collection->add_mapper($pair2);
28 # create a position and map it
29 $pos = Bio::Location::Simple->new (-start => 5, -end => 9 );
30 $match = $collection->map($pos);
32 sprintf "Matches at %d-%d\n", $match->start, $match->end,
39 This class assumes that you have built several mappers and want to
40 link them together so that output from the previous mapper is the next
41 mappers input. This way you can build arbitrarily complex mappers from
44 Note that Chain does not do any sanity checking on its mappers. You
45 are solely responsible that input and output coordinate systems,
46 direction of mapping and parameters internal to mappers make sense
47 when chained together.
49 To put it bluntly, the present class is just a glorified foreach loop
50 over an array of mappers calling the map method.
52 It would be neat to an internal function that would generate a new
53 single step mapper from those included in the chain. It should speed
54 things up considerably. Any volunteers?
60 User feedback is an integral part of the evolution of this and other
61 Bioperl modules. Send your comments and suggestions preferably to the
62 Bioperl mailing lists Your participation is much appreciated.
64 bioperl-l@bioperl.org - General discussion
65 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
69 Please direct usage questions or support issues to the mailing list:
71 I<bioperl-l@bioperl.org>
73 rather than to the module maintainer directly. Many experienced and
74 reponsive experts will be able look at the problem and quickly
75 address it. Please include a thorough description of the problem
76 with code and data examples if at all possible.
80 Report bugs to the Bioperl bug tracking system to help us keep track
81 the bugs and their resolution. Bug reports can be submitted via the
84 http://bugzilla.open-bio.org/
86 =head1 AUTHOR - Heikki Lehvaslaiho
88 Email: heikki-at-bioperl-dot-org
92 Ewan Birney, birney@ebi.ac.uk
96 The rest of the documentation details each of the object
97 methods. Internal methods are usually preceded with a _
102 # Let the code begin...
104 package Bio
::Coordinate
::Chain
;
107 # Object preamble - inherits from Bio::Root::Root
109 use Bio
::Coordinate
::Result
;
111 use base
qw(Bio::Coordinate::Collection Bio::Coordinate::MapperI);
117 Usage : $newpos = $obj->map($pos);
118 Function: Map the location through all the mappers in the chain.
120 Returns : new Location in the output coordiante system
121 Args : a Bio::Location::Simple object
126 my ($self,$value) = @_;
128 $self->throw("Need to pass me a value.")
129 unless defined $value;
130 $self->throw("I need a Bio::Location, not [$value]")
131 unless $value->isa('Bio::LocationI');
132 $self->throw("No coordinate mappers!")
133 unless $self->each_mapper;
135 my $res = Bio
::Coordinate
::Result
->new();
137 foreach my $mapper ($self->each_mapper) {
139 my $res = $mapper->map($value);
140 return unless $res->each_match;
141 $value = $res->match;
148 =head2 Inherited methods
155 Usage : $obj->add_mapper($mapper)
156 Function: Pushes one Bio::Coodinate::MapperI into the list of mappers.
157 Sets _is_sorted() to false.
159 Returns : 1 when succeeds, 0 for failure.
167 Usage : $obj->mappers();
168 Function: Returns or sets a list of mappers.
170 Returns : array of mappers
171 Args : array of mappers
178 Usage : $obj->each_mapper();
179 Function: Returns a list of mappers.
181 Returns : array of mappers
190 Function: Swap the direction of mapping;input <-> output
201 Function: test that both components of all pairs are of the same length.
213 $self->warn("You do not really want to sort your chain, do you!\nDoing nothing.");