tripal.terms.api.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * @section
  4. * Vocabulary Hooks.
  5. */
  6. /**
  7. * A hook for specifying information about the data store for vocabularies.
  8. *
  9. * The storage backend for controlled vocabularies has traditionally been
  10. * the Chado CV term tables. However, Tripal v3.0 introduces APIs for supporting
  11. * other backends. Therefore, this function indicates to Tripal which
  12. * data stores are capable of providing support for terms.
  13. *
  14. * @return
  15. * An array describing the storage backends implemented by the module. The
  16. * keys are storage backend names. To avoid name clashes, storage
  17. * backend names should be prefixed with the name of the module that
  18. * exposes them. The values are arrays describing the storage backend,
  19. * with the following key/value pairs:
  20. *
  21. * label: The human-readable name of the storage backend.
  22. * module: The name of the module providing the support for this backend.
  23. * description: A short description for the storage backend.
  24. * settings: An array whose keys are the names of the settings available for
  25. * the storage backend, and whose values are the default values for
  26. * those settings.
  27. */
  28. function hook_vocab_storage_info() {
  29. return array(
  30. 'term_chado_storage' => array(
  31. 'label' => t('Chado storage'),
  32. 'description' => t('Integrates terms stored in the local Chado database with Tripal entities.'),
  33. 'settings' => array(),
  34. ),
  35. );
  36. }
  37. /**
  38. * Creates a form for specifying a term for TripalEntity creation.
  39. *
  40. * This hook allows the module that implements a vocabulary storage backend
  41. * to provide the form necessary to select a term that will then be used for
  42. * creating a new TripalEntity type. Tripal will expect that a 'vocabulary' and
  43. * 'accession' are in the $form_state['storage'] array. The 'vocabulary' and
  44. * must be the abbreviated uppercase vocabulary for the vocabulary (e.g. 'RO',
  45. * 'SO', 'PATO', etc.). The 'accession' must be the unique term ID (or
  46. * accession) for the term in the vocabulary.
  47. *
  48. * @param $form
  49. * @param $form_state
  50. *
  51. * @return
  52. * A form object.
  53. */
  54. function hook_vocab_select_term_form(&$form, &$form_state) {
  55. return $form;
  56. }
  57. /**
  58. * Validates the hook_vocab_select_term_form().
  59. *
  60. * @param $name
  61. */
  62. function hook_vocab_select_term_form_validate($form, &$form_state) {
  63. }
  64. /**
  65. * Provides a form for importing vocabularies and their terms.
  66. *
  67. * Tripal allows for vocabularies to be stored separately from the biological
  68. * data. This hook allows the default term storage backend to provide an
  69. * approprite form for importing ontologies (either in OBO or OWL format).
  70. *
  71. * @param $form
  72. * @param $form_state
  73. *
  74. */
  75. function hook_vocab_import_form($form, &$form_state) {
  76. return $form;
  77. }
  78. function hook_vocab_import_form_validate($form, &$form_state) {
  79. }
  80. function hook_vocab_import_form_submit($form, &$form_state) {
  81. }
  82. /**
  83. * Hook used by the default term storage backend to provide details for a term.
  84. *
  85. * This hook is called by the tripal_entity module to retrieve information
  86. * about the term from the storage backend. It must return an array with
  87. * a set of keys.
  88. *
  89. * @param $vocabulary
  90. * The vocabulary of the vocabulary in which the term is found.
  91. * @param $accession
  92. * The unique identifier (accession) for this term.
  93. *
  94. * @return
  95. * An array with at least the following keys:
  96. * -vocabulary : An associative array with the following keys
  97. * -name: The short name for the vocabulary (e.g. SO, PATO, etc).
  98. * -description: The description of this vocabulary.
  99. * -url: The URL for the vocabulary.
  100. * -accession : The name unique ID of the term.
  101. * -url : The URL for the term.
  102. * -name : The name of the term.
  103. * -definition : The term's description.
  104. * any other keys may be added as desired. Returns NULL if the term
  105. * cannot be found.
  106. */
  107. function hook_vocab_get_term($vocabulary, $accession) {
  108. // See the tripal_chado_vocab_get_term() function for an example.
  109. }
  110. /**
  111. * Hook used by the default term storage backend to add new terms.
  112. *
  113. * @param $details
  114. * An array with at least the following keys:
  115. * -vocabulary : An associative array with the following keys
  116. * -name: The short name for the vocabulary (e.g. SO, PATO, etc).
  117. * -description: The description of this vocabulary.
  118. * -url: The URL for the vocabulary.
  119. * -accession : The name unique ID of the term.
  120. * -url : The URL for the term.
  121. * -name : The name of the term.
  122. * -definition : The term's description.
  123. * @return
  124. * TRUE if the term was added, FALSE otherwise. If the term already exists
  125. * it will be updated and the return value will be TRUE,
  126. */
  127. function hook_vocab_add_term($details) {
  128. // See the tripal_chado_vocab_set_term() function for an example.
  129. }
  130. /**
  131. * Adds a term to the vocabulary storage backend.
  132. *
  133. * Use this function to add new terms dynamically to the vocabulary storage
  134. * backend. If the term already exists no new term is added.
  135. *
  136. * @param $details
  137. * An array with at least the following keys:
  138. * -vocabulary : An associative array with the following keys
  139. * -name: The short name for the vocabulary (e.g. SO, PATO, etc).
  140. * -description: The description of this vocabulary.
  141. * -url: The URL for the vocabulary.
  142. * -accession : The name unique ID of the term.
  143. * -url : The URL for the term.
  144. * -name : The name of the term.
  145. * -definition : The term's description.
  146. * @return
  147. * TRUE if the term was added, FALSE otherwise. If the term already exists
  148. * it will be updated and the return value will be TRUE,
  149. */
  150. function tripal_add_term($details) {
  151. // TODO: we need some sort of administrative interface that lets the user
  152. // switch to the desired vocabulary type. For now, we'll just use the
  153. // first one in the list.
  154. $stores = module_invoke_all('vocab_storage_info');
  155. if (is_array($stores) and count($stores) > 0) {
  156. $keys = array_keys($stores);
  157. $module = $stores[$keys[0]]['module'];
  158. $function = $module . '_vocab_add_term';
  159. if (function_exists($function)) {
  160. return $function($details);
  161. }
  162. }
  163. }
  164. /**
  165. * Retrieves full information about a vocabulary term.
  166. *
  167. * Vocabularies are stored in a database backend. Tripal has no requirements
  168. * for how terms are stored. By default, the tripal_chado modules provides
  169. * storage for vocabularies and terms. This function will call the
  170. * hook_vocab_get_term() function for the database backend that is housing the
  171. * vocabularies and allow it to return the details about the term.
  172. *
  173. * @param $vocabulary
  174. * The vocabulary of the vocabulary in which the term is found.
  175. * @param $accession
  176. * The unique identifier (accession) for this term.
  177. *
  178. * @return
  179. * An array with at least the following keys:
  180. * - vocabulary : An array containing the following keys:
  181. * - name : The full name of the vocabulary.
  182. * - short_name : The short name abbreviation for the vocabulary.
  183. * - description : A brief description of the vocabulary.
  184. * - url : (optional) A URL for the online resources for the vocabulary.
  185. * - accession : The name unique ID of the term.
  186. * - url : The URL for the term.
  187. * - name : The name of the term.
  188. * - definition : The term's description.
  189. * any other keys may be added as desired. Returns NULL if the term
  190. * cannot be found.
  191. */
  192. function tripal_get_term_details($vocabulary, $accession) {
  193. // TODO: we need some sort of administrative interface that lets the user
  194. // switch to the desired vocabulary type. For now, we'll just use the
  195. // first one in the list.
  196. $stores = module_invoke_all('vocab_storage_info');
  197. if (is_array($stores) and count($stores) > 0) {
  198. $keys = array_keys($stores);
  199. $module = $stores[$keys[0]]['module'];
  200. $function = $module . '_vocab_get_term';
  201. if (function_exists($function)) {
  202. return $function($vocabulary, $accession);
  203. }
  204. }
  205. }