diff --git a/modules/Bio/EnsEMBL/DBSQL/ChromosomeAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/ChromosomeAdaptor.pm index 6124168814100d0a576d2324f9bbc38c50941cb3..d55aed74081f4ed54cfb77bba65909bff8af8afa 100644 --- a/modules/Bio/EnsEMBL/DBSQL/ChromosomeAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/ChromosomeAdaptor.pm @@ -80,6 +80,7 @@ sub fetch_by_dbID { unless(defined $self->{'_chr_cache'} ) { $self->{'_chr_cache'} = {}; + $self->{'_chr_name_cache'} = {}; } # @@ -90,8 +91,8 @@ sub fetch_by_dbID { my $sth = $self->prepare( "SELECT name, known_genes, unknown_genes, snps, length FROM chromosome - WHERE chromosome_id = $id" ); - $sth->execute(); + WHERE chromosome_id = ?" ); + $sth->execute( $id ); my($name, $known_genes, $unknown_genes, $snps, $length); $sth->bind_columns(\$name,\$known_genes,\$unknown_genes,\$snps,\$length); @@ -108,14 +109,16 @@ sub fetch_by_dbID { } $chr = new Bio::EnsEMBL::Chromosome( -adaptor => $self, + -dbID => $id, -chr_name => $name, - -chromosome_id => $id, -known_genes => $known_genes, -unknown_genes => $unknown_genes, -snps => $snps, '-length' => $length ); $self->{'_chr_cache'}->{$id} = $chr; + $self->{'_chr_name_cache'}->{$name} = $chr; + } return $chr; @@ -137,15 +140,46 @@ sub fetch_by_dbID { sub fetch_by_chr_name{ my ($self,$chr_name) = @_; - #Convert the name to the dbID - my $dbID = $self->get_dbID_by_chr_name($chr_name); + my $chr = (); - unless(defined $dbID) { - $self->warn("chromosome with name $chr_name not in database"); - return undef; - } - - return $self->fetch_by_dbID($dbID); + unless(defined $chr_name) { + $self->throw("Chromosome name argument required\n"); + } + + unless(defined $self->{'_chr_cache'} ) { + $self->{'_chr_cache'} = {}; + $self->{'_chr_name_cache'} = {}; + } + + # + # If there is not already a cached version of this chromosome pull it + # from the database and add it to the cache. + # + unless($chr = $self->{'_chr_name_cache'}->{$chr_name}) { + my $sth = $self->prepare( "SELECT chromosome_id, known_genes, unknown_genes, + snps, length + FROM chromosome + WHERE name = ?" ); + $sth->execute( $chr_name ); + + my($dbID, $known_genes, $unknown_genes, $snps, $length); + $sth->bind_columns(\$dbID,\$known_genes,\$unknown_genes,\$snps,\$length); + $sth->fetch(); + + $chr = new Bio::EnsEMBL::Chromosome( -adaptor => $self, + -dbID => $dbID, + -chr_name => $chr_name, + -known_genes => $known_genes, + -unknown_genes => $unknown_genes, + -snps => $snps, + '-length' => $length ); + + $self->{'_chr_cache'}->{$dbID} = $chr; + $self->{'_chr_name_cache'}->{$chr_name} = $chr; + + } + + return $chr; } @@ -179,13 +213,14 @@ sub fetch_all { my $chr = new Bio::EnsEMBL::Chromosome( -adaptor => $self, -chr_name => $name, - -chromosome_id => $chromosome_id, + -dbID => $chromosome_id, -known_genes => $known_genes, -unknown_genes => $unknown_genes, -snps => $snps, '-length' => $length ); $self->{'_chr_cache'}->{$chromosome_id} = $chr; + $self->{'_chr_name_cache'}->{$name} = $chr; push @chrs, $chr; } diff --git a/modules/Bio/EnsEMBL/DBSQL/DBAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/DBAdaptor.pm index da8183d11c127069ffddbf240ac2c034fff8d9bc..2ff40d556051a3e87f5f8eedfaa53b28af7d0f6e 100755 --- a/modules/Bio/EnsEMBL/DBSQL/DBAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/DBAdaptor.pm @@ -734,7 +734,6 @@ sub assembly_type{ $obj->{'assembly'} = $value; } if (! defined $obj->{'assembly'}) { - print STDERR "DBAdaptor.pm: using default assembly type\n"; my $ass; eval { $ass = $obj->get_MetaContainer()->get_default_assembly(); diff --git a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm index 0e337428946f34620b57e6a9cd8b27c768dce7d5..a76e21ef527fdd5843217cdb788bada3dfb743e5 100644 --- a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm @@ -123,6 +123,8 @@ sub list_stable_geneIds { Arg [1] : int $geneId the unique internal database id of the Gene to be retrieved + Arg [2] : int $chromosomal_coordinates (optional) + if defined, try to return chromosomal coordinates. Example : $gene = $gene_adaptor->fetch_by_dbID Description: Retrieves a gene object from the database using its unique internal identifier. @@ -133,7 +135,7 @@ sub list_stable_geneIds { =cut sub fetch_by_dbID { - my ( $self, $geneId ) = @_; + my ( $self, $geneId, $chr_coordinates ) = @_; my $exonAdaptor = $self->db->get_ExonAdaptor(); my @exons = @{$exonAdaptor->fetch_all_by_gene_id( $geneId )}; @@ -223,6 +225,18 @@ sub fetch_by_dbID { $gene->add_Transcript( $transcript ); } + # if chromosomal coordinates are needed, transform with empty slice + + if( defined $chr_coordinates ) { + my $sa = $self->db->get_SliceAdaptor(); + my $empty_slice = Bio::EnsEMBL::Slice->new + ( + -empty => 1, + -adaptor => $sa + ); + $gene->transform( $empty_slice ); + } + return $gene; } diff --git a/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm index 63bdfc2876c20d70d7487b445dd2d9d706603846..d90ace976fc1bac6298274085712d44a41ddce7d 100644 --- a/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/SliceAdaptor.pm @@ -106,7 +106,7 @@ sub fetch_by_chr_start_end { -chr_start => $start, -chr_end => $end, -assembly_type => $type, - -adaptor => $self->db->get_SliceAdaptor() + -adaptor => $self ); return $slice; @@ -177,8 +177,14 @@ sub fetch_by_fpc_name { my $slice; - $slice = new Bio::EnsEMBL::Slice($chr,$slice_start,$slice_end, - $strand,$type); + $slice = new Bio::EnsEMBL::Slice + ( + -chr_name => $chr, + -chr_start =>$slice_start, + -chr_end => $slice_end, + -strand => $strand, + -assembly_type => $type + ); return $slice; } @@ -394,7 +400,18 @@ sub fetch_by_chr_name{ my $chromosome = $ca->fetch_by_chr_name($chr_name); my $chr_end = $chromosome->length(); - return $self->fetch_by_chr_start_end($chr_name, $chr_start, $chr_end); + my $type = $self->db->assembly_type(); + + my $slice = Bio::EnsEMBL::Slice->new + ( + -chr_name => $chr_name, + -chr_start => 1, + -chr_end => $chr_end, + -assembly_type => $type, + -adaptor => $self + ); + + return $slice; }