tripal_cv.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. // D7 @todo Fix tripal_mviews_get_mview_id()
  55. /**
  56. if ($mview = tripal_mviews_get_mview_id('cv_root_mview')) {
  57. tripal_mviews_action('delete', $mview);
  58. }
  59. */
  60. }
  61. /**
  62. * Implementation of hook_schema().
  63. *
  64. * @ingroup tripal_cv
  65. */
  66. function tripal_cv_schema() {
  67. $schema['tripal_cv_obo'] = array(
  68. 'fields' => array(
  69. 'obo_id' => array(
  70. 'type' => 'serial',
  71. 'unsigned' => TRUE,
  72. 'not null' => TRUE
  73. ),
  74. 'name' => array(
  75. 'type' => 'varchar',
  76. 'length' => 255
  77. ),
  78. 'path' => array(
  79. 'type' => 'varchar',
  80. 'length' => 1024
  81. ),
  82. ),
  83. 'indexes' => array(
  84. 'tripal_cv_obo_idx1' => array('obo_id'),
  85. ),
  86. 'primary key' => array('obo_id'),
  87. );
  88. return $schema;
  89. }
  90. /**
  91. *
  92. * @ingroup tripal_cv
  93. */
  94. function tripal_cv_add_cv_root_mview() {
  95. $mv_name = 'cv_root_mview';
  96. $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
  97. $schema = array(
  98. 'table' => $mv_name,
  99. 'description' => $comment,
  100. 'fields' => array(
  101. 'name' => array(
  102. 'type' => 'varchar',
  103. 'length' => 255,
  104. 'not null' => TRUE,
  105. ),
  106. 'cvterm_id' => array(
  107. 'type' => 'int',
  108. 'not null' => TRUE,
  109. ),
  110. 'cv_id' => array(
  111. 'type' => 'int',
  112. 'not null' => TRUE,
  113. ),
  114. 'cv_name' => array(
  115. 'type' => 'varchar',
  116. 'length' => 255,
  117. 'not null' => TRUE,
  118. ),
  119. ),
  120. 'indexes' => array(
  121. 'cv_root_mview_indx1' => array('cvterm_id'),
  122. 'cv_root_mview_indx2' => array('cv_id'),
  123. ),
  124. );
  125. $sql = "
  126. SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  127. FROM cvterm_relationship CVTR
  128. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  129. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  130. WHERE CVTR.object_id not in
  131. (SELECT subject_id FROM cvterm_relationship)
  132. ";
  133. // Create the MView
  134. tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
  135. }
  136. /**
  137. * Add's defaults to the tripal_cv_obo table
  138. *
  139. * @ingroup tripal_cv
  140. */
  141. function tripal_cv_add_obo_defaults() {
  142. // insert commonly used ontologies into the tables
  143. $ontologies = array(
  144. array('Chado Feature Properties', drupal_get_path('module', 'tripal_cv') . '/feature_property.obo'),
  145. array('Relationship Ontology', 'http://www.obofoundry.org/ro/ro.obo'),
  146. array('Sequence Ontology', 'http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo'),
  147. array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
  148. array('Cell Ontology', 'http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD'),
  149. array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
  150. array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
  151. );
  152. foreach ($ontologies as $o) {
  153. db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
  154. }
  155. }