tripal_analysis.api.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /****************************************************************************
  3. * @section Chado Table Descriptions
  4. ****************************************************************************/
  5. /**
  6. * Implements hook_chado_analysis_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 analysis table
  12. *
  13. * @ingroup tripal_analysis
  14. */
  15. function tripal_analysis_chado_analysis_schema() {
  16. $description = array();
  17. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_analysis_schema()
  18. $referring_tables = array(
  19. 'analysisfeature',
  20. 'analysisprop',
  21. 'phylotree',
  22. 'quantification'
  23. );
  24. $description['referring_tables'] = $referring_tables;
  25. return $description;
  26. }
  27. /****************************************************************************
  28. * Implements hook_chado_analysisfeature_schema()
  29. * Purpose: To add descriptions and foreign keys to default table description
  30. * Note: This array will be merged with the array from all other implementations
  31. *
  32. * @return
  33. * Array describing the analysisfeature table
  34. */
  35. function tripal_analysis_chado_analysisfeature_schema() {
  36. $description = array();
  37. $description['foreign keys']['feature'] = array(
  38. 'table' => 'feature',
  39. 'columns' => array(
  40. 'feature_id' => 'feature_id',
  41. ),
  42. );
  43. $description['foreign keys']['analysis'] = array(
  44. 'table' => 'analysis',
  45. 'columns' => array(
  46. 'analysis_id' => 'analysis_id',
  47. ),
  48. );
  49. return $description;
  50. }
  51. /****************************************************************************
  52. * Implements hook_chado_analysisfeatureprop_schema()
  53. * Purpose: To add descriptions and foreign keys to default table description
  54. * Note: This array will be merged with the array from all other implementations
  55. *
  56. * @return
  57. * Array describing the analysisfeatureprop table
  58. */
  59. function tripal_analysis_chado_analysisfeatureprop_schema() {
  60. $description = array();
  61. $description['foreign keys']['analysisfeature_id'] = array(
  62. 'table' => 'analysisfeature',
  63. 'columns' => array(
  64. 'analysisfeature_id' => 'analysisfeature_id',
  65. ),
  66. );
  67. $description['foreign keys']['cvterm'] = array(
  68. 'table' => 'cvterm',
  69. 'columns' => array(
  70. 'type_id' => 'cvterm_id',
  71. ),
  72. );
  73. return $description;
  74. }
  75. /****************************************************************************
  76. * Implements hook_chado_analysisprop_schema()
  77. * Purpose: To add descriptions and foreign keys to default table description
  78. * Note: This array will be merged with the array from all other implementations
  79. *
  80. * @return
  81. * Array describing the analysisprop table
  82. */
  83. function tripal_analysis_chado_analysisprop_schema() {
  84. $description = array();
  85. $description['foreign keys']['cvterm'] = array(
  86. 'table' => 'cvterm',
  87. 'columns' => array(
  88. 'type_id' => 'cvterm_id',
  89. ),
  90. );
  91. $description['foreign keys']['analysis'] = array(
  92. 'table' => 'analysis',
  93. 'columns' => array(
  94. 'analysis_id' => 'analysis_id',
  95. ),
  96. );
  97. return $description;
  98. }
  99. /**
  100. * Adds a single property to an existing analysis record.
  101. *
  102. * @ingroup tripal_api
  103. */
  104. function tripal_analysis_get_property($analysis_id,$property){
  105. // construct the array of values to be inserted
  106. $values = array (
  107. 'analysis_id' => $analysis_id,
  108. 'type_id' => array (
  109. 'cv_id' => array (
  110. 'name' => 'tripal',
  111. ),
  112. 'name' => $property,
  113. 'is_obsolete' => 0
  114. ),
  115. );
  116. $results = tripal_core_generate_chado_var('analysisprop',$values);
  117. $results = tripal_core_expand_chado_vars($results,'field','analysisprop.value');
  118. return $results;
  119. }
  120. /**
  121. * Adds a single property to an existing analysis record.
  122. *
  123. * @ingroup tripal_api
  124. */
  125. function tripal_analysis_insert_property($analysis_id,$property,$value,$update_if_present = 0){
  126. // first see if the property already exists, if so we can't insert
  127. $prop = tripal_analysis_get_property($analysis_id,$property);
  128. if(count($prop)>0){
  129. if($update_if_present){
  130. return tripal_analysis_update_property($analysis_id,$property,$value) ;
  131. } else {
  132. return FALSE;
  133. }
  134. }
  135. // construct the array of values to be inserted
  136. $values = array (
  137. 'analysis_id' => $analysis_id,
  138. 'type_id' => array (
  139. 'cv_id' => array (
  140. 'name' => 'tripal',
  141. ),
  142. 'name' => $property,
  143. 'is_obsolete' => 0
  144. ),
  145. 'value' => $value,
  146. 'rank' => 0,
  147. );
  148. return tripal_core_chado_insert('analysisprop',$values);
  149. }
  150. /**
  151. * Adds a single property to an existing analysis record.
  152. *
  153. * @ingroup tripal_api
  154. */
  155. function tripal_analysis_update_property($analysis_id,$property,$value,$insert_if_missing = 0){
  156. // first see if the property is missing (we can't update a missing property
  157. $prop = tripal_analysis_get_property($analysis_id,$property);
  158. if(count($prop)==0){
  159. if($insert_if_missing){
  160. return tripal_analysis_insert_property($analysis_id,$property,$value);
  161. } else {
  162. return FALSE;
  163. }
  164. }
  165. // construct the array that will match the exact record to update
  166. $match = array (
  167. 'analysis_id' => $analysis_id,
  168. 'type_id' => array (
  169. 'cv_id' => array (
  170. 'name' => 'tripal',
  171. ),
  172. 'name' => $property,
  173. ),
  174. );
  175. // construct the array of values to be updated
  176. $values = array (
  177. 'value' => $value,
  178. );
  179. return tripal_core_chado_update('analysisprop',$match,$values);
  180. }
  181. /**
  182. * Adds a single property to an existing analysis record.
  183. *
  184. * @ingroup tripal_api
  185. */
  186. function tripal_analysis_delete_property($analysis_id,$property){
  187. // construct the array that will match the exact record to update
  188. $match = array (
  189. 'analysis_id' => $analysis_id,
  190. 'type_id' => array (
  191. 'cv_id' => array (
  192. 'name' => 'tripal',
  193. ),
  194. 'name' => $property,
  195. ),
  196. );
  197. return tripal_core_chado_delete('analysisprop',$match);
  198. }