tripal_analysis.install 8.0 KB

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