ensembl-hive  2.8.1
AssemblySliceAdaptor.pm
Go to the documentation of this file.
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 
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 
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 
74 use strict;
75 use warnings;
76 no warnings 'uninitialized';
77 
78 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
79 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
83 
85 
86 
87 =head2 new
88 
89  Example : my $assembly_slice_adaptor =
91  Description : Constructor.
93  Exceptions : none
94  Caller : general
95  Status : At Risk
96  : under development
97 
98 =cut
99 
100 sub new {
101  my $caller = shift;
102 
103  my $class = ref($caller) || $caller;
104  my $self = $class->SUPER::new(@_);
105 
106  return $self;
107 }
108 
109 
110 =head2 fetch_by_version
111 
112  Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container
113  to attach MappedSlices to
114  Arg[2] : String $version - the assembly version to fetch
115  Example : my ($mapped_slice) = @{ $msc->fetch_by_version('NCBIM36') };
116  Description : Creates a MappedSlice representing an alternative assembly
117  version of the container's reference slice.
118  Return type : listref of Bio::EnsEMBL::MappedSlice
119  Exceptions : thrown on wrong or missing arguments
120  Caller : general, Bio::EnsEMBL::MappedSliceContainer
121  Status : At Risk
122  : under development
123 
124 =cut
125 
126 sub fetch_by_version {
127  my $self = shift;
128  my $container = shift;
129  my $version = shift;
130 
131  # arguement check
132  unless ($container and ref($container) and
133  $container->isa('Bio::EnsEMBL::MappedSliceContainer')) {
134  throw("Need a MappedSliceContainer.");
135  }
136 
137  unless ($version) {
138  throw("Need an assembly version.");
139  }
140 
141  my $slice = $container->ref_slice;
142 
143  # project slice onto other assembly and construct MappedSlice for result
144  my $mapped_slice = Bio::EnsEMBL::MappedSlice->new(
145  -ADAPTOR => $self,
146  -CONTAINER => $container,
147  -NAME => $slice->name."\#mapped_$version",
148  );
149 
150  my $cs_name = $slice->coord_system_name;
151 
152  foreach my $seg (@{ $slice->project($cs_name, $version) }) {
153 
154  my $proj_slice = $seg->to_Slice;
155 
156  # create a Mapper to map to/from the mapped_slice artificial coord system
157  my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice');
158 
159  # tell the mapper how to map this segment
160  $mapper->add_map_coordinates(
161  'mapped_slice',
162  $seg->from_start,
163  $seg->from_end,
164  ($slice->strand * $proj_slice->strand),
165  $proj_slice->seq_region_name,
166  $proj_slice->start,
167  $proj_slice->end
168  );
169 
170  # add the Slice/Mapper pair to the MappedSlice
171  $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper);
172  }
173 
174  return [$mapped_slice];
175 }
176 
177 
178 =head2 fetch_by_name
179 
180  Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container
181  to attach MappedSlices to
182  Arg[2] : String $name - the assembly name to fetch
183  Arg[3] : (optional) String $version -- the version for the new assembly
184  Example : my ($mapped_slice) = @{ $msc->fetch_by_name('LRG1','1') };
185  Description : Creates a MappedSlice representing an alternative assembly
186  version of the container's reference slice.
187  Return type : listref of Bio::EnsEMBL::MappedSlice
188  Exceptions : thrown on wrong or missing arguments
189  Caller : general, Bio::EnsEMBL::MappedSliceContainer
190  Status : At Risk
191  : under development
192 
193 =cut
194 
195 sub fetch_by_name {
196  my $self = shift;
197  my $container = shift;
198  my $name = shift;
199  my $version = shift;
200 
201  # arguement check
202  unless ($container and ref($container) and
203  $container->isa('Bio::EnsEMBL::MappedSliceContainer')) {
204  throw("Need a MappedSliceContainer.");
205  }
206 
207  unless ($name) {
208  throw("Need an assembly name.");
209  }
210 
211  $version ||= '';
212  my $slice = $container->ref_slice;
213 
214  # project slice onto other assembly and construct MappedSlice for result
215  my $mapped_slice = Bio::EnsEMBL::MappedSlice->new(
216  -ADAPTOR => $self,
217  -CONTAINER => $container,
218  -NAME => $slice->name."\#mapped_$name:$version",
219  );
220 
221 
222  foreach my $seg (@{ $slice->project($name, $version) }) {
223 
224  my $proj_slice = $seg->to_Slice;
225 
226  # create a Mapper to map to/from the mapped_slice artificial coord system
227  my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice');
228 
229  # tell the mapper how to map this segment
230  $mapper->add_map_coordinates(
231  'mapped_slice',
232  $seg->from_start,
233  $seg->from_end,
234  ($slice->strand * $proj_slice->strand),
235  $proj_slice->seq_region_name,
236  $proj_slice->start,
237  $proj_slice->end
238  );
239 
240  # add the Slice/Mapper pair to the MappedSlice
241  $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper);
242  }
243 
244  return [$mapped_slice];
245 }
246 
247 
248 1;
249 
map
public map()
Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor::fetch_by_version
public Listref fetch_by_version()
Bio::EnsEMBL::MappedSlice
Definition: MappedSlice.pm:75
Bio::EnsEMBL::MappedSlice::new
public Bio::EnsEMBL::MappedSlice new()
Bio::EnsEMBL::MappedSliceContainer
Definition: MappedSliceContainer.pm:62
Bio::EnsEMBL::DBSQL::BaseAdaptor
Definition: BaseAdaptor.pm:71
Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor
Definition: AssemblySliceAdaptor.pm:33
Bio::EnsEMBL::MappedSliceContainer::new
public Bio::EnsEMBL::MappedSliceContainer new()
Bio::EnsEMBL::MappedSliceContainer::ref_slice
public Bio::EnsEMBL::Slice ref_slice()
Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor::new
public Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor new()
Bio::EnsEMBL::Utils::Argument
Definition: Argument.pm:34
Bio::EnsEMBL::Utils::Exception
Definition: Exception.pm:68
Bio::EnsEMBL::Mapper
Definition: Coordinate.pm:3