Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/DBSQL/AssemblySliceAdaptor.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 =head1 LICENSE | |
| 2 | |
| 3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
| 4 Genome Research Limited. All rights reserved. | |
| 5 | |
| 6 This software is distributed under a modified Apache license. | |
| 7 For license details, please see | |
| 8 | |
| 9 http://www.ensembl.org/info/about/code_licence.html | |
| 10 | |
| 11 =head1 CONTACT | |
| 12 | |
| 13 Please email comments or questions to the public Ensembl | |
| 14 developers list at <dev@ensembl.org>. | |
| 15 | |
| 16 Questions may also be sent to the Ensembl help desk at | |
| 17 <helpdesk@ensembl.org>. | |
| 18 | |
| 19 =cut | |
| 20 | |
| 21 =head1 NAME | |
| 22 | |
| 23 Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor - adaptor/factory for MappedSlices | |
| 24 representing alternative assemblies | |
| 25 | |
| 26 =head1 SYNOPSIS | |
| 27 | |
| 28 my $slice = | |
| 29 $slice_adaptor->fetch_by_region( 'chromosome', 14, 900000, 950000 ); | |
| 30 | |
| 31 my $msc = Bio::EnsEMBL::MappedSliceContainer->new( -SLICE => $slice ); | |
| 32 | |
| 33 my $asa = Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor->new; | |
| 34 | |
| 35 my ($mapped_slice) = @{ $asa->fetch_by_version( $msc, 'NCBIM36' ) }; | |
| 36 | |
| 37 =head1 DESCRIPTION | |
| 38 | |
| 39 NOTE: this code is under development and not fully functional nor tested | |
| 40 yet. Use only for development. | |
| 41 | |
| 42 This adaptor is a factory for creating MappedSlices representing | |
| 43 alternative assemblies and attaching them to a MappedSliceContainer. A | |
| 44 mapper will be created to map between the reference slice and the common | |
| 45 container slice coordinate system. | |
| 46 | |
| 47 =head1 METHODS | |
| 48 | |
| 49 new | |
| 50 fetch_by_version | |
| 51 | |
| 52 =head1 REALTED MODULES | |
| 53 | |
| 54 Bio::EnsEMBL::MappedSlice | |
| 55 Bio::EnsEMBL::MappedSliceContainer | |
| 56 Bio::EnsEMBL::Compara::AlignSlice | |
| 57 Bio::EnsEMBL::Compara::AlignSlice::Slice | |
| 58 Bio::EnsEMBL::AlignStrainSlice | |
| 59 Bio::EnsEMBL::StrainSlice | |
| 60 | |
| 61 =cut | |
| 62 | |
| 63 package Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor; | |
| 64 | |
| 65 use strict; | |
| 66 use warnings; | |
| 67 no warnings 'uninitialized'; | |
| 68 | |
| 69 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
| 70 use Bio::EnsEMBL::Utils::Exception qw(throw warning); | |
| 71 use Bio::EnsEMBL::MappedSlice; | |
| 72 use Bio::EnsEMBL::Mapper; | |
| 73 use Bio::EnsEMBL::DBSQL::BaseAdaptor; | |
| 74 | |
| 75 our @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor); | |
| 76 | |
| 77 | |
| 78 =head2 new | |
| 79 | |
| 80 Example : my $assembly_slice_adaptor = | |
| 81 Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor->new; | |
| 82 Description : Constructor. | |
| 83 Return type : Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor | |
| 84 Exceptions : none | |
| 85 Caller : general | |
| 86 Status : At Risk | |
| 87 : under development | |
| 88 | |
| 89 =cut | |
| 90 | |
| 91 sub new { | |
| 92 my $caller = shift; | |
| 93 | |
| 94 my $class = ref($caller) || $caller; | |
| 95 my $self = $class->SUPER::new(@_); | |
| 96 | |
| 97 return $self; | |
| 98 } | |
| 99 | |
| 100 | |
| 101 =head2 fetch_by_version | |
| 102 | |
| 103 Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container | |
| 104 to attach MappedSlices to | |
| 105 Arg[2] : String $version - the assembly version to fetch | |
| 106 Example : my ($mapped_slice) = @{ $msc->fetch_by_version('NCBIM36') }; | |
| 107 Description : Creates a MappedSlice representing an alternative assembly | |
| 108 version of the container's reference slice. | |
| 109 Return type : listref of Bio::EnsEMBL::MappedSlice | |
| 110 Exceptions : thrown on wrong or missing arguments | |
| 111 Caller : general, Bio::EnsEMBL::MappedSliceContainer | |
| 112 Status : At Risk | |
| 113 : under development | |
| 114 | |
| 115 =cut | |
| 116 | |
| 117 sub fetch_by_version { | |
| 118 my $self = shift; | |
| 119 my $container = shift; | |
| 120 my $version = shift; | |
| 121 | |
| 122 # arguement check | |
| 123 unless ($container and ref($container) and | |
| 124 $container->isa('Bio::EnsEMBL::MappedSliceContainer')) { | |
| 125 throw("Need a MappedSliceContainer."); | |
| 126 } | |
| 127 | |
| 128 unless ($version) { | |
| 129 throw("Need an assembly version."); | |
| 130 } | |
| 131 | |
| 132 my $slice = $container->ref_slice; | |
| 133 | |
| 134 # project slice onto other assembly and construct MappedSlice for result | |
| 135 my $mapped_slice = Bio::EnsEMBL::MappedSlice->new( | |
| 136 -ADAPTOR => $self, | |
| 137 -CONTAINER => $container, | |
| 138 -NAME => $slice->name."\#mapped_$version", | |
| 139 ); | |
| 140 | |
| 141 my $cs_name = $slice->coord_system_name; | |
| 142 | |
| 143 foreach my $seg (@{ $slice->project($cs_name, $version) }) { | |
| 144 | |
| 145 my $proj_slice = $seg->to_Slice; | |
| 146 | |
| 147 # create a Mapper to map to/from the mapped_slice artificial coord system | |
| 148 my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice'); | |
| 149 | |
| 150 # tell the mapper how to map this segment | |
| 151 $mapper->add_map_coordinates( | |
| 152 'mapped_slice', | |
| 153 $seg->from_start, | |
| 154 $seg->from_end, | |
| 155 ($slice->strand * $proj_slice->strand), | |
| 156 $proj_slice->seq_region_name, | |
| 157 $proj_slice->start, | |
| 158 $proj_slice->end | |
| 159 ); | |
| 160 | |
| 161 # add the Slice/Mapper pair to the MappedSlice | |
| 162 $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper); | |
| 163 } | |
| 164 | |
| 165 return [$mapped_slice]; | |
| 166 } | |
| 167 | |
| 168 | |
| 169 =head2 fetch_by_name | |
| 170 | |
| 171 Arg[1] : Bio::EnsEMBL::MappedSliceContainer $container - the container | |
| 172 to attach MappedSlices to | |
| 173 Arg[2] : String $name - the assembly name to fetch | |
| 174 Arg[3] : (optional) String $version -- the version for the new assembly | |
| 175 Example : my ($mapped_slice) = @{ $msc->fetch_by_name('LRG1','1') }; | |
| 176 Description : Creates a MappedSlice representing an alternative assembly | |
| 177 version of the container's reference slice. | |
| 178 Return type : listref of Bio::EnsEMBL::MappedSlice | |
| 179 Exceptions : thrown on wrong or missing arguments | |
| 180 Caller : general, Bio::EnsEMBL::MappedSliceContainer | |
| 181 Status : At Risk | |
| 182 : under development | |
| 183 | |
| 184 =cut | |
| 185 | |
| 186 sub fetch_by_name { | |
| 187 my $self = shift; | |
| 188 my $container = shift; | |
| 189 my $name = shift; | |
| 190 my $version = shift; | |
| 191 | |
| 192 # arguement check | |
| 193 unless ($container and ref($container) and | |
| 194 $container->isa('Bio::EnsEMBL::MappedSliceContainer')) { | |
| 195 throw("Need a MappedSliceContainer."); | |
| 196 } | |
| 197 | |
| 198 unless ($name) { | |
| 199 throw("Need an assembly name."); | |
| 200 } | |
| 201 | |
| 202 $version ||= ''; | |
| 203 my $slice = $container->ref_slice; | |
| 204 | |
| 205 # project slice onto other assembly and construct MappedSlice for result | |
| 206 my $mapped_slice = Bio::EnsEMBL::MappedSlice->new( | |
| 207 -ADAPTOR => $self, | |
| 208 -CONTAINER => $container, | |
| 209 -NAME => $slice->name."\#mapped_$name:$version", | |
| 210 ); | |
| 211 | |
| 212 | |
| 213 foreach my $seg (@{ $slice->project($name, $version) }) { | |
| 214 | |
| 215 my $proj_slice = $seg->to_Slice; | |
| 216 | |
| 217 # create a Mapper to map to/from the mapped_slice artificial coord system | |
| 218 my $mapper = Bio::EnsEMBL::Mapper->new('mapped_slice', 'native_slice'); | |
| 219 | |
| 220 # tell the mapper how to map this segment | |
| 221 $mapper->add_map_coordinates( | |
| 222 'mapped_slice', | |
| 223 $seg->from_start, | |
| 224 $seg->from_end, | |
| 225 ($slice->strand * $proj_slice->strand), | |
| 226 $proj_slice->seq_region_name, | |
| 227 $proj_slice->start, | |
| 228 $proj_slice->end | |
| 229 ); | |
| 230 | |
| 231 # add the Slice/Mapper pair to the MappedSlice | |
| 232 $mapped_slice->add_Slice_Mapper_pair($proj_slice, $mapper); | |
| 233 } | |
| 234 | |
| 235 return [$mapped_slice]; | |
| 236 } | |
| 237 | |
| 238 | |
| 239 1; | |
| 240 |
