tripal_cv.api.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <?php
  2. /**
  3. * @file
  4. * Controlled Vocabulary API
  5. *
  6. * @defgroup tripal_cv_api CV Module API
  7. * @ingroup tripal_api
  8. * @ingroup tripal_cv
  9. * This module provides a set of functions to simplify working with
  10. * controlled vocabularies. Most of the API functions deal with retrieving
  11. * terms or their parent vocabularies.
  12. *
  13. * However, the API also supports
  14. * generation of trees for browsing a vocabulary as well as generation of
  15. * pie graphs for display of hierarchical counts of terms. Version 0.3b of
  16. * Tripal provides a feature browser and a feature summary chart uses
  17. * the API functions provided here. But in general charts and trees can be
  18. * created for any controlled vocabulary.
  19. *
  20. */
  21. /**
  22. * Purpose: To retrieve a chado controlled vocabulary object
  23. *
  24. * @param $select_values
  25. * An array meant to uniquely select a given controlled vocabulary
  26. *
  27. * @return
  28. * Chado controlled vocabulary object
  29. *
  30. * The controlled vocabulary is selected using tripal_core_chado select and as such the
  31. * $select_values array parameter meant to uniquely identify the controlled vocab to be
  32. * returned follows the same form as when using tripal_core_chado_select directly.
  33. *
  34. * Example Usage:
  35. * @code
  36. $select_values = array(
  37. 'name' => 'feature_property'
  38. );
  39. $cv_object = tripal_cv_get_cv($select_values);
  40. * @endcode
  41. * The above code selects the feature_property cv and returns the following object:
  42. * @code
  43. $cv_object = stdClass Object (
  44. [cv_id] => 13
  45. [name] => feature_property
  46. [definition] =>
  47. );
  48. * @endcode
  49. *
  50. * @ingroup tripal_cv_api
  51. */
  52. function tripal_cv_get_cv($select_values) {
  53. $columns = array(
  54. 'cv_id',
  55. 'name',
  56. 'definition',
  57. );
  58. $results = tripal_core_chado_select('cv', $columns, $select_values);
  59. if (sizeof($results) == 1) {
  60. return $results[0];
  61. }
  62. elseif (empty($results)) {
  63. watchdog('tripal_cv',
  64. 'tripal_cv_get_cv: No cv matches criteria values:%values',
  65. array('%values' => print_r($select_values, TRUE)),
  66. WATCHDOG_WARNING
  67. );
  68. return FALSE;
  69. }
  70. else {
  71. watchdog('tripal_cv',
  72. 'tripal_cv_get_cv: 2+ cvs match criteria values:%values',
  73. array('%values' => print_r($select_values, TRUE)),
  74. WATCHDOG_WARNING
  75. );
  76. }
  77. }
  78. // Purpose: To retrieve a chado cv object
  79. // @param $where_options
  80. // @code
  81. // array(
  82. // <column_name> => array(
  83. // 'type' => <type of column: INT/STRING>,
  84. // 'value' => <the vlaue you want to filter on>,
  85. // 'exact' => <if TRUE use =; if FALSE use ~>,
  86. // )
  87. // )
  88. // @endcode
  89. //
  90. // @return
  91. // Chado cv object with all fields from the chado cv table
  92. //
  93. // @ingroup tripal_cv_api
  94. //
  95. //function tripal_cv_get_cv ($where_options)
  96. /**
  97. * Retrieve a cv given the cv name
  98. *
  99. * @param $name
  100. * The name of the cv to be returned
  101. * @return
  102. * The cv object for the specified CV name
  103. *
  104. * @ingroup tripal_cv_api
  105. */
  106. function tripal_cv_get_cv_by_name($name) {
  107. $r = tripal_core_chado_select('cv', array('*'), array('name' => $name));
  108. return $r[0];
  109. }
  110. /**
  111. * Retrieve the cv object for the specified CV id
  112. *
  113. * NOTE: This function is deprecated.
  114. * @see tripal_core_chado_generate_vars()
  115. *
  116. * @param $cv_id
  117. * The unique identifier for the cv retrieve
  118. *
  119. * @return
  120. * An object describing the cv
  121. *
  122. * @ingroup tripal_cv_api
  123. */
  124. function tripal_cv_get_cv_by_id($cv_id) {
  125. $r = tripal_core_chado_select('cv', array('*'), array('cv_id' => $cv_id));
  126. return $r;
  127. }
  128. /**
  129. * Create an options array to be used in a form element which provides a list of all chado cvs
  130. *
  131. * @return
  132. * An array(cv_id => name) for each cv in the chado cv table
  133. *
  134. * @ingroup tripal_cv_api
  135. */
  136. function tripal_cv_get_cv_options() {
  137. $results = tripal_core_chado_select('cv', array('cv_id', 'name'), array());
  138. $options = array();
  139. foreach ($results as $r) {
  140. $options[$r->cv_id] = $r->name;
  141. }
  142. return $options;
  143. }
  144. /**
  145. * Retrieve a chado cvterm object with a given name
  146. *
  147. * @param $name
  148. * the cvterm.name
  149. * @param $cv_id
  150. * the cv_id of the term you are looking for
  151. * @param $cv_name
  152. * the name of the CV
  153. *
  154. * @return
  155. * cvterm object
  156. *
  157. * @ingroup tripal_cv_api
  158. */
  159. function tripal_cv_get_cvterm_by_name($name, $cv_id = 0, $cv_name = 'tripal') {
  160. if ($cv_id) {
  161. $values = array(
  162. 'name' => $name,
  163. 'cv_id' => $cv_id,
  164. );
  165. $r = tripal_core_chado_select('cvterm', array('*'), $values);
  166. }
  167. elseif ($cv_name) {
  168. $values = array(
  169. 'name' => $name,
  170. 'cv_id' => array(
  171. 'name' => $cv_name,
  172. ),
  173. );
  174. $r = tripal_core_chado_select('cvterm', array('*'), $values);
  175. }
  176. else {
  177. $values = array(
  178. 'name' => $name,
  179. );
  180. $r = tripal_core_chado_select('cvterm', array('*'), $values);
  181. }
  182. if (!$r) {
  183. return FALSE;
  184. }
  185. if (count($r) > 0) {
  186. return FALSE;
  187. }
  188. return $r[0];
  189. }
  190. /**
  191. * Create an options array to be used in a form element
  192. * which provides a list of all chado cvterms
  193. *
  194. * @param $cv_id
  195. * The chado cv_id;
  196. * only cvterms with the supplied cv_id will be returned
  197. * @return
  198. * An array(cvterm_id => name)
  199. * for each cvterm in the chado cvterm table where cv_id=that supplied
  200. *
  201. * @ingroup tripal_cv_api
  202. */
  203. function tripal_cv_get_cvterm_options($cv_id = 0) {
  204. if ($cv_id > 0) {
  205. $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $cv_id));
  206. }
  207. else {
  208. $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array());
  209. }
  210. $options = array();
  211. foreach ($results as $r) {
  212. $options[$r->cvterm_id] = $r->name;
  213. }
  214. return $options;
  215. }
  216. /**
  217. * Adds a controlled vocabular to the CV table of Chado.
  218. *
  219. * @param $name
  220. * The name of the controlled vocabulary. These are typically all lower case
  221. * with no special characters other than an undrescore (for spaces).
  222. * @param $comment
  223. * A description or definition of the vocabulary.
  224. *
  225. * @return
  226. * An object populated with fields from the newly added database.
  227. *
  228. * @ingroup tripal_cv_api
  229. */
  230. function tripal_cv_add_cv($name, $definition) {
  231. // insert/update values
  232. $ins_values = array(
  233. 'name' => $name,
  234. 'definition' => $definition
  235. );
  236. // see if the CV (default-namespace) exists already in the database
  237. $sel_values = array('name' => $name);
  238. $sel_options = array('statement_name' => 'sel_cv_na');
  239. $results = tripal_core_chado_select('cv', array('*'), $sel_values, $sel_options);
  240. // if it does not exists then add it
  241. if (count($results) == 0) {
  242. $ins_options = array('statement_name' => 'ins_cv_nade');
  243. $success = tripal_core_chado_insert('cv', $ins_values, $ins_options);
  244. if (!$success) {
  245. watchdog('tripal_cv', "Failed to create the CV record", NULL, WATCHDOG_WARNING);
  246. return FALSE;
  247. }
  248. $results = tripal_core_chado_select('cv', array('*'), $sel_values, $sel_options);
  249. }
  250. // if it already exists then do an update
  251. else {
  252. $upd_options = array('statement_name' => 'upd_cv_nade');
  253. $success = tripal_core_chado_update('cv', $sel_values, $ins_values, $upd_options);
  254. if (!$success) {
  255. watchdog('tripal_cv', "Failed to update the CV record", NULL, WATCHDOG_WARNING);
  256. return FALSE;
  257. }
  258. $results = tripal_core_chado_select('cv', array('*'), $sel_values, $sel_options);
  259. }
  260. // return the cv object
  261. return $results[0];
  262. }
  263. /**
  264. * Add's a CV term to the cvterm table. If the parent CV does not exist then
  265. * that too is added to the CV table. If the cvterm is a relationship term
  266. * then the $is_relationship argument should be set. The function will try
  267. * to first find the relationship in the relationship ontology for updating and
  268. * if it can't be found will add the relationship to the __global CV. All terms
  269. * must also have a corresponding database. This is specified in the term's
  270. * ID just before the colon (e.g. GO:003824). If the database does not exist
  271. * in the DB table then it will be added automatically. The accession (the
  272. * value just after the colon in the term's ID) will be added to the dbxref
  273. * table. If the CVterm already exists and $update is set (default) then the
  274. * cvterm is updated. If the CVTerm already exists and $update is not set, then
  275. * no changes are made and the CVTerm object is returned.
  276. *
  277. * @param $term
  278. * An associative array with the following keys: 'id', 'name' and 'namespace',
  279. * 'is_obsolete', and 'def'. Where 'id' is the term accession, 'name' is the
  280. * term name, 'namespace' is the CV name for the term, 'def' is the term
  281. * definition and 'is_obsolete' is present and set to 1 if the term is defunct.
  282. * The 'id' must be of the form <DB>:<ACCESSION>, where <DB> is the name of
  283. * the database to which the cvterm belongs and the <ACCESSION> is the
  284. * term's accession number in the database.
  285. * @param $defaultcv
  286. * Optional. The CV name to which the term
  287. * belongs. If this arugment is null or not provided then the function tries
  288. * to find a record in the CV table with the same name provided in the
  289. * $term[namespace]. If this field is provided then it overrides what the
  290. * value in $term[namespace]
  291. * @param $is_relationship
  292. * If this term is a relationship term then this value should be 1.
  293. * @param $update
  294. * By default this is set to 1. If the term exists it is automatically updated.
  295. * @param $dbname
  296. * In some cases the database name will not be part of the $term['id'] and it
  297. * needs to be explicitly set. Use this argument only if the database name
  298. * cannot be specififed in the term ID (e.g. <DB>:<ACCESSION>).
  299. *
  300. * @return
  301. * A CVTerm object
  302. *
  303. * @ingroup tripal_cv_api
  304. */
  305. function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship = 0,
  306. $update = 1, $dbname = 'internal') {
  307. // get the term properties
  308. $id = $term['id'];
  309. $name = '';
  310. $cvname = '';
  311. $definition = '';
  312. $is_obsolete = 0;
  313. $accession = '';
  314. if (array_key_exists('name', $term)) {
  315. $name = $term['name'];
  316. }
  317. else {
  318. $name = $id;
  319. }
  320. if (array_key_exists('namespace', $term)) {
  321. $cvname = $term['namespace'];
  322. }
  323. else {
  324. $cvname = $defaultcv;
  325. }
  326. if (array_key_exists('def', $term)) {
  327. $definition = preg_replace('/^\"(.*)\"/', '\1', $term['def']);
  328. }
  329. else {
  330. $definition = '';
  331. }
  332. if (array_key_exists('is_obsolete', $term)) {
  333. $is_obsolete = $term['is_obsolete'];
  334. if (strcmp($is_obsolete, 'true') == 0) {
  335. $is_obsolete = 1;
  336. }
  337. }
  338. if (!$name and !$id) {
  339. watchdog('tripal_cv', "Cannot find cvterm without 'id' or 'name'", NULL, WATCHDOG_WARNING);
  340. return 0;
  341. }
  342. if (!$id) {
  343. $id = $name;
  344. }
  345. // get the accession and the database from the cvterm id
  346. if ($dbname) {
  347. $accession = $id;
  348. }
  349. if (preg_match('/^.+?:.*$/', $id)) {
  350. $accession = preg_replace('/^.+?:(.*)$/', '\1', $id);
  351. $dbname = preg_replace('/^(.+?):.*$/', '\1', $id);
  352. }
  353. // check that we have a database name, give a different message if it's a relationship
  354. if ($is_relationship and !$dbname) {
  355. watchdog('tripal_cv', "A database name is not provided for this relationship term: $id", NULL, WATCHDOG_WARNING);
  356. return 0;
  357. }
  358. if (!$is_relationship and !$dbname) {
  359. watchdog('tripal_cv', "A database identifier is missing from the term: $id", NULL, WATCHDOG_WARNING);
  360. return 0;
  361. }
  362. // make sure the CV name exists
  363. $cv = tripal_cv_add_cv($cvname, '');
  364. if (!$cv) {
  365. watchdog('tripal_cv', "Cannot find namespace '$cvname' when adding/updating $id", NULL, WATCHDOG_WARNING);
  366. return 0;
  367. }
  368. // this SQL statement will be used a lot to find a cvterm so just set it
  369. // here for easy reference below. Because CV terms can change their names
  370. // but accessions don't change, the following SQL finds cvterms based on
  371. // their accession rather than the name
  372. if (!tripal_core_is_sql_prepared('sel_cvterm_by_accession')) {
  373. $pcvtermsql = "
  374. PREPARE sel_cvterm_by_accession(text, text) AS
  375. SELECT CVT.name, CVT.cvterm_id, CV.cv_id, CV.name as cvname,
  376. DB.name as dbname, DB.db_id, DBX.accession
  377. FROM cvterm CVT
  378. INNER JOIN dbxref DBX on CVT.dbxref_id = DBX.dbxref_id
  379. INNER JOIN db DB on DBX.db_id = DB.db_id
  380. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  381. WHERE DBX.accession = $1 and DB.name = $2";
  382. if (!tripal_core_chado_prepare('sel_cvterm_by_accession', $pcvtermsql, array('text', 'text'))) {
  383. watchdog('tripal_cv', "Cannot prepare statement 'sel_cvterm_by_accession'", NULL, WATCHDOG_WARNING);
  384. return 0;
  385. }
  386. }
  387. $cvtermsql = "EXECUTE sel_cvterm_by_accession('%s','%s')";
  388. // add the database. The function will just return the DB object if the
  389. // database already exists.
  390. $db = tripal_db_add_db($dbname);
  391. if (!$db) {
  392. watchdog('tripal_cv', "Cannot find database '$dbname' in Chado.", NULL, WATCHDOG_WARNING);
  393. return 0;
  394. }
  395. // the cvterm table has two unique dependencies. We need to check both.
  396. // first check the (name, cv_id, is_obsolete) constraint
  397. $values = array(
  398. 'name' => $name,
  399. 'is_obsolete' => $is_obsolete,
  400. 'cv_id' => array(
  401. 'name' => $cvname,
  402. ),
  403. );
  404. $options = array('statement_name' => 'sel_cvterm_c1');
  405. $result = tripal_core_chado_select('cvterm', array('*'), $values, $options);
  406. // if the constraint is met then let's check it to see if
  407. // the database name matches the one we have been provided
  408. if (count($result) == 1) {
  409. $cvterm = $result[0];
  410. // get the dbxref record
  411. $values = array('dbxref_id' => $cvterm->dbxref_id);
  412. $options = array('statement_name' => 'sel_dbxref_id');
  413. $result = tripal_core_chado_select('dbxref', array('*'), $values, $options);
  414. $dbxref = $result[0];
  415. // get the db
  416. $values = array('db_id' => $dbxref->db_id);
  417. $options = array('statement_name' => 'sel_db_id');
  418. $result = tripal_core_chado_select('db', array('*'), $values, $options);
  419. $db_check = $result[0];
  420. // the database name for this existing term does not match that of the
  421. // one provided to this function. The CV name matches otherwise we
  422. // wouldn't have made it this far. So, let's swap the database for
  423. // this term
  424. if ($db_check->name != $db->name) {
  425. // look to see if the correct dbxref record already exists for this database
  426. $values = array(
  427. 'db_id' => $db->db_id,
  428. 'accession' => $accession,
  429. );
  430. $options = array('statement_name' => 'sel_dbxref_idac');
  431. $result = tripal_core_chado_select('dbxref', array('*'), $values, $options);
  432. // if we already have a good dbxref then we want to update our cvterm
  433. // to use this dbxref
  434. if (count($result) > 0) {
  435. $dbxref = $result[0];
  436. $match = array('cvterm_id' => $cvterm->cvterm_id);
  437. $values = array('dbxref_id' => $dbxref->dbxref_id);
  438. $options = array('statement_name' => 'upd_cvterm_db');
  439. $success = tripal_core_chado_update('cvterm', $match, $values, $options);
  440. if (!$success) {
  441. watchdog('tripal_cv', "Failed to correct the dbxref id for the cvterm " .
  442. "'$name' (id: $accession), for database $dbname", NULL, WATCHDOG_WARNING);
  443. return 0;
  444. }
  445. }
  446. // if we don't have the record then we want to delete our cvterm and let the code
  447. // below recreate it with the correct info
  448. else {
  449. $match = array('cvterm_id' => $cvterm->cvterm_id);
  450. $options = array('statement_name' => 'del_cvterm_cv');
  451. tripal_core_chado_delete('cvterm', $match, $options);
  452. }
  453. }
  454. // check that the accession matches. Sometimes an OBO can define the same term
  455. // multiple times but with different accessions. If this is the case we
  456. // can't do an insert or it will violate the constraint in the cvterm table.
  457. // so we'll need to add the record to the cvterm_dbxref table instead
  458. if ($dbxref->accession != $accession) {
  459. // get/add the dbxref fort his term
  460. $dbxref_new = tripal_db_add_dbxref($db->db_id, $accession);
  461. if (!$dbxref_new) {
  462. watchdog('tripal_cv', "Failed to find or insert the dbxref record for cvterm, " .
  463. "$name (id: $accession), for database $dbname", NULL, WATCHDOG_WARNING);
  464. return 0;
  465. }
  466. // check to see if the cvterm_dbxref record already exists
  467. $values = array(
  468. 'cvterm_id' => $cvterm->cvterm_id,
  469. 'dbxref_id' => $dbxref_new->dbxref_id,
  470. 'is_for_definition' => 1,
  471. );
  472. $options = array('statement_name' => 'sel_cvtermdbxref_cvdbis');
  473. $result = tripal_core_chado_select('cvterm_dbxref', array('*'), $values, $options);
  474. // if the cvterm_dbxref record does not exists then add it
  475. if (count($result)==0) {
  476. $options = array(
  477. 'statement_name' => 'ins_cvtermdbxref_cvdbis',
  478. 'return_record' => FALSE,
  479. );
  480. $success = tripal_core_chado_insert('cvterm_dbxref', $values, $options);
  481. if (!$success) {
  482. watchdog('tripal_cv', "Failed to find or insert the cvterm_dbxref record for a " .
  483. "duplicated cvterm: $name (id: $accession), for database $dbname", NULL, WATCHDOG_WARNING);
  484. return 0;
  485. }
  486. }
  487. // get the original cvterm with the same name and return that.
  488. $cvterm = db_fetch_object(chado_query($cvtermsql, $dbxref->accession, $dbname));
  489. return $cvterm;
  490. }
  491. // continue on, we've fixed the record if the db_id did not match,
  492. // we can now perform and updated if we need to.
  493. }
  494. // get the CVterm record
  495. $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname));
  496. //print "$pcvtermsql\n$cvtermsql\n$accession, $dbname\n";
  497. //print "CVTERM:\n";
  498. //print_r($cvterm);
  499. if (!$cvterm) {
  500. // check to see if the dbxref exists if not, add it
  501. $dbxref = tripal_db_add_dbxref($db->db_id, $accession);
  502. if (!$dbxref) {
  503. watchdog('tripal_cv', "Failed to find or insert the dbxref record for cvterm, " .
  504. "$name (id: $accession), for database $dbname", NULL, WATCHDOG_WARNING);
  505. return 0;
  506. }
  507. // check to see if the dbxref already has an entry in the cvterm table
  508. // this is the second constraint in the cvterm table
  509. $values = array('dbxref_id' => $dbxref->dbxref_id);
  510. $options = array('statement_name' => 'sel_cvterm_db');
  511. $check = tripal_core_chado_select('cvterm', array('cvterm_id'), $values, $options);
  512. if (count($check) == 0) {
  513. // now add the cvterm
  514. $ins_values = array(
  515. 'cv_id' => $cv->cv_id,
  516. 'name' => $name,
  517. 'definition' => $definition,
  518. 'dbxref_id' => $dbxref->dbxref_id,
  519. 'is_obsolete' => $is_obsolete,
  520. 'is_relationshiptype' => $is_relationship,
  521. );
  522. $ins_options = array('statement_name' => 'ins_cvterm_all');
  523. $success = tripal_core_chado_insert('cvterm', $ins_values, $ins_options);
  524. if (!$success) {
  525. if (!$is_relationship) {
  526. watchdog('tripal_cv', "Failed to insert the term: $name ($dbname)", NULL, WATCHDOG_WARNING);
  527. return 0;
  528. }
  529. else {
  530. watchdog('tripal_cv', "Failed to insert the relationship term: $name (cv: " . $cvname . " db: $dbname)", NULL, WATCHDOG_WARNING);
  531. return 0;
  532. }
  533. }
  534. }
  535. // this dbxref already exists in the cvterm table
  536. else {
  537. watchdog('tripal_cv', "The dbxref already exists for another cvterm record: $name (cv: " . $cvname . " db: $dbname)", NULL, WATCHDOG_WARNING);
  538. return 0;
  539. }
  540. $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname));
  541. }
  542. // upate the cvterm
  543. elseif ($update) {
  544. $match = array('cvterm_id' => $cvterm->cvterm_id);
  545. $upd_values = array(
  546. 'name' => $name,
  547. 'definition' => $definition,
  548. 'is_obsolete' => $is_obsolete,
  549. 'is_relationshiptype' => $is_relationship,
  550. );
  551. $upd_options = array('statement_name' => 'upd_cvterm_nadeisis');
  552. $success = tripal_core_chado_update('cvterm', $match, $upd_values, $upd_options);
  553. if (!$success) {
  554. watchdog('tripal_cv', "Failed to update the term: $name", NULL, WATCHDOG_WARNING);
  555. return 0;
  556. }
  557. $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname));
  558. }
  559. else {
  560. // do nothing, we have the cvterm but we don't want to update
  561. }
  562. // return the cvterm
  563. return $cvterm;
  564. }
  565. /**
  566. * This function defines the custom tables that will be created
  567. * in the chado schema.
  568. *
  569. * @ingroup tripal_cv
  570. */
  571. function tripal_cv_get_custom_tables($table = NULL) {
  572. if (!$table or strcmp($table, 'tripal_obo_temp')==0) {
  573. $schema['tripal_obo_temp'] = array(
  574. 'table' => 'tripal_obo_temp',
  575. 'fields' => array(
  576. 'id' => array(
  577. 'type' => 'varchar',
  578. 'length' => '255',
  579. 'not null' => TRUE,
  580. ),
  581. 'stanza' => array(
  582. 'type' => 'text',
  583. 'not null' => TRUE,
  584. ),
  585. 'type' => array(
  586. 'type' => 'varchar',
  587. 'length' => '50',
  588. 'not null' => TRUE,
  589. ),
  590. ),
  591. 'indexes' => array(
  592. 'tripal_obo_temp_idx0' => array('id'),
  593. 'tripal_obo_temp_idx0' => array('type'),
  594. ),
  595. 'unique keys' => array(
  596. 'tripal_obo_temp_uq0' => array('id'),
  597. ),
  598. );
  599. }
  600. return $schema;
  601. }