tripal_analysis.api.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_analysisfeatureprop_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 analysisfeatureprop table
  36. */
  37. function tripal_analysis_chado_analysisfeatureprop_schema() {
  38. $description = array();
  39. $description['foreign keys']['analysisfeature_id'] = array(
  40. 'table' => 'analysisfeature',
  41. 'columns' => array(
  42. 'analysisfeature_id' => 'analysisfeature_id',
  43. ),
  44. );
  45. $description['foreign keys']['cvterm'] = array(
  46. 'table' => 'cvterm',
  47. 'columns' => array(
  48. 'type_id' => 'cvterm_id',
  49. ),
  50. );
  51. return $description;
  52. }
  53. /****************************************************************************
  54. * Implements hook_chado_analysisprop_schema()
  55. * Purpose: To add descriptions and foreign keys to default table description
  56. * Note: This array will be merged with the array from all other implementations
  57. *
  58. * @return
  59. * Array describing the analysisprop table
  60. */
  61. function tripal_analysis_chado_analysisprop_schema() {
  62. $description = array();
  63. $description['foreign keys']['cvterm'] = array(
  64. 'table' => 'cvterm',
  65. 'columns' => array(
  66. 'type_id' => 'cvterm_id',
  67. ),
  68. );
  69. $description['foreign keys']['analysis'] = array(
  70. 'table' => 'analysis',
  71. 'columns' => array(
  72. 'analysis_id' => 'analysis_id',
  73. ),
  74. );
  75. return $description;
  76. }
  77. /**
  78. * Adds a single property to an existing analysis record.
  79. *
  80. * @ingroup tripal_api
  81. */
  82. function tripal_analysis_get_property($analysis_id,$property){
  83. // construct the array of values to be inserted
  84. $values = array (
  85. 'analysis_id' => $analysis_id,
  86. 'type_id' => array (
  87. 'cv_id' => array (
  88. 'name' => 'tripal',
  89. ),
  90. 'name' => $property,
  91. 'is_obsolete' => 0
  92. ),
  93. );
  94. $results = tripal_core_generate_chado_var('analysisprop',$values);
  95. return $results;
  96. }
  97. /**
  98. * Adds a single property to an existing analysis record.
  99. *
  100. * @ingroup tripal_api
  101. */
  102. function tripal_analysis_insert_property($analysis_id,$property,$value,$update_if_present = 0){
  103. // first see if the property already exists, if so we can't insert
  104. $prop = tripal_analysis_get_property($analysis_id,$property);
  105. if(count($prop)>0){
  106. if($update_if_present){
  107. return tripal_analysis_update_property($analysis_id,$property,$value) ;
  108. } else {
  109. return FALSE;
  110. }
  111. }
  112. // construct the array of values to be inserted
  113. $values = array (
  114. 'analysis_id' => $analysis_id,
  115. 'type_id' => array (
  116. 'cv_id' => array (
  117. 'name' => 'tripal',
  118. ),
  119. 'name' => $property,
  120. 'is_obsolete' => 0
  121. ),
  122. 'value' => $value,
  123. 'rank' => 0,
  124. );
  125. return tripal_core_chado_insert('analysisprop',$values);
  126. }
  127. /**
  128. * Adds a single property to an existing analysis record.
  129. *
  130. * @ingroup tripal_api
  131. */
  132. function tripal_analysis_update_property($analysis_id,$property,$value,$insert_if_missing = 0){
  133. // first see if the property is missing (we can't update a missing property
  134. $prop = tripal_analysis_get_property($analysis_id,$property);
  135. if(count($prop)==0){
  136. if($insert_if_missing){
  137. return tripal_analysis_insert_property($analysis_id,$property,$value);
  138. } else {
  139. return FALSE;
  140. }
  141. }
  142. // construct the array that will match the exact record to update
  143. $match = array (
  144. 'analysis_id' => $analysis_id,
  145. 'type_id' => array (
  146. 'cv_id' => array (
  147. 'name' => 'tripal',
  148. ),
  149. 'name' => $property,
  150. ),
  151. );
  152. // construct the array of values to be updated
  153. $values = array (
  154. 'value' => $value,
  155. );
  156. return tripal_core_chado_update('analysisprop',$match,$values);
  157. }
  158. /**
  159. * Adds a single property to an existing analysis record.
  160. *
  161. * @ingroup tripal_api
  162. */
  163. function tripal_analysis_delete_property($analysis_id,$property){
  164. // construct the array that will match the exact record to update
  165. $match = array (
  166. 'analysis_id' => $analysis_id,
  167. 'type_id' => array (
  168. 'cv_id' => array (
  169. 'name' => 'tripal',
  170. ),
  171. 'name' => $property,
  172. ),
  173. );
  174. return tripal_core_chado_delete('analysisprop',$match);
  175. }