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
37 $sa = $db->get_SliceAdaptor;
40 $sa->fetch_by_region(
'LRG',
'LRG3');
42 # get some attributes of the slice
44 my $start = $slice->start();
45 my $end = $slice->end();
47 # get the sequence from the slice
48 my $seq = $slice->seq();
50 # get some features from the slice
51 foreach $gene ( @{ $slice->get_all_Genes } ) {
52 # do something with a gene
55 foreach my $feature ( @{ $slice->get_all_DnaAlignFeatures } ) {
56 # do something with dna-dna alignments
61 A LRG Slice
object represents a region of a genome. It can be used to retrieve
62 sequence or features from an area of interest.
68 package Bio::EnsEMBL::LRGSlice;
84 my $self = bless {}, $class ;
86 my $slice = $self = $class->SUPER::new( @_);
93 return $self->seq_region_name;
99 return $self->seq_region_name;
104 return $self->{_chrom_slice}
if defined($self->{_chrom_slice});
112 foreach my $segment (@{$self->project(
'chromosome')}) {
113 my $from_start = $segment->from_start();
114 my $from_end = $segment->from_end();
115 my $slice = $segment->to_Slice;
117 my $seq_region_id = $slice->adaptor->get_seq_region_id($slice);
118 my $to_name = $slice->seq_region_name();
120 next
if (!$seq_region_id);
122 if (!$segments{$seq_region_id}) {
123 $segments{$seq_region_id}{
'chr_name'} = $to_name;
124 $segments{$seq_region_id}{
'strand'} = $slice->strand;
128 $max = $segments{$seq_region_id}{
'max'};
129 $min = $segments{$seq_region_id}{
'min'};
132 my $to_start = $slice->start();
133 my $to_end = $slice->end();
134 if($to_start > $max){
137 if($to_start < $min){
147 $segments{$seq_region_id}{
'max'} = $max;
148 $segments{$seq_region_id}{
'min'} = $min;
151 my @seq_region_ids = sort {$a <=> $b} keys (%segments);
153 # Keep the chromosome mapping instead of the patch, if possible
154 if (scalar @seq_region_ids) {
155 my $seq_id = $seq_region_ids[0];
156 $chrom = $segments{$seq_id}{
'chr_name'};
157 $max = $segments{$seq_id}{
'max'};
158 $min = $segments{$seq_id}{
'min'};
159 $strand = $segments{$seq_id}{
'strand'};
162 if(!defined($chrom)){
163 warn
"Could not project to chromosome for ".$self->name.
" ??\n";
166 my $chrom_slice = $self->adaptor->fetch_by_region(
"chromosome",$chrom, $min, $max, $strand);
167 $self->{_chrom_slice} = $chrom_slice;
168 return $self->{_chrom_slice};
174 sub get_all_differences{
179 # get seq_region_attrib diffs (always same-length substitutions)
180 ################################################################
182 my $sth = $self->adaptor->prepare(qq{
184 FROM seq_region_attrib sra, attrib_type at
185 WHERE at.code =
'_rna_edit'
186 AND at.attrib_type_id = sra.attrib_type_id
187 AND sra.seq_region_id = ?
190 $sth->execute($self->get_seq_region_id);
194 $sth->bind_columns(\$edit_string);
196 while($sth->fetch()) {
197 my ($start, $end, $edit) = split
" ", $edit_string;
199 my $slice = $self->sub_Slice($start, $end);
200 my $chr_proj = $slice->project(
"chromosome");
202 if(scalar @$chr_proj == 1) {
203 $ref_seq = $chr_proj->[0]->[2]->seq;
210 'type' =>
'substitution',
215 push @results, $diff;
218 # get more complex differences via projections
219 ##############################################
221 # project the LRG slice to contig coordinates
222 my @segs = @{$self->project(
"contig")};
224 # if the LRG projects into more than one segment
225 if(scalar @segs > 1) {
227 my ($prev_end, $prev_chr_start, $prev_chr_end, $prev_was_chr);
229 foreach my $seg(@segs) {
231 # is this a novel LRG contig, or does it project to a chromosome?
232 my @chr_proj = @{$seg->[2]->project(
"chromosome")};
234 # if it is a normal contig
235 if(scalar @chr_proj) {
237 # check if there has been a deletion in LRG
238 if($prev_was_chr && $prev_end == $seg->[0] - 1) {
240 # check it's not just a break in contigs
242 ($chr_proj[0]->[2]->strand != $self->strand && $prev_chr_start == $chr_proj[0]->[2]->end + 1) ||
243 ($chr_proj[0]->[2]->strand != $self->strand && $prev_chr_end == $chr_proj[0]->[2]->start - 1)
246 # now get deleted slice coords, depends on the strand rel to LRG
250 if($chr_proj[0]->[2]->strand != $self->strand) {
251 ($s, $e) = ($prev_chr_start - 1, $chr_proj[0]->[2]->end + 1);
256 ($s, $e) = ($prev_chr_end + 1, $chr_proj[0]->[2]->start - 1);
260 warn
"Oops, trying to create a slice from $s to $e (could have been ", $prev_chr_start - 1,
"-", $chr_proj[0]->[2]->end + 1,
" or ", $prev_chr_end + 1,
"-", $chr_proj[0]->[2]->start - 1,
")";
264 # get a slice representing the sequence that was deleted
265 my $deleted_slice = $self->adaptor->fetch_by_region(
"chromosome", $chr_proj[0]->[2]->seq_region_name, $s, $e, $chr_proj[0]->[2]->strand);
268 'start' => $seg->[0],
270 'type' =>
'deletion',
272 'ref' => $deleted_slice->seq.
" ".$deleted_slice->start.
'-'.$deleted_slice->end,
275 push @results, $diff;
282 $prev_chr_start = $chr_proj[0]->[2]->start;
283 $prev_chr_end = $chr_proj[0]->[2]->end;
286 # if it is an LRG made-up contig for an insertion
291 'start' => $seg->[0],
293 'type' =>
'insertion',
294 'seq' => substr($self->seq, $seg->[0] - 1, $seg->[1] - $seg->[0] + 1),
298 push @results, $diff;
301 $prev_end = $seg->[1];
305 # return results sorted by start, then end position
306 return [sort {$a->{start} <=> $b->{start} || $a->{end} <=> $b->{end}} @results];