Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

changed m5nr resource call for returning children of parent from hierarc... #217

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 3, 2013
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 20 deletions.
  1. +18 −9 src/MGRAST/lib/Analysis.pm
  2. +7 −11 src/MGRAST/lib/resources2/m5nr.pm
View
27 src/MGRAST/lib/Analysis.pm
@@ -564,22 +564,31 @@ sub get_hierarchy {
}
sub get_hierarchy_slice {
- my ($self, $type, $src, $pname, $plevel) = @_;
+ my ($self, $type, $source, $parent_name, $child_level) = @_;
my $tbl = exists($self->_atbl->{$type}) ? $self->_atbl->{$type} : '';
my $col = $self->_get_table_cols($tbl);
- unless ($tbl && @$col && $pname && $plevel && grep(/^$plevel$/, @$col)) {
+ unless ($tbl && @$col && $parent_name && $child_level && grep(/^$child_level$/, @$col)) {
return [];
}
- my $data = [];
- my $index = first { $col->[$_] eq $plevel } 0..$#{$col};
- if ($plevel eq 'tax_domain') { $index += 1; } # ncbi hack
- if ((! $index) || ($index == $#{$col})) {
+ my $data = [];
+ my $child_index = first { $col->[$_] eq $child_level } 0..$#{$col};
+ # level does not exist
+ unless ($child_index) {
return [];
}
- my $sql = "SELECT DISTINCT ".$col->[$index+1]." FROM ".$self->_atbl->{$type}." WHERE ".$plevel." = ".$self->_dbh->quote($pname);
- if (($type eq 'ontology') && $src) {
- $sql .= " AND source = ".$self->_src_id->{$src};
+ # no parent available
+ if (($child_level eq 'tax_domain') || ($child_level eq 'level1')) {
+ return [];
+ }
+ my $parent_index = $child_index - 1;
+ # ncbi hack
+ if ($child_level eq 'tax_phylum') {
+ $parent_index -= 1;
+ }
+ my $sql = "SELECT DISTINCT ".$col->[$child_index]." FROM ".$self->_atbl->{$type}." WHERE ".$col->[$parent_index]." = ".$self->_dbh->quote($parent_name);
+ if (($type eq 'ontology') && $source) {
+ $sql .= " AND source = ".$self->_src_id->{$source};
}
my $cols = $self->_dbh->selectcol_arrayref($sql);
return ($cols && @$cols) ? $cols : [];
View
18 src/MGRAST/lib/resources2/m5nr.pm
@@ -73,7 +73,6 @@ sub info {
['NOG', 'returns 3 level NOG ontology'],
['KO', 'returns 4 level KEGG-KO ontology' ]],
'min_level' => ['cv', $self->{hierarchy}{ontology}],
- 'parent_level' => ['string', 'level of ontology group to retrieve children of'],
'parent_name' => ['string', 'name of ontology group to retrieve children of']
},
'required' => {},
@@ -86,7 +85,6 @@ sub info {
'type' => "synchronous",
'attributes' => $self->attributes->{taxonomy},
'parameters' => { 'options' => { 'min_level' => ['cv', $self->{hierarchy}{taxonomy}],
- 'parent_level' => ['string', 'level of taxanomy group to retrieve children of'],
'parent_name' => ['string', 'name of taxanomy group to retrieve children of']
},
'required' => {},
@@ -131,7 +129,6 @@ sub static {
}
my $data = [];
my $pname = $self->cgi->param('parent_name') || '';
- my $plvl = $self->cgi->param('parent_level') || '';
if ($type eq 'ontology') {
my @ont_hier = map { $_->[0] } @{$self->{hierarchy}{ontology}};
@@ -144,24 +141,23 @@ sub static {
} else {
$self->return_data({"ERROR" => "invalid min_level for m5nr/ontology: ".$min_lvl." - valid types are [".join(", ", @ont_hier)."]"}, 500);
}
- unless ($pname && $plvl && grep(/^$plvl$/, @ont_hier)) {
- @$data = values %{ $mgdb->get_hierarchy('ontology', $source, undef, undef, $min_lvl) };
+ if ($pname && ($min_lvl ne 'level1')) {
+ @$data = $mgdb->get_hierarchy_slice('ontology', $source, $pname, $min_lvl);
} else {
- @$data = $mgdb->get_hierarchy_slice('ontology', $source, $pname, $plvl);
+ @$data = values %{ $mgdb->get_hierarchy('ontology', $source, undef, undef, $min_lvl) };
}
} elsif ($type eq 'taxonomy') {
my @tax_hier = map { $_->[0] } @{$self->{hierarchy}{taxonomy}};
- my $min_lvl = $self->cgi->param('min_level') || 'species';
+ my $min_lvl = $self->cgi->param('min_level') || 'species';
if ( grep(/^$min_lvl$/, @tax_hier) ) {
$min_lvl = 'tax_'.$min_lvl;
} else {
$self->return_data({"ERROR" => "invalid min_level for m5nr/taxonomy: ".$min_lvl." - valid types are [".join(", ", @tax_hier)."]"}, 500);
}
- unless ($pname && $plvl && grep(/^$plvl$/, @tax_hier)) {
- @$data = values %{ $mgdb->get_hierarchy('organism', undef, undef, undef, $min_lvl) };
+ if ($pname && ($min_lvl ne 'tax_domain')) {
+ @$data = $mgdb->get_hierarchy_slice('organism', undef, $pname, $min_lvl);
} else {
- $plvl = 'tax_'.$plvl;
- @$data = $mgdb->get_hierarchy_slice('organism', undef, $pname, $plvl);
+ @$data = values %{ $mgdb->get_hierarchy('organism', undef, undef, undef, $min_lvl) };
}
} elsif ($type eq 'sources') {
$data = $mgdb->_sources();
Something went wrong with that request. Please try again.