tripal_feature.api.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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 of a given type for a given analysis featire
  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 a property for an analysis feature
  326. *
  327. * @param $analysis_id
  328. * The analysis ID for the analysis feature. This argument is optional but
  329. * if specified it must also be accompanied with a feature ID.
  330. * @param $feature_id
  331. * The feature ID for the analysis feature. This argument is optional but
  332. * if specified it must also be accompanied with an analysis ID.
  333. * @param $analysisfeature_id
  334. * The analysis feature ID for the analysis feature. This argument is
  335. * optional and can be used rather than specifying the $analysis_id and
  336. * $feature_id arguments. If all three arguments are specified (e.g.
  337. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  338. * $analysisfeature_id is used and the other two arguments are ignored.
  339. * @param $property
  340. * The cvterm name of the property to update
  341. * @param $value
  342. * The value of the property to update
  343. * @param $insert_if_missing
  344. * A boolean indicated whether to insert the record if it's absent
  345. * @param $cv_name
  346. * Optional. The name of the cv to which the property belongs. By
  347. * default this is the 'tripal' cv.
  348. *
  349. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  350. * and then it will be updated with the supplied value
  351. *
  352. * @return
  353. * True of success, False otherwise
  354. *
  355. * @ingroup tripal_feature_api
  356. */
  357. function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
  358. $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
  359. $cv_name = 'tripal')
  360. {
  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. * Delete a property for an analysis feature
  380. *
  381. * @param $analysis_id
  382. * The analysis ID for the analysis feature. This argument is optional but
  383. * if specified it must also be accompanied with a feature ID.
  384. * @param $feature_id
  385. * The feature ID for the analysis feature. This argument is optional but
  386. * if specified it must also be accompanied with an analysis ID.
  387. * @param $analysisfeature_id
  388. * The analysis feature ID for the analysis feature. This argument is
  389. * optional and can be used rather than specifying the $analysis_id and
  390. * $feature_id arguments. If all three arguments are specified (e.g.
  391. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  392. * $analysisfeature_id is used and the other two arguments are ignored.
  393. * @param $property
  394. * The cvterm name of the property to delete
  395. * @param $cv_name
  396. * Optional. The name of the cv to which the property belongs. By
  397. * default this is the 'tripal' cv.
  398. *
  399. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  400. * and then it will be deleted
  401. *
  402. * @return
  403. * True of success, False otherwise
  404. *
  405. * @ingroup tripal_feature_api
  406. */
  407. function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
  408. $analysisfeature_id = NULL, $property, $cv_name = 'tripal')
  409. {
  410. // check that the incoming arguments are correct
  411. if(($analysis_id and !$feature_id) or
  412. (!$analysis_id and $feature_id)){
  413. watchdog('tripal_feature',
  414. 'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
  415. array(), WATCHDOG_WARNING);
  416. }
  417. // get the analysisfeature_id if one is not provided
  418. if(!$analysisfeature_id){
  419. $columns = array('analysisfeature_id');
  420. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  421. $result = tripal_core_chado_select('analysisfeature',$columns,$values);
  422. $analysisfeature_id = $result[0]->analysisfeature_id;
  423. }
  424. // get the property.
  425. return tripal_core_delete_property('analysisfeature',$analysisfeature_id,$property,$cv_name);
  426. }
  427. /**
  428. * Retrieve properties of a given type for a given feature
  429. *
  430. * @param $feature_id
  431. * The feature_id of the properties you would like to retrieve
  432. * @param $property
  433. * The cvterm name of the properties to retrieve
  434. * @param $cv_name
  435. * Optional. The name of the cv to which the property belongs. By
  436. * default this is the 'tripal' cv.
  437. *
  438. * @return
  439. * A feature chado variable with the specified properties expanded
  440. *
  441. * @ingroup tripal_feature_api
  442. */
  443. function tripal_feature_get_property($feature_id,$property,$cv_name='tripal')
  444. {
  445. return tripal_core_get_property('feature',$feature_id,$property,$cv_name);
  446. }
  447. /**
  448. * Insert a given property
  449. *
  450. * @param $feature_id
  451. * The feature_id of the property to insert
  452. * @param $property
  453. * The cvterm name of the property to insert
  454. * @param $value
  455. * The value of the property to insert
  456. * @param $update_if_present
  457. * A boolean indicated whether to update the record if it's already present
  458. * @param $cv_name
  459. * Optional. The name of the cv to which the property belongs. By
  460. * default this is the 'tripal' cv.
  461. *
  462. * @return
  463. * True of success, False otherwise
  464. *
  465. * @ingroup tripal_feature_api
  466. */
  467. function tripal_feature_insert_property($feature_id, $property, $value,
  468. $update_if_present = 0, $cv_name = 'tripal')
  469. {
  470. return tripal_core_insert_property('feature',$feature_id,$property,$cv_name,$value,$update_if_present);
  471. }
  472. /**
  473. * Update a feature property using the property name. Only use this
  474. * if the property is unique and only exist once for the feature.
  475. *
  476. * @param $feature_id
  477. * The feature_id of the property to update
  478. * @param $property
  479. * The cvterm name of the property to update
  480. * @param $value
  481. * The value of the property to update
  482. * @param $insert_if_missing
  483. * A boolean indicated whether to insert the record if it's absent
  484. * @param $cv_name
  485. * Optional. The name of the cv to which the property belongs. By
  486. * default this is the 'tripal' cv.
  487. *
  488. * Note: The property will be identified using the unique combination of the $feature_id and $property
  489. * and then it will be updated with the supplied value
  490. *
  491. * @return
  492. * True of success, False otherwise
  493. *
  494. * @ingroup tripal_feature_api
  495. */
  496. function tripal_feature_update_property($feature_id, $property,
  497. $value, $insert_if_missing = 0, $cv_name = 'tripal')
  498. {
  499. return tripal_core_update_property('feature',$feature_id,$property,$cv_name,$value, $insert_if_missing);
  500. }
  501. /**
  502. * Update a given feature property using the featureprop_id
  503. *
  504. * @param $featureprop_id
  505. * The featureprop_id of the property to update
  506. * @param $property
  507. * The cvterm name of the property
  508. * @param $value
  509. * The value of the property
  510. * @param $cv_name
  511. * Optional. The name of the cv to which the property belongs. By
  512. * default this is the 'tripal' cv.
  513. *
  514. * @return
  515. * True of success, False otherwise
  516. *
  517. * @ingroup tripal_feature_api
  518. */
  519. function tripal_feature_update_property_by_id($featureprop_id, $property,
  520. $value, $cv_name = 'tripal')
  521. {
  522. return tripal_core_update_property_by_id('feature',$featureprop_id,$property,$cv_name,$value);
  523. }
  524. /**
  525. * Delete a given feature property using the property name. Only use this
  526. * if the property is unique and only exists once for the feature.
  527. *
  528. * @param $feature_id
  529. * The feature_id of the property to delete
  530. * @param $property
  531. * The cvterm name of the property to delete
  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 deleted
  538. *
  539. * @return
  540. * True of success, False otherwise
  541. *
  542. * @ingroup tripal_feature_api
  543. */
  544. function tripal_feature_delete_property($feature_id,$property,$cv_name='tripal'){
  545. return tripal_core_delete_property('feature',$feature_id,$property,$cv_name);
  546. }
  547. /**
  548. * Delete a given feature property using the featureprop_id
  549. *
  550. * @param $featureprop_id
  551. * The feature_id of the property to delete
  552. *
  553. * @return
  554. * True of success, False otherwise
  555. *
  556. * @ingroup tripal_feature_api
  557. */
  558. function tripal_feature_delete_property_by_id($featureprop_id){
  559. return tripal_core_delete_property_by_id('feature',$featureprop_id);
  560. }