tripal_analysis.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // we may need the analysisfeatureprop table if it doesn't already exist
  15. tripal_analysis_create_analysisfeatureprop();
  16. // add cvterms
  17. tripal_analysis_add_cvterms();
  18. }
  19. /*
  20. *
  21. */
  22. function tripal_analysis_create_analysisfeatureprop(){
  23. // Create analysisfeatureprop table in chado. This is needed for Chado
  24. // version 1.11, the table exists in Chado 1.2.
  25. if (!db_table_exists('analysisfeatureprop')) {
  26. $sql = "CREATE TABLE analysisfeatureprop (".
  27. " analysisfeatureprop_id SERIAL PRIMARY KEY, ".
  28. " analysisfeature_id INTEGER NOT NULL REFERENCES analysisfeature(analysisfeature_id) " .
  29. " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  30. " type_id INTEGER NOT NULL REFERENCES cvterm(cvterm_id) ".
  31. " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
  32. " value TEXT, ".
  33. " rank INTEGER NOT NULL, ".
  34. " CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)".
  35. ")";
  36. chado_query($sql);
  37. }
  38. }
  39. /*
  40. *
  41. */
  42. function tripal_analysis_add_cvterms(){
  43. // add analysis_type
  44. $term = array(
  45. 'name' => 'analysis_type',
  46. 'def' => 'The type of analysis was performed. This value is automatically set by '.
  47. 'each Tripal Analysis module and should be equal to the module name '.
  48. '(e.g. tripal_analysis_blast, tripal_analysis_go).'
  49. );
  50. tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
  51. // add analysis_date
  52. $term = array(
  53. 'name' => 'analysis_date',
  54. 'def' => 'The date that an analysis was performed.'
  55. );
  56. tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
  57. // add analysis_short_name
  58. $term = array(
  59. 'name' => 'analysis_short_name',
  60. 'def' => 'A computer legible (no spaces or special characters) abbreviation for the analysis.'
  61. );
  62. tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal');
  63. }
  64. /**
  65. * Implementation of hook_uninstall().
  66. */
  67. function tripal_analysis_uninstall() {
  68. // Use schema API to delete database table.
  69. drupal_uninstall_schema('tripal_analysis');
  70. // Remove analysis nodes from drupal.
  71. $sql_ana_id = "SELECT nid, vid ".
  72. "FROM {node} ".
  73. "WHERE type like 'chado_analysi%'";
  74. $result = db_query($sql_ana_id);
  75. while ($ana = db_fetch_object($result)) {
  76. node_delete($ana->nid);
  77. }
  78. }
  79. /**
  80. * Implementation of hook_schema() creates two tables.
  81. *
  82. * - chado_analysis table
  83. * stores nodes that are also saved in the analysis table of chado database.
  84. * - tripal_analysis table
  85. * stores the sub-module names, such as tripal_analysis_blast, that are registered
  86. * with this module.
  87. */
  88. function tripal_analysis_schema() {
  89. // chado_analysis table
  90. $schema['chado_analysis'] = array(
  91. 'fields' => array(
  92. 'vid' => array(
  93. 'type' => 'int',
  94. 'unsigned' => TRUE,
  95. 'not null' => TRUE,
  96. 'default' => 0
  97. ),
  98. 'nid' => array(
  99. 'type' => 'int',
  100. 'unsigned' => TRUE,
  101. 'not null' => TRUE,
  102. 'default' => 0
  103. ),
  104. 'analysis_id' => array(
  105. 'type' => 'int',
  106. 'not null' => TRUE,
  107. 'default' => 0
  108. )
  109. ),
  110. 'indexes' => array(
  111. 'analysis_id' => array('analysis_id')
  112. ),
  113. 'unique keys' => array(
  114. 'nid_vid' => array('nid', 'vid'),
  115. 'vid' => array('vid')
  116. ),
  117. 'primary key' => array('nid'),
  118. );
  119. // tripal_analysis table
  120. $schema['tripal_analysis'] = array(
  121. 'description' => t('Table to store analysis sub-modules'),
  122. 'fields' => array(
  123. 'modulename' => array(
  124. 'type' => 'text',
  125. 'size' => 'small',
  126. 'not null' => TRUE,
  127. 'description' => t('The module name. Tripal Analysis will use the '.
  128. 'module name to call module_setting_form()')
  129. )
  130. ),
  131. 'unique keys' => array(
  132. 'modulename' => array('modulename')
  133. )
  134. );
  135. return $schema;
  136. }
  137. /**
  138. * Provide update script for adding new cvterms
  139. */
  140. function tripal_analysis_update_6001() {
  141. // we have some new cvterms to add
  142. 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');
  143. 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');
  144. $ret = array(
  145. '#finished' => 1,
  146. );
  147. return $ret;
  148. }
  149. /**
  150. * Implementation of hook_requirements().
  151. */
  152. function tripal_analysis_requirements($phase) {
  153. $requirements = array();
  154. if ($phase == 'install') {
  155. // make sure chado is installed
  156. if (!tripal_core_is_chado_installed()) {
  157. $requirements ['tripal_analysis'] = array(
  158. 'title' => "tripal_analysis",
  159. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  160. 'severity' => REQUIREMENT_ERROR,
  161. );
  162. }
  163. }
  164. return $requirements;
  165. }