tripal_library.install 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. if ($mview_id = tripal_mviews_get_mview_id('library_feature_count')) {
  55. tripal_mviews_action("delete", $mview_id);
  56. }
  57. }
  58. /**
  59. * Implementation of hook_schema().
  60. *
  61. * @ingroup tripal_library
  62. */
  63. function tripal_library_schema() {
  64. $schema['chado_library'] = array(
  65. 'fields' => array(
  66. 'vid' => array(
  67. 'type' => 'int',
  68. 'unsigned' => TRUE,
  69. 'not null' => TRUE,
  70. 'default' => 0
  71. ),
  72. 'nid' => array(
  73. 'type' => 'int',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'default' => 0
  77. ),
  78. 'library_id' => array(
  79. 'type' => 'int',
  80. 'not null' => TRUE,
  81. 'default' => 0
  82. )
  83. ),
  84. 'indexes' => array(
  85. 'chado_library_idx1' => array('library_id')
  86. ),
  87. 'unique keys' => array(
  88. 'chado_library_uq1' => array('nid', 'vid'),
  89. 'chado_library_uq2' => array('vid')
  90. ),
  91. 'primary key' => array('nid'),
  92. );
  93. return $schema;
  94. }
  95. /**
  96. * @ingroup tripal_library
  97. */
  98. function tripal_library_add_mview_library_feature_count(){
  99. $view_name = 'library_feature_count';
  100. $comment = 'Provides count of feature by type that are associated with all libraries';
  101. $schema = array(
  102. 'table' => $view_name,
  103. 'description' => $comment,
  104. 'fields' => array(
  105. 'library_id' => array(
  106. 'type' => 'int',
  107. 'not null' => TRUE,
  108. ),
  109. 'name' => array(
  110. 'type' => 'varchar',
  111. 'length' => 255,
  112. 'not null' => TRUE,
  113. ),
  114. 'num_features' => array(
  115. 'type' => 'int',
  116. 'not null' => TRUE,
  117. ),
  118. 'feature_type' => array(
  119. 'type' => 'varchar',
  120. 'length' => 255,
  121. 'not null' => TRUE,
  122. ),
  123. ),
  124. 'indexes' => array(
  125. 'library_feature_count_idx1' => array('library_id'),
  126. ),
  127. );
  128. $sql = "
  129. SELECT
  130. L.library_id, L.name,
  131. count(F.feature_id) as num_features,
  132. CVT.name as feature_type
  133. FROM library L
  134. INNER JOIN library_feature LF ON LF.library_id = L.library_id
  135. INNER JOIN feature F ON LF.feature_id = F.feature_id
  136. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  137. GROUP BY L.library_id, L.name, CVT.name
  138. ";
  139. tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
  140. }
  141. /**
  142. * @ingroup tripal_library
  143. */
  144. function tripal_library_add_cvterms() {
  145. // Insert cvterm 'library_description' into cvterm table of chado
  146. // database. This CV term is used to keep track of the library
  147. // description in the libraryprop table.
  148. tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'),
  149. 'tripal', 0, 1, 'tripal');
  150. // add cvterms for the map unit types
  151. tripal_cv_add_cvterm(array('name' => 'cdna_library','def' => 'cDNA library'),
  152. 'tripal_library_types', 0, 1, 'tripal');
  153. tripal_cv_add_cvterm(array('name' => 'bac_library','def' => 'Bacterial Artifical Chromsome (BAC) library'),
  154. 'tripal_library_types', 0, 1, 'tripal');
  155. tripal_cv_add_cvterm(array('name' => 'fosmid_library','def' => 'Fosmid library'),
  156. 'tripal_library_types', 0, 1, 'tripal');
  157. tripal_cv_add_cvterm(array('name' => 'cosmid_library','def' => 'Cosmid library'),
  158. 'tripal_library_types', 0, 1, 'tripal');
  159. tripal_cv_add_cvterm(array('name' => 'yac_library','def' => 'Yeast Artificial Chromosome (YAC) library'),
  160. 'tripal_library_types', 0, 1, 'tripal');
  161. tripal_cv_add_cvterm(array('name' => 'genomic_library','def' => 'Genomic Library'),
  162. 'tripal_library_types', 0, 1, 'tripal');
  163. }