tripal_analysis_blast.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. //$Id:
  3. /*******************************************************************************
  4. * Implementation of hook_install().
  5. */
  6. function tripal_analysis_blast_install() {
  7. // create the module's data directory
  8. tripal_create_moddir('tripal_analysis_blast');
  9. // We need to register to tripal_analysis module so it can provide a control
  10. // for our blast result. Basically the registration is done by inserting
  11. // modulename into the drupal {tripal_analysis} table AND inserting required
  12. // information to the chado Analysis table. Also in tripal_analysis_blast.module,
  13. // we need to define HOOK_get_settings() for the module to work properly.
  14. // Inert into drupal's {tripal_analysis}
  15. tripal_analysis_register_child('tripal_analysis_blast');
  16. // Add cvterm 'analysis_blast_output_iteration_hits' for inserting into featureprop table
  17. tripal_add_cvterms('analysis_blast_output_iteration_hits', 'Hits of a blast '.
  18. 'output iteration. Each iteration corresponds to a chado feature, and is '.
  19. 'the content between <iteration> and </iteration> tags in the blast xml '.
  20. 'output file. This cvterm represents all hits in the iteration');
  21. // Add cveterm 'analysis_blast_settings' for inserting into analysisprop table
  22. tripal_add_cvterms('analysis_blast_settings', 'Settings of a blast analysis, '.
  23. 'including db_id, output file, and run parameters separated by a bar |');
  24. // Create a tripal_analysis_blast table to store parsers
  25. drupal_install_schema('tripal_analysis_blast');
  26. // Create default parser for swissprot, DB:genbank, and go-seqdb
  27. $sql_db = "SELECT db_id, name FROM {db} WHERE name like '%s'";
  28. $sql_parser = "INSERT INTO {tripal_analysis_blast} ".
  29. " (db_id, displayname, regex_hit_id, regex_hit_def, regex_hit_accession, genbank_style) ".
  30. "VALUES (%d, '%s', '%s', '%s', '%s', %d)";
  31. // Add swissprot parser
  32. $previous_db = tripal_db_set_active ('chado');
  33. $results = db_query($sql_db, "%swissprot%");
  34. tripal_db_set_active($previous_db);
  35. while ($db = db_fetch_object($results)) {
  36. db_query($sql_parser, $db->db_id, 'ExPASy Swissprot', '^sp\|.*?\|(.*?)\s.*?$', '^sp\|.*?\|.*?\s(.*)$', 'sp\|(.*?)\|.*?\s.*?$', 0);
  37. }
  38. // Add trembl parser
  39. $previous_db = tripal_db_set_active ('chado');
  40. $results = db_query($sql_db, "%trembl%");
  41. tripal_db_set_active($previous_db);
  42. while ($db = db_fetch_object($results)) {
  43. db_query($sql_parser, $db->db_id, 'ExPASy TrEMBL', '^.*?\|(.*?)\s.*?$', '^.*?\|.*?\s(.*)$', '^(.*?)\|.*?\s.*?$', 0);
  44. }
  45. // Add genbank parser
  46. $previous_db = tripal_db_set_active ('chado');
  47. $results = db_query($sql_db, "%genbank%");
  48. tripal_db_set_active($previous_db);
  49. while ($db = db_fetch_object($results)) {
  50. db_query($sql_parser, $db->db_id, 'Genbank', '', '', '', 1);
  51. }
  52. }
  53. /*******************************************************************************
  54. * Implementation of hook_uninstall().
  55. */
  56. function tripal_analysis_blast_uninstall() {
  57. // Delete all information associate with the module
  58. // Drupal complains when the user tries to uninstall tripal_analysis
  59. // and tripal_analysis_blast at the same time. This is because Drupal drops
  60. // the {tripal_analysis} table before we can delete anything from it. Thus,
  61. // we perform a db_table_exists() check before the deletion
  62. //Delete the settings from {tripal_analysis} table
  63. tripal_analysis_unregister_child('tripal_analysis_blast');
  64. // Delete module's variables from variables table.
  65. db_query("DELETE FROM {variable} WHERE name='%s'",
  66. 'tripal_analysis_blast_setting');
  67. // Delete a tripal_analysis_blast table
  68. drupal_uninstall_schema('tripal_analysis_blast');
  69. }
  70. /*******************************************************************************
  71. * Implementation of hook_schema(). This table stores the parsers for blast xml
  72. * xml results.
  73. */
  74. function tripal_analysis_blast_schema() {
  75. $schema = array();
  76. $schema['tripal_analysis_blast'] = array(
  77. 'fields' => array(
  78. 'db_id' => array(
  79. 'type' => 'int',
  80. 'unsigned' => TRUE,
  81. 'not null' => TRUE,
  82. 'default' => 0
  83. ),
  84. 'displayname' => array(
  85. 'type' => 'varchar',
  86. 'length' => 100,
  87. 'not null' => TRUE,
  88. ),
  89. 'regex_hit_id' => array(
  90. 'type' => 'varchar',
  91. 'length' => 30,
  92. ),
  93. 'regex_hit_def' => array(
  94. 'type' => 'varchar',
  95. 'length' => 30,
  96. ),
  97. 'regex_hit_accession' => array(
  98. 'type' => 'varchar',
  99. 'length' => 30,
  100. ),
  101. 'genbank_style' => array(
  102. 'type' => 'int',
  103. 'unsigned' => TRUE,
  104. 'default' => 0
  105. ),
  106. ),
  107. 'indexes' => array(
  108. 'db_id' => array('db_id')
  109. ),
  110. 'primary key' => array('db_id'),
  111. );
  112. return $schema;
  113. }
  114. /*******************************************************************************
  115. * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  116. * Analysis' are enabled before installation
  117. */
  118. function tripal_analysis_blast_requirements($phase) {
  119. $requirements = array();
  120. if ($phase == 'install') {
  121. if (!function_exists('tripal_create_moddir') || !function_exists('tripal_analysis_register_child')) {
  122. $requirements ['tripal_analysis_blast'] = array(
  123. 'title' => "tripal_analysis_blast",
  124. 'value' => "error. Some required modules are just being installed. Please try again.",
  125. 'severity' => REQUIREMENT_ERROR,
  126. );
  127. }
  128. }
  129. return $requirements;
  130. }