tripal_cv.install 4.7 KB

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