tripal_analysis.install 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @file
  4. * Implements hooks from the Schema API
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. */
  9. function tripal_analysis_install() {
  10. // create the module's data directory
  11. tripal_create_moddir('tripal_analysis');
  12. // Use schema API to create database table.
  13. drupal_install_schema('tripal_analysis');
  14. // Create analysisfeatureprop table in chado. This cannot be accomplished
  15. // by calling drupal_install_schema because it's not in the drupal db. This
  16. // table is used to store Blast xml and Interpro html/goterms
  17. if (!db_table_exists('analysisfeatureprop')) {
  18. $sql = "CREATE TABLE analysisfeatureprop (".
  19. " analysisfeatureprop_id SERIAL PRIMARY KEY, ".
  20. " analysisfeature_id INTEGER NOT NULL REFERENCES analysisfeature(analysisfeature_id) " .
  21. " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  22. " type_id INTEGER NOT NULL REFERENCES cvterm(cvterm_id) ".
  23. " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  24. " value TEXT, ".
  25. " rank INTEGER NOT NULL, ".
  26. " CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)".
  27. ")";
  28. chado_query($sql);
  29. }
  30. // add some cvterms
  31. $term = array(
  32. 'name' => 'analysis_type',
  33. 'def' => 'The type of analysis was performed. This value is automatically set by '.
  34. 'each Tripal Analysis module and should be equal to the module name '.
  35. '(e.g. tripal_analysis_blast, tripal_analysis_go).'
  36. );
  37. tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
  38. $term = array(
  39. 'name' => 'analysis_date',
  40. 'def' => 'The date that an analysis was performed.'
  41. );
  42. tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
  43. $term = array(
  44. 'name' => 'analysis_short_name',
  45. 'def' => 'A computer legible (no spaces or special characters) abbreviation for the analysis.'
  46. );
  47. tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal');
  48. }
  49. /**
  50. * Implementation of hook_uninstall().
  51. */
  52. function tripal_analysis_uninstall() {
  53. // Use schema API to delete database table.
  54. drupal_uninstall_schema('tripal_analysis');
  55. // Remove analysis nodes from drupal.
  56. $sql_ana_id = "SELECT nid, vid ".
  57. "FROM {node} ".
  58. "WHERE type like 'chado_analysi%'";
  59. $result = db_query($sql_ana_id);
  60. while ($ana = db_fetch_object($result)) {
  61. node_delete($ana->nid);
  62. }
  63. }
  64. /**
  65. * Implementation of hook_schema() creates two tables.
  66. *
  67. * - chado_analysis table
  68. * stores nodes that are also saved in the analysis table of chado database.
  69. * - tripal_analysis table
  70. * stores the sub-module names, such as tripal_analysis_blast, that are registered
  71. * with this module.
  72. */
  73. function tripal_analysis_schema() {
  74. // chado_analysis table
  75. $schema['chado_analysis'] = array(
  76. 'fields' => array(
  77. 'vid' => array(
  78. 'type' => 'int',
  79. 'unsigned' => TRUE,
  80. 'not null' => TRUE,
  81. 'default' => 0
  82. ),
  83. 'nid' => array(
  84. 'type' => 'int',
  85. 'unsigned' => TRUE,
  86. 'not null' => TRUE,
  87. 'default' => 0
  88. ),
  89. 'analysis_id' => array(
  90. 'type' => 'int',
  91. 'not null' => TRUE,
  92. 'default' => 0
  93. )
  94. ),
  95. 'indexes' => array(
  96. 'analysis_id' => array('analysis_id')
  97. ),
  98. 'unique keys' => array(
  99. 'nid_vid' => array('nid', 'vid'),
  100. 'vid' => array('vid')
  101. ),
  102. 'primary key' => array('nid'),
  103. );
  104. // tripal_analysis table
  105. $schema['tripal_analysis'] = array(
  106. 'description' => t('Table to store analysis sub-modules'),
  107. 'fields' => array(
  108. 'modulename' => array(
  109. 'type' => 'text',
  110. 'size' => 'small',
  111. 'not null' => TRUE,
  112. 'description' => t('The module name. Tripal Analysis will use the '.
  113. 'module name to call module_setting_form()')
  114. )
  115. ),
  116. 'unique keys' => array(
  117. 'modulename' => array('modulename')
  118. )
  119. );
  120. return $schema;
  121. }
  122. /**
  123. * Provide update script for adding new cvterms
  124. */
  125. function tripal_analysis_update_6001() {
  126. // we have some new cvterms to add
  127. tripal_cv_add_cvterm(array('name' => 'based_on_analysis', 'def' => 'The analysis that this analysis was based on. For example, blast/kegg/interpro analyses are based on a unigene analysis. The unigene analysis_id should be stored in analysisprop as the rank using this cvterm. The name of said unigene analysis can be inserted as the value in analysisprop.'), 'tripal', 0, 1, 'tripal');
  128. tripal_cv_add_cvterm(array('name' => 'additional_files', 'def' => 'Additional files for this analysis. Each file should be separated by a semi-colon and have this format: <file description>, <file path>;'), 'tripal', 0, 1, 'tripal');
  129. $ret = array(
  130. '#finished' => 1,
  131. );
  132. return $ret;
  133. }
  134. /**
  135. * Implementation of hook_requirements().
  136. */
  137. function tripal_analysis_requirements($phase) {
  138. $requirements = array();
  139. if ($phase == 'install') {
  140. // make sure chado is installed
  141. if (!tripal_core_is_chado_installed()) {
  142. $requirements ['tripal_analysis'] = array(
  143. 'title' => "tripal_analysis",
  144. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  145. 'severity' => REQUIREMENT_ERROR,
  146. );
  147. }
  148. }
  149. return $requirements;
  150. }