tripal_analysis.install 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. tripal_db_set_default_search_path();
  11. // create the module's data directory
  12. tripal_create_moddir('tripal_analysis');
  13. // Use schema API to create database table.
  14. drupal_install_schema('tripal_analysis');
  15. // Create analysisfeatureprop table in chado. This cannot be accomplished
  16. // by calling drupal_install_schema because it's not in the drupal db. This
  17. // table is used to store Blast xml and Interpro html/goterms
  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. chado_query($sql);
  28. }
  29. 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');
  30. tripal_cv_add_cvterm(array('name' => 'analysis_date', 'def' => 'The date that an analysis was performed.'), 'tripal', 0, 1, 'tripal');
  31. tripal_cv_add_cvterm(array('name' => 'analysis_short_name', 'def' => 'A computer legible (no spaces ' .
  32. 'or special characters) abbreviation for the analysis.'), 'tripal', 0, 1 , 'tripal');
  33. }
  34. /**
  35. * Implementation of hook_uninstall().
  36. */
  37. function tripal_analysis_uninstall() {
  38. // Use schema API to delete database table.
  39. drupal_uninstall_schema('tripal_analysis');
  40. // Remove analysis nodes from drupal.
  41. $sql_ana_id = "SELECT nid, vid ".
  42. "FROM {node} ".
  43. "WHERE type like 'chado_analysi%'";
  44. $result = db_query($sql_ana_id);
  45. while ($ana = db_fetch_object($result)) {
  46. node_delete($ana->nid);
  47. }
  48. }
  49. /**
  50. * Implementation of hook_schema() creates two tables.
  51. *
  52. * - chado_analysis table
  53. * stores nodes that are also saved in the analysis table of chado database.
  54. * - tripal_analysis table
  55. * stores the sub-module names, such as tripal_analysis_blast, that are registered
  56. * with this module.
  57. */
  58. function tripal_analysis_schema() {
  59. // chado_analysis table
  60. $schema['chado_analysis'] = array(
  61. 'fields' => array(
  62. 'vid' => array(
  63. 'type' => 'int',
  64. 'unsigned' => TRUE,
  65. 'not null' => TRUE,
  66. 'default' => 0
  67. ),
  68. 'nid' => array(
  69. 'type' => 'int',
  70. 'unsigned' => TRUE,
  71. 'not null' => TRUE,
  72. 'default' => 0
  73. ),
  74. 'analysis_id' => array(
  75. 'type' => 'int',
  76. 'not null' => TRUE,
  77. 'default' => 0
  78. )
  79. ),
  80. 'indexes' => array(
  81. 'analysis_id' => array('analysis_id')
  82. ),
  83. 'unique keys' => array(
  84. 'nid_vid' => array('nid', 'vid'),
  85. 'vid' => array('vid')
  86. ),
  87. 'primary key' => array('nid'),
  88. );
  89. // tripal_analysis table
  90. $schema['tripal_analysis'] = array(
  91. 'description' => t('Table to store analysis sub-modules'),
  92. 'fields' => array(
  93. 'modulename' => array(
  94. 'type' => 'text',
  95. 'size' => 'small',
  96. 'not null' => TRUE,
  97. 'description' => t('The module name. Tripal Analysis will use the '.
  98. 'module name to call module_setting_form()')
  99. )
  100. ),
  101. 'unique keys' => array(
  102. 'modulename' => array('modulename')
  103. )
  104. );
  105. return $schema;
  106. }
  107. /**
  108. * Provide update script for adding new cvterms
  109. */
  110. function tripal_analysis_update_6001() {
  111. // we have some new cvterms to add
  112. 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');
  113. 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');
  114. $ret = array(
  115. '#finished' => 1,
  116. );
  117. return $ret;
  118. }
  119. /**
  120. * Implementation of hook_requirements().
  121. */
  122. function tripal_analysis_requirements($phase) {
  123. $requirements = array();
  124. if ($phase == 'install') {
  125. // make sure chado is installed
  126. if (!tripal_core_is_chado_installed()) {
  127. $requirements ['tripal_analysis'] = array(
  128. 'title' => "tripal_analysis",
  129. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  130. 'severity' => REQUIREMENT_ERROR,
  131. );
  132. }
  133. }
  134. return $requirements;
  135. }