tripal_analysis.install 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * @file
  4. * Implements hooks from the Schema API
  5. */
  6. /**
  7. * Disable default views when module is disabled
  8. */
  9. function tripal_analysis_disable() {
  10. // Disable all default views provided by this module
  11. require_once("tripal_analysis.views_default.inc");
  12. $views = tripal_analysis_views_default_views();
  13. foreach (array_keys($views) as $view_name) {
  14. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  15. }
  16. }
  17. /**
  18. * Implementation of hook_requirements().
  19. */
  20. function tripal_analysis_requirements($phase) {
  21. $requirements = array();
  22. if ($phase == 'install') {
  23. // make sure chado is installed
  24. if (!$GLOBALS["chado_is_installed"]) {
  25. $requirements ['tripal_analysis'] = array(
  26. 'title' => "tripal_analysis",
  27. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  28. 'severity' => REQUIREMENT_ERROR,
  29. );
  30. }
  31. }
  32. return $requirements;
  33. }
  34. /**
  35. * Implementation of hook_install().
  36. */
  37. function tripal_analysis_install() {
  38. // create the module's data directory
  39. tripal_create_moddir('tripal_analysis');
  40. // we may need the analysisfeatureprop table if it doesn't already exist
  41. tripal_analysis_create_analysisfeatureprop();
  42. // add cvterms
  43. tripal_analysis_add_cvterms();
  44. // add materialized views
  45. tripal_analysis_add_mview_analysis_organism();
  46. }
  47. /**
  48. * Implementation of hook_uninstall().
  49. */
  50. function tripal_analysis_uninstall() {
  51. }
  52. /**
  53. *
  54. */
  55. function tripal_analysis_create_analysisfeatureprop() {
  56. // Create analysisfeatureprop table in chado. This is needed for Chado
  57. // version 1.11, the table exists in Chado 1.2.
  58. if (!db_table_exists('chado.analysisfeatureprop')) {
  59. $sql = "
  60. CREATE TABLE {analysisfeatureprop} (
  61. analysisfeatureprop_id SERIAL PRIMARY KEY,
  62. analysisfeature_id INTEGER NOT NULL,
  63. type_id INTEGER NOT NULL,
  64. value TEXT,
  65. rank INTEGER NOT NULL,
  66. CONSTRAINT analysisfeature_id_type_id_rank UNIQUE (analysisfeature_id, type_id, rank),
  67. CONSTRAINT analysisfeatureprop_analysisfeature_id_fkey FOREIGN KEY (analysisfeature_id) REFERENCES {analysisfeature}(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
  68. CONSTRAINT analysisfeatureprop_type_id_fkey FOREIGN KEY (type_id) REFERENCES {cvterm}(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  69. )
  70. ";
  71. chado_query($sql);
  72. }
  73. }
  74. /*
  75. *
  76. */
  77. function tripal_analysis_add_cvterms() {
  78. tripal_cv_add_cv('tripal_analysis', 'Terms used for managing analyses in Tripal');
  79. // add analysis_date. This is no longer used (as far as we can tell) but we don't
  80. // get rid of it in case it is used, so just keep it in the Tripal CV
  81. $term = array(
  82. 'name' => 'analysis_date',
  83. 'def' => 'The date that an analysis was performed.'
  84. );
  85. tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
  86. // add analysis_short_name. This is no longer used (as far as we can tell) but we don't
  87. // get rid of it in case it is used, so just keep it in the Tripal CV
  88. $term = array(
  89. 'name' => 'analysis_short_name',
  90. 'def' => 'A computer legible (no spaces or special characters) abbreviation for the analysis.'
  91. );
  92. tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal');
  93. // the 'analysis_property' vocabulary is for user definable properties.
  94. tripal_cv_add_cvterm(array('name' => 'Analysis Type', 'def' => 'The type of analysis that was performed.'),
  95. 'analysis_property', 0, 1, 'tripal');
  96. }
  97. /**
  98. * Implementation of hook_schema() creates two tables.
  99. *
  100. * - chado_analysis table
  101. * stores nodes that are also saved in the analysis table of chado database.
  102. * - tripal_analysis table
  103. * stores the sub-module names, such as tripal_analysis_blast, that are registered
  104. * with this module.
  105. */
  106. function tripal_analysis_schema() {
  107. // chado_analysis table
  108. $schema['chado_analysis'] = array(
  109. 'fields' => array(
  110. 'vid' => array(
  111. 'type' => 'int',
  112. 'unsigned' => TRUE,
  113. 'not null' => TRUE,
  114. 'default' => 0
  115. ),
  116. 'nid' => array(
  117. 'type' => 'int',
  118. 'unsigned' => TRUE,
  119. 'not null' => TRUE,
  120. 'default' => 0
  121. ),
  122. 'analysis_id' => array(
  123. 'type' => 'int',
  124. 'not null' => TRUE,
  125. 'default' => 0
  126. )
  127. ),
  128. 'indexes' => array(
  129. 'analysis_id' => array('analysis_id')
  130. ),
  131. 'unique keys' => array(
  132. 'nid_vid' => array('nid', 'vid'),
  133. 'vid' => array('vid')
  134. ),
  135. 'primary key' => array('nid'),
  136. );
  137. // tripal_analysis table
  138. $schema['tripal_analysis'] = array(
  139. 'description' => 'Table to store analysis sub-modules',
  140. 'fields' => array(
  141. 'modulename' => array(
  142. 'type' => 'text',
  143. 'size' => 'small',
  144. 'not null' => TRUE,
  145. 'description' => 'The module name. Tripal Analysis will use the module name to call module_setting_form()'
  146. )
  147. ),
  148. 'unique keys' => array(
  149. 'modulename' => array('modulename')
  150. )
  151. );
  152. return $schema;
  153. }
  154. /*
  155. *
  156. * @ingroup tripal_network
  157. */
  158. function tripal_analysis_add_mview_analysis_organism() {
  159. $view_name = 'analysis_organism';
  160. $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
  161. // this is the SQL used to identify the organism to which an analsysis
  162. // has been used. This is obtained though the analysisfeature -> feature -> organism
  163. // joins
  164. $sql = "
  165. SELECT DISTINCT A.analysis_id, O.organism_id
  166. FROM analysis A
  167. INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
  168. INNER JOIN feature F ON AF.feature_id = F.feature_id
  169. INNER JOIN organism O ON O.organism_id = F.organism_id
  170. ";
  171. // the schema array for describing this view
  172. $schema = array(
  173. 'table' => $view_name,
  174. 'description' => $comment,
  175. 'fields' => array(
  176. 'analysis_id' => array(
  177. 'type' => 'int',
  178. 'not null' => TRUE,
  179. ),
  180. 'organism_id' => array(
  181. 'type' => 'int',
  182. 'not null' => TRUE,
  183. ),
  184. ),
  185. 'indexes' => array(
  186. 'networkmod_qtl_indx0' => array('analysis_id'),
  187. 'networkmod_qtl_indx1' => array('organism_id'),
  188. ),
  189. 'foreign keys' => array(
  190. 'analysis' => array(
  191. 'table' => 'analysis',
  192. 'columns' => array(
  193. 'analysis_id' => 'analysis_id',
  194. ),
  195. ),
  196. 'organism' => array(
  197. 'table' => 'organism',
  198. 'columns' => array(
  199. 'organism_id' => 'organism_id',
  200. ),
  201. ),
  202. ),
  203. );
  204. // add the view
  205. tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
  206. }