EnsEMBL/DBSQL/AssemblySliceAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 17 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 107 CC 5 SCAR 17.9
CC
5
Cov
0%
fetch_by_version
12.0
fetch_by_name
12.0
new
2.0
CRAP 6.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor - adaptor/factory for MappedSlices
34 representing alternative assemblies
35  
36 =head1 SYNOPSIS
37  
38 my $slice =
39 $slice_adaptor->fetch_by_region( 'chromosome', 14, 900000, 950000 );
40  
41 my $msc = Bio::EnsEMBL::MappedSliceContainer->new( -SLICE => $slice );
42  
43 my $asa = Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor->new;
44  
45 my ($mapped_slice) = @{ $asa->fetch_by_version( $msc, 'NCBIM36' ) };
46  
47 =head1 DESCRIPTION
48  
49 NOTE: this code is under development and not fully functional nor tested
50 yet. Use only for development.
51  
52 This adaptor is a factory for creating MappedSlices representing
53 alternative assemblies and attaching them to a MappedSliceContainer. A
54 mapper will be created to map between the reference slice and the common
55 container slice coordinate system.
56  
57 =head1 METHODS
58  
59 new
60 fetch_by_version
61  
62 =head1 REALTED MODULES
63  
64 Bio::EnsEMBL::MappedSlice
65 Bio::EnsEMBL::MappedSliceContainer
66 Bio::EnsEMBL::Compara::AlignSlice
67 Bio::EnsEMBL::Compara::AlignSlice::Slice
68 Bio::EnsEMBL::Variation::StrainSlice
69  
70 =cut
71  
72 package Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor;
73 $Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor::VERSION = '114.0.0_50'; # TRIAL
74 $Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor::VERSION = '114.0.050';
75 use strict;
76 use warnings;
77 no warnings 'uninitialized';
78  
79 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
80 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
81 use Bio::EnsEMBL::MappedSlice;
82 use Bio::EnsEMBL::Mapper;
83 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
84  
85 our @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
86  
87  
88 =head2 new
89  
90 Example : my $assembly_slice_adaptor =
91 Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor->new;
92 Description : Constructor.
93 Return type : Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor
94 Exceptions : none
95 Caller : general
96 Status : At Risk
97 : under development
98  
99 =cut
100  
101 sub new {
102 my $caller = shift;
103  
104 my $class = ref($caller) || $caller;
105 my $self = $class->SUPER::new(@_);
106
107 return $self;
108 }
109  
110  
111 =head2 fetch_by_version
112  
113 Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container
114 to attach MappedSlices to
115 Arg[2] : String $version - the assembly version to fetch
116 Example : my ($mapped_slice) = @{ $msc->fetch_by_version('NCBIM36') };
117 Description : Creates a MappedSlice representing an alternative assembly
118 version of the container's reference slice.
119 Return type : listref of Bio::EnsEMBL::MappedSlice
120 Exceptions : thrown on wrong or missing arguments
121 Caller : general, Bio::EnsEMBL::MappedSliceContainer
122 Status : At Risk
123 : under development
124  
125 =cut
126  
127 sub fetch_by_version {
128 my $self = shift;
129 my $container = shift;
130 my $version = shift;
131  
132 # arguement check
133 unless ($container and ref($container) and
134 $container->isa('Bio::EnsEMBL::MappedSliceContainer')) {
135 throw("Need a MappedSliceContainer.");
136 }
137  
138 unless ($version) {
139 throw("Need an assembly version.");
140 }
141  
142 my $slice = $container->ref_slice;
143  
144 # project slice onto other assembly and construct MappedSlice for result
145 my $mapped_slice = Bio::EnsEMBL::MappedSlice->new(
146 -ADAPTOR => $self,
147 -CONTAINER => $container,
148 -NAME => $slice->name."\#mapped_$version",
149 );
150  
151 my $cs_name = $slice->coord_system_name;
152  
153 foreach my $seg (@{ $slice->project($cs_name, $version) }) {
154
155 my $proj_slice = $seg->to_Slice;
156
157 # create a Mapper to map to/from the mapped_slice artificial coord system
158 my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice');
159
160 # tell the mapper how to map this segment
161 $mapper->add_map_coordinates(
162 'mapped_slice',
163 $seg->from_start,
164 $seg->from_end,
165 ($slice->strand * $proj_slice->strand),
166 $proj_slice->seq_region_name,
167 $proj_slice->start,
168 $proj_slice->end
169 );
170
171 # add the Slice/Mapper pair to the MappedSlice
172 $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper);
173 }
174  
175 return [$mapped_slice];
176 }
177  
178  
179 =head2 fetch_by_name
180  
181 Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container
182 to attach MappedSlices to
183 Arg[2] : String $name - the assembly name to fetch
184 Arg[3] : (optional) String $version -- the version for the new assembly
185 Example : my ($mapped_slice) = @{ $msc->fetch_by_name('LRG1','1') };
186 Description : Creates a MappedSlice representing an alternative assembly
187 version of the container's reference slice.
188 Return type : listref of Bio::EnsEMBL::MappedSlice
189 Exceptions : thrown on wrong or missing arguments
190 Caller : general, Bio::EnsEMBL::MappedSliceContainer
191 Status : At Risk
192 : under development
193  
194 =cut
195  
196 sub fetch_by_name {
197 my $self = shift;
198 my $container = shift;
199 my $name = shift;
200 my $version = shift;
201  
202 # arguement check
203 unless ($container and ref($container) and
204 $container->isa('Bio::EnsEMBL::MappedSliceContainer')) {
205 throw("Need a MappedSliceContainer.");
206 }
207  
208 unless ($name) {
209 throw("Need an assembly name.");
210 }
211  
212 $version ||= '';
213 my $slice = $container->ref_slice;
214  
215 # project slice onto other assembly and construct MappedSlice for result
216 my $mapped_slice = Bio::EnsEMBL::MappedSlice->new(
217 -ADAPTOR => $self,
218 -CONTAINER => $container,
219 -NAME => $slice->name."\#mapped_$name:$version",
220 );
221  
222  
223 foreach my $seg (@{ $slice->project($name, $version) }) {
224
225 my $proj_slice = $seg->to_Slice;
226
227 # create a Mapper to map to/from the mapped_slice artificial coord system
228 my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice');
229
230 # tell the mapper how to map this segment
231 $mapper->add_map_coordinates(
232 'mapped_slice',
233 $seg->from_start,
234 $seg->from_end,
235 ($slice->strand * $proj_slice->strand),
236 $proj_slice->seq_region_name,
237 $proj_slice->start,
238 $proj_slice->end
239 );
240
241 # add the Slice/Mapper pair to the MappedSlice
242 $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper);
243 }
244  
245 return [$mapped_slice];
246 }
247  
248  
249 1;
250