tripal_cv.install 3.4 KB

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