tripal_chado.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. function tripal_chado_install() {
  3. // Unfortunately, some Chado base tables do not have a type_id, so we must
  4. // take special action for those tables. These include: organism and
  5. // analysis. Until we can find an appropriate controlled vocabulary
  6. // that is well supported by the community with types for these tables we
  7. // will have to use in-house terms.
  8. // Add a term to be used for an inherent 'type_id' for the organism table.
  9. tripal_insert_cvterm(array(
  10. 'id' => 'local:organism',
  11. 'name' => 'organism',
  12. 'definition' => 'An individual form of life, such as a bacterium, protist, ' .
  13. 'fungus, plant, or animal, composed of a single cell or a complex of cells ' .
  14. 'in which organelles or organs work together to carry out the various ' .
  15. 'processes of life. (American Heritage® Dictionary of the English ' .
  16. 'Language, Fifth Edition. Copyright © 2011 by Houghton Mifflin ' .
  17. 'Harcourt Publishing Company).',
  18. 'cv_name' => 'local',
  19. ));
  20. // Add a term to be used for an inherent 'type_id' for the organism table.
  21. tripal_insert_cvterm(array(
  22. 'id' => 'local:analysis',
  23. 'name' => 'analysis',
  24. 'definition' => 'A process as a method of studying the nature of something ' .
  25. 'or of determining its essential features and their relations. ' .
  26. '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
  27. 'Dictionaries Ltd).',
  28. 'cv_name' => 'local',
  29. ));
  30. tripal_insert_cvterm(array(
  31. 'id' => 'local:project',
  32. 'name' => 'project',
  33. 'definition' => 'A plan or proposal for accomplishing something. ' .
  34. '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
  35. 'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
  36. 'cv_name' => 'local',
  37. ));
  38. // We want to provide a set of commonly used entity types by default. This
  39. // way when a user first installs Tripal there are some commonly used
  40. // formats.
  41. module_load_include('inc', 'tripal_entities', 'api/tripal_entities.api');
  42. module_load_include('inc', 'tripal_entities', 'includes/tripal_entities.admin');
  43. // Create the 'Organism' entity type. This uses the local:organism term.
  44. $error = '';
  45. $term = array('name' => 'organism', 'cv_id' => array('name' => 'local'));
  46. $cvterm = chado_generate_var('cvterm', $term);
  47. if (!tripal_create_entity_type($cvterm, $error)) {
  48. throw new Exception($error);
  49. }
  50. // Create the 'Analysis' entity type. This uses the local:analysis term.
  51. $error = '';
  52. $term = array('name' => 'analysis', '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 'Project' entity type. This uses the local:project term.
  58. $error = '';
  59. $term = array('name' => 'project', '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. }
  65. /**
  66. * Implements hook_schema().
  67. */
  68. function tripal_chado_schema() {
  69. // Links TripalEntity entities to the chado record.
  70. $schema['chado_entity'] = tripal_chado_chado_entity_schema();
  71. return $schema;
  72. }
  73. /**
  74. * @section
  75. * Schema Definitions.
  76. */
  77. /**
  78. * Links Biological Data Entities to the chado "base" table the data is stored in.
  79. * This is where we would specify that a particular gene maps to the record in the
  80. * chado.feature table with a feature_id=2432;
  81. */
  82. function tripal_chado_chado_entity_schema() {
  83. $schema = array(
  84. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  85. 'fields' => array(
  86. 'chado_entity_id' => array(
  87. 'description' => 'The primary identifier for this table.',
  88. 'type' => 'serial',
  89. 'unsigned' => TRUE,
  90. 'not null' => TRUE,
  91. ),
  92. 'entity_id' => array(
  93. 'description' => 'The unique entity id.',
  94. 'type' => 'int',
  95. 'not null' => TRUE,
  96. ),
  97. 'record_id' => array(
  98. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  99. 'type' => 'int',
  100. 'not null' => TRUE,
  101. ),
  102. 'data_table' => array(
  103. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  104. 'type' => 'varchar',
  105. 'length' => 128,
  106. 'not null' => TRUE,
  107. 'default' => '',
  108. ),
  109. 'type_table' => array(
  110. '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.',
  111. 'type' => 'varchar',
  112. 'length' => 128,
  113. 'not null' => TRUE,
  114. 'default' => '',
  115. ),
  116. 'field' => array(
  117. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  118. 'type' => 'varchar',
  119. 'length' => 128,
  120. 'not null' => FALSE,
  121. 'default' => ''
  122. ),
  123. ),
  124. 'indexes' => array(
  125. 'record_id' => array('record_id'),
  126. 'entity_id' => array('entity_id'),
  127. 'data_table' => array('data_table'),
  128. ),
  129. 'unique keys' => array(
  130. 'record' => array('data_table', 'record_id'),
  131. 'entity_id' => array('entity_id'),
  132. ),
  133. 'primary key' => array('chado_entity_id'),
  134. );
  135. return $schema;
  136. }