tripal_library.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implementation of hook_requirements().
  8. */
  9. function tripal_library_requirements($phase) {
  10. $requirements = array();
  11. if ($phase == 'install') {
  12. // make sure chado is installed
  13. if (!tripal_core_is_chado_installed()) {
  14. $requirements ['tripal_library'] = array(
  15. 'title' => "tripal_library",
  16. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  17. 'severity' => REQUIREMENT_ERROR,
  18. );
  19. }
  20. }
  21. return $requirements;
  22. }
  23. /**
  24. * Implementation of hook_install().
  25. *
  26. * @ingroup tripal_library
  27. */
  28. function tripal_library_install() {
  29. // create the module's data directory
  30. tripal_create_moddir('tripal_library');
  31. // add the materialized view
  32. tripal_library_add_mview_library_feature_count();
  33. // add cvterms
  34. tripal_library_add_cvterms();
  35. }
  36. /**
  37. * Implementation of hook_uninstall().
  38. *
  39. * @ingroup tripal_library
  40. */
  41. function tripal_library_uninstall() {
  42. // Drop the MView table if it exists
  43. if ($mview_id = tripal_mviews_get_mview_id('library_feature_count')) {
  44. tripal_mviews_action("delete", $mview_id);
  45. }
  46. }
  47. /**
  48. * Implementation of hook_schema().
  49. *
  50. * @ingroup tripal_library
  51. */
  52. function tripal_library_schema() {
  53. $schema['chado_library'] = array(
  54. 'fields' => array(
  55. 'vid' => array(
  56. 'type' => 'int',
  57. 'unsigned' => TRUE,
  58. 'not null' => TRUE,
  59. 'default' => 0
  60. ),
  61. 'nid' => array(
  62. 'type' => 'int',
  63. 'unsigned' => TRUE,
  64. 'not null' => TRUE,
  65. 'default' => 0
  66. ),
  67. 'library_id' => array(
  68. 'type' => 'int',
  69. 'not null' => TRUE,
  70. 'default' => 0
  71. )
  72. ),
  73. 'indexes' => array(
  74. 'chado_library_idx1' => array('library_id')
  75. ),
  76. 'unique keys' => array(
  77. 'chado_library_uq1' => array('nid', 'vid'),
  78. 'chado_library_uq2' => array('vid')
  79. ),
  80. 'primary key' => array('nid'),
  81. );
  82. return $schema;
  83. }
  84. /**
  85. * @ingroup tripal_library
  86. */
  87. function tripal_library_add_mview_library_feature_count(){
  88. $view_name = 'library_feature_count';
  89. $comment = 'Provides count of feature by type that are associated with all libraries';
  90. $schema = array(
  91. 'table' => $view_name,
  92. 'description' => $comment,
  93. 'fields' => array(
  94. 'library_id' => array(
  95. 'type' => 'int',
  96. 'not null' => TRUE,
  97. ),
  98. 'name' => array(
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => TRUE,
  102. ),
  103. 'num_features' => array(
  104. 'type' => 'int',
  105. 'not null' => TRUE,
  106. ),
  107. 'feature_type' => array(
  108. 'type' => 'varchar',
  109. 'length' => 255,
  110. 'not null' => TRUE,
  111. ),
  112. ),
  113. 'indexes' => array(
  114. 'library_feature_count_idx1' => array('library_id'),
  115. ),
  116. );
  117. $sql = "
  118. SELECT
  119. L.library_id, L.name,
  120. count(F.feature_id) as num_features,
  121. CVT.name as feature_type
  122. FROM library L
  123. INNER JOIN library_feature LF ON LF.library_id = L.library_id
  124. INNER JOIN feature F ON LF.feature_id = F.feature_id
  125. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  126. GROUP BY L.library_id, L.name, CVT.name
  127. ";
  128. tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
  129. }
  130. /**
  131. * @ingroup tripal_library
  132. */
  133. function tripal_library_add_cvterms() {
  134. // Insert cvterm 'library_description' into cvterm table of chado
  135. // database. This CV term is used to keep track of the library
  136. // description in the libraryprop table.
  137. tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'),
  138. 'tripal', 0, 1, 'tripal');
  139. // add cvterms for the map unit types
  140. tripal_cv_add_cvterm(array('name' => 'cdna_library','def' => 'cDNA library'),
  141. 'tripal_library_types', 0, 1, 'tripal');
  142. tripal_cv_add_cvterm(array('name' => 'bac_library','def' => 'Bacterial Artifical Chromsome (BAC) library'),
  143. 'tripal_library_types', 0, 1, 'tripal');
  144. tripal_cv_add_cvterm(array('name' => 'fosmid_library','def' => 'Fosmid library'),
  145. 'tripal_library_types', 0, 1, 'tripal');
  146. tripal_cv_add_cvterm(array('name' => 'cosmid_library','def' => 'Cosmid library'),
  147. 'tripal_library_types', 0, 1, 'tripal');
  148. tripal_cv_add_cvterm(array('name' => 'yac_library','def' => 'Yeast Artificial Chromosome (YAC) library'),
  149. 'tripal_library_types', 0, 1, 'tripal');
  150. tripal_cv_add_cvterm(array('name' => 'genomic_library','def' => 'Genomic Library'),
  151. 'tripal_library_types', 0, 1, 'tripal');
  152. }