tripal_analysis.install 5.0 KB

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