Skip to content
Snippets Groups Projects
Commit 2dd70b3c authored by Magali Ruffier's avatar Magali Ruffier
Browse files

ENSCORESW-678: added special case for density feature

unlike other features, the related analysis is stored in the density type table
parent 2b6a87aa
No related branches found
No related tags found
No related merge requests found
...@@ -146,32 +146,47 @@ sub fetch_all { ...@@ -146,32 +146,47 @@ sub fetch_all {
sub fetch_all_by_feature_class { sub fetch_all_by_feature_class {
my $self = shift; my $self = shift;
deprecate("Deprecated. Hard-coded logic is not supported");
my $feat_class = shift || throw( "Need a feature type, e.g. SimpleFeature" ); my $feat_class = shift || throw( "Need a feature type, e.g. SimpleFeature" );
my @feature_classes = $self->feature_classes; # List of all feature classes # Need a special case for density
my %feat_table_map; # DensityFeature is the feature, but the analysis is linked to the DensityType
foreach my $class( @feature_classes ){ if ($feat_class =~ /Density/) {
# Map e.g. DnaAlignFeature to dna_align_feature $feat_class = 'DensityType';
my $table = join( "_", map lc, ( $class =~ /([A-Z][a-z]+)/g ) ); }
$feat_table_map{$class} = $table;
my $adaptor = $self->db->get_adaptor($feat_class);
if (!$adaptor) {
throw("$feat_class is not a know feature. No adaptor found");
}
# Check that feature has an analysis
my $has_analysis = 0;
my @columns = $adaptor->_columns;
foreach my $column (@columns) {
if ($column =~ /analysis/) {
$has_analysis = 1;
last;
}
} }
$feat_table_map{DensityFeature}='density_type'; # analysis_id in diff table if ($has_analysis == 0) {
my $feat_table = $feat_table_map{$feat_class} || throw("$feat_class does not have an analysis column");
( warning( "No feature type corresponding to $feat_class" ) && }
return [] );
# Retrieve the name of the table
my @tables = $adaptor->_tables();
my $table = $tables[0]->[0];
my $sql_t = qq| my $sql_t = qq|
SELECT DISTINCT analysis_id FROM %s |; SELECT DISTINCT analysis_id FROM %s |;
my $sql = sprintf( $sql_t, $feat_table ); my $sql = sprintf( $sql_t, $table );
my $sth = $self->prepare( $sql ); my $sth = $self->prepare( $sql );
my $rv = $sth->execute(); my $rv = $sth->execute();
my $res = $sth->fetchall_arrayref; my $res = $sth->fetchall_arrayref;
my @analyses; my @analyses;
foreach my $r( @{$res} ){ foreach my $r( @{$res} ){
my $analysis = $self->fetch_by_dbID($r->[0]) my $analysis = $self->fetch_by_dbID($r->[0])
|| throw( "analysis_id $r->[0] from $feat_table table " || throw( "analysis_id $r->[0] from $table table "
. "is not in the analysis table!" ); . "is not in the analysis table!" );
push @analyses, $analysis; push @analyses, $analysis;
} }
......
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