tripal_chado.install 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // For the TripalBundle entities we will want to associate the cvterm_id,
  39. // and the chado table and field that it maps to. We will use a few
  40. // variables to do this:
  41. tripal_insert_variable('chado_cvterm_id', 'The cvterm_id that a TripalBundle maps to.');
  42. tripal_insert_variable('chado_table', 'The name of the table to which a TripalBundle maps.');
  43. tripal_insert_variable('chado_column', 'The name of the column within the table that a TripalBundle maps to.');
  44. // We want to provide a set of commonly used entity types by default. This
  45. // way when a user first installs Tripal there are some commonly used
  46. // formats.
  47. module_load_include('inc', 'tripal_entities', 'api/tripal_entities.api');
  48. module_load_include('inc', 'tripal_entities', 'includes/tripal_entities.admin');
  49. // Create the 'Organism' entity type. This uses the local:organism term.
  50. $error = '';
  51. $term = array('name' => 'organism', 'cv_id' => array('name' => 'local'));
  52. $cvterm = chado_generate_var('cvterm', $term);
  53. if (!tripal_create_bundle('local', 'organism', 'organism', $error)) {
  54. throw new Exception($error);
  55. }
  56. // Create the 'Analysis' entity type. This uses the local:analysis term.
  57. $error = '';
  58. $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local'));
  59. $cvterm = chado_generate_var('cvterm', $term);
  60. if (!tripal_create_bundle('local', 'analysis', 'analysis', $error)) {
  61. throw new Exception($error);
  62. }
  63. // Create the 'Project' entity type. This uses the local:project term.
  64. $error = '';
  65. $term = array('name' => 'project', 'cv_id' => array('name' => 'local'));
  66. $cvterm = chado_generate_var('cvterm', $term);
  67. if (!tripal_create_bundle('local', 'project', 'project', $error)) {
  68. throw new Exception($error);
  69. }
  70. }
  71. /**
  72. * Implements hook_schema().
  73. */
  74. function tripal_chado_schema() {
  75. // Links TripalEntity entities to the chado record.
  76. $schema['chado_entity'] = tripal_chado_chado_entity_schema();
  77. return $schema;
  78. }
  79. /**
  80. * @section
  81. * Schema Definitions.
  82. */
  83. /**
  84. * Links Biological Data Entities to the chado "base" table the data is stored in.
  85. * This is where we would specify that a particular gene maps to the record in the
  86. * chado.feature table with a feature_id=2432;
  87. */
  88. function tripal_chado_chado_entity_schema() {
  89. $schema = array(
  90. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  91. 'fields' => array(
  92. 'chado_entity_id' => array(
  93. 'description' => 'The primary identifier for this table.',
  94. 'type' => 'serial',
  95. 'unsigned' => TRUE,
  96. 'not null' => TRUE,
  97. ),
  98. 'entity_id' => array(
  99. 'description' => 'The unique entity id.',
  100. 'type' => 'int',
  101. 'not null' => TRUE,
  102. ),
  103. 'record_id' => array(
  104. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  105. 'type' => 'int',
  106. 'not null' => TRUE,
  107. ),
  108. 'data_table' => array(
  109. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  110. 'type' => 'varchar',
  111. 'length' => 128,
  112. 'not null' => TRUE,
  113. 'default' => '',
  114. ),
  115. 'type_table' => array(
  116. '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.',
  117. 'type' => 'varchar',
  118. 'length' => 128,
  119. 'not null' => TRUE,
  120. 'default' => '',
  121. ),
  122. 'field' => array(
  123. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  124. 'type' => 'varchar',
  125. 'length' => 128,
  126. 'not null' => FALSE,
  127. 'default' => ''
  128. ),
  129. ),
  130. 'indexes' => array(
  131. 'record_id' => array('record_id'),
  132. 'entity_id' => array('entity_id'),
  133. 'data_table' => array('data_table'),
  134. ),
  135. 'unique keys' => array(
  136. 'record' => array('data_table', 'record_id'),
  137. 'entity_id' => array('entity_id'),
  138. ),
  139. 'primary key' => array('chado_entity_id'),
  140. );
  141. return $schema;
  142. }