tripal_cv.install 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions executed only on install/uninstall of this module
  5. */
  6. /**
  7. * Disable default views when module is disabled
  8. */
  9. function tripal_cv_disable() {
  10. // Disable all default views provided by this module
  11. require_once("tripal_cv.views_default.inc");
  12. $views = tripal_cv_views_default_views();
  13. foreach (array_keys($views) as $view_name) {
  14. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  15. }
  16. }
  17. /**
  18. * Implementation of hook_requirements().
  19. */
  20. function tripal_cv_requirements($phase) {
  21. $requirements = array();
  22. if ($phase == 'install') {
  23. // make sure chado is installed
  24. if (!tripal_core_is_chado_installed()) {
  25. $requirements ['tripal_cv'] = array(
  26. 'title' => "tripal_cv",
  27. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  28. 'severity' => REQUIREMENT_ERROR,
  29. );
  30. }
  31. }
  32. return $requirements;
  33. }
  34. /**
  35. * Implementation of hook_install().
  36. *
  37. * @ingroup tripal_cv
  38. */
  39. function tripal_cv_install() {
  40. // create the module's data directory
  41. tripal_create_moddir('tripal_cv');
  42. // add the cv_root_mview
  43. tripal_cv_add_cv_root_mview();
  44. // create the tables that correlate OBO files/references with a chado CV
  45. tripal_cv_add_obo_defaults();
  46. }
  47. /**
  48. * Implementation of hook_uninstall().
  49. *
  50. * @ingroup tripal_cv
  51. */
  52. function tripal_cv_uninstall() {
  53. // remove the materialized view
  54. if ($mview = tripal_mviews_get_mview_id('cv_root_mview')) {
  55. tripal_mviews_action('delete', $mview);
  56. }
  57. }
  58. /**
  59. * Implementation of hook_schema().
  60. *
  61. * @ingroup tripal_cv
  62. */
  63. function tripal_cv_schema() {
  64. $schema['tripal_cv_obo'] = array(
  65. 'fields' => array(
  66. 'obo_id' => array(
  67. 'type' => 'serial',
  68. 'unsigned' => TRUE,
  69. 'not null' => TRUE
  70. ),
  71. 'name' => array(
  72. 'type' => 'varchar',
  73. 'length' => 255
  74. ),
  75. 'path' => array(
  76. 'type' => 'varchar',
  77. 'length' => 1024
  78. ),
  79. ),
  80. 'indexes' => array(
  81. 'tripal_cv_obo_idx1' => array('obo_id'),
  82. ),
  83. 'primary key' => array('obo_id'),
  84. );
  85. return $schema;
  86. }
  87. /**
  88. *
  89. * @ingroup tripal_cv
  90. */
  91. function tripal_cv_add_cv_root_mview() {
  92. $mv_name = 'cv_root_mview';
  93. $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
  94. $schema = array(
  95. 'table' => $mv_name,
  96. 'description' => $comment,
  97. 'fields' => array(
  98. 'name' => array(
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => TRUE,
  102. ),
  103. 'cvterm_id' => array(
  104. 'type' => 'int',
  105. 'not null' => TRUE,
  106. ),
  107. 'cv_id' => array(
  108. 'type' => 'int',
  109. 'not null' => TRUE,
  110. ),
  111. 'cv_name' => array(
  112. 'type' => 'varchar',
  113. 'length' => 255,
  114. 'not null' => TRUE,
  115. ),
  116. ),
  117. 'indexes' => array(
  118. 'cv_root_mview_indx1' => array('cvterm_id'),
  119. 'cv_root_mview_indx2' => array('cv_id'),
  120. ),
  121. );
  122. $sql = "
  123. SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  124. FROM cvterm_relationship CVTR
  125. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  126. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  127. WHERE CVTR.object_id not in
  128. (SELECT subject_id FROM cvterm_relationship)
  129. ";
  130. // Create the MView
  131. tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
  132. }
  133. /**
  134. * Add's defaults to the tripal_cv_obo table
  135. *
  136. * @ingroup tripal_cv
  137. */
  138. function tripal_cv_add_obo_defaults() {
  139. // insert commonly used ontologies into the tables
  140. $ontologies = array(
  141. array('Chado Feature Properties', drupal_get_path('module', 'tripal_cv') . '/feature_property.obo'),
  142. array('Relationship Ontology', 'http://www.obofoundry.org/ro/ro.obo'),
  143. array('Sequence Ontology', 'http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo'),
  144. array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
  145. array('Cell Ontology', 'http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD'),
  146. array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
  147. array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
  148. );
  149. foreach ($ontologies as $o) {
  150. db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
  151. }
  152. }