sub _fetch_ancestor_chart {
my ( $this, $term, $ontology ) = @_;
assert_ref( $term, 'Bio::EnsEMBL::OntologyTerm' );
my $statement = q(
SELECT subparent_term.term_id,
parent_term.term_id,
relation_type.name
FROM closure
JOIN relation
ON (relation.parent_term_id = closure.parent_term_id
AND relation.child_term_id = closure.subparent_term_id
AND closure.ontology_id = relation.ontology_id)
JOIN relation_type USING (relation_type_id)
JOIN term subparent_term
ON (subparent_term.term_id = closure.subparent_term_id)
JOIN term parent_term ON (parent_term.term_id = closure.parent_term_id)
JOIN ontology ON (ontology.ontology_id = closure.ontology_id)
WHERE closure.child_term_id = ?
AND ontology.name = ?
ORDER BY closure.distance);
my $sth = $this->prepare($statement);
$sth->bind_param( 1, $term->dbID(), SQL_INTEGER );
if (!defined $ontology) {
$ontology = $term->{'ontology'};
}
$sth->bind_param( 2, $ontology, SQL_VARCHAR );
$sth->execute();
my ( $subparent_id, $parent_id, $relation );
$sth->bind_columns( \( $subparent_id, $parent_id, $relation ) );
my %id_chart;
my %acc_chart;
while ( $sth->fetch() ) {
if ( !exists( $id_chart{$parent_id} ) ) {
$id_chart{$parent_id} = {};
}
push( @{ $id_chart{$subparent_id}{$relation} }, $parent_id );
}
my @terms = @{ $this->fetch_all_by_dbID_list( [ keys(%id_chart) ] ) };
foreach my $term (@terms) {
$id_chart{ $term->dbID() }{'term'} = $term;
$acc_chart{ $term->accession() }{'term'} = $term;
}
foreach my $term (@terms) {
my $accession = $term->accession();
my $dbID = $term->dbID();
foreach my $relation ( keys( %{ $id_chart{$dbID} } ) ) {
if ( $relation eq 'term' ) { next }
foreach my $id ( @{ $id_chart{$dbID}{$relation} } ) {
push( @{ $acc_chart{$accession}{$relation} },
$id_chart{$id}{'term'} );
}
}
}
return \%acc_chart;
} ## end sub _fetch_ancestor_chart
Inheritance diagram for Bio::EnsEMBL::DBSQL::OntologyTermAdaptor:
