tripal_analysis_unigene.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_analysis_unigene_add_cvterms();
  24. tripal_analysis_unigene_add_organism_unigene_mview();
  25. }
  26. /**
  27. *
  28. */
  29. function tripal_analysis_unigene_update_6000(){
  30. // we have some new cvterms to add
  31. tripal_analysis_unigene_add_cvterms();
  32. // remove the old unigene materialized view and add the new one.
  33. $mview = tripal_mviews_get_mview_id('unigene_mview');
  34. if($mview){
  35. tripal_mviews_action('delete',$mview);
  36. }
  37. tripal_analysis_unigene_add_organism_unigene_mview();
  38. $ret = array(
  39. '#finished' => 1,
  40. );
  41. return $ret;
  42. }
  43. /**
  44. *
  45. */
  46. function tripal_analysis_unigene_add_cvterms(){
  47. tripal_add_cvterms('unigene_version','The version number for the unigene ".
  48. "(e.g. v1, v2, etc...) ');
  49. tripal_add_cvterms('analysis_unigene_name', 'The name for a unigene.');
  50. tripal_add_cvterms('analysis_unigene_num_contigs','The number of contigs in the unigene assembly');
  51. tripal_add_cvterms('analysis_unigene_num_singlets','The number of singlets remaining in the unigene assembly');
  52. tripal_add_cvterms('analysis_unigene_num_clusters','The number of clusters in the unigene assembly');
  53. tripal_add_cvterms('analysis_unigene_num_reads','The number of reads, after filtering, used as input for the assembly');
  54. tripal_add_cvterms('singlet',"Indicates the feature is a singlet in a ".
  55. "specific unigene version (e.g. v1, v2, etc...). The value specified ".
  56. "should match that of the unigene_version");
  57. // Add cveterm 'analysis_unigene_settings' for inserting into analysisprop table
  58. tripal_add_cvterms('analysis_unigene_settings', 'Settings of a unigene analysis');
  59. }
  60. /**
  61. *
  62. */
  63. function tripal_analysis_unigene_add_organism_unigene_mview(){
  64. $view_name = 'organism_unigene_mview';
  65. // Drop the MView table if it exists
  66. $mview_id = tripal_mviews_get_mview_id($view_name);
  67. if($mview_id){
  68. tripal_mviews_action("delete",$mview_id);
  69. }
  70. tripal_add_mview(
  71. // view name
  72. $view_name,
  73. // tripal module name
  74. 'tripal_analysis_unigene',
  75. // table name
  76. $view_name,
  77. // table schema definition
  78. 'analysis_id integer, organism_id integer',
  79. // columns for indexing
  80. 'analysis_id, organism_id',
  81. // SQL statement to populate the view
  82. "SELECT DISTINCT A.analysis_id, O.organism_id ".
  83. "FROM {Analysis} A ".
  84. " INNER JOIN analysisprop AP ON AP.analysis_id = A.analysis_id ".
  85. " INNER JOIN cvterm CVT ON AP.type_id = CVT.cvterm_id ".
  86. " INNER JOIN cv CV ON CV.cv_id = CVT.cv_id ".
  87. " INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id ".
  88. " INNER JOIN feature F ON AF.feature_id = F.feature_id ".
  89. " INNER JOIN organism O ON F.organism_id = O.organism_id ".
  90. "WHERE CV.name = 'tripal' AND CVT.name='analysis_unigene_name'",
  91. // special index
  92. ''
  93. );
  94. // add a job to the job queue so this view gets updated automatically next
  95. // time the job facility is run
  96. $mview_id = tripal_mviews_get_mview_id($view_name);
  97. if($mview_id){
  98. tripal_mviews_action('update',$mview_id);
  99. }
  100. }
  101. /*******************************************************************************
  102. * Implementation of hook_uninstall().
  103. */
  104. function tripal_analysis_unigene_uninstall() {
  105. $mview = tripal_mviews_get_mview_id('unigene_mview');
  106. if($mview){
  107. tripal_mviews_action('delete',$mview);
  108. }
  109. $mview = tripal_mviews_get_mview_id('unigene_libraries_mview');
  110. if($mview){
  111. tripal_mviews_action('delete',$mview);
  112. }
  113. // Delete the settings from {tripal_analysis} table
  114. // Drupal complains when the user tries to uninstall tripal_analysis
  115. // and tripal_analysis_unigene at the same time. This is because Drupal drops
  116. // the {tripal_analysis} table before we can delete anything from it. Thus,
  117. // we perform a db_table_exists() check before the deletion
  118. tripal_analysis_unregister_child('tripal_analysis_unigene');
  119. // Delete module's variables from variables table.
  120. db_query("DELETE FROM {variable} WHERE name='%s'",
  121. 'tripal_analysis_unigene_setting');
  122. }
  123. /*******************************************************************************
  124. * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  125. * Analysis' are enabled before installation
  126. */
  127. function tripal_analysis_unigene_requirements($phase) {
  128. $requirements = array();
  129. if ($phase == 'install') {
  130. if (!function_exists('tripal_create_moddir') || !function_exists('tripal_analysis_register_child')) {
  131. $requirements ['tripal_analysis_unigene'] = array(
  132. 'title' => "tripal_analysis_unigene",
  133. 'value' => "error. Some required modules are just being installed. Please try again.",
  134. 'severity' => REQUIREMENT_ERROR,
  135. );
  136. }
  137. }
  138. return $requirements;
  139. }