Commit 5248d635 authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-635]. Merge from HEAD. Code now supports karyotype retrieval and display.

Code has been altered to support new REST requirements.
parent 5c63bcc3
......@@ -109,27 +109,26 @@ sub fetch_info {
$assembly_info{'schema_build'} = $schema_build;
}
#fetch available coordinate systems
#fetch available coordinate systems
my $csa = $self->db()->get_adaptor('CoordSystem');
my %versions;
foreach my $cs (@{$csa->fetch_all()}) {
$versions{$cs->version()} = 1;
}
my @coord_system_versions = keys %versions;
$assembly_info{'coord_system_versions'} = \@coord_system_versions;
my $coord_systems = $csa->fetch_all();
my %versions = map { $_->version(), 1 } @{$coord_systems};
$assembly_info{'coord_system_versions'} = [keys %versions];
my ($default_assembly) = @{$coord_systems};
$assembly_info{default_coord_system_version} = $default_assembly->version();
#fetch top level seq_region names
my $sa = $self->db()->get_adaptor('Slice');
my $slices = $sa->fetch_all('toplevel');
my %unique = map { $_->seq_region_name(), 0 } @{$slices};
my $names = [sort { $a cmp $b } keys %unique];
$assembly_info{'top_level_seq_region_names'} = $names;
my $karyotype = $sa->fetch_all_karyotype();
$assembly_info{karyotype} = [ map { $_->seq_region_name() } @{$karyotype}];
return \%assembly_info;
}
......
......@@ -1147,18 +1147,18 @@ sub fetch_all_karyotype {
my $sth =
$self->prepare( 'SELECT sr.seq_region_id, sr.name, '
. 'sr.length, sr.coord_system_id '
. 'sr.length, sr.coord_system_id, sra.value '
. 'FROM seq_region sr, seq_region_attrib sra, '
. 'attrib_type at, coord_system cs '
. 'WHERE at.code = "karyotype_rank" '
. 'AND at.attrib_type_id = sra.attrib_type_id '
. 'AND sra.seq_region_id = sr.seq_region_id '
. 'AND sr.coord_system_id = cs.coord_system_id '
. 'AND cs.species_id = ?' );
. 'AND cs.species_id = ?');
$sth->bind_param( 1, $self->species_id(), SQL_INTEGER );
$sth->execute();
my ( $seq_region_id, $name, $length, $cs_id );
$sth->bind_columns( \( $seq_region_id, $name, $length, $cs_id ) );
my ( $seq_region_id, $name, $length, $cs_id, $rank );
$sth->bind_columns( \( $seq_region_id, $name, $length, $cs_id, $rank ) );
my @out;
while($sth->fetch()) {
......@@ -1166,17 +1166,22 @@ sub fetch_all_karyotype {
my $slice = Bio::EnsEMBL::Slice->new_fast({
'start' => 1,
'end' => $length,
'end' => ($length+0),
'strand' => 1,
'seq_region_name' => $name,
'seq_region_length'=> $length,
'seq_region_length'=> ($length+0),
'coord_system' => $cs,
'adaptor' => $self});
'adaptor' => $self,
'karyotype' => 1,
'karyotype_rank' => ($rank+0),
});
push @out, $slice;
}
#Sort using Perl as value in MySQL is a text field and not portable
@out = sort { $a->{karyotype_rank} <=> $b->{karyotype_rank} } @out;
return \@out;
}
......
......@@ -551,6 +551,24 @@ sub has_karyotype {
return $self->{'karyotype'};
}
=head2 karyotype_rank
Arg : none
Example : my $rank = $slice->karyotype_rank()
Description: Returns the numeric ranking in the karyotype. Otherwise 0 is returned
Returntype : int
Caller : general
Status : At Risk
=cut
sub karyotype_rank {
my ($self) = @_;
if(! defined( $self->{karyotype_rank})) {
my $rank = $self->adaptor()->get_karyotype_rank($self->get_seq_region_id());
$self->{karyotype_rank} = $rank if $rank;
}
return $self->{karyotype_rank} || 0;
}
=head2 is_circular
Arg : none
......
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