tripal_analysis.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  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. chado_analysis table
  52. * stores nodes that are also saved in the analysis table of chado database.
  53. * tripal_analysis table stores the sub-module names, such as
  54. * tripal_analysis_blast, that are registered with this module.
  55. */
  56. function tripal_analysis_schema() {
  57. // chado_analysis table
  58. $schema['chado_analysis'] = array(
  59. 'fields' => array(
  60. 'vid' => array(
  61. 'type' => 'int',
  62. 'unsigned' => TRUE,
  63. 'not null' => TRUE,
  64. 'default' => 0
  65. ),
  66. 'nid' => array(
  67. 'type' => 'int',
  68. 'unsigned' => TRUE,
  69. 'not null' => TRUE,
  70. 'default' => 0
  71. ),
  72. 'analysis_id' => array(
  73. 'type' => 'int',
  74. 'not null' => TRUE,
  75. 'default' => 0
  76. )
  77. ),
  78. 'indexes' => array(
  79. 'analysis_id' => array('analysis_id')
  80. ),
  81. 'unique keys' => array(
  82. 'nid_vid' => array('nid', 'vid'),
  83. 'vid' => array('vid')
  84. ),
  85. 'primary key' => array('nid'),
  86. );
  87. // tripal_analysis table
  88. $schema['tripal_analysis'] = array(
  89. 'description' => t('Table to store analysis sub-modules'),
  90. 'fields' => array(
  91. 'modulename' => array(
  92. 'type' => 'text',
  93. 'size' => 'small',
  94. 'not null' => TRUE,
  95. 'description' => t('The module name. Tripal Analysis will use the '.
  96. 'module name to call module_setting_form()')
  97. )
  98. ),
  99. 'unique keys' => array(
  100. 'modulename' => array('modulename')
  101. )
  102. );
  103. return $schema;
  104. }
  105. /*******************************************************************************
  106. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  107. * before installation
  108. */
  109. function tripal_analysis_requirements($phase) {
  110. $requirements = array();
  111. if ($phase == 'install') {
  112. if (!function_exists('tripal_create_moddir')) {
  113. $requirements ['tripal_analysis'] = array(
  114. 'title' => "tripal_analysis",
  115. 'value' => "error. Some required modules are just being installed. Please try again.",
  116. 'severity' => REQUIREMENT_ERROR,
  117. );
  118. }
  119. }
  120. return $requirements;
  121. }
  122. /*******************************************************************************
  123. * Provide update script for adding new cvterms
  124. */
  125. function tripal_analysis_update_6001() {
  126. // we have some new cvterms to add
  127. 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');
  128. 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');
  129. $ret = array(
  130. '#finished' => 1,
  131. );
  132. return $ret;
  133. }