-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1607 from pdtouch/tv4g1-issue1414-data__sequence_…
…length Tripal 4 Fields: Sequence Length + Sequence Checksum
- Loading branch information
Showing
10 changed files
with
407 additions
and
6 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceChecksumFormatterDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldFormatter; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoFormatterBase; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field formatter for sequence data | ||
* | ||
* @FieldFormatter( | ||
* id = "chado_sequence_checksum_formatter_default", | ||
* label = @Translation("Chado Sequence checksum Formatter"), | ||
* description = @Translation("A chado sequence checksum formatter"), | ||
* field_types = { | ||
* "chado_sequence_checksum_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceChecksumFormatterDefault extends ChadoFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
foreach($items as $delta => $item) { | ||
$seqlen_val = $item->get('seqlen')->getString(); | ||
if ( intval($seqlen_val) > 0 ) { | ||
$elements[$delta] = [ | ||
"#markup" => $item->get('md5checksum')->getString() | ||
]; | ||
} | ||
} | ||
|
||
return $elements; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceLengthFormatterCommas.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldFormatter; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoFormatterBase; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field formatter for sequence data | ||
* | ||
* @FieldFormatter( | ||
* id = "chado_sequence_length_formatter_commas", | ||
* label = @Translation("Chado Sequence Length with Commas Formatter 1,000,000"), | ||
* description = @Translation("A chado sequence length commas (ex. 1,000,000) formatter"), | ||
* field_types = { | ||
* "chado_sequence_length_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceLengthFormatterCommas extends ChadoFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
$elements['#attached']['library'][] = 'tripal_chado/tripal_chado.field.ChadoSequenceLengthFormatterCommas'; | ||
|
||
foreach($items as $delta => $item) { | ||
$elements[$delta] = [ | ||
"#markup" => number_format(floatval($item->get('seqlen')->getString())) | ||
]; | ||
} | ||
|
||
return $elements; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tripal_chado/src/Plugin/Field/FieldFormatter/ChadoSequenceLengthFormatterDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldFormatter; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoFormatterBase; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field formatter for sequence data | ||
* | ||
* @FieldFormatter( | ||
* id = "chado_sequence_length_formatter_default", | ||
* label = @Translation("Chado Sequence Length Formatter"), | ||
* description = @Translation("A chado sequence length formatter"), | ||
* field_types = { | ||
* "chado_sequence_length_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceLengthFormatterDefault extends ChadoFormatterBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(FieldItemListInterface $items, $langcode) { | ||
$elements = []; | ||
$elements['#attached']['library'][] = 'tripal_chado/tripal_chado.field.ChadoSequenceLengthFormatterDefault'; | ||
|
||
foreach($items as $delta => $item) { | ||
$elements[$delta] = [ | ||
"#markup" => $item->get('seqlen')->getString() | ||
]; | ||
} | ||
|
||
return $elements; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
tripal_chado/src/Plugin/Field/FieldType/ChadoSequenceChecksumDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldType; | ||
|
||
use Drupal\tripal_chado\TripalField\ChadoFieldItemBase; | ||
use Drupal\tripal_chado\TripalStorage\ChadoIntStoragePropertyType; | ||
use Drupal\tripal_chado\TripalStorage\ChadoBpCharStoragePropertyType; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field for sequence data. | ||
* | ||
* @FieldType( | ||
* id = "chado_sequence_checksum_default", | ||
* label = @Translation("Chado Feature Sequence Checksum"), | ||
* description = @Translation("A chado feature sequence md5 checksum"), | ||
* default_widget = "chado_sequence_checksum_widget_default", | ||
* default_formatter = "chado_sequence_checksum_formatter_default" | ||
* ) | ||
*/ | ||
class ChadoSequenceChecksumDefault extends ChadoFieldItemBase { | ||
|
||
public static $id = "chado_sequence_checksum_default"; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function mainPropertyName() { | ||
return 'md5checksum'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultFieldSettings() { | ||
$settings = parent::defaultFieldSettings(); | ||
$settings['termIdSpace'] = 'data'; | ||
$settings['termAccession'] = '2190'; | ||
$settings['fixed_value'] = TRUE; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultStorageSettings() { | ||
$settings = parent::defaultStorageSettings(); | ||
$settings['storage_plugin_settings']['base_table'] = 'feature'; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tripalTypes($field_definition) { | ||
$entity_type_id = $field_definition->getTargetEntityTypeId(); | ||
|
||
// Get the base table columns needed for this field. | ||
$settings = $field_definition->getSetting('storage_plugin_settings'); | ||
|
||
// Get the property terms by using the Chado table columns they map to. | ||
$storage = \Drupal::entityTypeManager()->getStorage('chado_term_mapping'); | ||
$mapping = $storage->load('core_mapping'); | ||
$record_id_term = 'SIO:000729'; | ||
$md5checksum_term = $mapping->getColumnTermId('feature', 'md5checksum'); | ||
$seqlen_term = $mapping->getColumnTermId('feature', 'seqlen'); | ||
|
||
// Get the length of the database fields so we don't go over the size limit. | ||
$chado = \Drupal::service('tripal_chado.database'); | ||
$schema = $chado->schema(); | ||
$feature_def = $schema->getTableDef('feature', ['format' => 'Drupal']); | ||
$md5_checksum_len = $feature_def['fields']['md5checksum']['size']; | ||
|
||
// Return the properties for this field. | ||
$properties = []; | ||
$properties[] = new ChadoIntStoragePropertyType($entity_type_id, self::$id, 'record_id', $record_id_term, [ | ||
'action' => 'store_id', | ||
'drupal_store' => TRUE, | ||
'chado_table' => 'feature', | ||
'chado_column' => 'feature_id' | ||
]); | ||
$properties[] = new ChadoIntStoragePropertyType($entity_type_id, self::$id, 'seqlen', $seqlen_term, [ | ||
'action' => 'store', | ||
'chado_column' => 'seqlen', | ||
'chado_table' => 'feature' | ||
]); | ||
$properties[] = new ChadoBpCharStoragePropertyType($entity_type_id, self::$id, 'md5checksum', $md5checksum_term, $md5_checksum_len, [ | ||
'action' => 'store', | ||
'chado_column' => 'md5checksum', | ||
'chado_table' => 'feature' | ||
]); | ||
return $properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
tripal_chado/src/Plugin/Field/FieldType/ChadoSequenceLengthDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldType; | ||
|
||
use Drupal\tripal_chado\TripalField\ChadoFieldItemBase; | ||
use Drupal\tripal_chado\TripalStorage\ChadoIntStoragePropertyType; | ||
|
||
/** | ||
* Plugin implementation of Default Tripal field for sequence data. | ||
* | ||
* @FieldType( | ||
* id = "chado_sequence_length_default", | ||
* label = @Translation("Chado Feature Sequence Length"), | ||
* description = @Translation("A chado feature sequence length"), | ||
* default_widget = "chado_sequence_length_widget_default", | ||
* default_formatter = "chado_sequence_length_formatter_default" | ||
* ) | ||
*/ | ||
|
||
|
||
class ChadoSequenceLengthDefault extends ChadoFieldItemBase { | ||
|
||
public static $id = "chado_sequence_length_default"; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function mainPropertyName() { | ||
return 'seqlen'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultFieldSettings() { | ||
$settings = parent::defaultFieldSettings(); | ||
$settings['termIdSpace'] = 'data'; | ||
$settings['termAccession'] = '1249'; | ||
$settings['fixed_value'] = TRUE; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultStorageSettings() { | ||
$settings = parent::defaultStorageSettings(); | ||
$settings['storage_plugin_settings']['base_table'] = 'feature'; | ||
return $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tripalTypes($field_definition) { | ||
$entity_type_id = $field_definition->getTargetEntityTypeId(); | ||
|
||
// Get the base table columns needed for this field. | ||
$settings = $field_definition->getSetting('storage_plugin_settings'); | ||
|
||
// Get the property terms by using the Chado table columns they map to. | ||
$storage = \Drupal::entityTypeManager()->getStorage('chado_term_mapping'); | ||
$mapping = $storage->load('core_mapping'); | ||
$record_id_term = 'SIO:000729'; | ||
$seqlen_term = $mapping->getColumnTermId('feature', 'seqlen'); | ||
|
||
// Return the properties for this field. | ||
$properties = []; | ||
$properties[] = new ChadoIntStoragePropertyType($entity_type_id, self::$id, 'record_id', $record_id_term, [ | ||
'action' => 'store_id', | ||
'drupal_store' => TRUE, | ||
'chado_table' => 'feature', | ||
'chado_column' => 'feature_id' | ||
]); | ||
$properties[] = new ChadoIntStoragePropertyType($entity_type_id, self::$id, 'seqlen', $seqlen_term, [ | ||
'action' => 'store', | ||
'chado_column' => 'seqlen', | ||
'chado_table' => 'feature' | ||
]); | ||
return $properties; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tripal_chado/src/Plugin/Field/FieldWidget/ChadoSequenceChecksumWidgetDefault.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Drupal\tripal_chado\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\tripal_chado\TripalField\ChadoWidgetBase; | ||
|
||
/** | ||
* Plugin implementation of default Chado Sequence Checksum widget. | ||
* | ||
* @FieldWidget( | ||
* id = "chado_sequence_checksum_widget_default", | ||
* label = @Translation("Chado Sequence Checksum Widget"), | ||
* description = @Translation("The default chado sequence checksum widget."), | ||
* field_types = { | ||
* "chado_sequence_checksum_default" | ||
* } | ||
* ) | ||
*/ | ||
class ChadoSequenceChecksumWidgetDefault extends ChadoWidgetBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { | ||
|
||
$item_vals = $items[$delta]->getValue(); | ||
$elements = []; | ||
$elements['record_id'] = [ | ||
'#type' => 'value', | ||
'#default_value' => $item_vals['record_id'] ?? 0, | ||
]; | ||
|
||
return $elements; | ||
} | ||
|
||
} |
Oops, something went wrong.