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;
83 my $self = bless {}, $class ;
85 my $slice = $self = $class->SUPER::new( @_);
92 return $self->seq_region_name;
98 return $self->seq_region_name;
103 return $self->{_chrom_slice}
if defined($self->{_chrom_slice});
111 foreach my $segment (@{$self->project(
'chromosome')}) {
112 my $from_start = $segment->from_start();
113 my $from_end = $segment->from_end();
114 my $slice = $segment->to_Slice;
116 my $seq_region_id = $slice->adaptor->get_seq_region_id($slice);
117 my $to_name = $slice->seq_region_name();
119 next
if (!$seq_region_id);
121 if (!$segments{$seq_region_id}) {
122 $segments{$seq_region_id}{
'chr_name'} = $to_name;
123 $segments{$seq_region_id}{
'strand'} = $slice->strand;
127 $max = $segments{$seq_region_id}{
'max'};
128 $min = $segments{$seq_region_id}{
'min'};
131 my $to_start = $slice->start();
132 my $to_end = $slice->end();
133 if($to_start > $max){
136 if($to_start < $min){
146 $segments{$seq_region_id}{
'max'} = $max;
147 $segments{$seq_region_id}{
'min'} = $min;
150 my @seq_region_ids = sort {$a <=> $b} keys (%segments);
152 # Keep the chromosome mapping instead of the patch, if possible
153 if (scalar @seq_region_ids) {
154 my $seq_id = $seq_region_ids[0];
155 $chrom = $segments{$seq_id}{
'chr_name'};
156 $max = $segments{$seq_id}{
'max'};
157 $min = $segments{$seq_id}{
'min'};
158 $strand = $segments{$seq_id}{
'strand'};
161 if(!defined($chrom)){
162 warn
"Could not project to chromosome for ".$self->name.
" ??\n";
165 my $chrom_slice = $self->adaptor->fetch_by_region(
"chromosome",$chrom, $min, $max, $strand);
166 $self->{_chrom_slice} = $chrom_slice;
167 return $self->{_chrom_slice};
173 sub get_all_differences{
178 # get seq_region_attrib diffs (always same-length substitutions)
179 ################################################################
181 my $sth = $self->adaptor->prepare(qq{
183 FROM seq_region_attrib sra, attrib_type at
184 WHERE at.code =
'_rna_edit'
185 AND at.attrib_type_id = sra.attrib_type_id
186 AND sra.seq_region_id = ?
189 $sth->execute($self->get_seq_region_id);
193 $sth->bind_columns(\$edit_string);
195 while($sth->fetch()) {
196 my ($start, $end, $edit) = split
" ", $edit_string;
198 my $slice = $self->sub_Slice($start, $end);
199 my $chr_proj = $slice->project(
"chromosome");
201 if(scalar @$chr_proj == 1) {
202 $ref_seq = $chr_proj->[0]->[2]->seq;
209 'type' =>
'substitution',
214 push @results, $diff;
217 # get more complex differences via projections
218 ##############################################
220 # project the LRG slice to contig coordinates
221 my @segs = @{$self->project(
"contig")};
223 # if the LRG projects into more than one segment
224 if(scalar @segs > 1) {
226 my ($prev_end, $prev_chr_start, $prev_chr_end, $prev_was_chr);
228 foreach my $seg(@segs) {
230 # is this a novel LRG contig, or does it project to a chromosome?
231 my @chr_proj = @{$seg->[2]->project(
"chromosome")};
233 # if it is a normal contig
234 if(scalar @chr_proj) {
236 # check if there has been a deletion in LRG
237 if($prev_was_chr && $prev_end == $seg->[0] - 1) {
239 # check it's not just a break in contigs
241 ($chr_proj[0]->[2]->strand != $self->strand && $prev_chr_start == $chr_proj[0]->[2]->end + 1) ||
242 ($chr_proj[0]->[2]->strand != $self->strand && $prev_chr_end == $chr_proj[0]->[2]->start - 1)
245 # now get deleted slice coords, depends on the strand rel to LRG
249 if($chr_proj[0]->[2]->strand != $self->strand) {
250 ($s, $e) = ($prev_chr_start - 1, $chr_proj[0]->[2]->end + 1);
255 ($s, $e) = ($prev_chr_end + 1, $chr_proj[0]->[2]->start - 1);
259 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,
")";
263 # get a slice representing the sequence that was deleted
264 my $deleted_slice = $self->adaptor->fetch_by_region(
"chromosome", $chr_proj[0]->[2]->seq_region_name, $s, $e, $chr_proj[0]->[2]->strand);
267 'start' => $seg->[0],
269 'type' =>
'deletion',
271 'ref' => $deleted_slice->seq.
" ".$deleted_slice->start.
'-'.$deleted_slice->end,
274 push @results, $diff;
281 $prev_chr_start = $chr_proj[0]->[2]->start;
282 $prev_chr_end = $chr_proj[0]->[2]->end;
285 # if it is an LRG made-up contig for an insertion
290 'start' => $seg->[0],
292 'type' =>
'insertion',
293 'seq' => substr($self->seq, $seg->[0] - 1, $seg->[1] - $seg->[0] + 1),
297 push @results, $diff;
300 $prev_end = $seg->[1];
304 # return results sorted by start, then end position
305 return [sort {$a->{start} <=> $b->{start} || $a->{end} <=> $b->{end}} @results];