tripal_analysis.install 5.6 KB

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