tripal_analysis.install 5.2 KB

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