Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Coordinate/Chain.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 # $Id: Chain.pm,v 1.1 2002/10/24 17:35:30 heikki Exp $ | |
2 # | |
3 # bioperl module for Bio::Coordinate::Chain | |
4 # | |
5 # Cared for by Heikki Lehvaslaiho <heikki@ebi.ac.uk> | |
6 # | |
7 # Copyright Heikki Lehvaslaiho | |
8 # | |
9 # You may distribute this module under the same terms as perl itself | |
10 | |
11 # POD documentation - main docs before the code | |
12 | |
13 =head1 NAME | |
14 | |
15 Bio::Coordinate::Chain - Mapping locations through a chain of coordinate mappers | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 # create Bio::Coordinate::Pairs, or any MapperIs, somehow | |
20 $pair1; $pair2; | |
21 | |
22 # add them into a Chain | |
23 $collection = Bio::Coordinate::Chain->new; | |
24 $collection->add_mapper($pair1); | |
25 $collection->add_mapper($pair2); | |
26 | |
27 # create a position and map it | |
28 $pos = Bio::Location::Simple->new (-start => 5, -end => 9 ); | |
29 $match = $collection->map($pos); | |
30 if ($match) { | |
31 sprintf "Matches at %d-%d\n", $match->start, $match->end, | |
32 } else { | |
33 print "No match\n"; | |
34 } | |
35 | |
36 =head1 DESCRIPTION | |
37 | |
38 This class assumes that you have built several mappers and want to | |
39 link them together so that output from the previous mapper is the next | |
40 mappers input. This way you can build arbitrarily complex mappers from | |
41 simpler components. | |
42 | |
43 Note that Chain does not do any sanity checking on its mappers. You | |
44 are solely responsible that input and output coordinate systems, | |
45 direction of mapping and parameters internal to mappers make sense | |
46 when chained together. | |
47 | |
48 To put it bluntly, the present class is just a glorified foreach loop | |
49 over an array of mappers calling the map method. | |
50 | |
51 It would be neat to an internal function that would generate a new | |
52 single step mapper from those included in the chain. It should speed | |
53 things up considerably. Any volunteers? | |
54 | |
55 =head1 FEEDBACK | |
56 | |
57 =head2 Mailing Lists | |
58 | |
59 User feedback is an integral part of the evolution of this and other | |
60 Bioperl modules. Send your comments and suggestions preferably to the | |
61 Bioperl mailing lists Your participation is much appreciated. | |
62 | |
63 bioperl-l@bioperl.org - General discussion | |
64 http://bio.perl.org/MailList.html - About the mailing lists | |
65 | |
66 =head2 Reporting Bugs | |
67 | |
68 report bugs to the Bioperl bug tracking system to help us keep track | |
69 the bugs and their resolution. Bug reports can be submitted via | |
70 email or the web: | |
71 | |
72 bioperl-bugs@bio.perl.org | |
73 http://bio.perl.org/bioperl-bugs/ | |
74 | |
75 =head1 AUTHOR - Heikki Lehvaslaiho | |
76 | |
77 Email: heikki@ebi.ac.uk | |
78 Address: | |
79 | |
80 EMBL Outstation, European Bioinformatics Institute | |
81 Wellcome Trust Genome Campus, Hinxton | |
82 Cambs. CB10 1SD, United Kingdom | |
83 | |
84 =head1 CONTRIBUTORS | |
85 | |
86 Ewan Birney, birney@ebi.ac.uk | |
87 | |
88 =head1 APPENDIX | |
89 | |
90 The rest of the documentation details each of the object | |
91 methods. Internal methods are usually preceded with a _ | |
92 | |
93 =cut | |
94 | |
95 | |
96 # Let the code begin... | |
97 | |
98 package Bio::Coordinate::Chain; | |
99 use vars qw(@ISA ); | |
100 use strict; | |
101 | |
102 # Object preamble - inherits from Bio::Root::Root | |
103 use Bio::Root::Root; | |
104 use Bio::Coordinate::MapperI; | |
105 use Bio::Coordinate::Result; | |
106 use Bio::Coordinate::Collection; | |
107 | |
108 @ISA = qw(Bio::Coordinate::Collection Bio::Coordinate::MapperI); | |
109 | |
110 | |
111 =head2 map | |
112 | |
113 Title : map | |
114 Usage : $newpos = $obj->map($pos); | |
115 Function: Map the location through all the mappers in the chain. | |
116 Example : | |
117 Returns : new Location in the output coordiante system | |
118 Args : a Bio::Location::Simple object | |
119 | |
120 =cut | |
121 | |
122 sub map { | |
123 my ($self,$value) = @_; | |
124 | |
125 $self->throw("Need to pass me a value.") | |
126 unless defined $value; | |
127 $self->throw("I need a Bio::Location, not [$value]") | |
128 unless $value->isa('Bio::LocationI'); | |
129 $self->throw("No coordinate mappers!") | |
130 unless $self->each_mapper; | |
131 | |
132 my $res = new Bio::Coordinate::Result; | |
133 | |
134 foreach my $mapper ($self->each_mapper) { | |
135 | |
136 my $res = $mapper->map($value); | |
137 return undef unless $res->each_match; | |
138 $value = $res->match; | |
139 } | |
140 | |
141 return $value; | |
142 } | |
143 | |
144 | |
145 =head2 Inherited methods | |
146 | |
147 =cut | |
148 | |
149 =head2 add_mapper | |
150 | |
151 Title : add_mapper | |
152 Usage : $obj->add_mapper($mapper) | |
153 Function: Pushes one Bio::Coodinate::MapperI into the list of mappers. | |
154 Sets _is_sorted() to false. | |
155 Example : | |
156 Returns : 1 when succeeds, 0 for failure. | |
157 Args : mapper object | |
158 | |
159 =cut | |
160 | |
161 =head2 mappers | |
162 | |
163 Title : mappers | |
164 Usage : $obj->mappers(); | |
165 Function: Returns or sets a list of mappers. | |
166 Example : | |
167 Returns : array of mappers | |
168 Args : array of mappers | |
169 | |
170 =cut | |
171 | |
172 =head2 each_mapper | |
173 | |
174 Title : each_mapper | |
175 Usage : $obj->each_mapper(); | |
176 Function: Returns a list of mappers. | |
177 Example : | |
178 Returns : array of mappers | |
179 Args : none | |
180 | |
181 =cut | |
182 | |
183 =head2 swap | |
184 | |
185 Title : swap | |
186 Usage : $obj->swap; | |
187 Function: Swap the direction of mapping;input <-> output | |
188 Example : | |
189 Returns : 1 | |
190 Args : | |
191 | |
192 =cut | |
193 | |
194 =head2 test | |
195 | |
196 Title : test | |
197 Usage : $obj->test; | |
198 Function: test that both components of all pairs are of the same length. | |
199 Ran automatically. | |
200 Example : | |
201 Returns : boolean | |
202 Args : | |
203 | |
204 =cut | |
205 | |
206 | |
207 | |
208 sub sort{ | |
209 my ($self) = @_; | |
210 $self->warn("You do not really want to sort your chain, do you!\nDoing nothing."); | |
211 } | |
212 | |
213 1; | |
214 |