tripal_analysis.api.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /****************************************************************************
  3. * @section Chado Table Descriptions
  4. ****************************************************************************/
  5. /****************************************************************************
  6. * Implements hook_chado_analysisfeature_schema()
  7. * Purpose: To add descriptions and foreign keys to default table description
  8. * Note: This array will be merged with the array from all other implementations
  9. *
  10. * @return
  11. * Array describing the analysisfeature table
  12. */
  13. function tripal_analysis_chado_analysisfeature_schema() {
  14. $description = array();
  15. $description['foreign keys']['feature'] = array(
  16. 'table' => 'feature',
  17. 'columns' => array(
  18. 'feature_id' => 'feature_id',
  19. ),
  20. );
  21. $description['foreign keys']['analysis'] = array(
  22. 'table' => 'analysis',
  23. 'columns' => array(
  24. 'analysis_id' => 'analysis_id',
  25. ),
  26. );
  27. return $description;
  28. }
  29. /****************************************************************************
  30. * Implements hook_chado_analysisprop_schema()
  31. * Purpose: To add descriptions and foreign keys to default table description
  32. * Note: This array will be merged with the array from all other implementations
  33. *
  34. * @return
  35. * Array describing the analysisprop table
  36. */
  37. function tripal_analysis_chado_analysisprop_schema() {
  38. $description = array();
  39. $description['foreign keys']['cvterm'] = array(
  40. 'table' => 'cvterm',
  41. 'columns' => array(
  42. 'type_id' => 'cvterm_id',
  43. ),
  44. );
  45. $description['foreign keys']['analysis'] = array(
  46. 'table' => 'analysis',
  47. 'columns' => array(
  48. 'analysis_id' => 'analysis_id',
  49. ),
  50. );
  51. return $description;
  52. }
  53. /**
  54. * Adds a single property to an existing analysis record.
  55. *
  56. * @ingroup tripal_api
  57. */
  58. function tripal_analysis_get_property($analysis_id,$property){
  59. // construct the array of values to be inserted
  60. $values = array (
  61. 'analysis_id' => $analysis_id,
  62. 'type_id' => array (
  63. 'cv_id' => array (
  64. 'name' => 'tripal',
  65. ),
  66. 'name' => $property,
  67. 'is_obsolete' => 0
  68. ),
  69. );
  70. $results = tripal_core_generate_chado_var('analysisprop',$values);
  71. return $results;
  72. }
  73. /**
  74. * Adds a single property to an existing analysis record.
  75. *
  76. * @ingroup tripal_api
  77. */
  78. function tripal_analysis_insert_property($analysis_id,$property,$value,$update_if_present = 0){
  79. // first see if the property already exists, if so we can't
  80. $prop = tripal_analysis_get_property($analysis_id,$property);
  81. if(count($prop)>0){
  82. if($update_if_present){
  83. return tripal_analysis_update_property($analysis_id,$property,$value) ;
  84. } else {
  85. return FALSE;
  86. }
  87. }
  88. // construct the array of values to be inserted
  89. $values = array (
  90. 'analysis_id' => $analysis_id,
  91. 'type_id' => array (
  92. 'cv_id' => array (
  93. 'name' => 'tripal',
  94. ),
  95. 'name' => $property,
  96. 'is_obsolete' => 0
  97. ),
  98. 'value' => $value,
  99. 'rank' => 0,
  100. );
  101. return tripal_core_chado_insert('analysisprop',$values);
  102. }
  103. /**
  104. * Adds a single property to an existing analysis record.
  105. *
  106. * @ingroup tripal_api
  107. */
  108. function tripal_analysis_update_property($analysis_id,$property,$value,$insert_if_missing = 0){
  109. // first see if the property is missing (we can't update a missing property
  110. $prop = tripal_analysis_get_property($analysis_id,$property);
  111. if(count($prop)==0){
  112. if($insert_if_missing){
  113. return tripal_analysis_insert_property($analysis_id,$property,$value);
  114. } else {
  115. return FALSE;
  116. }
  117. }
  118. // construct the array that will match the exact record to update
  119. $match = array (
  120. 'analysis_id' => $analysis_id,
  121. 'type_id' => array (
  122. 'cv_id' => array (
  123. 'name' => 'tripal',
  124. ),
  125. 'name' => $property,
  126. ),
  127. );
  128. // construct the array of values to be updated
  129. $values = array (
  130. 'value' => $value,
  131. );
  132. return tripal_core_chado_update('analysisprop',$match,$values);
  133. }
  134. /**
  135. * Adds a single property to an existing analysis record.
  136. *
  137. * @ingroup tripal_api
  138. */
  139. function tripal_analysis_delete_property($analysis_id,$property){
  140. // construct the array that will match the exact record to update
  141. $match = array (
  142. 'analysis_id' => $analysis_id,
  143. 'type_id' => array (
  144. 'cv_id' => array (
  145. 'name' => 'tripal',
  146. ),
  147. 'name' => $property,
  148. ),
  149. );
  150. return tripal_core_chado_delete('analysisprop',$match);
  151. }