tripal_analysis.api.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @file
  4. * Provides functions for managing analysis'.
  5. *
  6. * @ingroup tripal_analysis
  7. */
  8. /**
  9. * @defgroup tripal_analysis_api Analysis Module API
  10. * @ingroup tripal_api
  11. * @{
  12. * Provides an interface for specialized analysis modules to extend the basic functionality.
  13. * @}
  14. */
  15. /**
  16. * Register tripal_analysis_api sub-modules
  17. *
  18. * @param $modulename
  19. * The name of the module to be registered as a tripal analysis submodule
  20. *
  21. * @ingroup tripal_analysis_api
  22. */
  23. function tripal_analysis_api_register_child($modulename) {
  24. $sql = "SELECT * FROM {tripal_analysis_api} WHERE modulename = :modname";
  25. if (!db_query($sql, array(':modname' => $modulename))->fetchField()) {
  26. $sql = "INSERT INTO {tripal_analysis_api} (modulename) VALUES (:modname)";
  27. db_query($sql, array(':modname' => $modulename));
  28. }
  29. }
  30. /**
  31. * Un-register a tripal analysis sub-module
  32. *
  33. * @param $modulename
  34. * The name of the module to un-register
  35. *
  36. * @ingroup tripal_analysis_api
  37. */
  38. function tripal_analysis_api_unregister_child($modulename) {
  39. if (db_table_exists('tripal_analysis_api')) {
  40. $sql = "DELETE FROM {tripal_analysis_api} WHERE modulename = :modname";
  41. db_query($sql, array(':modname' => $modulename));
  42. }
  43. }
  44. /**
  45. * Retrieve properties of a given type for a given analysis
  46. *
  47. * @param $analysis_id
  48. * The analysis_id of the properties you would like to retrieve
  49. * @param $property
  50. * The cvterm name of the properties to retrieve
  51. * @param $cvname
  52. * The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  53. *
  54. * @return
  55. * An analysis chado variable with the specified properties expanded
  56. *
  57. * @ingroup tripal_analysis_api
  58. */
  59. function tripal_analysis_api_get_property($analysis_id, $property, $cvname = 'tripal') {
  60. return chado_get_property('analysis', $analysis_id, $property, $cvname);
  61. }
  62. /**
  63. * Insert a given property
  64. *
  65. * @param $analysis_id
  66. * The analysis_id of the property to insert
  67. * @param $property
  68. * The cvterm name of the property to insert
  69. * @param $value
  70. * The value of the property to insert
  71. * @param $update_if_present
  72. * A boolean indicated whether to update the record if it's already present
  73. * @param $cvname
  74. * The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  75. *
  76. * @return
  77. * True of success, False otherwise
  78. *
  79. * @ingroup tripal_analysis_api
  80. */
  81. function tripal_analysis_api_insert_property($analysis_id, $property, $value, $update_if_present = 0, $cvname = 'tripal') {
  82. return chado_insert_property('analysis', $analysis_id, $property, $cvname, $value, $update_if_present);
  83. }
  84. /**
  85. * Update a given property
  86. *
  87. * @param $analysis_id
  88. * The analysis_id of the property to update
  89. * @param $property
  90. * The cvterm name of the property to update
  91. * @param $value
  92. * The value of the property to update
  93. * @param $insert_if_missing
  94. * A boolean indicated whether to insert the record if it's absent
  95. * @param $cvname
  96. * The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  97. *
  98. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  99. * and then it will be updated with the supplied value
  100. *
  101. * @return
  102. * True of success, False otherwise
  103. *
  104. * @ingroup tripal_analysis_api
  105. */
  106. function tripal_analysis_api_update_property($analysis_id, $property, $value, $insert_if_missing = 0, $cvname = 'tripal') {
  107. return chado_update_property('analysis', $analysis_id, $property, $cvname, $value, $insert_if_missing);
  108. }
  109. /**
  110. * Delete a given property
  111. *
  112. * @param $analysis_id
  113. * The analysis_id of the property to delete
  114. * @param $property
  115. * The cvterm name of the property to delete
  116. * @param $cvname
  117. * The name of the vocabulary to which the term belongs. Defaults to 'tripal'.
  118. *
  119. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  120. * and then it will be deleted
  121. *
  122. * @return
  123. * True of success, False otherwise
  124. *
  125. * @ingroup tripal_analysis_api
  126. */
  127. function tripal_analysis_api_delete_property($analysis_id, $property, $cvname = 'tripal') {
  128. return chado_delete_property('analysis', $analysis_id, $property, $cvname);
  129. }
  130. /**
  131. * Retreives the node of a sync'ed analysis
  132. *
  133. * @param $analysis_id
  134. * The analysis_id of the property to delete
  135. *
  136. * @return
  137. * node of analysis on success, null otherwise
  138. *
  139. * @ingroup tripal_analysis_api
  140. */
  141. function tripal_analysis_api_get_node($analysis_id) {
  142. $sql = "SELECT *
  143. FROM {chado_analysis} CA
  144. INNER JOIN {node} N on CA.nid = N.nid
  145. WHERE analysis_id = :analysis_id";
  146. $node = db_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
  147. return $node;
  148. }