tripal_cv.install 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Implementation of hook_install();
  4. *
  5. * @ingroup tripal_cv
  6. */
  7. function tripal_cv_install(){
  8. // create the module's data directory
  9. tripal_create_moddir('tripal_cv');
  10. // Add the materialized view needed to keep track of the
  11. //
  12. $previous_db = tripal_db_set_active('chado');
  13. if (db_table_exists('cv_root_mview')) {
  14. $sql = "DROP TABLE cv_root_mview";
  15. db_query($sql);
  16. }
  17. tripal_db_set_active($previous_db);
  18. // Create the MView
  19. tripal_add_mview(
  20. // view name
  21. 'cv_root_mview',
  22. // module name
  23. 'tripal_cv',
  24. // table name
  25. 'cv_root_mview',
  26. // table schema
  27. 'name character varying(1024), cvterm_id integer, cv_id integer,
  28. cv_name character varying(255)',
  29. // indexed columns
  30. 'cvterm_id, cv_id',
  31. // SQL statement that populates the view
  32. 'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  33. FROM {cvterm_relationship} CVTR
  34. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  35. INNER JOIN CV on CV.cv_id = CVT.cv_id
  36. WHERE CVTR.object_id not in
  37. (SELECT subject_id FROM {cvterm_relationship}) ',
  38. // special index
  39. ''
  40. );
  41. // create the tables that correlate OBO files/references with a chado CV
  42. drupal_install_schema('tripal_cv');
  43. tripal_cv_add_obo_defaults();
  44. }
  45. /**
  46. * This update adds the new tripal_obo table. This is an upgrade from
  47. * Tripal version 0.2
  48. *
  49. * @ingroup tripal_cv
  50. */
  51. function tripal_cv_update_6000(){
  52. drupal_install_schema('tripal_cv');
  53. tripal_cv_add_obo_defaults();
  54. $ret = array(
  55. '#finished' => 1,
  56. );
  57. return $ret;
  58. }
  59. /**
  60. * Implementation of hook_uninstall()
  61. *
  62. * @ingroup tripal_cv
  63. */
  64. function tripal_cv_uninstall(){
  65. // remove the materialized view
  66. $mview = tripal_mviews_get_mview_id('cv_root_mview');
  67. if($mview){
  68. tripal_mviews_action('delete',$mview);
  69. }
  70. drupal_uninstall_schema('tripal_cv');
  71. }
  72. /**
  73. * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
  74. * before installation
  75. *
  76. * @ingroup tripal_cv
  77. */
  78. function tripal_cv_requirements($phase) {
  79. $requirements = array();
  80. if ($phase == 'install') {
  81. if (!function_exists('tripal_create_moddir')) {
  82. $requirements ['tripal_cv'] = array(
  83. 'title' => "tripal_cv",
  84. 'value' => "Required modules must be installed first before Tripal CV module can be installed",
  85. 'severity' => REQUIREMENT_ERROR,
  86. );
  87. }
  88. }
  89. return $requirements;
  90. }
  91. /**
  92. * Implementation of hook_schema().
  93. *
  94. * @ingroup tripal_cv
  95. */
  96. function tripal_cv_schema() {
  97. $schema = tripal_cv_get_schemas();
  98. return $schema;
  99. }
  100. /**
  101. * This function simply defines all tables needed for the module to work
  102. * correctly. By putting the table definitions in a separate function we
  103. * can easily provide the entire list for hook_install or individual
  104. * tables for an update.
  105. *
  106. * @ingroup tripal_cv
  107. */
  108. function tripal_cv_get_schemas (){
  109. $schema = array();
  110. $schema['tripal_cv_obo'] = array(
  111. 'fields' => array(
  112. 'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  113. 'name' => array('type' => 'varchar','length' => 255),
  114. 'path' => array('type' => 'varchar','length' => 1024),
  115. ),
  116. 'indexes' => array(
  117. 'obo_id' => array('obo_id'),
  118. ),
  119. 'primary key' => array('obo_id'),
  120. );
  121. return $schema;
  122. }
  123. /**
  124. * Add's defaults to the tripal_cv_obo table
  125. *
  126. * @ingroup tripal_cv
  127. */
  128. function tripal_cv_add_obo_defaults(){
  129. // insert commonly used ontologies into the tables
  130. $isql = "INSERT INTO tripal_cv_obo (name,path) VALUES ('%s','%s')";
  131. db_query($isql,'Chado Feature Properties',drupal_get_path('module','tripal_cv').'/feature_property.obo');
  132. db_query($isql,'Relationship Ontology','http://www.obofoundry.org/ro/ro.obo');
  133. db_query($isql,'Sequence Ontology','http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo');
  134. db_query($isql,'Gene Ontology','http://www.geneontology.org/ontology/gene_ontology.obo');
  135. db_query($isql,'Cell Ontology','http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD');
  136. db_query($isql,'Plant Structure Ontology','http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co');
  137. db_query($isql,'Plant Growth and Development Stages Ontology','http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co');
  138. }