Skip to content
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 19, 2012
Travis Harrison fixed hierarchy subselection 882f779
Travis Harrison Analysis.pm: fixed bug in delete_job 3cadc18
Commits on Dec 20, 2012
@jaredbischof jaredbischof Merge pull request #212 from teharrison/develop
bug fixes in analysis.pm
bc9c838
Showing with 36 additions and 29 deletions.
  1. +34 −27 src/MGRAST/lib/Analysis.pm
  2. +2 −2 src/MGRAST/lib/resources2/matrix.pm
View
61 src/MGRAST/lib/Analysis.pm
@@ -520,40 +520,47 @@ sub _gammaln {
####################
sub get_hierarchy {
- my ($self, $type, $src, $use_taxid, $get_ids) = @_;
+ my ($self, $type, $src, $use_taxid, $get_ids, $max_lvl) = @_;
my $tbl = exists($self->_atbl->{$type}) ? $self->_atbl->{$type} : '';
- unless ($tbl) { return {}; }
+ my $col = $self->_get_table_cols($tbl);
+ unless ($tbl && @$col) { return {}; }
+ unless ($max_lvl) { $max_lvl = ''; }
+ if (($max_lvl eq 'level4') && ($src =~ /^[NC]OG$/)) { $max_lvl = 'level3'; }
+ my @cols = ();
my $hier = {};
- my $sql = "";
- if ($type eq 'ontology') {
- my $key = $get_ids ? '_id' : 'name';
- $sql = "SELECT $key,level1,level2,level3,level4 FROM ".$self->_atbl->{$type};
- if ($src) {
- $sql .= " WHERE source = ".$self->_src_id->{$src};
+ my $key = $get_ids ? '_id' : 'name';
+ my $pref = ($type eq 'ontology') ? 'level' : 'tax_';
+
+ foreach my $c ( grep {$_ =~ /^$pref/} @$col ) {
+ next if ($c eq 'tax_kingdom'); # ncbi hack
+ next if (($c eq 'level4') && ($src =~ /^[NC]OG$/)); # n|cog hack
+ if ($c ne $max_lvl) {
+ push @cols, $c;
}
- } else {
- $sql = "SELECT ncbi_tax_id,tax_domain,tax_phylum,tax_class,tax_order,tax_family,tax_genus,tax_species,name,_id FROM ".$self->_atbl->{$type};
- }
- my $tmp = $self->_dbh->selectall_arrayref($sql);
- unless ($tmp && @$tmp) { return {}; }
- if ($type eq 'ontology') {
- if ($tmp->[0][4]) {
- map { $hier->{$_->[0]} = [ @$_[1..4] ] } @$tmp;
- } else {
- map { $hier->{$_->[0]} = [ @$_[1..3] ] } @$tmp;
- }
- } else {
- if ($use_taxid) {
- map { $hier->{$_->[0]} = [ @$_[1..8] ] } grep { $_->[0] } @$tmp;
- } elsif ($get_ids) {
- map { $hier->{$_->[9]} = [ @$_[1..7] ] } @$tmp;
- } else {
- map { $hier->{$_->[8]} = [ @$_[1..7] ] } @$tmp;
+ else {
+ push @cols, $c;
+ $key = $c;
+ last;
}
}
+ if (($type eq 'organism') && $use_taxid && (! $max_lvl)) {
+ $key = 'ncbi_tax_id';
+ }
+ push @cols, $key;
+
+ my $sql = "SELECT DISTINCT ".join(", ", @cols)." FROM ".$self->_atbl->{$type};
+ if (($type eq 'ontology') && $src) {
+ $sql .= " WHERE source = ".$self->_src_id->{$src};
+ }
+ foreach my $row ( @{$self->_dbh->selectall_arrayref($sql)} ) {
+ my $id = pop @$row;
+ next unless ($id && ($id =~ /\S/));
+ $hier->{$id} = $row;
+ }
return $hier;
+ # { end_node => [ hierachy of node ] }
}
sub _get_annotation_map {
@@ -729,7 +736,7 @@ sub delete_job {
my $all = $self->_dbh->selectcol_arrayref("SELECT DISTINCT version FROM job_info WHERE job = ".$job);
eval {
$self->_dbh->do("DELETE FROM job_info WHERE job = ".$job);
- foreach my $tbl (keys %{$self->_jtbl}) {
+ foreach my $tbl (values %{$self->_jtbl}) {
$self->_dbh->do("DELETE FROM $tbl WHERE version IN (".join(",", @$all).") AND job = ".$job);
}
};
View
4 src/MGRAST/lib/resources2/matrix.pm
@@ -367,9 +367,9 @@ sub prepare_data {
sub get_hierarchy {
my ($self, $mgdb, $type, $level, $src, $leaf_node) = @_;
if ($type eq 'organism') {
- return $leaf_node ? $self->{org2tax} : $mgdb->ach->get_taxonomy4level_full($level, 1);
+ return $leaf_node ? $self->{org2tax} : $mgdb->get_hierarchy('organism', undef, undef, undef, $level);
} elsif ($type eq 'function') {
- return $leaf_node ? $mgdb->ach->get_all_ontology4source_hash($src) : $mgdb->ach->get_level4ontology_full($src, $level, 1);
+ return $leaf_node ? $mgdb->get_hierarchy('ontology', $src) : $mgdb->get_hierarchy('ontology', $src, undef, undef, $level);
} else {
return {};
}

No commit comments for this range

Something went wrong with that request. Please try again.