tripal_chado.schema.api.inc

Provides an application programming interface (API) for describing Chado tables.

File

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

Related topics