tripal_cv.install 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. // add defaults to the tables that correlate OBO files/references with a chado CV
  45. tripal_cv_add_obo_defaults();
  46. // add the custom tables to Chado
  47. tripal_cv_add_custom_tables();
  48. }
  49. /**
  50. * Implementation of hook_uninstall().
  51. *
  52. * @ingroup tripal_cv
  53. */
  54. function tripal_cv_uninstall() {
  55. // remove the materialized view
  56. // D7 @todo Fix tripal_mviews_get_mview_id()
  57. /**
  58. if ($mview = tripal_mviews_get_mview_id('cv_root_mview')) {
  59. tripal_mviews_action('delete', $mview);
  60. }
  61. */
  62. }
  63. /**
  64. * Implementation of hook_schema().
  65. *
  66. * @ingroup tripal_cv
  67. */
  68. function tripal_cv_schema() {
  69. $schema['tripal_cv_obo'] = array(
  70. 'fields' => array(
  71. 'obo_id' => array(
  72. 'type' => 'serial',
  73. 'unsigned' => TRUE,
  74. 'not null' => TRUE
  75. ),
  76. 'name' => array(
  77. 'type' => 'varchar',
  78. 'length' => 255
  79. ),
  80. 'path' => array(
  81. 'type' => 'varchar',
  82. 'length' => 1024
  83. ),
  84. ),
  85. 'indexes' => array(
  86. 'tripal_cv_obo_idx1' => array('obo_id'),
  87. ),
  88. 'primary key' => array('obo_id'),
  89. );
  90. return $schema;
  91. }
  92. /**
  93. *
  94. * @ingroup tripal_cv
  95. */
  96. function tripal_cv_add_cv_root_mview() {
  97. $mv_name = 'cv_root_mview';
  98. $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
  99. $schema = array(
  100. 'table' => $mv_name,
  101. 'description' => $comment,
  102. 'fields' => array(
  103. 'name' => array(
  104. 'type' => 'varchar',
  105. 'length' => 255,
  106. 'not null' => TRUE,
  107. ),
  108. 'cvterm_id' => array(
  109. 'type' => 'int',
  110. 'not null' => TRUE,
  111. ),
  112. 'cv_id' => array(
  113. 'type' => 'int',
  114. 'not null' => TRUE,
  115. ),
  116. 'cv_name' => array(
  117. 'type' => 'varchar',
  118. 'length' => 255,
  119. 'not null' => TRUE,
  120. ),
  121. ),
  122. 'indexes' => array(
  123. 'cv_root_mview_indx1' => array('cvterm_id'),
  124. 'cv_root_mview_indx2' => array('cv_id'),
  125. ),
  126. );
  127. $sql = "
  128. SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  129. FROM cvterm_relationship CVTR
  130. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  131. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  132. WHERE CVTR.object_id not in
  133. (SELECT subject_id FROM cvterm_relationship)
  134. ";
  135. // Create the MView
  136. tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
  137. }
  138. /**
  139. * Add's defaults to the tripal_cv_obo table
  140. *
  141. * @ingroup tripal_cv
  142. */
  143. function tripal_cv_add_obo_defaults() {
  144. // insert commonly used ontologies into the tables
  145. $ontologies = array(
  146. array('Chado Feature Properties', drupal_get_path('module', 'tripal_cv') . '/feature_property.obo'),
  147. array('Relationship Ontology', 'http://www.obofoundry.org/ro/ro.obo'),
  148. array('Sequence Ontology', 'http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo'),
  149. array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
  150. array('Cell Ontology', 'http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD'),
  151. array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
  152. array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
  153. );
  154. foreach ($ontologies as $o) {
  155. db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
  156. }
  157. }
  158. /**
  159. *
  160. */
  161. function tripal_cv_add_custom_tables() {
  162. $schema = array(
  163. 'table' => 'tripal_obo_temp',
  164. 'fields' => array(
  165. 'id' => array(
  166. 'type' => 'varchar',
  167. 'length' => '255',
  168. 'not null' => TRUE,
  169. ),
  170. 'stanza' => array(
  171. 'type' => 'text',
  172. 'not null' => TRUE,
  173. ),
  174. 'type' => array(
  175. 'type' => 'varchar',
  176. 'length' => '50',
  177. 'not null' => TRUE,
  178. ),
  179. ),
  180. 'indexes' => array(
  181. 'tripal_obo_temp_idx0' => array('id'),
  182. 'tripal_obo_temp_idx0' => array('type'),
  183. ),
  184. 'unique keys' => array(
  185. 'tripal_obo_temp_uq0' => array('id'),
  186. ),
  187. );
  188. tripal_core_create_custom_table('tripal_obo_temp', $schema, TRUE);
  189. }