123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404 |
- <?php
- /**
- * Implements hook_field_create_info().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_create_tripalfields($entity_type, $bundle) {
- // Get the table this bundle is mapped to.
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
- // Get the details about the mapping of this bundle to the Chado table:
- $details = array(
- 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
- 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
- 'chado_table' => $mapped_table->chado_table,
- 'chado_type_table' => $mapped_table->chado_table,
- 'chado_type_column' => $mapped_table->chado_field,
- );
- $info = array();
- // Create the fields for each column in the table.
- tripal_chado_create_tripalfields_base($info, $details, $entity_type, $bundle);
- // Create custom fields.
- tripal_chado_create_tripalfields_custom($info, $details, $entity_type, $bundle);
- // Create fields for linking tables.
- tripal_chado_create_tripalfields_linker($info, $details, $entity_type, $bundle);
- return $info;
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_create_tripalfields_base(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- // Iterate through the columns of the table and see if fields have been
- // created for each one. If not, then create them.
- $schema = chado_get_schema($table_name);
- if (!$schema) {
- return;
- }
- // Get the list of columns for this table and create a new field for each one.
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- $field_name = $table_name . '__' . $column_name;
- // Skip fields with a custom field:
- if ($field_name == 'dbxref_id' or $field_name == 'organism_id') {
- continue;
- }
- if ($table_name == 'feature' and ($field_name == 'md5checksum' or
- $field_name == 'residues' or $field_name == 'seqlen')) {
- continue;
- }
- if ($table_name == 'organism' and ($field_name == 'type_id')) {
- continue;
- }
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field.
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
- // Set some defaults for the field.
- $base_info = array(
- 'field_name' => $field_name,
- 'type' => '',
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => $column_name,
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, $column_name),
- ),
- );
- // Alter the field info array depending on the column details.
- switch($details['type']) {
- case 'char':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = $details['length'];
- break;
- case 'varchar':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = $details['length'];
- break;
- case 'text':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = 17179869184;
- $base_info['settings']['text_processing'] = 1;
- break;
- case 'blob':
- // not sure how to support a blob field.
- continue;
- break;
- case 'int':
- $base_info['type'] = 'number_integer';
- break;
- case 'float':
- $base_info['type'] = 'number_float';
- $base_info['settings']['precision'] = 10;
- $base_info['settings']['scale'] = 2;
- $base_info['settings']['decimal_separator'] = '.';
- break;
- case 'numeric':
- $base_info['type'] = 'number_decimal';
- break;
- case 'serial':
- // Serial fields are most likely not needed as a field.
- break;
- case 'boolean':
- $base_info['type'] = 'list_boolean';
- $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
- break;
- case 'datetime':
- // Use the Drupal Date and Date API to create the field/widget
- $base_info['type'] = 'datetime';
- break;
- }
- // Set some default semantic web information
- if ($column_name == 'uniquename') {
- $base_info['settings']['text_processing'] = 0;
- }
- //
- // PUB TABLE
- //
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $base_info['type'] = 'text';
- $base_info['settings']['text_processing'] = 0;
- }
- //
- // ANALYSIS TABLE
- //
- elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $base_info['type'] = 'text';
- $base_info['settings']['text_processing'] = 0;
- }
- $info[$field_name] = $base_info;
- }
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = $table_name . '__dbxref_id';
- $field_type = 'chado_base__dbxref_id';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'dbxref_id',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
- ),
- );
- }
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
- $field_name = $table_name . '__organism_id';
- $field_type = 'chado_base__organism_id';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'organism_id',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'organism_id'),
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = $table_name . '__md5checksum';
- $field_type = 'chado_feature__md5checksum';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'md5checksum',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'md5checksum'),
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'feature__residues';
- $field_type = 'chado_feature__residues';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'residues',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'residues'),
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'feature__seqlen';
- $field_type = 'chado_feature__seqlen';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $table_name,
- 'chado_column' => 'seqlen',
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'seqlen'),
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'gene_transcripts';
- $field_type = 'chado_gene__transcripts';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $rel_table,
- 'chado_column' => 'md5checksum',
- 'base_table' => $table_name,
- 'semantic_web' => 'SO:0000673',
- ),
- );
- }
- // ORGANISM TYPE_ID
- if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- $field_name = 'organism__type_id';
- $field_type = 'chado_organism__type_id';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => 'organism',
- 'chado_column' => 'type_id',
- 'semantic_web' => tripal_get_chado_semweb_term('organism', 'type_id'),
- ),
- );
- }
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_create_tripalfields_linker(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- // CONTACTS
- $contact_table = $table_name . '_contact';
- if (chado_table_exists($contact_table)) {
- $schema = chado_get_schema($contact_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_contact';
- $field_type = 'chado_linker__contact';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $contact_table,
- 'chado_column' => 'contact_id',
- 'base_table' => $table_name,
- 'semantic_web' => 'local:contact'
- ),
- );
- }
- // CVTERM
- $cvterm_table = $table_name . '_cvterm';
- if (chado_table_exists($cvterm_table)) {
- $field_name = $table_name . '_cvterm';
- $field_type = 'chado_linker__cvterm_adder';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $dbxref_table = $table_name . '_dbxref';
- $schema = chado_get_schema($dbxref_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_dbxref';
- $field_type = 'chado_linker__dbxref';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $dbxref_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'SBO:0000554',
- ),
- );
- }
- // EXPRESSION
- $expression_table = $table_name . '_expression';
- if (chado_table_exists($expression_table)) {
- $schema = chado_get_schema($expression_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_expression';
- $field_type = 'chado_linker__expression';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $expression_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'local:expression',
- ),
- );
- }
- // FEATURELOC
- if ($table_name == 'feature') {
- $schema = chado_get_schema('featureloc');
- $pkey = $schema['primary key'][0];
- $field_name = 'featureloc';
- $field_type = 'chado_linker__featureloc';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => 'featureloc',
- 'chado_column' => $pkey,
- 'base_table' => 'feature',
- 'semantic_web' => 'SO:position_of',
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $schema = chado_get_schema($genotype_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_genotype';
- $field_type = 'chado_linker__genotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $genotype_table,
- 'chado_column' => $pkey,
- 'semantic_web' => 'SO:0001027',
- 'base_table' => $table_name,
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $schema = chado_get_schema($phenotype_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_phenotype';
- $field_type = 'chado_linker__phenotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $phenotype_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'SBO:0000358',
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- $field_name = $table_name . 'prop';
- $field_type = 'chado_linker__prop_adder';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- ),
- );
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $schema = chado_get_schema($pub_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_pub';
- $field_type = 'chado_linker__pub';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $pub_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'schema:publication',
- ),
- );
- }
- // RELATIONSHIPS
- // If the linker table does not exists then we don't want to add attach.
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table)) {
- $schema = chado_get_schema($rel_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_relationship';
- $field_type = 'chado_linker__relationship';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $rel_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'SBO:0000374',
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $schema = chado_get_schema($syn_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_synonym';
- $field_type = 'chado_linker__synonym';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $syn_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- 'semantic_web' => 'schema:alternateName',
- ),
- );
- }
- }
- /**
- * Impelments hook_create_tripalfield_instance().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_create_tripalfield_instance($entity_type, $bundle) {
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
- // Get the details about the mapping of this bundle to the Chado table:
- $details = array(
- 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
- 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
- 'chado_table' => $mapped_table->chado_table,
- 'chado_type_table' => $mapped_table->chado_table,
- 'chado_type_column' => $mapped_table->chado_field,
- );
- tripal_chado_create_tripalfield_instance_base($info, $entity_type, $bundle, $details);
- tripal_chado_create_tripalfield_instance_custom($info, $entity_type, $bundle, $details);
- tripal_chado_create_tripalfield_instance_linker($info, $entity_type, $bundle, $details);
- return $info;
- }
- /**
- * Helper function for the hook_create_tripalfield_instance().
- *
- * Add the field instances that corresond to the columns of the base table.
- *
- * @param $entity_type
- * @param $bundle
- * @param $details
- */
- function tripal_chado_create_tripalfield_instance_base(&$info, $entity_type, $bundle, $details) {
- $fields = array();
- // Get Chado information
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- // Iterate through the columns of the table and see if fields have been
- // created for each one. If not, then create them.
- $schema = chado_get_schema($table_name);
- if (!$schema) {
- return;
- }
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- $field_name = $table_name . '__' . $column_name;
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field.
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
- $base_info = array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'settings' => array(),
- ),
- ),
- );
- // Determine if the field is required.
- if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
- $base_info['required'] = TRUE;
- }
- // Alter the field info array depending on the column details.
- switch($details['type']) {
- case 'char':
- $base_info['widget']['type'] = 'text_textfield';
- break;
- case 'varchar':
- $base_info['widget']['type'] = 'text_textfield';
- break;
- case 'text':
- $base_info['widget']['type'] = 'text_textarea';
- $base_info['widget']['settings']['format'] = filter_default_format();
- break;
- case 'blob':
- // not sure how to support a blob field.
- continue;
- break;
- case 'int':
- $base_info['widget']['type'] = 'number';
- break;
- case 'float':
- $base_info['widget']['type'] = 'number';
- break;
- case 'numeric':
- $base_info['widget']['type'] = 'number';
- break;
- case 'serial':
- // Serial fields are most likely not needed as a field.
- break;
- case 'boolean':
- $base_info['widget']['type'] = 'options_onoff';
- break;
- case 'datetime':
- $base_info['widget']['type'] = 'date_select';
- $base_info['widget']['settings']['increment'] = 1;
- $base_info['widget']['settings']['tz_handling'] = 'none';
- $base_info['widget']['settings']['collapsible'] = TRUE;
- // TODO: Add settings so that the minutes increment by 1.
- // And turn off the timezone, as the Chado field doesn't support it.
- break;
- }
- // Set some default semantic web information
- if ($column_name == 'uniquename') {
- $base_info['label'] = 'Identifier';
- $base_info['widget_type'] = 'text_textfield';
- }
- elseif ($base_info['label'] == 'Timeaccessioned') {
- $base_info['label'] = 'Time Accessioned';
- $base_info['description'] = 'Please enter the time that this record was first added to the database.';
- }
- elseif ($base_info['label'] == 'Timelastmodified') {
- $base_info['label'] = 'Time Last Modified';
- $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
- }
- //
- // ORGANISM TABLE
- //
- elseif ($table_name == 'organism' and $column_name == 'comment') {
- $base_info['label'] = 'Description';
- }
- //
- // PUB TABLE
- //
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $base_info['widget_type'] = 'text_textfield';
- }
- //
- // ANALYSIS TABLE
- //
- elseif ($table_name == 'analysis' and $column_name == 'program') {
- $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
- $base_info['label'] = 'Program, Pipeline, Workflow or Method Name.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $base_info['widget_type'] = 'text_textfield';
- $base_info['label'] = 'Source URL';
- $base_info['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
- $base_info['label'] = 'Source Name';
- $base_info['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
- $base_info['label'] = 'Source Version';
- $base_info['description'] = 'If hte source data set has a version include it here.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
- $base_info['label'] = 'Source Version';
- $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'programversion') {
- $base_info['label'] = 'Program Version';
- $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
- }
- //
- // PROJECT TABLE
- //
- elseif ($table_name == 'project' and $column_name == 'description') {
- $base_info['label'] = 'Short Description';
- }
- $info[$field_name] = $base_info;
- }
- }
- /**
- * Helper function for the hook_create_tripalfield_instance().
- *
- * Adds custom fields for base fields. These override the settings provided
- * in the tripal_chado_create_tripalfield_instance_base() function.
- *
- * @param $entity_type
- * @param $bundle
- * @param $details
- */
- function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $bundle, $details) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = $table_name . '__dbxref_id';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Accession',
- 'description' => 'This field specifies the unique stable accession (ID) for
- this record. It requires that this site have a database entry.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_base__dbxref_id_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_base__dbxref_id_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
- $field_name = $table_name . '__organism_id';
- $is_required = FALSE;
- if (array_key_exists('not null', $schema['fields']['organism_id']) and
- $schema['fields']['organism_id']['not null']) {
- $is_required = TRUE;
- }
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Organism',
- 'description' => 'Select an organism.',
- 'required' => $is_required,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_base__organism_id_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_base__organism_id_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = $table_name . '__md5checksum';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence Checksum',
- 'description' => 'The MD5 checksum for the sequence. The checksum here
- will always be unique for the raw unformatted sequence. To verify that the
- sequence has not been corrupted, download the raw sequence and use an MD5 tool
- to calculate the value. If the value calculated is identical the one shown
- here, then the downloaded sequence is uncorrupted.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_feature__md5checksum_widget',
- 'settings' => array(
- 'display_label' => 1,
- 'md5_fieldname' => 'feature__md5checksum',
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_feature__md5checksum_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'feature__residues';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequences',
- 'description' => 'All available sequences for this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_feature__residues_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_feature__residues_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'feature__seqlen';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Raw Sequence Length',
- 'description' => 'The number of residues in the raw sequence. This length
- is only for the assigned raw sequence and does not represent the length of any
- sequences derived from alignments. If this value is zero but aligned sequences
- are present then this record has no official assigned sequence.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_feature__seqlen_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_feature__seqlen_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'gene_transcripts';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Transcripts',
- 'description' => 'These transcripts are associated with this gene.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_gene__transcripts_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_gene__transcripts_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // ORGANISM TYPE_ID
- if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- $field_name = 'organism__type_id';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Infraspecific Type',
- 'description' => 'The Infraspecific Type.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_organism__type_id_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_organism__type_id_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- /**
- *
- * @param unknown $entity_type
- * @param unknown $bundle
- * @param unknown $details
- */
- function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $bundle, $details) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cv_id = $details['chado_cv_id'];
- $cvterm_id = $details['chado_cvterm_id'];
- // CONTACTS
- $contact_table = $table_name . '_contact';
- if (chado_table_exists($contact_table)) {
- $field_name = $table_name . '_contact';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Contacts',
- 'description' => 'An individual, organization or entity that has had
- some responsibility for the creation, delivery or maintenance of
- the associated data.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__contact_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__contact_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // CVTERM
- $cvterm_table = $table_name . '_cvterm';
- if (chado_table_exists($cvterm_table)) {
- $field_name = $table_name . '_cvterm';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Add Annotation Types',
- 'description' => 'Add additional annotations types to this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__cvterm_adder_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__cvterm_adder_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $field_name = $table_name . '_dbxref';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Cross References',
- 'description' => 'The IDs where this record may be available in other external online databases.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__dbxref_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__dbxref_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // EXPRESSION
- $expression_table = $table_name . '_expression';
- if (chado_table_exists($expression_table)) {
- $field_name = $table_name . '_expression';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Expression',
- 'description' => 'Information about the expression of this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__expression_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__expression_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURELOC
- if ($table_name == 'feature') {
- $field_name = 'featureloc';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Aligned Locations',
- 'description' => 'The locations on other genomic sequences where this
- record has been aligned.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__featureloc_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__featureloc_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $field_name = $table_name . '_genotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Genotypes',
- 'description' => 'The genotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__genotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__genotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $field_name = $table_name . '_phenotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Phenotypes',
- 'description' => 'The phenotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__phenotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__phenotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- $field_name = $table_name . 'prop';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Add Properties',
- 'description' => 'Add additional property types to this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__prop_adder_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__prop_adder_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $field_name = $table_name . '_pub';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Publications',
- 'description' => 'This record has been referenced or is sourced from
- these publications.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__pub_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__pub_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // RELATIONSHIPS
- // If the linker table does not exists then we don't want to add attach.
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table)) {
- $field_name = $table_name . '_relationship';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Relationships',
- 'description' => 'Other records with relationships to this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__relationship_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__relationship_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $field_name = $table_name . '_synonym';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Synonyms',
- 'description' => 'Alternate names, aliases or synonyms for this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__synonym_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__synonym_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- *
- * The field_ui_field_overview_form is used for ordering and configuring the
- * fields attached to an entity.
- *
- * This function removes the property adder field as that is really not meant
- * for users to show or manage.
- */
- function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
- // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
- // on the add/edit form of an entity for adding new property fields.
- $fields_names = element_children($form['fields']);
- foreach ($fields_names as $field_name) {
- $field_info = field_info_field($field_name);
- if ($field_info['type'] == 'kvproperty_adder') {
- unset($form['fields'][$field_name]);
- }
- if ($field_info['type'] == 'cvterm_class_adder') {
- unset($form['fields'][$field_name]);
- }
- }
- }
|