tripal_entities.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /**
  3. * @file
  4. * Install for a tripal data entity - creates the base table for our entity.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function tripal_entities_install() {
  10. // Unfortunately, some Chado base tables do not have a type_id, so we must
  11. // take special action for those tables. These include: organism and
  12. // analysis. Until we can find an appropriate controlled vocabulary
  13. // that is well supported by the community with types for these tables we
  14. // will have to use in-house terms.
  15. // Add a term to be used for an inherent 'type_id' for the organism table.
  16. tripal_insert_cvterm(array(
  17. 'id' => 'local:organism',
  18. 'name' => 'organism',
  19. 'definition' => 'An individual form of life, such as a bacterium, protist, ' .
  20. 'fungus, plant, or animal, composed of a single cell or a complex of cells ' .
  21. 'in which organelles or organs work together to carry out the various ' .
  22. 'processes of life. (American Heritage® Dictionary of the English ' .
  23. 'Language, Fifth Edition. Copyright © 2011 by Houghton Mifflin ' .
  24. 'Harcourt Publishing Company).',
  25. 'cv_name' => 'local',
  26. ));
  27. // Add a term to be used for an inherent 'type_id' for the organism table.
  28. tripal_insert_cvterm(array(
  29. 'id' => 'local:analysis',
  30. 'name' => 'analysis',
  31. 'definition' => 'A process as a method of studying the nature of something ' .
  32. 'or of determining its essential features and their relations. ' .
  33. '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
  34. 'Dictionaries Ltd).',
  35. 'cv_name' => 'local',
  36. ));
  37. tripal_insert_cvterm(array(
  38. 'id' => 'local:project',
  39. 'name' => 'project',
  40. 'definition' => 'A plan or proposal for accomplishing something. ' .
  41. '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
  42. 'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
  43. 'cv_name' => 'local',
  44. ));
  45. // We want to provide a set of commonly used entity types by default. This
  46. // way when a user first installs Tripal there are some commonly used
  47. // formats.
  48. module_load_include('inc', 'tripal_entities', 'api/tripal_entities.api');
  49. module_load_include('inc', 'tripal_entities', 'includes/tripal_entities.admin');
  50. // Create the 'Organism' entity type. This uses the local:organism term.
  51. $error = '';
  52. $term = array('name' => 'organism', 'cv_id' => array('name' => 'local'));
  53. $cvterm = chado_generate_var('cvterm', $term);
  54. if (!tripal_create_entity_type($cvterm, $error)) {
  55. throw new Exception($error);
  56. }
  57. // Create the 'Analysis' entity type. This uses the local:analysis term.
  58. $error = '';
  59. $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local'));
  60. $cvterm = chado_generate_var('cvterm', $term);
  61. if (!tripal_create_entity_type($cvterm, $error)) {
  62. throw new Exception($error);
  63. }
  64. // Create the 'Project' entity type. This uses the local:project term.
  65. $error = '';
  66. $term = array('name' => 'project', 'cv_id' => array('name' => 'local'));
  67. $cvterm = chado_generate_var('cvterm', $term);
  68. if (!tripal_create_entity_type($cvterm, $error)) {
  69. throw new Exception($error);
  70. }
  71. }
  72. /**
  73. * Implements hook_schema().
  74. */
  75. function tripal_entities_schema() {
  76. // Adds a table for managing TripalEntity entities.
  77. $schema['tripal_entity'] = tripal_entities_tripal_entity_schema();
  78. // Adds a table for managing the TripalEntity entity types (bundles).
  79. $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema();
  80. // Links TripalEntity entities to the chado record.
  81. $schema['chado_entity'] = tripal_entities_chado_entity_schema();
  82. return $schema;
  83. }
  84. /**
  85. * Implements hook_uninstall().
  86. *
  87. * At uninstall time we'll notify field.module that the entity was deleted
  88. * so that attached fields can be cleaned up.
  89. */
  90. function tripal_entities_uninstall() {
  91. // $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
  92. // foreach ($terms as $term) {
  93. // $bundle_id = 'bio-data_' . $term->cvterm_id;
  94. // field_attach_delete_bundle('TripalEntity', $bundle_id);
  95. // }
  96. }
  97. /**
  98. * @section
  99. * Schema Definitions.
  100. */
  101. /**
  102. * The base table for Biological Data Entities.
  103. *
  104. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  105. * this table will have 15 records and include both genes and mRNA's.
  106. */
  107. function tripal_entities_tripal_entity_schema() {
  108. $schema = array(
  109. 'description' => 'The base table for Tripal Vocabulary-based entities.',
  110. 'fields' => array(
  111. 'id' => array(
  112. 'description' => 'The primary identifier for a vocabulary entity.',
  113. 'type' => 'serial',
  114. 'unsigned' => TRUE,
  115. 'not null' => TRUE,
  116. ),
  117. 'type' => array(
  118. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  119. 'type' => 'varchar',
  120. 'length' => 64,
  121. 'not null' => TRUE,
  122. 'default' => '',
  123. ),
  124. 'bundle' => array(
  125. 'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  126. 'type' => 'varchar',
  127. 'length' => 1024,
  128. 'not null' => TRUE,
  129. 'default' => '',
  130. ),
  131. 'cvterm_id' => array(
  132. 'description' => 'The cvterm_id for the type of entity. This cvterm_id should match a record in the Chado cvterm table.',
  133. 'type' => 'int',
  134. 'not null' => TRUE,
  135. ),
  136. 'title' => array(
  137. 'description' => 'The title of this node, always treated as non-markup plain text.',
  138. 'type' => 'text',
  139. 'not null' => TRUE,
  140. 'default' => '',
  141. ),
  142. 'uid' => array(
  143. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  144. 'type' => 'int',
  145. 'not null' => TRUE,
  146. 'default' => 0,
  147. ),
  148. 'status' => array(
  149. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  150. 'type' => 'int',
  151. 'not null' => TRUE,
  152. 'default' => 1,
  153. ),
  154. 'created' => array(
  155. 'description' => 'The Unix timestamp when the node was created.',
  156. 'type' => 'int',
  157. 'not null' => TRUE,
  158. 'default' => 0,
  159. ),
  160. 'changed' => array(
  161. 'description' => 'The Unix timestamp when the node was most recently saved.',
  162. 'type' => 'int',
  163. 'not null' => TRUE,
  164. 'default' => 0,
  165. ),
  166. ),
  167. 'indexes' => array(
  168. 'cvterm_id' => array('cvterm_id'),
  169. 'entity_changed' => array('changed'),
  170. 'entity_created' => array('created'),
  171. 'type' => array('type'),
  172. 'uid' => array('uid'),
  173. ),
  174. 'unique keys' => array(
  175. ),
  176. 'primary key' => array('id'),
  177. );
  178. return $schema;
  179. }
  180. /**
  181. * The base table for Biological Data Type Entites.
  182. * This table contains a list of Biological Data Types.
  183. * For the example above (5 genes and 10 mRNAs), there would only be two records in
  184. * this table one for "gene" and another for "mRNA".
  185. */
  186. function tripal_entities_tripal_bundle_schema() {
  187. $schema = array(
  188. 'description' => 'Stores information about defined tripal data types.',
  189. 'fields' => array(
  190. 'id' => array(
  191. 'type' => 'serial',
  192. 'not null' => TRUE,
  193. 'description' => 'Primary Key: Unique Chado data type identifier.',
  194. ),
  195. 'type' => array(
  196. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  197. 'type' => 'varchar',
  198. 'length' => 64,
  199. 'not null' => TRUE,
  200. 'default' => '',
  201. ),
  202. 'bundle' => array(
  203. 'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  204. 'type' => 'varchar',
  205. 'length' => 1024,
  206. 'not null' => TRUE,
  207. 'default' => '',
  208. ),
  209. 'label' => array(
  210. 'description' => 'The human-readable name of this bundle.',
  211. 'type' => 'varchar',
  212. 'length' => 255,
  213. 'not null' => TRUE,
  214. 'default' => '',
  215. ),
  216. 'weight' => array(
  217. 'type' => 'int',
  218. 'not null' => TRUE,
  219. 'default' => 0,
  220. 'size' => 'tiny',
  221. 'description' => 'The weight of this tripal data type in relation to others.',
  222. ),
  223. 'data' => array(
  224. 'type' => 'text',
  225. 'not null' => FALSE,
  226. 'size' => 'big',
  227. 'serialize' => TRUE,
  228. 'description' => 'A serialized array of additional data related to this tripal data type.',
  229. ),
  230. ) + entity_exportable_schema_fields(),
  231. 'primary key' => array('id'),
  232. 'unique keys' => array(
  233. 'bundle' => array('bundle'),
  234. ),
  235. );
  236. return $schema;
  237. }
  238. /**
  239. * Links Biological Data Entities to the chado "base" table the data is stored in.
  240. * This is where we would specify that a particular gene maps to the record in the
  241. * chado.feature table with a feature_id=2432;
  242. */
  243. function tripal_entities_chado_entity_schema() {
  244. $schema = array(
  245. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  246. 'fields' => array(
  247. 'chado_entity_id' => array(
  248. 'description' => 'The primary identifier for this table.',
  249. 'type' => 'serial',
  250. 'unsigned' => TRUE,
  251. 'not null' => TRUE,
  252. ),
  253. 'entity_id' => array(
  254. 'description' => 'The unique entity id.',
  255. 'type' => 'int',
  256. 'not null' => TRUE,
  257. ),
  258. 'record_id' => array(
  259. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  260. 'type' => 'int',
  261. 'not null' => TRUE,
  262. ),
  263. 'data_table' => array(
  264. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  265. 'type' => 'varchar',
  266. 'length' => 128,
  267. 'not null' => TRUE,
  268. 'default' => '',
  269. ),
  270. 'type_table' => array(
  271. 'description' => 'Sometimes the record in the data table doesn’t have a field that specifies the record type. For example, an analysis type is stored in the analysisprop table. If the data_table does have a type field then this value will be the same as the data_table.',
  272. 'type' => 'varchar',
  273. 'length' => 128,
  274. 'not null' => TRUE,
  275. 'default' => '',
  276. ),
  277. 'field' => array(
  278. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  279. 'type' => 'varchar',
  280. 'length' => 128,
  281. 'not null' => FALSE,
  282. 'default' => ''
  283. ),
  284. ),
  285. 'indexes' => array(
  286. 'record_id' => array('record_id'),
  287. 'entity_id' => array('entity_id'),
  288. 'data_table' => array('data_table'),
  289. ),
  290. 'unique keys' => array(
  291. 'record' => array('data_table', 'record_id'),
  292. 'entity_id' => array('entity_id'),
  293. ),
  294. 'primary key' => array('chado_entity_id'),
  295. );
  296. return $schema;
  297. }