:SELECT 
  *
:FROM
  cvterm 
  INNER JOIN cvtermpath        
          ON (cvterm.cvterm_id=cvtermpath.object_id)
  INNER JOIN cvterm_relationship
          ON (cvtermpath.subject_id=cvterm_relationship.subject_id)
  INNER JOIN cvterm AS subj_cvterm
          ON (subj_cvterm.cvterm_id=cvterm_relationship.subject_id)
:WHERE
    [cvterm.accession => &cvterm_accession&]
    [cvterm.db => &cvterm_db&]
    [cvterm.name => &cvterm_name&]
    [cvterm.cvname => &cvterm_cvname&]
    [cvterm.definition => &cvterm_definition&]

    [subj_cvterm.accession => &subj_cvterm_accession&]
    [subj_cvterm.db => &subj_cvterm_db&]
    [subj_cvterm.name => &subj_cvterm_name&]
    [subj_cvterm.cvname => &subj_cvterm_cvname&]
    [subj_cvterm.definition => &subj_cvterm_definition&]
:ORDER BY cvterm.name
:USE NESTING (set(cvterm(cvtermpath(subj_cvterm(cvterm_relationship)))))

//
schema: chado
desc: 

  Fetches a graph based around a cvterm

  The graph is either built from object to subjects (downwards), based
  around cvterm

  OR it is build from subject to objects (upwards), based around
  subj_cvterm

  Of course, the data structure returned is not a graph
  
  As XML/Stag, the resulting data will have the object cvterm as root
  element, and will nest all descendents directly underneath. each
  descendent (subj_cvterm) will have it's parent relationships nested
  underneath it (with trailing cvterm_ids) - from this you can
  reconstruct the whole graph


example_input: cvterm_accession => SELECT DISTINCT cvterm.accession FROM cvterm WHERE cvterm_id IN (SELECT object_id FROM cvterm_relationship)
example_input: cvterm_name => SELECT DISTINCT cvterm.name FROM cvterm WHERE cvterm_id IN (SELECT object_id FROM cvterm_relationship)

