Commit 75130c9f authored by Arne Stabenau's avatar Arne Stabenau
Browse files

slices from chromosomes, chromosome adaptor caches on name, tests in a second

parent 55878cd9
......@@ -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;
}
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment