tripal_cv.install 4.1 KB

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