tripal_analysis.api.inc 6.3 KB

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