tripal_feature.install 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * @file
  4. * Installation of the feature module
  5. */
  6. /**
  7. * Implements hook_disable().
  8. *
  9. * Disable default views when module is disabled
  10. *
  11. * @ingroup tripal_feature
  12. */
  13. function tripal_feature_disable() {
  14. // Disable all default views provided by this module
  15. require_once("tripal_feature.views_default.inc");
  16. $views = tripal_feature_views_default_views();
  17. foreach (array_keys($views) as $view_name) {
  18. tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  19. }
  20. }
  21. /**
  22. * Implements hook_requirements().
  23. *
  24. * @ingroup tripal_feature
  25. */
  26. function tripal_feature_requirements($phase) {
  27. $requirements = array();
  28. if ($phase == 'install') {
  29. // make sure chado is installed
  30. if (!$GLOBALS["chado_is_installed"]) {
  31. $requirements ['tripal_feature'] = array(
  32. 'title' => "t ripal_feature",
  33. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  34. 'severity' => REQUIREMENT_ERROR,
  35. );
  36. }
  37. }
  38. return $requirements;
  39. }
  40. /**
  41. * Implements hook_install().
  42. *
  43. * @ingroup tripal_feature
  44. */
  45. function tripal_feature_install() {
  46. // Note: the feature_property OBO that came with Chado v1.2 should not
  47. // be automatically installed. Some of the terms are duplicates of
  48. // others in better maintained vocabularies. New Tripal sites should
  49. // use those.
  50. // $obo_path = '{tripal_feature}/files/feature_property.obo';
  51. // $obo_id = tripal_insert_obo('Chado Feature Properties', $obo_path);
  52. // tripal_submit_obo_job(array('obo_id' => $obo_id));
  53. // Add the materialized view.
  54. tripal_feature_add_organism_count_mview();
  55. // Add the custom tables.
  56. tripal_feature_add_tripal_gff_temp_table();
  57. tripal_feature_add_tripal_gffcds_temp_table();
  58. tripal_feature_add_tripal_gffprotein_temp_table();
  59. // Add the vocabularies used by the feature module.
  60. tripal_feature_add_cvs();
  61. // Set the default vocabularies.
  62. tripal_set_default_cv('feature', 'type_id', 'sequence');
  63. tripal_set_default_cv('featureprop', 'type_id', 'feature_property');
  64. tripal_set_default_cv('feature_relationship', 'type_id', 'feature_relationship');
  65. }
  66. /**
  67. * Implements hook_uninstall().
  68. *
  69. * @ingroup tripal_feature
  70. */
  71. function tripal_feature_uninstall() {
  72. }
  73. // This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
  74. /* function tripal_feature_add_tripal_gff_temp_table() {
  75. $schema = array(
  76. 'table' => 'tripal_gff_temp',
  77. 'fields' => array(
  78. 'feature_id' => array(
  79. 'type' => 'int',
  80. 'not null' => TRUE,
  81. ),
  82. 'organism_id' => array(
  83. 'type' => 'int',
  84. 'not null' => TRUE,
  85. ),
  86. 'uniquename' => array(
  87. 'type' => 'text',
  88. 'not null' => TRUE,
  89. ),
  90. 'type_name' => array(
  91. 'type' => 'varchar',
  92. 'length' => '1024',
  93. 'not null' => TRUE,
  94. ),
  95. ),
  96. 'indexes' => array(
  97. 'tripal_gff_temp_idx0' => array('feature_id'),
  98. 'tripal_gff_temp_idx0' => array('organism_id'),
  99. 'tripal_gff_temp_idx1' => array('uniquename'),
  100. ),
  101. 'unique keys' => array(
  102. 'tripal_gff_temp_uq0' => array('feature_id'),
  103. 'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
  104. ),
  105. );
  106. chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
  107. } */
  108. /**
  109. *
  110. */
  111. // This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
  112. /* function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
  113. $schema = array(
  114. 'table' => 'tripal_gffcds_temp',
  115. 'fields' => array(
  116. 'feature_id' => array(
  117. 'type' => 'int',
  118. 'not null' => TRUE,
  119. ),
  120. 'parent_id' => array(
  121. 'type' => 'int',
  122. 'not null' => TRUE,
  123. ),
  124. 'phase' => array(
  125. 'type' => 'int',
  126. 'not null' => TRUE,
  127. ),
  128. 'strand' => array(
  129. 'type' => 'int',
  130. 'not null' => TRUE,
  131. ),
  132. 'fmin' => array(
  133. 'type' => 'int',
  134. 'not null' => TRUE,
  135. ),
  136. 'fmax' => array(
  137. 'type' => 'int',
  138. 'not null' => TRUE,
  139. ),
  140. ),
  141. 'indexes' => array(
  142. 'tripal_gff_temp_idx0' => array('feature_id'),
  143. 'tripal_gff_temp_idx0' => array('parent_id'),
  144. ),
  145. );
  146. chado_create_custom_table('tripal_gffcds_temp', $schema, $skip_recreate);
  147. } */
  148. /**
  149. *
  150. */
  151. // This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
  152. /* function tripal_feature_add_tripal_gffprotein_temp_table() {
  153. $schema = array(
  154. 'table' => 'tripal_gffprotein_temp',
  155. 'fields' => array(
  156. 'feature_id' => array(
  157. 'type' => 'int',
  158. 'not null' => TRUE,
  159. ),
  160. 'parent_id' => array(
  161. 'type' => 'int',
  162. 'not null' => TRUE,
  163. ),
  164. 'fmin' => array(
  165. 'type' => 'int',
  166. 'not null' => TRUE,
  167. ),
  168. 'fmax' => array(
  169. 'type' => 'int',
  170. 'not null' => TRUE,
  171. ),
  172. ),
  173. 'indexes' => array(
  174. 'tripal_gff_temp_idx0' => array('feature_id'),
  175. 'tripal_gff_temp_idx0' => array('parent_id'),
  176. ),
  177. 'unique keys' => array(
  178. 'tripal_gff_temp_uq0' => array('feature_id'),
  179. ),
  180. );
  181. chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
  182. } */
  183. /**
  184. * Implementation of hook_schema().
  185. *
  186. * @ingroup tripal_feature
  187. */
  188. function tripal_feature_schema() {
  189. $schema['chado_feature'] = array(
  190. 'fields' => array(
  191. 'vid' => array(
  192. 'type' => 'int',
  193. 'unsigned' => TRUE,
  194. 'not null' => TRUE,
  195. 'default' => 0
  196. ),
  197. 'nid' => array(
  198. 'type' => 'int',
  199. 'unsigned' => TRUE,
  200. 'not null' => TRUE,
  201. 'default' => 0
  202. ),
  203. 'feature_id' => array(
  204. 'type' => 'int',
  205. 'not null' => TRUE,
  206. 'default' => 0
  207. ),
  208. 'sync_date' => array(
  209. 'type' => 'int',
  210. 'not null' => FALSE,
  211. 'description' => 'UNIX integer sync date/time'
  212. ),
  213. ),
  214. 'indexes' => array(
  215. 'chado_feature_idx1' => array('feature_id')
  216. ),
  217. 'unique keys' => array(
  218. 'chado_feature_uq1' => array('nid', 'vid'),
  219. 'chado_feature_uq2' => array('vid')
  220. ),
  221. 'primary key' => array('nid'),
  222. );
  223. return $schema;
  224. };
  225. /**
  226. * Creates a materialized view that stores the type & number of features per organism
  227. *
  228. * @ingroup tripal_feature
  229. */
  230. // This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
  231. /* function tripal_feature_add_organism_count_mview() {
  232. $view_name = 'organism_feature_count';
  233. $comment = 'Stores the type and number of features per organism';
  234. $schema = array(
  235. 'description' => $comment,
  236. 'table' => $view_name,
  237. 'fields' => array(
  238. 'organism_id' => array(
  239. 'size' => 'big',
  240. 'type' => 'int',
  241. 'not null' => TRUE,
  242. ),
  243. 'genus' => array(
  244. 'type' => 'varchar',
  245. 'length' => '255',
  246. 'not null' => TRUE,
  247. ),
  248. 'species' => array(
  249. 'type' => 'varchar',
  250. 'length' => '255',
  251. 'not null' => TRUE,
  252. ),
  253. 'common_name' => array(
  254. 'type' => 'varchar',
  255. 'length' => '255',
  256. 'not null' => FALSE,
  257. ),
  258. 'num_features' => array(
  259. 'type' => 'int',
  260. 'not null' => TRUE,
  261. ),
  262. 'cvterm_id' => array(
  263. 'size' => 'big',
  264. 'type' => 'int',
  265. 'not null' => TRUE,
  266. ),
  267. 'feature_type' => array(
  268. 'type' => 'varchar',
  269. 'length' => '255',
  270. 'not null' => TRUE,
  271. ),
  272. ),
  273. 'indexes' => array(
  274. 'organism_feature_count_idx1' => array('organism_id'),
  275. 'organism_feature_count_idx2' => array('cvterm_id'),
  276. 'organism_feature_count_idx3' => array('feature_type'),
  277. ),
  278. );
  279. $sql = "
  280. SELECT
  281. O.organism_id, O.genus, O.species, O.common_name,
  282. count(F.feature_id) as num_features,
  283. CVT.cvterm_id, CVT.name as feature_type
  284. FROM organism O
  285. INNER JOIN feature F ON O.Organism_id = F.organism_id
  286. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  287. GROUP BY
  288. O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
  289. ";
  290. tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
  291. } */
  292. /**
  293. * Add cvs related to publications
  294. *
  295. * @ingroup tripal_pub
  296. */
  297. function tripal_feature_add_cvs() {
  298. // Add cv for relationship types
  299. tripal_insert_cv(
  300. 'feature_relationship',
  301. 'Contains types of relationships between features.'
  302. );
  303. // The feature_property CV may already exists. It comes with Chado, but
  304. // we need to add it just in case it doesn't get added before the feature
  305. // module is installed. But as of Tripal v3.0 the Chado version of this
  306. // vocabulary is no longer loaded by default.
  307. tripal_insert_cv(
  308. 'feature_property',
  309. 'Stores properties about features'
  310. );
  311. // the feature type vocabulary should be the sequence ontology, and even though
  312. // this ontology should get loaded we will create it here just so that we can
  313. // set the default vocabulary for the feature.type_id field
  314. tripal_insert_cv(
  315. 'sequence',
  316. 'The Sequence Ontology'
  317. );
  318. }