tripal_feature.api.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. 'cvterm_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. {
  255. // check that the incoming arguments are correct
  256. if(($analysis_id and !$feature_id) or
  257. (!$analysis_id and $feature_id)){
  258. watchdog('tripal_feature',
  259. 'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
  260. array(), WATCHDOG_WARNING);
  261. }
  262. // get the analysisfeature_id if one is not provided
  263. if(!$analysisfeature_id){
  264. $columns = array('analysisfeature_id');
  265. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  266. $result = tripal_core_chado_select('analysisfeature',$columns,$values);
  267. $analysisfeature_id = $result[0]->analysisfeature_id;
  268. }
  269. // get the property.
  270. return tripal_core_get_property('analysisfeature',$analysisfeature_id,$property,$cv_name);
  271. }
  272. /**
  273. * Insert a property for an analysis feature
  274. *
  275. * @param $analysis_id
  276. * The analysis ID for the analysis feature. This argument is optional but
  277. * if specified it must also be accompanied with a feature ID.
  278. * @param $feature_id
  279. * The feature ID for the analysis feature. This argument is optional but
  280. * if specified it must also be accompanied with an analysis ID.
  281. * @param $analysisfeature_id
  282. * The analysis feature ID for the analysis feature. This argument is
  283. * optional and can be used rather than specifying the $analysis_id and
  284. * $feature_id arguments. If all three arguments are specified (e.g.
  285. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  286. * $analysisfeature_id is used and the other two arguments are ignored.
  287. * @param $property
  288. * The cvterm name of the property to insert
  289. * @param $value
  290. * The value of the property to insert
  291. * @param $update_if_present
  292. * A boolean indicated whether to update the record if it's already present
  293. * @param $cv_name
  294. * Optional. The name of the cv to which the property belongs. By
  295. * default this is the 'tripal' cv.
  296. *
  297. * @return
  298. * True of success, False otherwise
  299. *
  300. * @ingroup tripal_feature_api
  301. */
  302. function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
  303. $analysisfeature_id = NULL, $property, $value, $update_if_present = 0,
  304. $cv_name = 'tripal')
  305. {
  306. // check that the incoming arguments are correct
  307. if(($analysis_id and !$feature_id) or
  308. (!$analysis_id and $feature_id)){
  309. watchdog('tripal_feature',
  310. 'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
  311. array(), WATCHDOG_WARNING);
  312. }
  313. // get the analysisfeature_id if one is not provided
  314. if(!$analysisfeature_id){
  315. $columns = array('analysisfeature_id');
  316. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  317. $result = tripal_core_chado_select('analysisfeature',$columns,$values);
  318. $analysisfeature_id = $result[0]->analysisfeature_id;
  319. }
  320. // insert the property.
  321. return tripal_core_insert_property('analysisfeature',$analysisfeature_id,
  322. $property,$cv_name,$value,$update_if_present);
  323. }
  324. /**
  325. * Update an analysis feature property using the property name. Use this
  326. * when a property only exists once for a given analysis feature. When more
  327. * than one value can exist for the same property use the
  328. * tripal_feature_analysis_update_property_by_id() function.
  329. *
  330. * @param $analysis_id
  331. * The analysis ID for the analysis feature. This argument is optional but
  332. * if specified it must also be accompanied with a feature ID.
  333. * @param $feature_id
  334. * The feature ID for the analysis feature. This argument is optional but
  335. * if specified it must also be accompanied with an analysis ID.
  336. * @param $analysisfeature_id
  337. * The analysis feature ID for the analysis feature. This argument is
  338. * optional and can be used rather than specifying the $analysis_id and
  339. * $feature_id arguments. If all three arguments are specified (e.g.
  340. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  341. * $analysisfeature_id is used and the other two arguments are ignored.
  342. * @param $property
  343. * The cvterm name of the property to update
  344. * @param $value
  345. * The value of the property to update
  346. * @param $insert_if_missing
  347. * A boolean indicated whether to insert the record if it's absent
  348. * @param $cv_name
  349. * Optional. The name of the cv to which the property belongs. By
  350. * default this is the 'tripal' cv.
  351. *
  352. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  353. * and then it will be updated with the supplied value
  354. *
  355. * @return
  356. * True of success, False otherwise
  357. *
  358. * @ingroup tripal_feature_api
  359. */
  360. function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
  361. $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
  362. $cv_name = 'tripal')
  363. {
  364. // check that the incoming arguments are correct
  365. if(($analysis_id and !$feature_id) or
  366. (!$analysis_id and $feature_id)){
  367. watchdog('tripal_feature',
  368. 'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
  369. array(), WATCHDOG_WARNING);
  370. }
  371. // get the analysisfeature_id if one is not provided
  372. if(!$analysisfeature_id){
  373. $columns = array('analysisfeature_id');
  374. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  375. $result = tripal_core_chado_select('analysisfeature',$columns,$values);
  376. $analysisfeature_id = $result[0]->analysisfeature_id;
  377. }
  378. // update the property.
  379. return tripal_core_update_property('analysisfeature',$analysisfeature_id,$property,$cv_name,$value, $insert_if_missing);
  380. }
  381. /**
  382. * Update a property for an analysis feature using the analysisfeatureprop_id.
  383. *
  384. * @param $analysisfeatureprop_id
  385. * The analysis feature property ID for the analysis feature.
  386. * @param $property
  387. * The cvterm name of the property
  388. * @param $value
  389. * The value of the property
  390. * @param $cv_name
  391. * Optional. The name of the cv to which the property belongs. By
  392. * default this is the 'tripal' cv.
  393. * *
  394. * @return
  395. * True of success, False otherwise
  396. *
  397. * @ingroup tripal_feature_api
  398. */
  399. function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  400. $property, $value, $cv_name = 'tripal')
  401. {
  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. {
  441. // check that the incoming arguments are correct
  442. if(($analysis_id and !$feature_id) or
  443. (!$analysis_id and $feature_id)){
  444. watchdog('tripal_feature',
  445. 'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
  446. array(), WATCHDOG_WARNING);
  447. }
  448. // get the analysisfeature_id if one is not provided
  449. if(!$analysisfeature_id){
  450. $columns = array('analysisfeature_id');
  451. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  452. $result = tripal_core_chado_select('analysisfeature',$columns,$values);
  453. $analysisfeature_id = $result[0]->analysisfeature_id;
  454. }
  455. // get the property.
  456. return tripal_core_delete_property('analysisfeature',$analysisfeature_id,$property,$cv_name);
  457. }
  458. /**
  459. * Delete a property using the analysisfeatureprop_id
  460. *
  461. * @param $analysisfeatureprop_id
  462. * The analysis feature property ID for the analysis feature.
  463. *
  464. * @return
  465. * True of success, False otherwise
  466. *
  467. * @ingroup tripal_feature_api
  468. */
  469. function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id)
  470. {
  471. // get the property.
  472. return tripal_core_delete_property_by_id('analysisfeature',$analysisfeatureprop_id);
  473. }
  474. /**
  475. * Retrieve properties of a given type for a given feature
  476. *
  477. * @param $feature_id
  478. * The feature_id of the properties you would like to retrieve
  479. * @param $property
  480. * The cvterm name of the properties to retrieve
  481. * @param $cv_name
  482. * Optional. The name of the cv to which the property belongs. By
  483. * default this is the 'tripal' cv.
  484. *
  485. * @return
  486. * A feature chado variable with the specified properties expanded
  487. *
  488. * @ingroup tripal_feature_api
  489. */
  490. function tripal_feature_get_property($feature_id,$property,$cv_name='tripal')
  491. {
  492. return tripal_core_get_property('feature',$feature_id,$property,$cv_name);
  493. }
  494. /**
  495. * Insert a given property
  496. *
  497. * @param $feature_id
  498. * The feature_id of the property to insert
  499. * @param $property
  500. * The cvterm name of the property to insert
  501. * @param $value
  502. * The value of the property to insert
  503. * @param $update_if_present
  504. * A boolean indicated whether to update the record if it's already present
  505. * @param $cv_name
  506. * Optional. The name of the cv to which the property belongs. By
  507. * default this is the 'tripal' cv.
  508. *
  509. * @return
  510. * True of success, False otherwise
  511. *
  512. * @ingroup tripal_feature_api
  513. */
  514. function tripal_feature_insert_property($feature_id, $property, $value,
  515. $update_if_present = 0, $cv_name = 'tripal')
  516. {
  517. return tripal_core_insert_property('feature', $feature_id, $property,
  518. $cv_name, $value, $update_if_present);
  519. }
  520. /**
  521. * Update a feature property using the property name. Only use this
  522. * if the property is unique and only exist once for the feature.
  523. *
  524. * @param $feature_id
  525. * The feature_id of the property to update
  526. * @param $property
  527. * The cvterm name of the property to update
  528. * @param $value
  529. * The value of the property to update
  530. * @param $insert_if_missing
  531. * A boolean indicated whether to insert the record if it's absent
  532. * @param $cv_name
  533. * Optional. The name of the cv to which the property belongs. By
  534. * default this is the 'tripal' cv.
  535. *
  536. * Note: The property will be identified using the unique combination of the $feature_id and $property
  537. * and then it will be updated with the supplied value
  538. *
  539. * @return
  540. * True of success, False otherwise
  541. *
  542. * @ingroup tripal_feature_api
  543. */
  544. function tripal_feature_update_property($feature_id, $property,
  545. $value, $insert_if_missing = 0, $cv_name = 'tripal')
  546. {
  547. return tripal_core_update_property('feature',$feature_id,$property,$cv_name,$value, $insert_if_missing);
  548. }
  549. /**
  550. * Update a given feature property using the featureprop_id
  551. *
  552. * @param $featureprop_id
  553. * The featureprop_id of the property to update
  554. * @param $property
  555. * The cvterm name of the property
  556. * @param $value
  557. * The value of the property
  558. * @param $cv_name
  559. * Optional. The name of the cv to which the property belongs. By
  560. * default this is the 'tripal' cv.
  561. *
  562. * @return
  563. * True of success, False otherwise
  564. *
  565. * @ingroup tripal_feature_api
  566. */
  567. function tripal_feature_update_property_by_id($featureprop_id, $property,
  568. $value, $cv_name = 'tripal')
  569. {
  570. return tripal_core_update_property_by_id('feature',$featureprop_id,$property,$cv_name,$value);
  571. }
  572. /**
  573. * Delete a given feature property using the property name. Only use this
  574. * if the property is unique and only exists once for the feature.
  575. *
  576. * @param $feature_id
  577. * The feature_id of the property to delete
  578. * @param $property
  579. * The cvterm name of the property to delete
  580. * @param $cv_name
  581. * Optional. The name of the cv to which the property belongs. By
  582. * default this is the 'tripal' cv.
  583. *
  584. * Note: The property will be identified using the unique combination of the $feature_id and $property
  585. * and then it will be deleted
  586. *
  587. * @return
  588. * True of success, False otherwise
  589. *
  590. * @ingroup tripal_feature_api
  591. */
  592. function tripal_feature_delete_property($feature_id,$property,$cv_name='tripal'){
  593. return tripal_core_delete_property('feature',$feature_id,$property,$cv_name);
  594. }
  595. /**
  596. * Delete a given feature property using the featureprop_id
  597. *
  598. * @param $featureprop_id
  599. * The feature_id of the property to delete
  600. *
  601. * @return
  602. * True of success, False otherwise
  603. *
  604. * @ingroup tripal_feature_api
  605. */
  606. function tripal_feature_delete_property_by_id($featureprop_id){
  607. return tripal_core_delete_property_by_id('feature',$featureprop_id);
  608. }