Main Content


Find terms that are ancestors of specified Gene Ontology (GO) term



AncestorIDs = getancestors(GeneontObj,ID) searches GeneontObj, a geneont object, for GO terms that are ancestors of the GO term(s) specified by ID, which is a GO term identifier or vector of identifiers. The result AncestorIDs is a vector of GO term identifiers including ID.

[AncestorIDs,Counts] = getancestors(GeneontObj,ID) also returns the number of times each ancestor is found. Counts is a column vector with the same number of elements as terms in GeneontObj.


The Counts return value is useful when you tally counts in gene enrichment studies.

___ = getancestors(GeneontObj,ID,Name,Value), for any output arguments, specifies additional options using one or more name-value arguments. For example, you can restrict the search to have up to two levels up in the gene ontology by specifying AncestorIDs = getancestors(GeneontObj,ID,Height=2).


collapse all

Download the current version of the Gene Ontology database from the Web into a geneont object.

GO = geneont('Live',true)
Gene Ontology object with 47266 Terms.

Retrieve the ancestors of the Gene Ontology term with an identifier of 46680.

ancestors = getancestors(GO,46680)
ancestors = 8×1


Create a subordinate Gene Ontology.

subontology = GO(ancestors)
Gene Ontology object with 8 Terms.

Create and display a report of the subordinate Gene Ontology terms, that includes the GO identifier and name.

rpt = get(subontology.terms,{'id','name'})
rpt=8×2 cell array
    {[ 8150]}    {'biological_process'                 }
    {[ 9636]}    {'response to toxic substance'        }
    {[10033]}    {'response to organic substance'      }
    {[14070]}    {'response to organic cyclic compound'}
    {[17085]}    {'response to insecticide'            }
    {[42221]}    {'response to chemical'               }
    {[46680]}    {'response to DDT'                    }
    {[50896]}    {'response to stimulus'               }

View relationships of the subordinate Gene Ontology by using the getmatrix method to create a connection matrix to pass to the digraph function.

cm = getmatrix(subontology);
BG = digraph(cm,get(subontology.terms,"name"));

Input Arguments

collapse all

Gene ontology object, specified as the output of the geneont command.

Example: geneont('Live',true)

Gene ontology ID numbers, specified as a nonnegative integer vector.

Example: 5

Data Types: single | double

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: AncestorIDs = getancestors(GeneontObj,5,Height=2)

Names are case-insensitive.

Number of search levels up in gene ontology, specified as a positive integer.

Example: 4

Data Types: single | double

Relations to match, specified as one of the following:

  • 'is_a'

  • 'part_of'

  • 'both'

Example: 'is_a'

Data Types: char | string

Indication to exclude ID from AncestorIDs, specified as false or true. This argument can fail to apply when getancestors reaches the term while searching the ontology.

Example: true

Data Types: logical

Output Arguments

collapse all

ID numbers of ancestors of GeneontObj, returned as a nonnegative integer vector. By default, AncestorIDs includes ID, unless you set the Exclude argument to true.

Number of times each relative is found, returned as a column vector of integers. Counts has the same number of elements as terms in GeneontObj.

Version History

Introduced before R2006a