3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
41 # get all chromosomes in the database
42 my $slices = $slice_adaptor->fetch_all(
'chromosome');
44 # split the chromosomes into equal chunks of size less than 1MB
45 # with an overlap of 1kb
46 $slices = split_Slices( $slices, 1e6, 1e3 );
53 package Bio::EnsEMBL::Utils::Slice;
60 use vars qw(@ISA @EXPORT_OK);
64 @EXPORT_OK = qw(&split_Slices);
71 Arg [1] : ref to list of slices
72 Arg [2] :
int maxlength of sub slices
73 Arg [3] :
int overlap length (optional)
74 Example : my $sub_slices = split_Slices($slices,$maxlen,$overlap)
75 Description: splits a slice into smaller slices
76 Returntype : ref to list of slices
77 Exceptions : maxlen <1 or overlap < 0
82 my ($slice_big,$max_length,$overlap)=@_;
84 if(!defined($max_length) or $max_length < 1){
85 throw(
"maxlength needs to be set and > 0");
88 if(!defined($overlap)){
92 throw(
"negative overlaps not allowed");
97 foreach my $slice (@$slice_big){
99 my $start = $slice->start;
103 my $length = $slice->length;
105 if($max_length && ($length > $overlap)) {
106 #No seq region may be longer than max_length but we want to make
107 #them all similar size so that the last one isn't much shorter.
108 #Divide the seq_region into the largest equal pieces that are shorter
111 #calculate number of slices to create
112 $number = ($length-$overlap) / ($max_length-$overlap);
113 $number = ceil($number); #round up to
int
115 #calculate length of created slices
116 $multiple = $length / $number;
117 $multiple = floor($multiple); #round down to
int
119 #just one slice of the whole seq_region
125 for(my $i=0; $i < $number; $i++) {
126 $end = $start + $multiple + $overlap;
128 #any remainder gets added to the last slice of the seq_region
129 $end = $slice->end
if($i == $number-1);
134 -SEQ_REGION_NAME => $slice->seq_region_name,
135 -SEQ_REGION_LENGTH => $slice->seq_region_length,
136 -COORD_SYSTEM => $slice->coord_system,
137 -ADAPTOR => $slice->adaptor);
138 $start += $multiple + 1;