Commit a2e8fcab authored by Graham McVicker's avatar Graham McVicker
Browse files

-Restructured SliceAdaptor

-Deprecated SliceAdaptor related methods in StaticGoldenPathAdaptor
-Updated RepeatFeatureAdaptorI interface
-Updated ProxyRepeatFeatureAdaptor to implement interface changes
-Deprecated is_golden method of Clone
parent 4955e04b
......@@ -291,12 +291,19 @@ sub get_rawcontig_by_position {
sub is_golden{
my ($self,@args) = @_;
foreach my $contig ($self->get_all_Contigs) {
if ($contig->is_golden) {
return 1;
}
}
return 0;
$self->warn("Clone::is_golden is deprecated. " .
"Use \$assembly_mapper->in_assembly(\$clone)");
my $asma = $self->adaptor()->db()->get_AssemblyMapperAdaptor();
my $am = $asma->fetch_by_type($self->db()->assembly_type());
return $am->in_assembly($self);
# foreach my $contig ($self->get_all_Contigs) {
# if ($contig->is_golden) {
# return 1;
# }
# }
# return 0;
}
......
......@@ -53,7 +53,6 @@ sub new {
return $self;
}
sub fetch_by_Slice {
my ($self, @args) = @_;
......@@ -68,4 +67,39 @@ sub fetch_by_Slice {
return $self->{'_core_adaptor'}->fetch_by_Slice(@args);
}
sub fetch_by_RawContig {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->fetch_by_RawContig(@args);
}
sub fetch_by_contig_id {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->fetch_by_contig_id(@args);
}
sub fetch_by_dbID {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->fetch_by_dbID(@args);
}
sub fetch_by_assembly_location {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->fetch_by_assembly_location(@args);
}
sub fetch_by_assembly_location_constraint {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->fetch_by_assembly_location_constraint(@args);
}
sub store {
my ($self, @args) = @_;
return $self->{'_core_adaptor'}->store(@args);
}
......@@ -31,6 +31,18 @@ package Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptorI;
sub fetch_by_Slice {}
sub fetch_by_RawContig {}
sub fetch_by_contig_id {}
sub fetch_by_dbID {}
sub fetch_by_assembly_location {}
sub fetch_by_assembly_location_constraint {}
sub store {}
1;
__END__
......
......@@ -44,7 +44,6 @@ methods. Internal methods are usually preceded with a _
package Bio::EnsEMBL::DBSQL::SliceAdaptor;
use Bio::EnsEMBL::Utils::Eprof qw(eprof_start eprof_end);
use vars qw(@ISA);
use strict;
......@@ -58,190 +57,12 @@ use Bio::EnsEMBL::DBSQL::DBAdaptor;
@ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');
# new is inherieted from BaseAdaptor
# new is inherited from BaseAdaptor
=head2 new_slice
Title : new_slice
Usage :
Function:
Example :
Returns :
Args :
=cut
sub new_slice{
my ($self,$chr,$start,$end,$strand,$type) = @_;
my $slice = Bio::EnsEMBL::Slice->new( -chr_name => $chr,
-chr_start => $start,
-chr_end => $end,
-strand => $strand,
-assembly_type => $type,
-adaptor => $self);
return $slice;
}
=head2 new_web_slice
Title : new_web_slice
Usage :
Function:
Example :
Returns :
Args :
=cut
sub new_web_slice{
my ($self,$chr,$start,$end,$strand,$type) = @_;
die "Not implemented new slice yet";
}
sub fetch_all_repeat_features{
my($self, $slice, $logic_name) = @_;
if(!$slice){
$self->throw("can't fetch all repeat features if con't have a slice to fetch them for\n");
}
my @repeats = $self->db->get_RepeatFeatureAdaptor->fetch_by_Slice($slice, $logic_name);
return @repeats;
}
sub fetch_all_simple_features{
my($self, $slice, $logic_name) = @_;
if(!$slice){
$self->throw("can't fetch all simple features if con't have a slice to fetch them for\n");
}
my @simple = $self->db->get_SimpleFeatureAdaptor->fetch_by_Slice($slice, $logic_name);
return @simple;
}
sub fetch_all_similarity_features{
my($self, $slice, $logic_name) = @_;
if(!$slice){
$self->throw("can't fetch all simple features if con't have a slice to fetch them for\n");
}
my @out;
my @dnaalign = $self->db->get_DnaAlignFeatureAdaptor->fetch_by_Slice($slice, $logic_name);
my @pepalign = $self->db->get_ProteinAlignFeatureAdaptor->fetch_by_Slice($slice, $logic_name);
push(@out, @dnaalign);
push(@out, @pepalign);
return @out;
}
sub fetch_all_similarity_features_above_score{
my($self, $slice, $score, $logic_name) = @_;
if(!$slice){
$self->throw("can't fetch all simple features if con't have a slice to fetch them for\n");
}
if(!$score){
$self->throw("need score even if it 0\n");
}
my @out;
my @dnaalign = $self->db->get_DnaAlignFeatureAdaptor->fetch_by_Slice_and_score($slice, $score, $logic_name);
my @pepalign = $self->db->get_ProteinAlignFeatureAdaptor->fetch_by_Slice_and_score($slice, $score, $logic_name);
push(@out, @dnaalign);
push(@out, @pepalign);
return @out;
}
sub fetch_all_similarity_features_above_pid{
my($self, $slice, $pid, $logic_name) = @_;
if(!$slice){
$self->throw("can't fetch all simple features if con't have a slice to fetch them for\n");
}
if(!$pid){
$self->throw("need percent_id even if it 0\n");
}
my @out;
my @dnaalign = $self->db->get_DnaAlignFeatureAdaptor->fetch_by_Slice_and_pid($slice, $pid, $logic_name);
my @pepalign = $self->db->get_ProteinAlignFeatureAdaptor->fetch_by_Slice_and_pid($slice, $pid, $logic_name);
push(@out, @dnaalign);
push(@out, @pepalign);
return @out;
}
=head2 get_chr_start_end_of_contig
Title : get_chr_start_end_of_contig
Usage :
Function: returns the chromosome name, absolute start and absolute end of the
specified contig
Returns : returns chr,start,end
Args : contig id
=cut
sub get_chr_start_end_of_contig {
my ($self,$contigid) = @_;
if( !defined $contigid ) {
$self->throw("Must have contig id to fetch Slice of contig");
}
my $type = $self->db->assembly_type()
or $self->throw("No assembly type defined");
=head2 fetch_by_chr_start_end
my $sth = $self->db->prepare("SELECT c.name,
a.chr_start,
a.chr_end,
a.chromosome_id
FROM assembly a, contig c
WHERE c.name = '$contigid'
AND c.contig_id = a.contig_id
AND a.type = '$type'"
);
$sth->execute();
my ($contig,$start,$end,$chr_name) = $sth->fetchrow_array;
if( !defined $contig ) {
$self->throw("Contig $contigid is not on the golden path of type $type");
}
return ($chr_name,$start,$end);
}
=head2 fetch_Slice_by_chr_start_end
Title : fetch_Slice_by_chr_start_end
Title : fetch_by_chr_start_end
Usage :
Function: create a Slice based on a segment of a chromosome and
start/end
......@@ -252,7 +73,7 @@ sub get_chr_start_end_of_contig {
=cut
sub fetch_Slice_by_chr_start_end {
sub fetch_by_chr_start_end {
my ($self,$chr,$start,$end) = @_;
if( !defined $end ) { # Why defined? Is '0' a valid end?
......@@ -264,34 +85,25 @@ sub fetch_Slice_by_chr_start_end {
}
my $slice;
&eprof_start('Slice: staticcontig build');
my $type = $self->db->assembly_type();
eval {
$slice = Bio::EnsEMBL::Slice->new(
$slice = Bio::EnsEMBL::Slice->new(
-chr_name => $chr,
-chr_start => $start,
-chr_end => $end,
-assembly_type => $type,
-adaptor => $self->db->get_SliceAdaptor
);
} ;
if( $@ ) {
$self->throw("Unable to build a slice for $chr, $start,$end\n\nUnderlying exception $@\n");
}
&eprof_end('Slice: staticcontig build');
-adaptor => $self->db->get_SliceAdaptor()
);
return $slice;
}
=head2 fetch_Slice_by_contig
=head2 fetch_by_contig_accession
Title : fetch_Slice_by_contig
Usage : $slice = $slice_adaptor->fetch_Slice_by_contig('AC000012.00001',1000);
Title : fetch_by_contig_accession
Usage : $slice = $slice_adaptor->fetch_by_contig_id('AC000012.00001',1000);
Function: Creates a slice of the specified slice adaptor object. If a context size is given, the slice is extended by that number of basepairs on either side of the contig. Throws if the contig is not golden.
Returns : Slice object
Args : contig id, [context size in bp]
......@@ -299,25 +111,62 @@ sub fetch_Slice_by_chr_start_end {
=cut
sub fetch_Slice_by_contig{
sub fetch_by_contig_accession {
my ($self,$contigid,$size) = @_;
if( !defined $size ) {$size=0;}
my ($chr_name,$start,$end) = $self->get_chr_start_end_of_contig($contigid);
my ($chr_name,$start,$end) = $self->_get_chr_start_end_of_contig($contigid);
return $self->fetch_Slice_by_chr_start_end( $chr_name,
$start-$size,
$end+$size
);
return $self->fetch_Slice_by_chr_start_end($chr_name,
$start-$size,
$end+$size);
}
=head2 fetch_by_fpc_name
Title : fetch_by_fpc_name
Usage :
Function: create a Slice representing a complete FPC contig
Example :
Returns :
Args : the FPC contig id.
=cut
sub fetch_by_fpc_name {
my ($self,$fpc_name) = @_;
my $type = $self->db->assembly_type();
my $sth = $self->db->prepare("
SELECT chromosome_id, superctg_ori, MIN(chr_start), MAX(chr_end)
FROM assembly
WHERE superctg_name = '$fpc_name'
AND type = '$type'
GROUP by superctg_name
");
$sth->execute;
my ($chr, $strand, $slice_start, $slice_end) = $sth->fetchrow_array;
my $slice;
$slice = new Bio::EnsEMBL::Slice($chr,$slice_start,$slice_end,
$strand,$type);
return $slice;
}
=head2 fetch_Slice_by_clone
Title : fetch_Slice_by_clone
Usage : $slice = $slice_adaptor->fetch_Slice_by_clone('AC000012',1000);
=head2 fetch_by_clone_accession
Title : fetch_by_clone_accession
Usage : $slice = $slice_adaptor->fetch_by_clone_accession('AC000012',1000);
Function: Creates a Slice of the specified object. If a context size is given, the Slice is extended by that number of basepairs on either side of the clone. Throws if the clone is not golden.
Returns : Slice object
Args : clone id, [context size in bp]
......@@ -325,11 +174,11 @@ sub fetch_Slice_by_contig{
=cut
sub fetch_Slice_by_clone{
sub fetch_by_clone_accession{
my ($self,$clone,$size) = @_;
if( !defined $clone ) {
$self->throw("Must have clone to fetch Slice of clone");
$self->throw("Must have clone to fetch Slice of clone");
}
if( !defined $size ) {$size=0;}
......@@ -364,76 +213,18 @@ sub fetch_Slice_by_clone{
$self->throw("Clone is not on the golden path. Cannot build Slice");
}
my $slice = $self->fetch_Slice_by_chr_start_end( $chr_name,
$first_start-$size,
$end+$size
);
$slice->adaptor->db($self->db);
my $slice = $self->fetch_by_chr_start_end( $chr_name,
$first_start-$size,
$end+$size );
return $slice;
}
=head2 get_Gene_chr_bp
Title : get_Gene_chr_bp
Usage :
Function:
Returns :
Args :
=cut
=head2 fetch_by_transcript_stable_id
sub get_Gene_chr_bp {
my ($self,$geneid) = @_;
my $type = $self->db->assembly_type()
or $self->throw("No assembly type defined");
my $sth = $self->db->prepare("SELECT
if(a.contig_ori=1,(e.contig_start-a.contig_start+a.chr_start),
(a.chr_start+a.contig_end-e.contig_end)),
if(a.contig_ori=1,(e.contig_end-a.contig_start+a.chr_start),
(a.chr_start+a.contig_end-e.contig_start)),
a.chromosome_id
FROM exon e,
transcript tr,
exon_transcript et,
assembly a,
gene_stable_id gsi
WHERE e.exon_id=et.exon_id
AND et.transcript_id =tr.transcript_id
AND a.contig_id=e.contig_id
AND a.type = '$type'
AND tr.gene_id = gsi.gene_id
AND gsi.stable_id = '$geneid';"
);
$sth->execute();
my ($start,$end,$chr);
my @start;
while ( my @row=$sth->fetchrow_array){
($start,$end,$chr)=@row;
push @start,$start;
push @start,$end;
}
my @start_sorted=sort { $a <=> $b } @start;
$start=shift @start_sorted;
$end=pop @start_sorted;
return ($chr,$start,$end);
}
=head2 fetch_Slice_by_transcript
Title : fetch_Slice_by_transcript_dbID
Usage : $slice = $slice_adaptor->fetch_Slice_by_transcript(
Title : fetch_by_transcript_stable_id
Usage : $slice = $slice_adaptor->fetch_by_transcript_stable_id(
'ENST00000302930',1000);
Function: Creates a slice of the specified object. If a context
size is given, the slice is extended by that number of
......@@ -445,27 +236,22 @@ sub get_Gene_chr_bp {
=cut
sub fetch_Slice_by_transcript{
sub fetch_by_transcript_stable_id{
my ($self,$transcriptid,$size) = @_;
# Just get the dbID, then fetch slice by that
my $ta = $self->db->get_TranscriptAdaptor;
my $transcript_obj = $ta->fetch_by_stable_id($transcriptid);
my $dbID = $transcript_obj->dbID;
if (defined $size) {
return $self->fetch_Slice_by_transcript_dbID($dbID, $size);
} else {
return $self->fetch_Slice_by_transcript_dbID($dbID);
}
return $self->fetch_by_transcript_id($dbID, $size);
}
=head2 fetch_Slice_by_transcript_dbID
Title : fetch_Slice_by_transcript_dbID
Usage : $slice = $slice_adaptor->fetch_Slice_by_transcript_dbID(
24,1000);
=head2 fetch_by_transcript_id
Title : fetch_by_transcript_id
Usage : $slice = $slice_adaptor->fetch_by_transcript_id(24,1000);
Function: Creates a slice of the specified object. If a context
size is given, the slice is extended by that number of
basepairs on either side of the transcript. Throws if
......@@ -473,10 +259,9 @@ sub fetch_Slice_by_transcript{
Returns : Slice object
Args : transcript dbID, [context size in bp]
=cut
sub fetch_Slice_by_transcript_dbID{
sub fetch_by_transcript_id {
my ($self,$transcriptid,$size) = @_;
if( !defined $transcriptid ) {
$self->throw("Must have transcriptid id to fetch Slice of transcript");
......@@ -495,19 +280,18 @@ sub fetch_Slice_by_transcript_dbID{
$exon_transforms{ $exon } = $newExon;
}
$transcript_obj->transform( \%exon_transforms );
my $slice = $self->fetch_Slice_by_chr_start_end(
$emptyslice->chr_name,
$transcript_obj->start-$size,
$transcript_obj->end+$size);
my $slice = $self->fetch_by_chr_start_end(
$emptyslice->chr_name,
$transcript_obj->start-$size,
$transcript_obj->end+$size);
return $slice;
}
=head2 fetch_Slice_by_gene
=head2 fetch_by_gene_stable_id
Title : fetch_Slice_by_gene
Usage : $slice = $slice_adaptor->fetch_Slice_by_gene('ENSG00000012123',1000);
Title : fetch_by_gene_stable_id
Usage : $slice = $slice_adaptor->fetch_by_gene_stable_id('ENSG00000012123',1000);
Function: Creates a slice of the specified object. If a context size is given, the slice is extended by that number of basepairs on either side of the gene. Throws if the gene is not golden.
Returns : Slice object
Args : gene id, [context size in bp]
......@@ -515,7 +299,7 @@ sub fetch_Slice_by_transcript_dbID{
=cut
sub fetch_Slice_by_gene{
sub fetch_by_gene_stable_id{
my ($self,$geneid,$size) = @_;
if( !defined $geneid ) {
......@@ -523,37 +307,139 @@ sub fetch_Slice_by_gene{
}
if( !defined $size ) {$size=0;}
my ($chr_name,$start,$end) = $self->get_Gene_chr_bp($geneid);
my ($chr_name,$start,$end) = $self->_get_chr_start_end_of_gene($geneid);
if( !defined $start ) {
my $type = $self->adaptor->db->assembly_type()
or $self->throw("No assembly type defined");
$self->throw("Gene is not on the golden path '$type'. Cannot build Slice.");
my $type = $self->adaptor->db->assembly_type()
or $self->throw("No assembly type defined");
$self->throw("Gene is not on the golden path '$type'. Cannot build Slice.");
}
return $self->fetch_Slice_by_chr_start_end( $chr_name,
$start-$size,
$end+$size
);
return $self->fetch_by_chr_start_end($chr_name, $start-$size, $end+$size);
}