tripal_analysis_go.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*******************************************************************************
  3. * Implementation of hook_install();
  4. */
  5. function tripal_analysis_go_install(){
  6. tripal_analysis_register_child('tripal_analysis_go');
  7. // The following view will create counts of features that are assigned
  8. // either directly or by ancestry each GO term. The count is organized by
  9. // organisms.
  10. $previous_db = tripal_db_set_active('chado');
  11. if (db_table_exists('go_count_organism')) {
  12. $sql = "DROP TABLE go_count_organism";
  13. db_query($sql);
  14. }
  15. if (db_table_exists('go_count_analysis')) {
  16. $sql = "DROP TABLE go_count_analysis";
  17. db_query($sql);
  18. }
  19. tripal_db_set_active($previous_db);
  20. tripal_add_mview(
  21. // view name
  22. 'go_count_organism',
  23. // tripal module name
  24. 'tripal_analysis_go',
  25. // table name
  26. 'go_count_organism',
  27. // table schema definition
  28. 'cvname character varying(255),
  29. cvterm_id integer,
  30. organism_id integer,
  31. feature_count integer',
  32. // columns for indexing
  33. 'cvterm_id,organism_id',
  34. // SQL statement to populate the view
  35. "SELECT T1.cvname, T1.object_id, T1.organism_id, count(T1.feature_id)
  36. FROM
  37. (SELECT DISTINCT CVT3.name as cvname, CVTP.object_id,
  38. O.organism_id, F.feature_id
  39. FROM {cvtermpath} CVTP
  40. INNER JOIN CVTerm CVT ON CVTP.subject_id = CVT.cvterm_id
  41. INNER JOIN CVTerm CVT2 ON CVTP.type_id = CVT2.cvterm_id
  42. INNER JOIN CVTerm CVT3 ON CVTP.object_id = CVT3.cvterm_id
  43. INNER JOIN Feature_cvterm FCVT ON FCVT.cvterm_id = CVT.cvterm_id
  44. INNER JOIN Feature F ON FCVT.feature_id = F.feature_id
  45. INNER JOIN CV ON CV.cv_id = CVT.cv_id
  46. INNER JOIN Organism O ON O.organism_id = F.organism_id
  47. WHERE (CV.name = 'biological_process' or
  48. CV.name = 'molecular_function' or
  49. CV.name = 'cellular_component')
  50. ) as T1
  51. GROUP BY T1.cvname,T1.object_id,T1.organism_id",
  52. // special index
  53. ''
  54. );
  55. // The following view will create counts of features that are assigned
  56. // either directly or by ancestry each GO term. The count is organized by
  57. // tripal_go_analysis analyses.
  58. tripal_add_mview(
  59. // view name
  60. 'go_count_analysis',
  61. // tripal module name
  62. 'tripal_analysis_go',
  63. // table name
  64. 'go_count_analysis',
  65. // table schema definition
  66. 'cvname character varying(255),
  67. cvterm_id integer,
  68. analysis_id integer,
  69. organism_id integer,
  70. feature_count integer',
  71. // columns for indexing
  72. 'cvterm_id,analysis_id,organism_id',
  73. // SQL statement to populate the view
  74. "SELECT T1.cvname,T1.cvterm_id,T1.analysis_id,T1.organism_id,count(*) as feature_count
  75. FROM
  76. (SELECT DISTINCT AF.analysis_id, AF.feature_id,CVT.name as cvname,
  77. CVT.cvterm_id,CVTP.object_id,CV.name, F.organism_id
  78. FROM {analysisfeatureprop} AFP
  79. INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  80. INNER JOIN feature F ON AF.feature_id = F.feature_id
  81. INNER JOIN cvtermpath CVTP ON CVTP.subject_id = AFP.type_id
  82. INNER JOIN cvterm CVT ON CVTP.object_id = CVT.cvterm_id
  83. INNER JOIN CV ON CV.cv_id = CVT.cv_id
  84. WHERE
  85. (CV.name = 'biological_process' or
  86. CV.name = 'molecular_function' or
  87. CV.name = 'cellular_component')) as T1
  88. GROUP BY T1.cvname,T1.cvterm_id,T1.analysis_id,T1.organism_id",
  89. // special index
  90. ''
  91. );
  92. }
  93. /*******************************************************************************
  94. * Implementation of hook_uninstall()
  95. */
  96. function tripal_analysis_go_uninstall(){
  97. $mview = tripal_mviews_get_mview_id('go_count_organism');
  98. if($mview){
  99. tripal_mviews_action('delete',$mview);
  100. }
  101. $mview = tripal_mviews_get_mview_id('go_count_analysis');
  102. if($mview){
  103. tripal_mviews_action('delete',$mview);
  104. }
  105. tripal_analysis_unregister_child('tripal_analysis_go');
  106. }
  107. /*******************************************************************************
  108. * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  109. * Analysis' are enabled before installation
  110. */
  111. function tripal_analysis_go_requirements($phase) {
  112. $requirements = array();
  113. if ($phase == 'install') {
  114. if (!function_exists('tripal_create_moddir') || !function_exists('tripal_analysis_register_child')) {
  115. $requirements ['tripal_analysis_go'] = array(
  116. 'title' => "tripal_analysis_go",
  117. 'value' => "error. Some required modules are just being installed. Please try again.",
  118. 'severity' => REQUIREMENT_ERROR,
  119. );
  120. }
  121. }
  122. return $requirements;
  123. }