tripal_analysis.api.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /**
  3. * @defgroup tripal_analysis_api Analysis Module API
  4. * @ingroup tripal_analysis
  5. * @ingroup tripal_api
  6. */
  7. /****************************************************************************
  8. * @section Chado Table Descriptions
  9. ****************************************************************************/
  10. /**
  11. * Implements hook_chado_analysis_schema()
  12. * Purpose: To add descriptions and foreign keys to default table description
  13. * Note: This array will be merged with the array from all other implementations
  14. *
  15. * @return
  16. * Array describing the analysis table
  17. *
  18. * @ingroup tripal_schema_api
  19. */
  20. function tripal_analysis_chado_analysis_schema() {
  21. $description = array();
  22. // Default table description in tripal_core.schema.api.inc: tripal_core_chado_analysis_schema()
  23. $referring_tables = array(
  24. 'analysisfeature',
  25. 'analysisprop',
  26. 'phylotree',
  27. 'quantification'
  28. );
  29. $description['referring_tables'] = $referring_tables;
  30. return $description;
  31. }
  32. /****************************************************************************
  33. * Implements hook_chado_analysisfeature_schema()
  34. * Purpose: To add descriptions and foreign keys to default table description
  35. * Note: This array will be merged with the array from all other implementations
  36. *
  37. * @return
  38. * Array describing the analysisfeature table
  39. *
  40. * @ingroup tripal_schema_api
  41. */
  42. function tripal_analysis_chado_analysisfeature_schema() {
  43. $description = array();
  44. $description['foreign keys']['feature'] = array(
  45. 'table' => 'feature',
  46. 'columns' => array(
  47. 'feature_id' => 'feature_id',
  48. ),
  49. );
  50. $description['foreign keys']['analysis'] = array(
  51. 'table' => 'analysis',
  52. 'columns' => array(
  53. 'analysis_id' => 'analysis_id',
  54. ),
  55. );
  56. return $description;
  57. }
  58. /****************************************************************************
  59. * Implements hook_chado_analysisfeatureprop_schema()
  60. * Purpose: To add descriptions and foreign keys to default table description
  61. * Note: This array will be merged with the array from all other implementations
  62. *
  63. * @return
  64. * Array describing the analysisfeatureprop table
  65. *
  66. * @ingroup tripal_schema_api
  67. */
  68. function tripal_analysis_chado_analysisfeatureprop_schema() {
  69. $description = array();
  70. $description['foreign keys']['analysisfeature'] = array(
  71. 'table' => 'analysisfeature',
  72. 'columns' => array(
  73. 'analysisfeature_id' => 'analysisfeature_id',
  74. ),
  75. );
  76. $description['foreign keys']['cvterm'] = array(
  77. 'table' => 'cvterm',
  78. 'columns' => array(
  79. 'type_id' => 'cvterm_id',
  80. ),
  81. );
  82. return $description;
  83. }
  84. /****************************************************************************
  85. * Implements hook_chado_analysisprop_schema()
  86. * Purpose: To add descriptions and foreign keys to default table description
  87. * Note: This array will be merged with the array from all other implementations
  88. *
  89. * @return
  90. * Array describing the analysisprop table
  91. *
  92. * @ingroup tripal_schema_api
  93. */
  94. function tripal_analysis_chado_analysisprop_schema() {
  95. $description = array();
  96. $description['foreign keys']['cvterm'] = array(
  97. 'table' => 'cvterm',
  98. 'columns' => array(
  99. 'type_id' => 'cvterm_id',
  100. ),
  101. );
  102. $description['foreign keys']['analysis'] = array(
  103. 'table' => 'analysis',
  104. 'columns' => array(
  105. 'analysis_id' => 'analysis_id',
  106. ),
  107. );
  108. return $description;
  109. }
  110. /**
  111. * Retrieve properties of a given type for a given analysis
  112. *
  113. * @param $analysis_id
  114. * The analysis_id of the properties you would like to retrieve
  115. * @param $property
  116. * The cvterm name of the properties to retrieve
  117. *
  118. * @return
  119. * An analysis chado variable with the specified properties expanded
  120. *
  121. * @ingroup tripal_analysis_api
  122. */
  123. function tripal_analysis_get_property($analysis_id,$property){
  124. return tripal_core_get_property('analysis',$analysis_id,$property,'tripal');
  125. }
  126. /**
  127. * Insert a given property
  128. *
  129. * @param $analysis_id
  130. * The analysis_id of the property to insert
  131. * @param $property
  132. * The cvterm name of the property to insert
  133. * @param $value
  134. * The value of the property to insert
  135. * @param $update_if_present
  136. * A boolean indicated whether to update the record if it's already present
  137. *
  138. * @return
  139. * True of success, False otherwise
  140. *
  141. * @ingroup tripal_analysis_api
  142. */
  143. function tripal_analysis_insert_property($analysis_id,$property,$value,$update_if_present = 0){
  144. return tripal_core_insert_property('analysis',$analysis_id,$property,'tripal',$value,$update_if_present);
  145. }
  146. /**
  147. * Update a given property
  148. *
  149. * @param $analysis_id
  150. * The analysis_id of the property to update
  151. * @param $property
  152. * The cvterm name of the property to update
  153. * @param $value
  154. * The value of the property to update
  155. * @param $insert_if_missing
  156. * A boolean indicated whether to insert the record if it's absent
  157. *
  158. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  159. * and then it will be updated with the supplied value
  160. *
  161. * @return
  162. * True of success, False otherwise
  163. *
  164. * @ingroup tripal_analysis_api
  165. */
  166. function tripal_analysis_update_property($analysis_id,$property,$value,$insert_if_missing = 0){
  167. return tripal_core_update_property('analysis',$analysis_id,$property,'tripal',$value, $insert_if_missing);
  168. }
  169. /**
  170. * Delete a given property
  171. *
  172. * @param $analysis_id
  173. * The analysis_id of the property to delete
  174. * @param $property
  175. * The cvterm name of the property to delete
  176. *
  177. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  178. * and then it will be deleted
  179. *
  180. * @return
  181. * True of success, False otherwise
  182. *
  183. * @ingroup tripal_analysis_api
  184. */
  185. function tripal_analysis_delete_property($analysis_id,$property){
  186. return tripal_core_delete_property('analysis',$analysis_id,$property,'tripal');
  187. }
  188. /**
  189. * Retreives the node of a sync'ed analysis
  190. *
  191. * @param $analysis_id
  192. * The analysis_id of the property to delete
  193. *
  194. * @return
  195. * node of analysis on success, null otherwise
  196. *
  197. * @ingroup tripal_analysis_api
  198. */
  199. function tripal_analysis_get_node($analysis_id){
  200. $sql = "SELECT *
  201. FROM chado_analysis CA
  202. INNER JOIN node N on CA.nid = N.nid
  203. WHERE analysis_id = %d";
  204. $node = db_fetch_object(db_query($sql,$analysis_id));
  205. return $node;
  206. }