tripal_feature.api.inc 21 KB

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