tripal_analysis_unigene.install 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. //$Id:
  3. /*******************************************************************************
  4. * Implementation of hook_install().
  5. */
  6. function tripal_analysis_unigene_install() {
  7. // create the module's data directory
  8. tripal_create_moddir('tripal_analysis_unigene');
  9. // We need to register to tripal_analysis module so it can provide a control
  10. // for our unigene result. Basically the registration is done by inserting
  11. // required information into the {tripal_analysis} table.
  12. tripal_analysis_register_child('tripal_analysis_unigene');
  13. $previous_db = tripal_db_set_active('chado');
  14. if (db_table_exists('unigene_libraries_mview')) {
  15. $sql = "DROP TABLE unigene_libraries_mview";
  16. db_query($sql);
  17. }
  18. if (db_table_exists('unigene_mview')) {
  19. $sql = "DROP TABLE unigene_mview";
  20. db_query($sql);
  21. }
  22. tripal_db_set_active($previous_db);
  23. tripal_add_cvterms('unigene_version','The version number for the unigene ".
  24. "(e.g. v1, v2, etc...) ');
  25. tripal_add_cvterms('singlet',"Indicates the feature is a singlet in a ".
  26. "specific unigene version (e.g. v1, v2, etc...). The value specified ".
  27. "should match that of the unigene_version");
  28. //tripal_add_mview('unigene_libraries_mview',
  29. //'tripal_analysis_unigene',
  30. //'unigene_libraries_mview',
  31. //'analysis_name character varying(255), analysis_id integer, '.
  32. //'organism_common_name character varying(255), organism_id integer, '.
  33. //'library_name character varying(255), library_id integer, '.
  34. //'library_type character varying(255)',
  35. //'analysis_id,organism_id,library_id',
  36. //"select A.name as analysis_name, A.analysis_id, ".
  37. //" O.common_name as organism_common_name, O.organism_id, ".
  38. //" L.name as library_name, L.library_id,".
  39. //" CV.name as library_type ".
  40. //"FROM {Analysis} A ".
  41. //"INNER JOIN Analysisfeature AF ON A.analysis_id = AF.analysis_ID ".
  42. //"INNER JOIN Featureloc FL ON AF.feature_id = FL.feature_ID ".
  43. //"INNER JOIN Feature F ON FL.srcfeature_id = F.feature_id ".
  44. //"INNER JOIN Organism O ON F.organism_id = O.organism_id ".
  45. //"INNER JOIN Library_feature LF ON F.feature_id = LF.feature_id ".
  46. //"INNER JOIN Library L ON LF.library_id = L.library_id ".
  47. //"INNER JOIN CVterm CV ON L.type_id = CV.cvterm_id ".
  48. //"GROUP BY A.analysis_id, A.name, O.common_name, O.organism_id, ".
  49. //" L.library_id, L.name, CV.name",
  50. //''
  51. //);
  52. tripal_add_mview('unigene_mview',
  53. 'tripal_analysis_unigene',
  54. 'unigene_mview',
  55. 'analysis_id integer, name character varying(255), description text, '.
  56. 'program character varying(255), programversion character varying(255), '.
  57. 'algorithm character varying(255), sourcename character varying(255), '.
  58. 'sourceversion character varying(255), sourceuri text, '.
  59. 'timeexecuted timestamp, organism_id integer, '.
  60. 'uversion text, adate text, num_ests integer, '.
  61. 'num_contigs integer, num_singlets integer',
  62. 'analysis_id, organism_id',
  63. "SELECT Distinct A.analysis_id, A.name, A.description, A.program, A.programversion, A.algorithm, ".
  64. " A.sourcename, A.sourceversion, A.sourceuri, A.timeexecuted, O.organism_id, ".
  65. " AP.value as uversion, AP2.value as adate, ".
  66. " (SELECT count(*) FROM {feature} F ".
  67. " INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id ".
  68. " INNER JOIN CV on CVT.cv_id = CV.cv_id ".
  69. " INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
  70. " WHERE CVT.name = 'EST' and ".
  71. " CV.name = 'sequence' and ".
  72. " AF.analysis_id = A.analysis_id) as num_ests, ".
  73. " (SELECT count(*) FROM {feature} F ".
  74. " INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id ".
  75. " INNER JOIN CV on CVT.cv_id = CV.cv_id ".
  76. " INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
  77. " WHERE CVT.name = 'contig' and ".
  78. " CV.name = 'sequence' and ".
  79. " AF.analysis_id = A.analysis_id) as num_contigs, ".
  80. " (SELECT count(*) FROM {feature} F ".
  81. " INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id ".
  82. " INNER JOIN CV on CVT.cv_id = CV.cv_id ".
  83. " INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
  84. " INNER JOIN analysisprop AP on AP.analysis_id = AF.analysis_id ".
  85. " INNER JOIN CVTerm CVT2 on CVT2.cvterm_id = AP.type_id ".
  86. " INNER JOIN CV CV2 on CVT2.cv_id = CV2.cv_id ".
  87. " WHERE CVT.name = 'contig' and ".
  88. " CV.name = 'sequence' and ".
  89. " CVT2.name = 'singlet' and ".
  90. " CV.name = 'tripal' and ".
  91. " AF.analysis_id = A.analysis_id) as num_singlets ".
  92. "FROM {Analysis} A ".
  93. " INNER JOIN Analysisprop AP ".
  94. " ON A.analysis_id = AP.analysis_id ".
  95. " INNER JOIN CVterm CV ".
  96. " ON AP.type_id = CV.cvterm_ID ".
  97. " INNER JOIN Analysisprop AP2 ".
  98. " ON A.analysis_id = AP2.analysis_id ".
  99. " INNER JOIN CVterm CV2 ".
  100. " ON AP2.type_id = CV2.cvterm_ID ".
  101. " INNER JOIN Analysisfeature AF ".
  102. " ON A.analysis_id = AF.analysis_ID ".
  103. " INNER JOIN Feature F ".
  104. " ON AF.Feature_ID = F.Feature_ID ".
  105. " INNER JOIN CVterm CV4 ".
  106. " ON F.type_id = CV4.cvterm_id ".
  107. " INNER JOIN Organism O ".
  108. " ON F.Organism_ID = O.Organism_ID ".
  109. "WHERE ".
  110. " CV.name = 'unigene_version' ".
  111. " AND CV2.name = 'analysis_date' ".
  112. "GROUP BY A.analysis_id, A.name, A.description, A.program, ".
  113. " A.programversion, A.algorithm, A.sourcename, A.sourceversion, ".
  114. " A.sourceuri, A.timeexecuted, AP.value, AP2.value, O.organism_id",
  115. ''
  116. );
  117. }
  118. /*******************************************************************************
  119. * Implementation of hook_uninstall().
  120. */
  121. function tripal_analysis_unigene_uninstall() {
  122. $mview = tripal_mviews_get_mview_id('unigene_mview');
  123. if($mview){
  124. tripal_mviews_action('delete',$mview);
  125. }
  126. $mview = tripal_mviews_get_mview_id('unigene_libraries_mview');
  127. if($mview){
  128. tripal_mviews_action('delete',$mview);
  129. }
  130. // Delete the settings from {tripal_analysis} table
  131. // Drupal complains when the user tries to uninstall tripal_analysis
  132. // and tripal_analysis_unigene at the same time. This is because Drupal drops
  133. // the {tripal_analysis} table before we can delete anything from it. Thus,
  134. // we perform a db_table_exists() check before the deletion
  135. tripal_analysis_unregister_child('tripal_analysis_unigene');
  136. // Delete module's variables from variables table.
  137. db_query("DELETE FROM {variable} WHERE name='%s'",
  138. 'tripal_analysis_unigene_setting');
  139. }
  140. /*******************************************************************************
  141. * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  142. * Analysis' are enabled before installation
  143. */
  144. function tripal_analysis_unigene_requirements($phase) {
  145. $requirements = array();
  146. if ($phase == 'install') {
  147. if (!function_exists('tripal_create_moddir') || !function_exists('tripal_analysis_register_child')) {
  148. $requirements ['tripal_analysis_unigene'] = array(
  149. 'title' => "tripal_analysis_unigene",
  150. 'value' => "error. Some required modules are just being installed. Please try again.",
  151. 'severity' => REQUIREMENT_ERROR,
  152. );
  153. }
  154. }
  155. return $requirements;
  156. }