tripal_search_feature.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*******************************************************************************
  3. * Implementation of hook_install();
  4. */
  5. function tripal_search_feature_install(){
  6. // create the module's data directory
  7. tripal_create_moddir('tripal_search_feature');
  8. // Create a sequence as the primiry key for the feature_for_search
  9. $sql = "DROP SEQUENCE IF EXISTS feature_for_search_id; CREATE SEQUENCE feature_for_search_id";
  10. chado_query($sql);
  11. $view_name = 'feature_for_search';
  12. // Drop the MView table if it exists
  13. $mview_id = tripal_mviews_get_mview_id($view_name);
  14. if($mview_id){
  15. tripal_mviews_action("delete",$mview_id);
  16. }
  17. $schema = " feature_for_search_id integer,
  18. feature_id integer,
  19. feature_type character varying(1024),
  20. feature_name character varying(1024),
  21. feature_uniquename text,
  22. feature_is_obsolete boolean,
  23. organism_common_name character varying(255),
  24. feature_seqlen integer,
  25. go_term character varying(1024),
  26. unigene character varying(255),
  27. blast_value text,
  28. kegg_value text,
  29. interpro_value text
  30. ";
  31. $index = "feature_id, go_term, blast_value, kegg_value, interpro_value";
  32. $sql = "SELECT nextval ('feature_for_search_id') AS feature_for_search_id, T.* FROM (
  33. SELECT F.feature_id AS feature_id,
  34. (SELECT name FROM cvterm WHERE F.type_id = cvterm_id) AS feature_type,
  35. F.name AS feature_name,
  36. F.uniquename AS feature_uniquename,
  37. F.is_obsolete AS feature_is_obsolete,
  38. O.common_name AS organism_common_name,
  39. F.seqlen AS feature_seqlen,
  40. C.name AS go_term,
  41. UNIGENE.name AS unigene_name,
  42. BLAST.value AS blast_value,
  43. KEGG.value AS KEGG_value,
  44. INTERPRO.value AS interpro_value
  45. FROM feature F
  46. LEFT JOIN organism O ON F.organism_id = O.organism_id
  47. LEFT JOIN feature_cvterm FC ON F.feature_id = FC.feature_id
  48. LEFT JOIN cvterm C ON FC.cvterm_id = C.cvterm_id
  49. LEFT JOIN (SELECT * FROM analysisfeatureprop AFP
  50. INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  51. WHERE type_id = (SELECT cvterm_id FROM cvterm
  52. WHERE name = 'analysis_blast_besthit_description'
  53. AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal')
  54. )
  55. ) BLAST ON BLAST.feature_id = F.feature_id
  56. LEFT JOIN (SELECT * FROM analysisfeatureprop AFP
  57. INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  58. WHERE type_id = (SELECT cvterm_id FROM cvterm
  59. WHERE name = 'analysis_kegg_output_keywords'
  60. AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal')
  61. )
  62. ) KEGG ON KEGG.feature_id = F.feature_id
  63. LEFT JOIN (SELECT * FROM analysisfeatureprop AFP
  64. INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  65. WHERE type_id = (SELECT cvterm_id FROM cvterm
  66. WHERE name = 'analysis_interpro_output_keywords'
  67. AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal')
  68. )
  69. ) INTERPRO ON INTERPRO.feature_id = F.feature_id
  70. LEFT JOIN (SELECT * FROM analysisfeature AF
  71. INNER JOIN analysis A ON A.analysis_id = AF.analysis_id
  72. INNER JOIN analysisprop AP ON AF.analysis_id = AP.analysis_id
  73. WHERE AP.type_id = (SELECT cvterm_id FROM cvterm
  74. WHERE name = 'analysis_type'
  75. AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal')
  76. )
  77. AND value = 'tripal_analysis_unigene') UNIGENE ON F.feature_id = UNIGENE.feature_id
  78. ) T";
  79. // Create the MView
  80. tripal_add_mview(
  81. // view name
  82. $view_name,
  83. // tripal module name
  84. ' tripal_search_feature',
  85. // table name
  86. $view_name,
  87. // table schema definition
  88. $schema,
  89. // columns for indexing
  90. $index,
  91. // SQL statement to populate the view
  92. $sql,
  93. // special index
  94. ''
  95. );
  96. // add a job to the job queue so this view gets updated automatically next
  97. // time the job facility is run
  98. $mview_id = tripal_mviews_get_mview_id($view_name);
  99. if($mview_id){
  100. tripal_mviews_action('update',$mview_id);
  101. }
  102. }
  103. /*******************************************************************************
  104. * Implementation of hook_uninstall()
  105. */
  106. function tripal_search_feature_uninstall(){
  107. $view_name = 'feature_for_search';
  108. // Drop the MView table if it exists
  109. $mview_id = tripal_mviews_get_mview_id($view_name);
  110. if($mview_id){
  111. tripal_mviews_action("delete",$mview_id);
  112. }
  113. // Drop the sequence
  114. $sql = "DROP SEQUENCE IF EXISTS feature_for_search_id";
  115. chado_query($sql);
  116. }
  117. /*******************************************************************************
  118. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  119. * before installation
  120. */
  121. function tripal_search_feature_requirements($phase) {
  122. $requirements = array();
  123. if ($phase == 'install') {
  124. if (!function_exists('tripal_create_moddir')) {
  125. $requirements ['tripal_search_feature'] = array(
  126. 'title' => "tripal_search_feature",
  127. 'value' => "error. Some required modules are just being installed. Please try again.",
  128. 'severity' => REQUIREMENT_ERROR,
  129. );
  130. }
  131. }
  132. return $requirements;
  133. }