tripal_analysis.install 5.2 KB

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