'A pattern including tokens that can be used to generate tripal entity titles.', 'url_format' => 'A pattern including tokens that can be used to generate tripal entity url aliases.', 'description' => 'The description of a Tripal Entity type/bundle.' ); foreach ($vars as $name => $description) { $record = array( 'name' => $name, 'description' => $description ); drupal_write_record('tripal_variables', $record); } // Unfortunately, some Chado base tables do not have a type_id, so we must // take special action for those tables. These include: organism and // analysis. Until we can find an appropriate controlled vocabulary // that is well supported by the community with types for these tables we // will have to use in-house terms. // Add a term to be used for an inherent 'type_id' for the organism table. tripal_insert_cvterm(array( 'id' => 'local:organism', 'name' => 'organism', 'definition' => 'An individual form of life, such as a bacterium, protist, ' . 'fungus, plant, or animal, composed of a single cell or a complex of cells ' . 'in which organelles or organs work together to carry out the various ' . 'processes of life. (American Heritage® Dictionary of the English ' . 'Language, Fifth Edition. Copyright © 2011 by Houghton Mifflin ' . 'Harcourt Publishing Company).', 'cv_name' => 'local', )); // Add a term to be used for an inherent 'type_id' for the organism table. tripal_insert_cvterm(array( 'id' => 'local:analysis', 'name' => 'analysis', 'definition' => 'A process as a method of studying the nature of something ' . 'or of determining its essential features and their relations. ' . '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' . 'Dictionaries Ltd).', 'cv_name' => 'local', )); tripal_insert_cvterm(array( 'id' => 'local:project', 'name' => 'project', 'definition' => 'A plan or proposal for accomplishing something. ' . '(American Heritage® Dictionary of the English Language, Fifth Edition. ' . 'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).', 'cv_name' => 'local', )); // We want to provide a set of commonly used entity types by default. This // way when a user first installs Tripal there are some commonly used // formats. module_load_include('inc', 'tripal_entities', 'api/tripal_entities.api'); module_load_include('inc', 'tripal_entities', 'includes/tripal_entities.admin'); // Create the 'Organism' entity type. This uses the local:organism term. $error = ''; $term = array('name' => 'organism', 'cv_id' => array('name' => 'local')); $cvterm = chado_generate_var('cvterm', $term); if (!tripal_create_entity_type($cvterm, $error)) { throw new Exception($error); } // Create the 'Analysis' entity type. This uses the local:analysis term. $error = ''; $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local')); $cvterm = chado_generate_var('cvterm', $term); if (!tripal_create_entity_type($cvterm, $error)) { throw new Exception($error); } // Create the 'Project' entity type. This uses the local:project term. $error = ''; $term = array('name' => 'project', 'cv_id' => array('name' => 'local')); $cvterm = chado_generate_var('cvterm', $term); if (!tripal_create_entity_type($cvterm, $error)) { throw new Exception($error); } } /** * Implements hook_schema(). */ function tripal_entities_schema() { // Adds a table for managing TripalEntity entities. $schema['tripal_entity'] = tripal_entities_tripal_entity_schema(); // Adds a table for managing the TripalEntity entity types (bundles). $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema(); // Adds a table for additional information related to bundles. $schema['tripal_bundle_variables'] = tripal_entities_tripal_bundle_variables_schema(); // Links TripalEntity entities to the chado record. $schema['chado_entity'] = tripal_entities_chado_entity_schema(); return $schema; } /** * Implements hook_uninstall(). * * At uninstall time we'll notify field.module that the entity was deleted * so that attached fields can be cleaned up. */ function tripal_entities_uninstall() { // $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1)); // foreach ($terms as $term) { // $bundle_id = 'bio-data_' . $term->cvterm_id; // field_attach_delete_bundle('TripalEntity', $bundle_id); // } } /** * @section * Schema Definitions. */ /** * The base table for Biological Data Entities. * * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then * this table will have 15 records and include both genes and mRNA's. */ function tripal_entities_tripal_entity_schema() { $schema = array( 'description' => 'The base table for Tripal Vocabulary-based entities.', 'fields' => array( 'id' => array( 'description' => 'The primary identifier for a vocabulary entity.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'type' => array( 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).', 'type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => '', ), 'bundle' => array( '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.', 'type' => 'varchar', 'length' => 1024, 'not null' => TRUE, 'default' => '', ), 'cvterm_id' => array( 'description' => 'The cvterm_id for the type of entity. This cvterm_id should match a record in the Chado cvterm table.', 'type' => 'int', 'not null' => TRUE, ), 'title' => array( 'description' => 'The title of this node, always treated as non-markup plain text.', 'type' => 'text', 'not null' => TRUE, 'default' => '', ), 'uid' => array( 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'status' => array( 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).', 'type' => 'int', 'not null' => TRUE, 'default' => 1, ), 'created' => array( 'description' => 'The Unix timestamp when the node was created.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'changed' => array( 'description' => 'The Unix timestamp when the node was most recently saved.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'indexes' => array( 'cvterm_id' => array('cvterm_id'), 'entity_changed' => array('changed'), 'entity_created' => array('created'), 'type' => array('type'), 'uid' => array('uid'), ), 'unique keys' => array( ), 'primary key' => array('id'), ); return $schema; } /** * The base table for Biological Data Type Entites. * This table contains a list of Biological Data Types. * For the example above (5 genes and 10 mRNAs), there would only be two records in * this table one for "gene" and another for "mRNA". */ function tripal_entities_tripal_bundle_schema() { $schema = array( 'description' => 'Stores information about defined tripal data types.', 'fields' => array( 'id' => array( 'type' => 'serial', 'not null' => TRUE, 'description' => 'Primary Key: Unique Chado data type identifier.', ), 'type' => array( 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).', 'type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => '', ), 'bundle' => array( '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.', 'type' => 'varchar', 'length' => 1024, 'not null' => TRUE, 'default' => '', ), 'label' => array( 'description' => 'The human-readable name of this bundle.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'weight' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny', 'description' => 'The weight of this tripal data type in relation to others.', ), 'data' => array( 'type' => 'text', 'not null' => FALSE, 'size' => 'big', 'serialize' => TRUE, 'description' => 'A serialized array of additional data related to this tripal data type.', ), ) + entity_exportable_schema_fields(), 'primary key' => array('id'), 'unique keys' => array( 'bundle' => array('bundle'), ), ); return $schema; } /** * Additional Tripal Bundle Information. * * This table is used for storing any additonal information describing * a tripal bundle. For example, this is a good place to store title/url formats. */ function tripal_entities_tripal_bundle_variables_schema() { $schema = array( 'description' => 'This table is used for storing any additonal information describing a tripal bundle. For example, this is a good place to store title/url formats.', 'fields' => array ( 'bundle_variable_id' => array ( 'type' => 'serial', 'not null' => TRUE, ), 'bundle_id' => array ( 'type' => 'int', 'not null' => TRUE, ), 'variable_id' => array ( 'type' => 'int', 'not null' => TRUE, ), 'value' => array ( 'type' => 'text', 'not null' => FALSE, ), 'rank' => array ( 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array ( 0 => 'bundle_variable_id', ), 'unique keys' => array ( 'tripal_bundle_variables_c1' => array ( 0 => 'bundle_id', 1 => 'variable_id', 2 => 'rank', ), ), 'indexes' => array ( 'tripal_bundle_variables_idx1' => array ( 0 => 'variable_id', ), ), 'foreign keys' => array ( 'tripal_variables' => array ( 'table' => 'tripal_variables', 'columns' => array ( 'variable_id' => 'variable_id', ), ), ), ); return $schema; } /** * Links Biological Data Entities to the chado "base" table the data is stored in. * This is where we would specify that a particular gene maps to the record in the * chado.feature table with a feature_id=2432; */ function tripal_entities_chado_entity_schema() { $schema = array( 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado', 'fields' => array( 'chado_entity_id' => array( 'description' => 'The primary identifier for this table.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'entity_id' => array( 'description' => 'The unique entity id.', 'type' => 'int', 'not null' => TRUE, ), 'record_id' => array( 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).', 'type' => 'int', 'not null' => TRUE, ), 'data_table' => array( 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)', 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', ), 'type_table' => array( '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.', 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', ), 'field' => array( 'description' => 'The name of the field in the typetable that contains the cvterm record.', 'type' => 'varchar', 'length' => 128, 'not null' => FALSE, 'default' => '' ), ), 'indexes' => array( 'record_id' => array('record_id'), 'entity_id' => array('entity_id'), 'data_table' => array('data_table'), ), 'unique keys' => array( 'record' => array('data_table', 'record_id'), 'entity_id' => array('entity_id'), ), 'primary key' => array('chado_entity_id'), ); return $schema; }