diff --git a/tripal_chado/config/install/tripal.tripalfield_collection.default_chado.yml b/tripal_chado/config/install/tripal.tripalfield_collection.default_chado.yml index eb4c1b847c..23015eeb09 100644 --- a/tripal_chado/config/install/tripal.tripalfield_collection.default_chado.yml +++ b/tripal_chado/config/install/tripal.tripalfield_collection.default_chado.yml @@ -1041,6 +1041,33 @@ fields: region: content weight: 10 + - name: gene_sequence_coordinates + content_type: gene + label: Sequence Coordinates + type: chado_sequence_coordinates_default + description: Locations on reference sequences where the feature is located. + cardinality: -1 + required: false + storage_settings: + storage_plugin_id: chado_storage + storage_plugin_settings: + base_table: featureloc + linker_table: feature + linker_fkey_column: feature_id + settings: + termIdSpace: data + termAccession: "2012" + display: + view: + default: + region: content + label: above + weight: 10 + form: + default: + region: content + weight: 10 + - name: mrna_name content_type: mRNA label: Name diff --git a/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterDefault.php b/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterDefault.php new file mode 100755 index 0000000000..118f638aca --- /dev/null +++ b/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterDefault.php @@ -0,0 +1,75 @@ +get('fmin')->getString(); + if (!empty($fmin_val)) { + $loc_rec .= $item['value'][$feature_ref_val] . ':' .$fmin_val . ".."; + } + $fmax_val = $item->get('fmax')->getString(); + if (!empty($fmax_val)) { + $loc_rec .= $item['value'][$fmax_val].'; '; + } + $phase_val = $item->get('phase')->getString(); + if (!empty($phase_val)) { + $loc_rec .= $item['value'][$phase_val].'; '; + } + $strand_term = $item->get('strand')->getString(); + if (!empty($strand_val)) { + $strand_symb = match( $item['value'][$strand_term] ) { + -1 => '-', + 1 => '+', + default => '', + }; + $loc_rec .= $strand_symb; + } + $locations[] = $loc_rec; + } + } + if ( !$locations ) { + $content = 'This feature is not located on any sequence.'; + } + else { + $content = implode('
', $locations); + } + // The cardinality of this field is always 1, so only create element for $delta of zero. + $elements[0] = [ + '#type' => 'markup', + '#markup' => $content, + ]; + return $elements; + } +} \ No newline at end of file diff --git a/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterTable.php b/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterTable.php new file mode 100755 index 0000000000..13c036287d --- /dev/null +++ b/tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceCoordinatesFormatterTable.php @@ -0,0 +1,94 @@ + 'This @content_type has the following sequence coordinates:', + 'expand_strand' => TRUE, + ]; + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items, $langcode) { + $elements = []; + $reference_term = 'data:3002'; + + // Get the settings and set defaults. + $settings = $display['settings']; + foreach ($this::$default_settings as $key => $value) { + if (!isset($settings[$key])) { + $settings[$key] = $value; + } + } + + // Replace tokens in the caption. + $settings['caption'] = t($settings['caption'], + ['@content_type' => $entity->rdfs__type['und'][0]['value']]); + + // For each location, add it to the table. + $header = ['Name', 'Location', 'Strand', 'Phase']; + + $locations = []; + + foreach ($items as $item) { + + if (!empty($item['value'])) { + $fmin_term = $item->get('fmin')->getString(); + $fmax_term = $item->get('fmax')->getString(); + $strand_term = $item->get('strand')->getString(); + $phase_term = $item->get('phase')->getString(); + + $strand_val = $item['value'][$strand_term]; + if ($settings['expand_strand']) { + $strand_symb = match( $strand_val ) { + -1 => '-', + 1 => '+', + default => 'unknown', + }; + } + } + + $locations[] = [ + $item['value'][$reference_term], + $item['value'][$fmin_term] . '..' . $fmax = $item['value'][$fmax_term], + $strand_symb, $item['value'][$phase_term], + ]; + } + + if ( !$locations ) { + $content = 'This feature is not located on any sequence.'; + } + else { + $content = $locations; + } + + // The cardinality of this field is always 1, so only create element for $delta of zero. + $elements[0] = [ + '#type' => 'markup', + '#theme' => 'table', + '#header' => $header, + '#rows' => $content, + '#caption' => $settings['caption'], + ]; + + return $elements; + } +} \ No newline at end of file