12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961 |
- <?php
- /**
- * Implements hook_bundle_fields_info().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_bundle_fields_info($entity_type, $bundle) {
- $chado_bundle = db_select('chado_bundle', 'cb')
- ->fields('cb')
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchObject();
- // Get the details about the mapping of this bundle to the Chado table:
- $details = array(
- 'chado_cvterm_id' => $chado_bundle->type_id,
- 'chado_table' => $chado_bundle->data_table,
- 'chado_type_table' => $chado_bundle->type_linker_table,
- 'chado_type_column' => $chado_bundle->type_column,
- );
- $info = array();
- // Create the fields for each column in the table.
- tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
- // Create custom fields.
- tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
- // Create fields for linking tables.
- tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
- return $info;
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $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;
- }
- $pkey = $schema['primary key'][0];
- // 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) {
- // Skip the source columns in the analysis table. We have a custom
- // field for those columns
- if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
- $column_name == 'sourceversion' or $column_name == 'sourcename')) {
- continue;
- }
- // Don't create base fields for the primary key and the type_id field.
- if ($column_name == $pkey or $column_name == $type_field) {
- continue;
- }
- $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
- if (!$cvterm) {
- tripal_report_error('tripal', TRIPAL_ERROR,
- 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
- array('%table_name' => $table_name, '%column_name' => $column_name));
- drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
- array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
- continue;
- }
- $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
- $field_name = substr($field_name, 0, 32);
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field that will always be custom
- if (($table_name == $type_table and $column_name == $type_field) or
- $column_name == 'type_id') {
- 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',
- 'sql' => array(),
- ),
- );
- // 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;
- }
- $info[$field_name] = $base_info;
- }
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE TYPE_ID
- // Exclude the type_id field on base tables where content types are mapped
- // by the type_id field or on the organism table where the type_id is mean
- // as an infraspecific name type.
- if (array_key_exists('type_id', $schema['fields']) and
- $table_name != 'organism' and $type_field != 'type_id') {
- $field_name = 'schema__additional_type';
- $field_type = 'schema__additional_type';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and
- array_key_exists('organism_id', $schema['fields'])) {
- $field_name = 'obi__organism';
- $field_type = 'obi__organism';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = 'data__accession';
- $field_type = 'data__accession';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_checksum';
- $field_type = 'data__sequence_checksum';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'data__sequence';
- $field_type = 'data__sequence';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_length';
- $field_type = 'data__sequence_length';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'so__transcript';
- $field_type = 'so__transcript';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // ORGANISM TYPE_ID
- // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- // $field_name = 'taxarank__infraspecific_taxon';
- // $field_type = 'taxarank__infraspecific_taxon';
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'type' => $field_type,
- // 'cardinality' => 1,
- // 'locked' => FALSE,
- // 'storage' => array(
- // 'type' => 'field_chado_storage',
- // ),
- // 'settings' => array(
- // ),
- // );
- // }
- // FEATUREMAP UNITTYPE_ID
- if ($table_name == 'featuremap') {
- $field_name = 'uo__unit';
- $field_type = 'uo__unit';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // Analysis source
- if ($table_name == 'analysis') {
- $field_name = 'local__source_data';
- $field_type = 'local__source_data';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // Add an image field to the Organism type. This is a Drupal field and
- // not stored in Chado, but is used for backwards compatibility.
- if ($table_name == 'organism') {
- $field_name = 'data__image';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => 'image',
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_sql_storage',
- ),
- );
- }
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $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',
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $field_name = 'sbo__database_cross_reference';
- $field_type = 'sbo__database_cross_reference';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // EXPRESSION
- // TODO: this should only show up on gene or mRNA bunldes, not every feature.
- // $expression_table = $table_name . '_expression';
- // if (chado_table_exists($expression_table)) {
- // $field_name = 'go__gene_expression';
- // $field_type = 'go__gene_expression';
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'type' => $field_type,
- // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- // 'locked' => FALSE,
- // 'storage' => array(
- // 'type' => 'field_chado_storage',
- // ),
- // );
- // }
- // FEATURELOC
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_coordinates';
- $field_type = 'data__sequence_coordinates';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATUREPOS
- if ($table_name == 'feature') {
- $field_name = 'ogi__location_on_map';
- $field_type = 'ogi__location_on_map';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $field_name = 'so__genotype';
- $field_type = 'so__genotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $field_name = 'sbo__phenotype';
- $field_type = 'sbo__phenotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- // Get the list of existing property types for this table.
- $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
- $props = chado_query($sql);
- while ($prop = $props->fetchObject()) {
- $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
- // The tripal_analysis_KEGG, tripal_analysis_blast, and
- // tripal_analysis_interpro modules store results in the analysisprop
- // table which is probably not the best place, but we don't want to
- // create a ton of fields for this.
- if ($prop_table == 'analysisprop' and
- ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
- $term->dbxref_id->db_id->name == 'tripal')) {
- continue;
- }
- $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
- $field_name = substr($field_name, 0, 32);
- $field_type = 'chado_linker__prop';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $field_name = 'schema__publication';
- $field_type = 'schema__publication';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // PUBLICATIONS (in reverse)
- // We want to be able to show all of the content that a publication links
- // to. The sio__references field does that.
- if ($table_name == 'pub') {
- $field_name = 'sio__references';
- $field_type = 'sio__references';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // 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 = 'sbo__relationship';
- $field_type = 'sbo__relationship';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $field_name = 'schema__alternate_name';
- $field_type = 'schema__alternate_name';
- $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(
- ),
- );
- }
- }
- /**
- * Impelments hook_create_tripalfield_instance().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_bundle_instances_info($entity_type, $bundle) {
- $chado_bundle = db_select('chado_bundle', 'cb')
- ->fields('cb')
- ->condition('bundle_id', $bundle->id)
- ->execute()
- ->fetchObject();
- $details = array(
- 'chado_cvterm_id' => $chado_bundle->type_id,
- 'chado_table' => $chado_bundle->data_table,
- 'chado_type_table' => $chado_bundle->type_linker_table,
- 'chado_type_column' => $chado_bundle->type_column,
- );
- $info = array();
- tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
- tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
- tripal_chado_bundle_instances_info_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_bundle_instances_info_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'];
- $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;
- }
- $pkey = $schema['primary key'][0];
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- // Skip the source columns in the analysis table. We have a custom
- // field for those columns
- if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
- $column_name == 'sourceversion' or $column_name == 'sourcename')) {
- continue;
- }
- // Don't create base fields for the primary key and the type_id field.
- if ($column_name == $pkey or $column_name == $type_field) {
- continue;
- }
- // Skip the type field that will always be custom
- if (($table_name == $type_table and $column_name == $type_field) or
- $column_name == 'type_id') {
- continue;
- }
- $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
- if (!$cvterm) {
- // We already provided an error when creating the base field. So
- // don't create another one here.
- continue;
- }
- $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
- $field_name = substr($field_name, 0, 32);
- // 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,
- 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
- 'term_name' => $cvterm->name,
- 'term_accession' => $cvterm->dbxref_id->accession,
- 'chado_table' => $table_name,
- 'chado_column' => $column_name,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'region' =>'Left',
- '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['display']['default']['label'] = 'above';
- $base_info['widget']['type'] = 'text_textarea';
- $base_info['settings']['text_processing'] = '1';
- $base_info['settings']['format'] = 'full_html';
- 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';
- $base_info['required'] = FALSE;
- 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 == '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.';
- }
- if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
- $column_name == 'sourceversion' or $column_name == 'sourcename')) {
- // Skip the source columns in the analysis table. We have a custom
- // field for those columns
- continue;
- }
- //
- // 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_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE TYPE_ID
- // Exclude the type_id field on base tables where content types are mapped
- // by the type_id field or on the organism table where the type_id is mean
- // as an infraspecific name type.
- if (array_key_exists('type_id', $schema['fields']) and
- $table_name != 'organism' and $type_field != 'type_id') {
- $field_name = 'schema__additional_type';
- $is_required = FALSE;
- if (array_key_exists('not null', $schema['fields']['type_id']) and
- $schema['fields']['type_id']['not null']) {
- $is_required = TRUE;
- }
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Type',
- 'description' => 'Select a type for this record.',
- 'required' => $is_required,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'type_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'schema__additional_type_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'schema__additional_type_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
- $field_name = 'obi__organism';
- $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,
- 'chado_table' => $table_name,
- 'chado_column' => 'organism_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'obi__organism_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'obi__organism_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = 'data__accession';
- $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,
- 'chado_table' => $table_name,
- 'chado_column' => 'dbxref_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__accession_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__accession_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_checksum';
- $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,
- 'chado_table' => $table_name,
- 'chado_column' => 'md5checksum',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_checksum_widget',
- 'settings' => array(
- 'display_label' => 1,
- 'md5_fieldname' => 'feature__md5checksum',
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__sequence_checksum_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'data__sequence';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence',
- 'description' => 'All available sequences for this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $table_name,
- 'chado_column' => 'residues',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'data__sequence_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_length';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => '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,
- 'chado_table' => $table_name,
- 'chado_column' => 'seqlen',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_length_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__sequence_length_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'so__transcript';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Transcripts',
- 'description' => 'Transcripts that are part of this gene.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $rel_table,
- 'chado_column' => '',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'so__transcript_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'so__transcript_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // ORGANISM TYPE_ID
- // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- // $field_name = 'taxarank__infraspecific_taxon';
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'entity_type' => $entity_type,
- // 'bundle' => $bundle->name,
- // 'label' => 'Infraspecific Taxon',
- // 'description' => 'The Infraspecific Taxon.',
- // 'required' => FALSE,
- // 'settings' => array(
- // 'auto_attach' => TRUE,
- // 'chado_table' => 'organism',
- // 'chado_column' => 'type_id',
- // 'base_table' => 'organism',
- // ),
- // 'widget' => array(
- // 'type' => 'taxarank__infraspecific_taxon_widget',
- // 'settings' => array(
- // 'display_label' => 1,
- // ),
- // ),
- // 'display' => array(
- // 'default' => array(
- // 'label' => 'inline',
- // 'type' => 'taxarank__infraspecific_taxon_formatter',
- // 'settings' => array(),
- // ),
- // ),
- // );
- // }
- // FEATURE SEQLEN
- if ($table_name == 'featuremap') {
- $field_name = 'uo__unit';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Units',
- 'description' => 'The map\'s unit type.',
- 'required' => TRUE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'unittype_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'uo__unit_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'uo__unit_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // the analysis source.
- if ($table_name == 'analysis') {
- $field_name = 'local__source_data';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Data Source',
- 'description' => 'The source where data was obtained for this analysis.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'analysis_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'local__source_data_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'local__source_data_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // Add an image field to the Organism type. This is a Drupal field and
- // not stored in Chado, but is used for backwards compatibility.
- if ($table_name == 'organism') {
- $field_name = 'data__image';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Organism Image',
- 'description' => 'An image for the organism',
- 'required' => FALSE,
- 'settings' => array(
- 'term_vocabulary' => 'data',
- 'term_name' => 'Image',
- 'term_accession' => '2968',
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'hidden',
- ),
- ),
- );
- }
- }
- /**
- *
- * @param unknown $entity_type
- * @param unknown $bundle
- * @param unknown $details
- */
- function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $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] = $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Contact',
- 'description' => 'Associates an indviddual or organization with this record',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $contact_table,
- 'base_table' => $table_name,
- 'chado_column' => 'contact_id',
- ),
- 'widget' => array(
- 'type' => 'local__contact_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'local__contact_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $field_name = 'sbo__database_cross_reference';
- $schema = chado_get_schema($dbxref_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Cross Reference',
- 'description' => 'The IDs where this record may be available in other external online databases.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $dbxref_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__database_cross_reference_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'sbo__database_cross_reference_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // EXPRESSION
- // TODO: this should only show up on gene or mRNA and the GO must be
- // laoded or this field will crash things.
- // $expression_table = $table_name . '_expression';
- // if (chado_table_exists($expression_table)) {
- // $field_name = 'go__gene_expression';
- // $schema = chado_get_schema($expression_table);
- // $pkey = $schema['primary key'][0];
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'entity_type' => $entity_type,
- // 'bundle' => $bundle->name,
- // 'label' => 'Gene expression',
- // 'description' => 'Information about the expression of this record.',
- // 'required' => FALSE,
- // 'settings' => array(
- // 'auto_attach' => FALSE,
- // 'chado_table' => $expression_table,
- // 'chado_column' => $pkey,
- // 'base_table' => $table_name,
- // ),
- // 'widget' => array(
- // 'type' => 'go__gene_expression_widget',
- // 'settings' => array(
- // 'display_label' => 1,
- // ),
- // ),
- // 'display' => array(
- // 'default' => array(
- // 'label' => 'above',
- // 'type' => 'go__gene_expression_formatter',
- // 'settings' => array(),
- // ),
- // ),
- // );
- // }
- // FEATURELOC
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_coordinates';
- $schema = chado_get_schema('featureloc');
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence Coordinates',
- 'description' => 'The locations on other genomic sequences where this
- record has been aligned.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => 'featureloc',
- 'chado_column' => $pkey,
- 'base_table' => 'feature',
- ),
- 'widget' => array(
- 'type' => 'data__sequence_coordinates_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'data__sequence_coordinates_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATUREPOS
- if ($table_name == 'feature') {
- $field_name = 'ogi__location_on_map';
- $schema = chado_get_schema('featurepos');
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Location on Map',
- 'description' => 'The positions on a genetic map.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => 'featurepos',
- 'chado_column' => $pkey,
- 'base_table' => 'feature',
- ),
- 'widget' => array(
- 'type' => 'ogi__location_on_map_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'ogi__location_on_map_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $field_name = 'so__genotype';
- $schema = chado_get_schema($genotype_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Genotype',
- 'description' => 'The genotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $genotype_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'so__genotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'so__genotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $field_name = 'sbo__phenotype';
- $schema = chado_get_schema($phenotype_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Phenotype',
- 'description' => 'The phenotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $phenotype_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__phenotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'sbo__phenotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- $tschema = chado_get_schema($table_name);
- $schema = chado_get_schema($prop_table);
- $tpkey = $tschema['primary key'][0];
- $pkey = $schema['primary key'][0];
- // Get the list of existing property types for this table.
- $args = array();
- $sql = "
- SELECT DISTINCT P.type_id
- FROM {" . $prop_table . "} P
- ";
- if ($type_field) {
- $sql .= "
- INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
- WHERE T.type_id = :cvterm_id
- ";
- $args[':cvterm_id'] = $cvterm_id;
- }
- $props = chado_query($sql, $args);
- while ($prop = $props->fetchObject()) {
- $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
- // The tripal_analysis_KEGG, tripal_analysis_blast, and
- // tripal_analysis_interpro modules store results in the analysisprop
- // table which is probably not the best place, but we don't want to
- // create a ton of fields for this.
- if ($prop_table == 'analysisprop' and
- ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
- $term->dbxref_id->db_id->name == 'tripal')) {
- continue;
- }
- $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
- $field_name = substr($field_name, 0, 32);
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
- 'description' => $term->definition,
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'term_vocabulary' => $term->dbxref_id->db_id->name,
- 'term_accession' => $term->dbxref_id->accession,
- 'term_name' => $term->name,
- 'base_table' => $table_name,
- 'chado_table' => $prop_table,
- 'chado_column' => $pkey,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__prop_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__prop_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $field_name = 'schema__publication';
- $schema = chado_get_schema($pub_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Publication',
- 'description' => 'This record has been referenced or is sourced from these publications.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $pub_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'schema__publication_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'schema__publication_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PUBLICATIONS (in reverse)
- // We want to be able to show all of the content that a publication links
- // to. The sio__references field does that.
- if ($table_name == 'pub') {
- $field_name = 'sio__references';
- $schema = chado_get_schema($table_name);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'References',
- 'description' => 'Records that are referred to by the publication.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $table_name,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sio__references_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'sio__references_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 = 'sbo__relationship';
- $schema = chado_get_schema($rel_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Relationship',
- 'description' => 'Other records with relationships to this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $rel_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__relationship_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'sbo__relationship_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $field_name = 'schema__alternate_name';
- $schema = chado_get_schema($syn_table);
- $pkey = $schema['primary key'][0];
- $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,
- 'chado_table' => $syn_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'schema__alternate_name_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'schema__alternate_name_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- /**
- * Implements hook_bundle_create_user_field().
- *
- * A priviledged user has the ability to add new fields to the bundle. The
- * chado_linker__prop and chado_linker__cvterm fields are allowed to be
- * added dynamically by the user. But, Drupal doesn't know how to deal with
- * it, so this function is called for any field attached to a TripalEntity
- * bundle type. Any fields whose TripalField::$module argument is set to
- * 'tripal_chado' and that can be added dynamically will result in a call
- * to this function.
- */
- function tripal_chado_bundle_create_user_field($new_field, $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);
- $chado_table = $mapped_table->chado_table;
- $chado_type_table = $mapped_table->chado_table;
- $chado_type_column = $mapped_table->chado_field;
- // We allow site admins to add new chado_linker__prop fields to an entity.
- // This function will allow us to properly add them. But at this point we
- // don't know the controlled vocabulary term. We'll have to use the
- // defaults and let the user set it using the interface.
- if ($new_field['type'] == 'chado_linker__prop') {
- $table_name = $chado_table . 'prop';
- if (chado_table_exists($table_name)) {
- $schema = chado_get_schema($table_name);
- $pkey = $schema['primary key'][0];
- $field_name = $new_field['field_name'];
- $field_type = 'chado_linker__prop';
- // First add the field.
- field_create_field(array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- ));
- // Now add the instance
- field_create_instance(array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => $new_field['label'],
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'base_table' => $chado_table,
- 'chado_table' => $table_name,
- 'chado_column' => $pkey,
- 'term_vocabulary' => $vocab->vocabulary,
- 'term_accession' => $term->accession,
- 'term_name' => $term->name
- ),
- 'widget' => array(
- 'type' => 'chado_linker__prop_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__prop_formatter',
- 'settings' => array(),
- ),
- ),
- ));
- }
- else {
- drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
- }
- }
- // We allow site admins to add new chado_linker__cvterm fields to an entity.
- // This function will allow us to properly add them. But at this point we
- // don't know the controlled vocabulary term. We'll have to use the
- // defaults and let the user set it using the interface.
- if ($new_field['type'] == 'chado_linker__cvterm') {
- $table_name = $chado_table . '_cvterm';
- if (chado_table_exists($table_name)) {
- $schema = chado_get_schema($table_name);
- $pkey = $schema['primary key'][0];
- $field_name = $new_field['field_name'];
- $field_type = 'chado_linker__cvterm';
- // First add the field.
- field_create_field(array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'base_table' => $chado_table,
- 'chado_table' => $table_name,
- 'chado_column' => $pkey,
- ),
- ));
- // Now add the instance
- field_create_instance(array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => $new_field['label'],
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__cvterm_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__cvterm_formatter',
- 'settings' => array(),
- ),
- ),
- ));
- }
- else {
- drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
- }
- }
- }
- /**
- * Allows for altering of a field's instance setting form.
- *
- * This appears to be a Drupal hook but is actually a custom function created
- * by this module. It is called by the tripal_form_alter() function of this
- * module.
- *
- * Here we put additional form elements for any field, regardless if it is
- * a tripalField or not.
- *
- * @param $form
- * The form array. Alterations to the form can be made within this array.
- * @param $form_state
- * The form state array.
- */
- function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
- global $language;
- $field = $form['#field'];
- $instance = $form['#instance'];
- $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
- $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
- $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
- if ($chado_table) {
- // Construct a table for the vocabulary information.
- $headers = array();
- $rows = array();
- $rows[] = array(
- array(
- 'data' => 'Base Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $base_table
- );
- $rows[] = array(
- array(
- 'data' => 'Record Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_table
- );
- $rows[] = array(
- array(
- 'data' => 'ID Column',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_column
- );
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- ),
- 'sticky' => FALSE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $form['chado_mapping'] = array(
- '#type' => 'fieldset',
- '#title' => 'Chado Mapping',
- '#description' => t('This field maps to data in Chado to the following table:'),
- );
- $form['chado_mapping']['details'] = array(
- '#type' => 'item',
- '#markup' => theme_table($table),
- );
- }
- }
- /**
- * Implements hook_form_FROM_ID_alter()
- */
- function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
- global $language;
- $bundle = $form['#bundle'];
- $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
- $term = reset($term);
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
- $chado_table = $mapped_table->chado_table;
- $chado_column = $mapped_table->chado_field;
- // Construct a table for the vocabulary information.
- $headers = array();
- $rows = array();
- $rows[] = array(
- array(
- 'data' => 'Chado Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_table
- );
- $rows[] = array(
- array(
- 'data' => 'Type Column',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_column
- );
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- ),
- 'sticky' => FALSE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $form['chado_mapping'] = array(
- '#type' => 'item',
- '#title' => 'Chado Mapping',
- '#markup' => theme_table($table),
- '#description' => t('This content type maps to the table in Chado
- listed above. Chado allows multiple data types to be housed
- in a single table. Therefore, the column that is used to
- differentiate between data types is also listed above.'),
- '#weight' => 0,
- );
- }
|