tripal_chado.schema.api.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. /**
  3. * @defgroup tripal_chado_schema_api Chado Schema API
  4. * @ingroup tripal_chado_api
  5. * @{
  6. * Provides an application programming interface (API) for describing Chado tables.
  7. * This API consists of a set of functions, one for each table in Chado. Each
  8. * function simply returns a Drupal style array that defines the table.
  9. *
  10. * Because Drupal 6 does not handle foreign key (FK) relationships, however FK
  11. * relationships are needed to for Tripal Views. Therefore, FK relationships
  12. * have been added to the schema defintitions below.
  13. *
  14. * The functions provided in this documentation should not be called as is, but if you need
  15. * the Drupal-style array definition for any table, use the following function
  16. * call:
  17. *
  18. * $table_desc = chado_get_schema($table)
  19. *
  20. * where the variable $table contains the name of the table you want to
  21. * retireve. The chado_get_schema function determines the appropriate version of
  22. * Chado and uses the Drupal hook infrastructure to call the appropriate
  23. * hook function to retrieve the table schema.
  24. * @}
  25. */
  26. /**
  27. * Check that any given Chado table exists.
  28. *
  29. * This function is necessary because Drupal's db_table_exists() function will
  30. * not look in any other schema but the one were Drupal is installed
  31. *
  32. * @return
  33. * TRUE/FALSE depending upon whether it exists
  34. *
  35. * @ingroup tripal_chado_schema_api
  36. */
  37. function chado_table_exists($table) {
  38. global $databases;
  39. $default_db = $databases['default']['default']['database'];
  40. $cached_obj = cache_get('chado_tables', 'cache');
  41. if ($cached_obj) {
  42. $cached_tables = $cached_obj->data;
  43. if (is_array($cached_tables) and array_key_exists($table, $cached_tables)) {
  44. return $cached_tables[$table]['exists'];
  45. }
  46. }
  47. $sql = "
  48. SELECT 1
  49. FROM information_schema.tables
  50. WHERE
  51. table_name = :table_name AND
  52. table_schema = :chado AND
  53. table_catalog = :default_db
  54. ";
  55. $args = array(
  56. ':table_name' => $table,
  57. ':chado' => tripal_get_schema_name('chado'),
  58. ':default_db' => $default_db
  59. );
  60. $results = db_query($sql, $args);
  61. $exists = $results->fetchObject();
  62. if (!$exists) {
  63. $cached_tables[$table]['exists'] = FALSE;
  64. cache_set('chado_tables', $cached_tables, 'cache', CACHE_TEMPORARY);
  65. return FALSE;
  66. }
  67. $cached_tables[$table]['exists'] = TRUE;
  68. cache_set('chado_tables', $cached_tables, 'cache', CACHE_TEMPORARY);
  69. return TRUE;
  70. }
  71. /**
  72. * Check that any given column in a Chado table exists.
  73. *
  74. * This function is necessary because Drupal's db_field_exists() will not
  75. * look in any other schema but the one were Drupal is installed
  76. *
  77. * @param $table
  78. * The name of the chado table.
  79. * @param $column
  80. * The name of the column in the chado table.
  81. * @return
  82. * TRUE if the column exists for the table in the chado schema and
  83. * FALSE if it does not.
  84. *
  85. * @ingroup tripal_chado_schema_api
  86. */
  87. function chado_column_exists($table, $column) {
  88. global $databases;
  89. $default_db = $databases['default']['default']['database'];
  90. $cached_obj = cache_get('chado_table_columns', 'cache');
  91. $cached_cols = $cached_obj->data;
  92. if (is_array($cached_cols) and
  93. array_key_exists($table, $cached_cols) and
  94. array_key_Exists($column, $cached_cols[$table])) {
  95. return $cached_cols[$table][$column]['exists'];
  96. }
  97. $sql = "
  98. SELECT 1
  99. FROM information_schema.columns
  100. WHERE
  101. table_name = :table_name AND
  102. column_name = :column_name AND
  103. table_schema = :chado AND
  104. table_catalog = :default_db
  105. ";
  106. $args = array(
  107. ':table_name' => $table,
  108. ':column_name' => $column,
  109. ':chado' => tripal_get_schema_name('chado'),
  110. ':default_db' => $default_db
  111. );
  112. $results = db_query($sql, $args);
  113. $exists = $results->fetchField();
  114. if (!$exists) {
  115. $cached_cols[$table][$column]['exists'] = FALSE;
  116. cache_set('chado_table_columns', $cached_cols, 'cache', CACHE_TEMPORARY);
  117. return FALSE;
  118. }
  119. $cached_cols[$table][$column]['exists'] = TRUE;
  120. cache_set('chado_table_columns', $cached_cols, 'cache', CACHE_TEMPORARY);
  121. return TRUE;
  122. }
  123. /**
  124. * Check that any given column in a Chado table exists.
  125. *
  126. * This function is necessary because Drupal's db_field_exists() will not
  127. * look in any other schema but the one were Drupal is installed
  128. *
  129. * @param sequence
  130. * The name of the sequence
  131. * @return
  132. * TRUE if the seqeuence exists in the chado schema and FALSE if it does not.
  133. *
  134. * @ingroup tripal_chado_schema_api
  135. */
  136. function chado_sequence_exists($sequence) {
  137. global $databases;
  138. $default_db = $databases['default']['default']['database'];
  139. $cached_obj = cache_get('chado_sequences', 'cache');
  140. $cached_seqs = $cached_obj->data;
  141. if (is_array($cached_seqs) and array_key_exists($sequence, $cached_seqs)) {
  142. return $cached_seqs[$sequence]['exists'];
  143. }
  144. $sql = "
  145. SELECT 1
  146. FROM information_schema.sequences
  147. WHERE
  148. sequence_name = :sequence_name AND
  149. sequence_schema = :sequence_schema AND
  150. sequence_catalog = :sequence_catalog
  151. ";
  152. $args = array(
  153. ':sequence_name' => $sequence,
  154. ':sequence_schema' => tripal_get_schema_name('chado'),
  155. ':sequence_catalog' => $default_db
  156. );
  157. $results = db_query($sql, $args);
  158. $exists = $results->fetchField();
  159. if (!$exists) {
  160. $cached_seqs[$sequence]['exists'] = FALSE;
  161. cache_set('chado_sequences', $cached_seqs, 'cache', CACHE_TEMPORARY);
  162. return FALSE;
  163. }
  164. $cached_seqs[$sequence]['exists'] = FALSE;
  165. cache_set('chado_sequences', $cached_seqs, 'cache', CACHE_TEMPORARY);
  166. return TRUE;
  167. }
  168. /**
  169. * A Chado-aware replacement for the db_index_exists() function.
  170. *
  171. * @param $table
  172. * The table to be altered.
  173. * @param $name
  174. * The name of the index.
  175. */
  176. function chado_index_exists($table, $name) {
  177. global $databases;
  178. $indexname = $table . '_' . $name . '_idx';
  179. $default_db = $databases['default']['default']['database'];
  180. $sql = "
  181. SELECT 1 as exists
  182. FROM pg_indexes
  183. WHERE indexname = :indexname
  184. ";
  185. $result = db_query($sql, array(':indexname' => $indexname));
  186. $exists = $result->fetchObject();
  187. return $exists->exists;
  188. }
  189. /**
  190. * A Chado-aware wrapper for the db_add_index() function.
  191. *
  192. * @param $table
  193. * The table to be altered.
  194. * @param $name
  195. * The name of the index.
  196. * @param $fields
  197. * An array of field names.
  198. */
  199. function chado_add_index($table, $name, $fields) {
  200. $indexname = $table . '_' . $name . '_idx';
  201. $query = 'CREATE INDEX "' . $indexname . '" ON {' . $table . '} ';
  202. $query .= '(';
  203. $temp = array();
  204. foreach ($fields as $field) {
  205. if (is_array($field)) {
  206. $temp[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')';
  207. }
  208. else {
  209. $temp[] = '"' . $field . '"';
  210. }
  211. }
  212. $query .= implode(', ', $temp);
  213. $query .= ')';
  214. return chado_query($query);
  215. }
  216. /**
  217. * Check that any given schema exists.
  218. *
  219. * @param $schema
  220. * The name of the schema to check the existence of
  221. *
  222. * @return
  223. * TRUE/FALSE depending upon whether or not the schema exists
  224. *
  225. * @ingroup tripal_chado_schema_api
  226. */
  227. function chado_dbschema_exists($schema) {
  228. $sql = "
  229. SELECT nspname
  230. FROM pg_namespace
  231. WHERE
  232. has_schema_privilege(nspname, 'USAGE') AND
  233. nspname = :nspname
  234. ORDER BY nspname
  235. ";
  236. $schema = db_query($sql, array(':nspname' => $schema))->fetchField();
  237. if ($schema) {
  238. return TRUE;
  239. }
  240. return FALSE;
  241. }
  242. /**
  243. * Check that the Chado schema exists within the local database
  244. *
  245. * @return
  246. * TRUE/FALSE depending upon whether it exists
  247. *
  248. * @ingroup tripal_chado_schema_api
  249. */
  250. function chado_is_local() {
  251. // This is postgresql-specific code to check the existence of the chado schema
  252. // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
  253. $sql = "
  254. SELECT nspname
  255. FROM pg_namespace
  256. WHERE
  257. has_schema_privilege(nspname, 'USAGE') AND
  258. nspname = 'chado'
  259. ";
  260. $results = db_query($sql);
  261. $name = $results->fetchObject();
  262. if ($name) {
  263. variable_set('chado_schema_exists', FALSE);
  264. return TRUE;
  265. }
  266. else {
  267. variable_set('chado_schema_exists', TRUE);
  268. return FALSE;
  269. }
  270. }
  271. /**
  272. * Check whether chado is installed (either in the same or a different database)
  273. *
  274. * @return
  275. * TRUE/FALSE depending upon whether chado is installed.
  276. *
  277. * @ingroup tripal_chado_schema_api
  278. */
  279. function chado_is_installed() {
  280. global $databases;
  281. // first check if chado is in the $databases variable of the settings.php file
  282. if (array_key_exists('chado', $databases)) {
  283. return TRUE;
  284. }
  285. // check to make sure the chado schema exists
  286. return chado_is_local();
  287. }
  288. /**
  289. * Returns the version number of the currently installed Chado instance.
  290. * It can return the real or effective version. Note, this function
  291. * is executed in the hook_init() of the tripal_chado module which then
  292. * sets the $GLOBAL['exact_chado_version'] and $GLOBAL['chado_version']
  293. * variable. You can access these variables rather than calling this function.
  294. *
  295. * @param $exact
  296. * Set this argument to 1 to retrieve the exact version that is installed.
  297. * Otherwise, this function will set the version to the nearest 'tenth'.
  298. * Chado versioning numbers in the hundreds represent changes to the
  299. * software and not the schema. Changes in the tenth's represent changes
  300. * in the schema.
  301. *
  302. * @param $warn_if_unsupported
  303. * If the currently installed version of Chado is not supported by Tripal
  304. * this generates a Drupal warning.
  305. *
  306. * @returns
  307. * The version of Chado
  308. *
  309. * @ingroup tripal_chado_schema_api
  310. */
  311. function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
  312. global $databases;
  313. $version = '';
  314. $is_local = 0;
  315. // check that Chado is installed if not return 'uninstalled as the version'
  316. $chado_exists = chado_is_local();
  317. if (!$chado_exists) {
  318. // if it's not in the drupal database check to see if it's specified in the $db_url
  319. // in the settings.php
  320. if (!array_key_exists('chado', $databases)) {
  321. // if it's not in the drupal database or specified in the $db_url then
  322. // return uninstalled as the version
  323. return 'not installed';
  324. }
  325. $is_local = 0;
  326. $previous_db = chado_set_active('chado');
  327. $prop_exists = chado_table_exists('chadoprop');
  328. chado_set_active($previous_db);
  329. }
  330. else {
  331. $is_local = 1;
  332. $prop_exists = chado_table_exists('chadoprop');
  333. }
  334. // if the table doesn't exist then we don't know what version but we know
  335. // it must be 1.11 or older.
  336. if (!$prop_exists) {
  337. $version = "1.11 or older";
  338. }
  339. else {
  340. $sql = "
  341. SELECT value
  342. FROM {chadoprop} CP
  343. INNER JOIN {cvterm} CVT on CVT.cvterm_id = CP.type_id
  344. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  345. WHERE CV.name = 'chado_properties' and CVT.name = 'version'
  346. ";
  347. if (!$is_local) {
  348. $previous_db = chado_set_active('chado');
  349. $results = db_query($sql);
  350. chado_set_active($previous_db);
  351. }
  352. else {
  353. $results = chado_query($sql);
  354. }
  355. $v = $results->fetchObject();
  356. // if we don't have a version in the chadoprop table then it must be
  357. // v1.11 or older
  358. if (!$v) {
  359. $version = "1.11 or older";
  360. }
  361. else {
  362. $version = $v->value;
  363. }
  364. }
  365. // next get the exact Chado version that is installed
  366. $exact_version = $version;
  367. // Tripal only supports v1.11 or newer.. really this is the same as v1.1
  368. // but at the time the v1.11 schema API was written we didn't know that so
  369. // we'll return the version 1.11 so the schema API will work.
  370. if (strcmp($exact_version, '1.11 or older') == 0) {
  371. $exact_version = "1.11";
  372. if ($warn_if_unsupported) {
  373. drupal_set_message(t("WARNING: Tripal does not fully support Chado version less than v1.11. If you are certain this is v1.11
  374. or if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.11 or later"),
  375. 'warning');
  376. }
  377. }
  378. // if not returing an exact version, return the version to the nearest 10th.
  379. // return 1.2 for all versions of 1.2x
  380. $effective_version = $exact_version;
  381. if (preg_match('/^1\.2\d+$/', $effective_version)) {
  382. $effective_version = "1.2";
  383. }
  384. if ($warn_if_unsupported and ($effective_version < 1.11 and $effective_version != 'not installed')) {
  385. drupal_set_message(t("WARNING: The currently installed version of Chado, v$exact_version, is not fully compatible with Tripal."), 'warning');
  386. }
  387. // if the callee has requested the exact version then return it
  388. if ($exact) {
  389. return $exact_version;
  390. }
  391. return $effective_version;
  392. }
  393. /**
  394. * Retrieves the list of tables in the Chado schema. By default it only returns
  395. * the default Chado tables, but can return custom tables added to the
  396. * Chado schema if requested
  397. *
  398. * @param $include_custom
  399. * Optional. Set as TRUE to include any custom tables created in the
  400. * Chado schema. Custom tables are added to Chado using the
  401. * tripal_chado_chado_create_table() function.
  402. *
  403. * @returns
  404. * An associative array where the key and value pairs are the Chado table names.
  405. *
  406. * @ingroup tripal_chado_schema_api
  407. */
  408. function chado_get_table_names($include_custom = NULL) {
  409. // first get the chado version that is installed
  410. $v = $GLOBALS["chado_version"];
  411. $tables = array();
  412. if ($v == '1.3') {
  413. $tables_v1_3 = tripal_chado_chado_get_v1_3_tables();
  414. foreach ($tables_v1_3 as $table) {
  415. $tables[$table] = $table;
  416. }
  417. }
  418. if ($v == '1.2') {
  419. $tables_v1_2 = tripal_chado_chado_get_v1_2_tables();
  420. foreach ($tables_v1_2 as $table) {
  421. $tables[$table] = $table;
  422. }
  423. }
  424. if ($v == '1.11' or $v == '1.11 or older') {
  425. $tables_v1_11 = tripal_chado_chado_get_v1_11_tables();
  426. foreach ($tables_v1_11 as $table) {
  427. $tables[$table] = $table;
  428. }
  429. }
  430. // now add in the custom tables too if requested
  431. if ($include_custom) {
  432. $sql = "SELECT table_name FROM {tripal_custom_tables}";
  433. $resource = db_query($sql);
  434. foreach ($resource as $r) {
  435. $tables[$r->table_name] = $r->table_name;
  436. }
  437. }
  438. asort($tables);
  439. return $tables;
  440. }
  441. /**
  442. * Retrieves the chado tables Schema API array.
  443. *
  444. * @param $table
  445. * The name of the table to retrieve. The function will use the appopriate
  446. * Tripal chado schema API hooks (e.g. v1.11 or v1.2).
  447. *
  448. * @returns
  449. * A Drupal Schema API array defining the table.
  450. *
  451. * @ingroup tripal_chado_schema_api
  452. */
  453. function chado_get_schema($table) {
  454. // first get the chado version that is installed
  455. $v = $GLOBALS["chado_version"];
  456. // get the table array from the proper chado schema
  457. $v = preg_replace("/\./", "_", $v); // reformat version for hook name
  458. // Call the module_invoke_all.
  459. $hook_name = "chado_schema_v" . $v . "_" . $table;
  460. $table_arr = module_invoke_all($hook_name);
  461. // If the module_invoke_all returned nothing then let's make sure there isn't
  462. // An API call we can call directly. The only time this occurs is
  463. // during an upgrade of a major Drupal version and tripal_core is disabled.
  464. if ((!$table_arr or !is_array($table_arr)) and
  465. function_exists('tripal_core_' . $hook_name)) {
  466. $api_hook = "tripal_core_" . $hook_name;
  467. $table_arr = $api_hook();
  468. }
  469. // if the table_arr is empty then maybe this is a custom table
  470. if (!is_array($table_arr) or count($table_arr) == 0) {
  471. $table_arr = chado_get_custom_table_schema($table);
  472. }
  473. return $table_arr;
  474. }
  475. /**
  476. * Retrieves the schema in an array for the specified custom table.
  477. *
  478. * @param $table
  479. * The name of the table to create.
  480. *
  481. * @return
  482. * A Drupal-style Schema API array definition of the table. Returns
  483. * FALSE on failure.
  484. *
  485. * @ingroup tripal_chado_schema_api
  486. */
  487. function chado_get_custom_table_schema($table) {
  488. $sql = "SELECT schema FROM {tripal_custom_tables} WHERE table_name = :table_name";
  489. $results = db_query($sql, array(':table_name' => $table));
  490. $custom = $results->fetchObject();
  491. if (!$custom) {
  492. return FALSE;
  493. }
  494. else {
  495. return unserialize($custom->schema);
  496. }
  497. }
  498. /**
  499. * Returns all chado base tables.
  500. *
  501. * Base tables are those that contain the primary record for a data type. For
  502. * example, feature, organism, stock, are all base tables. Other tables
  503. * include linker tables (which link two or more base tables), property tables,
  504. * and relationship tables. These provide additional information about
  505. * primary data records and are therefore not base tables. This function
  506. * retreives only the list of tables that are considered 'base' tables.
  507. *
  508. * @return
  509. * An array of base table names.
  510. *
  511. * @ingroup tripal_chado_schema_api
  512. */
  513. function chado_get_base_tables() {
  514. // Initialize the base tables with those tables that are missing a type.
  515. // Ideally they should have a type, but that's for a future version of Chado.
  516. $base_tables = array('organism', 'project', 'analysis', 'biomaterial');
  517. // We'll use the cvterm table to guide which tables are base tables. Typically
  518. // base tables (with a few exceptions) all have a type. Iterate through the
  519. // referring tables.
  520. $schema = chado_get_schema('cvterm');
  521. $referring = $schema['referring_tables'];
  522. foreach ($referring as $tablename) {
  523. // Ignore the cvterm tables, relationships, chadoprop tables.
  524. if ($tablename == 'cvterm_dbxref' || $tablename == 'cvterm_relationship' ||
  525. $tablename == 'cvtermpath' || $tablename == 'cvtermprop' || $tablename == 'chadoprop' ||
  526. $tablename == 'cvtermsynonym' || preg_match('/_relationship$/', $tablename) ||
  527. preg_match('/_cvterm$/', $tablename) ||
  528. // Ignore prop tables
  529. preg_match('/prop$/', $tablename) || preg_match('/prop_.+$/', $tablename) ||
  530. // Ignore nd_tables
  531. preg_match('/^nd_/', $tablename)) {
  532. continue;
  533. }
  534. else {
  535. array_push($base_tables, $tablename);
  536. }
  537. }
  538. // Remove any linker tables that have snuck in. Linker tables are those
  539. // whose foreign key constraints link to two or more base table.
  540. $final_list = array();
  541. foreach ($base_tables as $i => $tablename) {
  542. $num_links = 0;
  543. $schema = chado_get_schema($tablename);
  544. $fkeys = $schema['foreign keys'];
  545. foreach ($fkeys as $fkid => $details) {
  546. $fktable = $details['table'];
  547. if (in_array($fktable, $base_tables)) {
  548. $num_links++;
  549. }
  550. }
  551. if ($num_links < 2) {
  552. $final_list[] = $tablename;
  553. }
  554. }
  555. // Sort the tables and return the list.
  556. sort($final_list);
  557. return $final_list;
  558. }
  559. /**
  560. * Get information about which Chado base table a cvterm is mapped to.
  561. *
  562. * Vocbulary terms that represent content types in Tripal must be mapped to
  563. * Chado tables. A cvterm can only be mapped to one base table in Chado.
  564. * This function will return an object that contains the chado table and
  565. * foreign key field to which the cvterm is mapped. The 'chado_table' property
  566. * of the returned object contains the name of the table, and the 'chado_field'
  567. * property contains the name of the foreign key field (e.g. type_id), and the
  568. * 'cvterm' property contains a cvterm object.
  569. *
  570. * @params
  571. * An associative array that contains the following keys:
  572. * - cvterm_id: the cvterm ID value for the term.
  573. * - vocabulary: the short name for the vocabulary (e.g. SO, GO, PATO)
  574. * - accession: the accession for the term.
  575. * - bundle_id: the ID for the bundle to which a term is associated.
  576. * The 'vocabulary' and 'accession' must be used together, the 'cvterm_id' can
  577. * be used on it's own.
  578. * @return
  579. * An object containing the chado_table and chado_field properties or NULL if
  580. * if no mapping was found for the term.
  581. */
  582. function chado_get_cvterm_mapping($params) {
  583. $cvterm_id = array_key_exists('cvterm_id', $params) ? $params['cvterm_id'] : NULL;
  584. $vocabulary = array_key_exists('vocabulary', $params) ? $params['vocabulary'] : NULL;
  585. $accession = array_key_exists('accession', $params) ? $params['accession'] : NULL;
  586. if ($cvterm_id) {
  587. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
  588. }
  589. else if ($vocabulary and $accession) {
  590. $match = array(
  591. 'dbxref_id' => array(
  592. 'db_id' => array(
  593. 'name' => $vocabulary,
  594. ),
  595. 'accession' => $accession,
  596. ),
  597. );
  598. $cvterm = chado_generate_var('cvterm', $match);
  599. }
  600. $result = db_select('chado_cvterm_mapping', 'tcm')
  601. ->fields('tcm')
  602. ->condition('cvterm_id', $cvterm->cvterm_id)
  603. ->execute();
  604. $result = $result->fetchObject();
  605. if ($result) {
  606. $result->cvterm = $cvterm;
  607. }
  608. return $result;
  609. }