tripal_library.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Disable default views when module is disabled
  8. */
  9. function tripal_library_disable() {
  10. // Disable all default views provided by this module
  11. require_once("tripal_library.views_default.inc");
  12. $views = tripal_library_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_library_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_library'] = array(
  26. 'title' => "tripal_library",
  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_library
  38. */
  39. function tripal_library_install() {
  40. // create the module's data directory
  41. tripal_create_moddir('tripal_library');
  42. // add the materialized view
  43. tripal_library_add_mview_library_feature_count();
  44. // add cvterms
  45. tripal_library_add_cvterms();
  46. }
  47. /**
  48. * Implementation of hook_uninstall().
  49. *
  50. * @ingroup tripal_library
  51. */
  52. function tripal_library_uninstall() {
  53. // Drop the MView table if it exists
  54. // D7 @todo Fix tripal_mviews_get_mview_id()
  55. /**
  56. if ($mview_id = tripal_mviews_get_mview_id('library_feature_count')) {
  57. tripal_mviews_action("delete", $mview_id);
  58. }
  59. */
  60. }
  61. /**
  62. * Implementation of hook_schema().
  63. *
  64. * @ingroup tripal_library
  65. */
  66. function tripal_library_schema() {
  67. $schema['chado_library'] = array(
  68. 'fields' => array(
  69. 'vid' => array(
  70. 'type' => 'int',
  71. 'unsigned' => TRUE,
  72. 'not null' => TRUE,
  73. 'default' => 0
  74. ),
  75. 'nid' => array(
  76. 'type' => 'int',
  77. 'unsigned' => TRUE,
  78. 'not null' => TRUE,
  79. 'default' => 0
  80. ),
  81. 'library_id' => array(
  82. 'type' => 'int',
  83. 'not null' => TRUE,
  84. 'default' => 0
  85. )
  86. ),
  87. 'indexes' => array(
  88. 'chado_library_idx1' => array('library_id')
  89. ),
  90. 'unique keys' => array(
  91. 'chado_library_uq1' => array('nid', 'vid'),
  92. 'chado_library_uq2' => array('vid')
  93. ),
  94. 'primary key' => array('nid'),
  95. );
  96. return $schema;
  97. }
  98. /**
  99. * @ingroup tripal_library
  100. */
  101. function tripal_library_add_mview_library_feature_count(){
  102. $view_name = 'library_feature_count';
  103. $comment = 'Provides count of feature by type that are associated with all libraries';
  104. $schema = array(
  105. 'table' => $view_name,
  106. 'description' => $comment,
  107. 'fields' => array(
  108. 'library_id' => array(
  109. 'type' => 'int',
  110. 'not null' => TRUE,
  111. ),
  112. 'name' => array(
  113. 'type' => 'varchar',
  114. 'length' => 255,
  115. 'not null' => TRUE,
  116. ),
  117. 'num_features' => array(
  118. 'type' => 'int',
  119. 'not null' => TRUE,
  120. ),
  121. 'feature_type' => array(
  122. 'type' => 'varchar',
  123. 'length' => 255,
  124. 'not null' => TRUE,
  125. ),
  126. ),
  127. 'indexes' => array(
  128. 'library_feature_count_idx1' => array('library_id'),
  129. ),
  130. );
  131. $sql = "
  132. SELECT
  133. L.library_id, L.name,
  134. count(F.feature_id) as num_features,
  135. CVT.name as feature_type
  136. FROM library L
  137. INNER JOIN library_feature LF ON LF.library_id = L.library_id
  138. INNER JOIN feature F ON LF.feature_id = F.feature_id
  139. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  140. GROUP BY L.library_id, L.name, CVT.name
  141. ";
  142. tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
  143. }
  144. /**
  145. * @ingroup tripal_library
  146. */
  147. function tripal_library_add_cvterms() {
  148. // Insert cvterm 'library_description' into cvterm table of chado
  149. // database. This CV term is used to keep track of the library
  150. // description in the libraryprop table.
  151. tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'),
  152. 'tripal', 0, 1, 'tripal');
  153. // add cvterms for the map unit types
  154. tripal_cv_add_cvterm(array('name' => 'cdna_library','def' => 'cDNA library'),
  155. 'tripal_library_types', 0, 1, 'tripal');
  156. tripal_cv_add_cvterm(array('name' => 'bac_library','def' => 'Bacterial Artifical Chromsome (BAC) library'),
  157. 'tripal_library_types', 0, 1, 'tripal');
  158. tripal_cv_add_cvterm(array('name' => 'fosmid_library','def' => 'Fosmid library'),
  159. 'tripal_library_types', 0, 1, 'tripal');
  160. tripal_cv_add_cvterm(array('name' => 'cosmid_library','def' => 'Cosmid library'),
  161. 'tripal_library_types', 0, 1, 'tripal');
  162. tripal_cv_add_cvterm(array('name' => 'yac_library','def' => 'Yeast Artificial Chromosome (YAC) library'),
  163. 'tripal_library_types', 0, 1, 'tripal');
  164. tripal_cv_add_cvterm(array('name' => 'genomic_library','def' => 'Genomic Library'),
  165. 'tripal_library_types', 0, 1, 'tripal');
  166. }