tripal_feature.api.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. /**
  3. * Implements hook_chado_feature_schema()
  4. * Purpose: To add descriptions and foreign keys to default table description
  5. * Note: This array will be merged with the array from all other implementations
  6. *
  7. * @return
  8. * Array describing the feature table
  9. *
  10. * @ingroup tripal_schema_api
  11. */
  12. function tripal_feature_chado_feature_schema() {
  13. $description = array();
  14. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_schema()
  15. $description['foreign keys']['organism'] = array(
  16. 'table' => 'organism',
  17. 'columns' => array(
  18. 'organism_id' => 'organism_id',
  19. ),
  20. );
  21. $description['foreign keys']['dbxref'] = array(
  22. 'table' => 'dbxref',
  23. 'columns' => array(
  24. 'dbxref_id' => 'dbxref_id',
  25. ),
  26. );
  27. $description['foreign keys']['cvterm'] = array(
  28. 'table' => 'cvterm',
  29. 'columns' => array(
  30. 'type_id' => 'cvterm_id',
  31. ),
  32. );
  33. $referring_tables = array('analysisfeature',
  34. 'element',
  35. 'feature_cvterm',
  36. 'feature_dbxref',
  37. 'feature_expression',
  38. 'feature_genotype',
  39. 'feature_phenotype',
  40. 'feature_pub',
  41. 'feature_relationship',
  42. 'feature_synonym',
  43. 'featureloc',
  44. 'featurepos',
  45. 'featureprop',
  46. 'featurerange',
  47. 'library_feature',
  48. 'phylonode',
  49. 'wwwuser_feature'
  50. );
  51. $description['referring_tables'] = $referring_tables;
  52. return $description;
  53. }
  54. /**
  55. * Implements hook_chado_featureprop_schema()
  56. * Purpose: To add descriptions and foreign keys to default table description
  57. * Note: This array will be merged with the array from all other implementations
  58. *
  59. * @return
  60. * Array describing the featureprop table
  61. *
  62. * @ingroup tripal_schema_api
  63. */
  64. function tripal_feature_chado_featureprop_schema() {
  65. $description = array();
  66. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_featureprop_schema()
  67. $description['foreign keys']['feature'] = array(
  68. 'table' => 'feature',
  69. 'columns' => array(
  70. 'feature_id' => 'feature_id',
  71. ),
  72. );
  73. $description['foreign keys']['cvterm'] = array(
  74. 'table' => 'cvterm',
  75. 'columns' => array(
  76. 'type_id' => 'cvterm_id',
  77. ),
  78. );
  79. $referring_tables = array('analysisfeature',
  80. 'featureprop_pub',
  81. );
  82. $description['referring_tables'] = $referring_tables;
  83. return $description;
  84. }
  85. /**
  86. * Implements hook_chado_featureloc_schema()
  87. * Purpose: To add descriptions and foreign keys to default table description
  88. * Note: This array will be merged with the array from all other implementations
  89. *
  90. * @return
  91. * Array describing the featureloc table
  92. *
  93. * @ingroup tripal_schema_api
  94. */
  95. function tripal_feature_chado_featureloc_schema() {
  96. $description = array();
  97. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_featureloc_schema()
  98. $description['foreign keys']['feature'] = array(
  99. 'table' => 'feature',
  100. 'columns' => array(
  101. 'feature_id' => 'feature_id',
  102. 'srcfeature_id' => 'feature_id'
  103. ),
  104. );
  105. $referring_tables = array('analysisfeature',
  106. 'featureloc_pub',
  107. );
  108. $description['referring_tables'] = $referring_tables;
  109. return $description;
  110. }
  111. /**
  112. * Implements hook_chado_feature_dbxref_schema()
  113. * Purpose: To add descriptions and foreign keys to default table description
  114. * Note: This array will be merged with the array from all other implementations
  115. *
  116. * @return
  117. * Array describing the feature_dbxref table
  118. *
  119. * @ingroup tripal_schema_api
  120. */
  121. function tripal_feature_chado_feature_dbxref_schema() {
  122. $description = array();
  123. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_dbxref_schema()
  124. $description['foreign keys']['feature'] = array(
  125. 'table' => 'feature',
  126. 'columns' => array(
  127. 'feature_id' => 'feature_id',
  128. ),
  129. );
  130. $description['foreign keys']['dbxref'] = array(
  131. 'table' => 'dbxref',
  132. 'columns' => array(
  133. 'dbxref_id' => 'dbxref_id',
  134. ),
  135. );
  136. return $description;
  137. }
  138. /**
  139. * Implements hook_chado_feature_relationship_schema()
  140. * Purpose: To add descriptions and foreign keys to default table description
  141. * Note: This array will be merged with the array from all other implementations
  142. *
  143. * @return
  144. * Array describing the feature_dbxref table
  145. *
  146. * @ingroup tripal_schema_api
  147. */
  148. function tripal_feature_chado_feature_relationship_schema() {
  149. $description = array();
  150. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_dbxref_schema()
  151. $description['foreign keys']['feature'] = array(
  152. 'table' => 'feature',
  153. 'columns' => array(
  154. 'object_id' => 'feature_id',
  155. 'subject_id' => 'feature_id',
  156. ),
  157. );
  158. $description['foreign keys']['cvterm'] = array(
  159. 'table' => 'cvterm',
  160. 'columns' => array(
  161. 'type_id' => 'cvterm_id',
  162. ),
  163. );
  164. return $description;
  165. }
  166. /**
  167. * Implements hook_chado_feature_relationship_schema()
  168. * Purpose: To add descriptions and foreign keys to default table description
  169. * Note: This array will be merged with the array from all other implementations
  170. *
  171. * @return
  172. * Array describing the feature_dbxref table
  173. *
  174. * @ingroup tripal_schema_api
  175. */
  176. function tripal_feature_chado_feature_cvterm_schema() {
  177. $description = array();
  178. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_dbxref_schema()
  179. $description['foreign keys']['feature'] = array(
  180. 'table' => 'feature',
  181. 'columns' => array(
  182. 'feature_id' => 'feature_id',
  183. ),
  184. );
  185. $description['foreign keys']['cvterm'] = array(
  186. 'table' => 'cvterm',
  187. 'columns' => array(
  188. 'type_id' => 'cvterm_id',
  189. ),
  190. );
  191. $description['foreign keys']['pub'] = array(
  192. 'table' => 'pub',
  193. 'columns' => array(
  194. 'pub_id' => 'pub_id',
  195. ),
  196. );
  197. return $description;
  198. }
  199. /**
  200. *
  201. * @ingroup tripal_schema_api
  202. */
  203. function tripal_feature_chado_feature_synonym_schema() {
  204. $description = array();
  205. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_dbxref_schema()
  206. $description['foreign keys']['feature'] = array(
  207. 'table' => 'feature',
  208. 'columns' => array(
  209. 'feature_id' => 'feature_id',
  210. ),
  211. );
  212. $description['foreign keys']['synonym'] = array(
  213. 'table' => 'synonym',
  214. 'columns' => array(
  215. 'synonym_id' => 'synonym_id',
  216. ),
  217. );
  218. $description['foreign keys']['pub'] = array(
  219. 'table' => 'pub',
  220. 'columns' => array(
  221. 'pub_id' => 'pub_id',
  222. ),
  223. );
  224. return $description;
  225. }
  226. /**
  227. * Retrieve properties from the analysisfeatureprop table for a feature.
  228. *
  229. * @param $analysis_id
  230. * The analysis ID for the analysis feature. This argument is optional but
  231. * if specified it must also be accompanied with a feature ID.
  232. * @param $feature_id
  233. * The feature ID for the analysis feature. This argument is optional but
  234. * if specified it must also be accompanied with an analysis ID.
  235. * @param $analysisfeature_id
  236. * The analysis feature ID for the analysis feature. This argument is
  237. * optional and can be used rather than specifying the $analysis_id and
  238. * $feature_id arguments. If all three arguments are specified (e.g.
  239. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  240. * $analysisfeature_id is used and the other two arguments are ignored.
  241. * @param $property
  242. * The cvterm name of the properties to retrieve
  243. * @param $cv_name
  244. * Optional. The name of the cv to which the property belongs. By
  245. * default this is the 'tripal' cv.
  246. *
  247. * @return
  248. * An analysisfeature chado variable with the specified properties expanded
  249. *
  250. * @ingroup tripal_feature_api
  251. */
  252. function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
  253. $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
  254. // check that the incoming arguments are correct
  255. if (($analysis_id and !$feature_id) or
  256. (!$analysis_id and $feature_id)) {
  257. watchdog('tripal_feature',
  258. 'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
  259. array(), WATCHDOG_WARNING);
  260. }
  261. // get the analysisfeature_id if one is not provided
  262. if (!$analysisfeature_id) {
  263. $columns = array('analysisfeature_id');
  264. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  265. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  266. $analysisfeature_id = $result[0]->analysisfeature_id;
  267. }
  268. // get the property.
  269. return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
  270. }
  271. /**
  272. * Insert a property for an analysis feature
  273. *
  274. * @param $analysis_id
  275. * The analysis ID for the analysis feature. This argument is optional but
  276. * if specified it must also be accompanied with a feature ID.
  277. * @param $feature_id
  278. * The feature ID for the analysis feature. This argument is optional but
  279. * if specified it must also be accompanied with an analysis ID.
  280. * @param $analysisfeature_id
  281. * The analysis feature ID for the analysis feature. This argument is
  282. * optional and can be used rather than specifying the $analysis_id and
  283. * $feature_id arguments. If all three arguments are specified (e.g.
  284. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  285. * $analysisfeature_id is used and the other two arguments are ignored.
  286. * @param $property
  287. * The cvterm name of the property to insert
  288. * @param $value
  289. * The value of the property to insert
  290. * @param $update_if_present
  291. * A boolean indicated whether to update the record if it's already present
  292. * @param $cv_name
  293. * Optional. The name of the cv to which the property belongs. By
  294. * default this is the 'tripal' cv.
  295. *
  296. * @return
  297. * True of success, False otherwise
  298. *
  299. * @ingroup tripal_feature_api
  300. */
  301. function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
  302. $analysisfeature_id = NULL, $property, $value, $update_if_present = 0,
  303. $cv_name = 'tripal') {
  304. // check that the incoming arguments are correct
  305. if (($analysis_id and !$feature_id) or
  306. (!$analysis_id and $feature_id)) {
  307. watchdog('tripal_feature',
  308. 'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
  309. array(), WATCHDOG_WARNING);
  310. }
  311. // get the analysisfeature_id if one is not provided
  312. if (!$analysisfeature_id) {
  313. $columns = array('analysisfeature_id');
  314. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  315. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  316. $analysisfeature_id = $result[0]->analysisfeature_id;
  317. }
  318. // insert the property.
  319. return tripal_core_insert_property('analysisfeature', $analysisfeature_id,
  320. $property, $cv_name, $value, $update_if_present);
  321. }
  322. /**
  323. * Update an analysis feature property using the property name. Use this
  324. * when a property only exists once for a given analysis feature. When more
  325. * than one value can exist for the same property use the
  326. * tripal_feature_analysis_update_property_by_id() function.
  327. *
  328. * @param $analysis_id
  329. * The analysis ID for the analysis feature. This argument is optional but
  330. * if specified it must also be accompanied with a feature ID.
  331. * @param $feature_id
  332. * The feature ID for the analysis feature. This argument is optional but
  333. * if specified it must also be accompanied with an analysis ID.
  334. * @param $analysisfeature_id
  335. * The analysis feature ID for the analysis feature. This argument is
  336. * optional and can be used rather than specifying the $analysis_id and
  337. * $feature_id arguments. If all three arguments are specified (e.g.
  338. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  339. * $analysisfeature_id is used and the other two arguments are ignored.
  340. * @param $property
  341. * The cvterm name of the property to update
  342. * @param $value
  343. * The value of the property to update
  344. * @param $insert_if_missing
  345. * A boolean indicated whether to insert the record if it's absent
  346. * @param $cv_name
  347. * Optional. The name of the cv to which the property belongs. By
  348. * default this is the 'tripal' cv.
  349. *
  350. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  351. * and then it will be updated with the supplied value
  352. *
  353. * @return
  354. * True of success, False otherwise
  355. *
  356. * @ingroup tripal_feature_api
  357. */
  358. function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
  359. $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
  360. $cv_name = 'tripal') {
  361. // check that the incoming arguments are correct
  362. if (($analysis_id and !$feature_id) or
  363. (!$analysis_id and $feature_id)) {
  364. watchdog('tripal_feature',
  365. 'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
  366. array(), WATCHDOG_WARNING);
  367. }
  368. // get the analysisfeature_id if one is not provided
  369. if (!$analysisfeature_id) {
  370. $columns = array('analysisfeature_id');
  371. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  372. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  373. $analysisfeature_id = $result[0]->analysisfeature_id;
  374. }
  375. // update the property.
  376. return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
  377. }
  378. /**
  379. * Update a property for an analysis feature using the analysisfeatureprop_id.
  380. *
  381. * @param $analysisfeatureprop_id
  382. * The analysis feature property ID for the analysis feature.
  383. * @param $property
  384. * The cvterm name of the property
  385. * @param $value
  386. * The value of the property
  387. * @param $cv_name
  388. * Optional. The name of the cv to which the property belongs. By
  389. * default this is the 'tripal' cv.
  390. * *
  391. * @return
  392. * True of success, False otherwise
  393. *
  394. * @ingroup tripal_feature_api
  395. */
  396. function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  397. $property, $value, $cv_name = 'tripal') {
  398. // update the property.
  399. return tripal_core_update_property_by_id('analysisfeature',
  400. $analysisfeatureprop_id, $property, $cv_name, $value);
  401. }
  402. /**
  403. * Delete an analysis feature property using the property name. Use this
  404. * when a property only exists once for a given analysis feature. When more
  405. * than one value can exist for the same property use the
  406. * tripal_feature_analysis_delete_property_by_id() function.
  407. *
  408. * @param $analysis_id
  409. * The analysis ID for the analysis feature. This argument is optional but
  410. * if specified it must also be accompanied with a feature ID.
  411. * @param $feature_id
  412. * The feature ID for the analysis feature. This argument is optional but
  413. * if specified it must also be accompanied with an analysis ID.
  414. * @param $analysisfeature_id
  415. * The analysis feature ID for the analysis feature. This argument is
  416. * optional and can be used rather than specifying the $analysis_id and
  417. * $feature_id arguments. If all three arguments are specified (e.g.
  418. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  419. * $analysisfeature_id is used and the other two arguments are ignored.
  420. * @param $property
  421. * The cvterm name of the property to delete
  422. * @param $cv_name
  423. * Optional. The name of the cv to which the property belongs. By
  424. * default this is the 'tripal' cv.
  425. *
  426. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  427. * and then it will be deleted
  428. *
  429. * @return
  430. * True of success, False otherwise
  431. *
  432. * @ingroup tripal_feature_api
  433. */
  434. function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
  435. $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
  436. // check that the incoming arguments are correct
  437. if (($analysis_id and !$feature_id) or
  438. (!$analysis_id and $feature_id)) {
  439. watchdog('tripal_feature',
  440. 'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
  441. array(), WATCHDOG_WARNING);
  442. }
  443. // get the analysisfeature_id if one is not provided
  444. if (!$analysisfeature_id) {
  445. $columns = array('analysisfeature_id');
  446. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  447. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  448. $analysisfeature_id = $result[0]->analysisfeature_id;
  449. }
  450. // get the property.
  451. return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
  452. }
  453. /**
  454. * Delete a property using the analysisfeatureprop_id
  455. *
  456. * @param $analysisfeatureprop_id
  457. * The analysis feature property ID for the analysis feature.
  458. *
  459. * @return
  460. * True of success, False otherwise
  461. *
  462. * @ingroup tripal_feature_api
  463. */
  464. function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
  465. // get the property.
  466. return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
  467. }
  468. /**
  469. * Retrieve properties of a given type for a given feature
  470. *
  471. * @param $feature_id
  472. * The feature_id of the properties you would like to retrieve
  473. * @param $property
  474. * The cvterm name of the properties to retrieve
  475. * @param $cv_name
  476. * Optional. The name of the cv to which the property belongs. By
  477. * default this is the 'tripal' cv.
  478. *
  479. * @return
  480. * A feature chado variable with the specified properties expanded
  481. *
  482. * @ingroup tripal_feature_api
  483. */
  484. function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
  485. return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
  486. }
  487. /**
  488. * Insert a given property
  489. *
  490. * @param $feature_id
  491. * The feature_id of the property to insert
  492. * @param $property
  493. * The cvterm name of the property to insert
  494. * @param $value
  495. * The value of the property to insert
  496. * @param $update_if_present
  497. * A boolean indicated whether to update the record if it's already present
  498. * @param $cv_name
  499. * Optional. The name of the cv to which the property belongs. By
  500. * default this is the 'tripal' cv.
  501. *
  502. * @return
  503. * True of success, False otherwise
  504. *
  505. * @ingroup tripal_feature_api
  506. */
  507. function tripal_feature_insert_property($feature_id, $property, $value,
  508. $update_if_present = 0, $cv_name = 'tripal') {
  509. return tripal_core_insert_property('feature', $feature_id, $property,
  510. $cv_name, $value, $update_if_present);
  511. }
  512. /**
  513. * Update a feature property using the property name. Only use this
  514. * if the property is unique and only exist once for the feature.
  515. *
  516. * @param $feature_id
  517. * The feature_id of the property to update
  518. * @param $property
  519. * The cvterm name of the property to update
  520. * @param $value
  521. * The value of the property to update
  522. * @param $insert_if_missing
  523. * A boolean indicated whether to insert the record if it's absent
  524. * @param $cv_name
  525. * Optional. The name of the cv to which the property belongs. By
  526. * default this is the 'tripal' cv.
  527. *
  528. * Note: The property will be identified using the unique combination of the $feature_id and $property
  529. * and then it will be updated with the supplied value
  530. *
  531. * @return
  532. * True of success, False otherwise
  533. *
  534. * @ingroup tripal_feature_api
  535. */
  536. function tripal_feature_update_property($feature_id, $property,
  537. $value, $insert_if_missing = 0, $cv_name = 'tripal') {
  538. return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
  539. }
  540. /**
  541. * Update a given feature property using the featureprop_id
  542. *
  543. * @param $featureprop_id
  544. * The featureprop_id of the property to update
  545. * @param $property
  546. * The cvterm name of the property
  547. * @param $value
  548. * The value of the property
  549. * @param $cv_name
  550. * Optional. The name of the cv to which the property belongs. By
  551. * default this is the 'tripal' cv.
  552. *
  553. * @return
  554. * True of success, False otherwise
  555. *
  556. * @ingroup tripal_feature_api
  557. */
  558. function tripal_feature_update_property_by_id($featureprop_id, $property,
  559. $value, $cv_name = 'tripal') {
  560. return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
  561. }
  562. /**
  563. * Delete a given feature property using the property name. Only use this
  564. * if the property is unique and only exists once for the feature.
  565. *
  566. * @param $feature_id
  567. * The feature_id of the property to delete
  568. * @param $property
  569. * The cvterm name of the property to delete
  570. * @param $cv_name
  571. * Optional. The name of the cv to which the property belongs. By
  572. * default this is the 'tripal' cv.
  573. *
  574. * Note: The property will be identified using the unique combination of the $feature_id and $property
  575. * and then it will be deleted
  576. *
  577. * @return
  578. * True of success, False otherwise
  579. *
  580. * @ingroup tripal_feature_api
  581. */
  582. function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
  583. return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
  584. }
  585. /**
  586. * Delete a given feature property using the featureprop_id
  587. *
  588. * @param $featureprop_id
  589. * The feature_id of the property to delete
  590. *
  591. * @return
  592. * True of success, False otherwise
  593. *
  594. * @ingroup tripal_feature_api
  595. */
  596. function tripal_feature_delete_property_by_id($featureprop_id) {
  597. return tripal_core_delete_property_by_id('feature', $featureprop_id);
  598. }