tripal_analysis_blast.install 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // Register the analysis type
  15. tripal_analysis_register_child('tripal_analysis_blast');
  16. // Add cvterms
  17. tripal_analysis_blast_add_cvterms();
  18. // Create a tripal_analysis_blast table to store parsers
  19. drupal_install_schema('tripal_analysis_blast');
  20. // Create default parser for swissprot, DB:genbank, and go-seqdb
  21. $sql_db = "SELECT db_id, name FROM {db} WHERE name like '%s'";
  22. $sql_parser = "INSERT INTO {tripal_analysis_blast} ".
  23. " (db_id, displayname, regex_hit_id, regex_hit_def, regex_hit_accession, genbank_style) ".
  24. "VALUES (%d, '%s', '%s', '%s', '%s', %d)";
  25. // Add swissprot parser
  26. $previous_db = tripal_db_set_active ('chado');
  27. $results = db_query($sql_db, "%swissprot%");
  28. tripal_db_set_active($previous_db);
  29. while ($db = db_fetch_object($results)) {
  30. db_query($sql_parser, $db->db_id, 'ExPASy Swissprot', '^sp\|.*?\|(.*?)\s.*?$', '^sp\|.*?\|.*?\s(.*)$', 'sp\|(.*?)\|.*?\s.*?$', 0);
  31. }
  32. // Add trembl parser
  33. $previous_db = tripal_db_set_active ('chado');
  34. $results = db_query($sql_db, "%trembl%");
  35. tripal_db_set_active($previous_db);
  36. while ($db = db_fetch_object($results)) {
  37. db_query($sql_parser, $db->db_id, 'ExPASy TrEMBL', '^.*?\|(.*?)\s.*?$', '^.*?\|.*?\s(.*)$', '^(.*?)\|.*?\s.*?$', 0);
  38. }
  39. // Add genbank parser
  40. $previous_db = tripal_db_set_active ('chado');
  41. $results = db_query($sql_db, "%genbank%");
  42. tripal_db_set_active($previous_db);
  43. while ($db = db_fetch_object($results)) {
  44. db_query($sql_parser, $db->db_id, 'Genbank', '', '', '', 1);
  45. }
  46. }
  47. /*******************************************************************************
  48. * Implementation of hook_uninstall().
  49. */
  50. function tripal_analysis_blast_uninstall() {
  51. // Delete all information associate with the module
  52. // Drupal complains when the user tries to uninstall tripal_analysis
  53. // and tripal_analysis_blast at the same time. This is because Drupal drops
  54. // the {tripal_analysis} table before we can delete anything from it. Thus,
  55. // we perform a db_table_exists() check before the deletion
  56. //Delete the settings from {tripal_analysis} table
  57. tripal_analysis_unregister_child('tripal_analysis_blast');
  58. // Delete module's variables from variables table.
  59. db_query("DELETE FROM {variable} WHERE name='%s'",
  60. 'tripal_analysis_blast_setting');
  61. // Delete a tripal_analysis_blast table
  62. drupal_uninstall_schema('tripal_analysis_blast');
  63. }
  64. /*******************************************************************************
  65. * Implementation of hook_schema(). This table stores the parsers for blast xml
  66. * xml results.
  67. */
  68. function tripal_analysis_blast_schema() {
  69. $schema = array();
  70. $schema['tripal_analysis_blast'] = array(
  71. 'fields' => array(
  72. 'db_id' => array(
  73. 'type' => 'int',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'default' => 0
  77. ),
  78. 'displayname' => array(
  79. 'type' => 'varchar',
  80. 'length' => 100,
  81. 'not null' => TRUE,
  82. ),
  83. 'regex_hit_id' => array(
  84. 'type' => 'varchar',
  85. 'length' => 30,
  86. ),
  87. 'regex_hit_def' => array(
  88. 'type' => 'varchar',
  89. 'length' => 30,
  90. ),
  91. 'regex_hit_accession' => array(
  92. 'type' => 'varchar',
  93. 'length' => 30,
  94. ),
  95. 'genbank_style' => array(
  96. 'type' => 'int',
  97. 'unsigned' => TRUE,
  98. 'default' => 0
  99. ),
  100. ),
  101. 'indexes' => array(
  102. 'db_id' => array('db_id')
  103. ),
  104. 'primary key' => array('db_id'),
  105. );
  106. return $schema;
  107. }
  108. /*******************************************************************************
  109. * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  110. * Analysis' are enabled before installation
  111. */
  112. function tripal_analysis_blast_requirements($phase) {
  113. $requirements = array();
  114. if ($phase == 'install') {
  115. if (!function_exists('tripal_create_moddir') || !function_exists('tripal_analysis_register_child')) {
  116. $requirements ['tripal_analysis_blast'] = array(
  117. 'title' => "tripal_analysis_blast",
  118. 'value' => "error. Some required modules are just being installed. Please try again.",
  119. 'severity' => REQUIREMENT_ERROR,
  120. );
  121. }
  122. }
  123. return $requirements;
  124. }
  125. /*******************************************************************************
  126. * Provide update script for adding new cvterms
  127. */
  128. function tripal_analysis_blast_update_6000(){
  129. // we have some new cvterms to add
  130. tripal_analysis_blast_add_cvterms();
  131. $ret = array(
  132. '#finished' => 1,
  133. );
  134. return $ret;
  135. }
  136. /*******************************************************************************
  137. * Function for adding cvterms
  138. */
  139. function tripal_analysis_blast_add_cvterms () {
  140. // Add the cvterms for the anlysisprop table
  141. tripal_add_cvterms('analysis_blast_settings', 'Settings of a blast analysis, '.
  142. 'including db_id, output file, and run parameters separated by a bar |');
  143. tripal_add_cvterms('analysis_blast_blastdb','The database used for blasting');
  144. tripal_add_cvterms('analysis_blast_blastfile','The input file or directory that contains the XML blast output');
  145. tripal_add_cvterms('analysis_blast_blastparameters','The parameters used when performing blast.');
  146. tripal_add_cvterms('analysis_blast_no_parsed','Indicates if the input file should be parsed to map results to features');
  147. tripal_add_cvterms('analysis_blast_query_re','The regular expression for finding the feature name in the query definition line of the blast results');
  148. tripal_add_cvterms('analysis_blast_query_type','The feature type (e.g. mRNA, polypeptide) of the query input file. This type is used to identify the query feature when multiple features have the same name');
  149. tripal_add_cvterms('analysis_blast_query_uniquename','Indicates if the matched name in the query definition line of the blast results is feature uniquename');
  150. tripal_add_cvterms('analysis_blast_blastfile_ext','Indicates the extension of the blast files. This is required if the blastfile setting is a directory.');
  151. tripal_add_cvterms('analysis_blast_is_concat','Indicates if the blast results XML file is a series of concatenated XML results. Such is the case, for example, if Blast2GO was used to perform the analysis.');
  152. // Add cvterm 'analysis_blast_output_iteration_hits' for inserting into featureprop table
  153. tripal_add_cvterms('analysis_blast_output_iteration_hits', 'Hits of a blast '.
  154. 'output iteration. Each iteration corresponds to a chado feature, and is '.
  155. 'the content between <iteration> and </iteration> tags in the blast xml '.
  156. 'output file. This cvterm represents all hits in the iteration');
  157. tripal_add_cvterms('analysis_blast_besthit_query', 'query name of the best hit
  158. associated with a feature and a blast analysis ');
  159. tripal_add_cvterms('analysis_blast_besthit_match', 'match name of the best hit
  160. associated with a feature and a blast analysis ');
  161. tripal_add_cvterms('analysis_blast_besthit_description', 'description of the best hit
  162. associated with a feature and a blast analysis ');
  163. tripal_add_cvterms('analysis_blast_besthit_evalue', 'evalue of the best hit
  164. associated with a feature and a blast analysis ');
  165. tripal_add_cvterms('analysis_blast_besthit_identity', 'identity (%) of the best hit
  166. associated with a feature and a blast analysis ');
  167. tripal_add_cvterms('analysis_blast_besthit_length', 'length of the best hit
  168. associated with a feature and a blast analysis ');
  169. }