diff --git a/includes/TripalFields/so__qtl/so__qtl.inc b/includes/TripalFields/so__qtl/so__qtl.inc index b8f21c5..6baa809 100644 --- a/includes/TripalFields/so__qtl/so__qtl.inc +++ b/includes/TripalFields/so__qtl/so__qtl.inc @@ -1,10 +1,11 @@ instance['field_name']; - // Retrieve the QTL associated with a given trait. + // Retrieve the type_ids we'll need for our query. + $type_id_obj = [ + 'start' => chado_get_cvterm(['id' => 'MAIN:start']), + 'end' => chado_get_cvterm(['id' => 'MAIN:end']), + 'lod' => chado_get_cvterm(['id' => 'MAIN:lod']), + 'addt_effect' => chado_get_cvterm(['id' => 'MAIN:additive_effect']), + 'parent' => chado_get_cvterm(['id' => 'MAIN:direction']), + 'instance_of' => chado_get_cvterm(['id' => 'OBO_REL:instance_of']), + ]; + $type_id = []; + foreach ($type_id_obj as $key => $obj) { + $type_id[$key] = 0; + if (is_object($obj)) { + $type_id[$key] = $obj->cvterm_id; + } + } + // @debug dpm($type_id, 'types'); + + // Retrieve the QTL associated with a given TRAIT. if ($entity->chado_table == 'cvterm') { $feature_ids = chado_query('SELECT feature_id FROM {feature_cvterm} WHERE cvterm_id=:id', [':id' => $entity->chado_record_id])->fetchCol(); // @debug dpm($feature_ids, 'feature_ids'); } + // Retrieve the QTL associated with a given GENETIC MAP. elseif ($entity->chado_table == 'featuremap') { $feature_ids = chado_query("SELECT qtl.feature_id FROM {featurepos} pos LEFT JOIN {feature} qtl ON pos.feature_id=qtl.feature_id @@ -123,24 +143,35 @@ class so__qtl extends ChadoField { [':id' => $entity->chado_record_id])->fetchCol(); // @debug dpm($feature_ids, 'feature_ids'); } + // Retrieve the QTL a given MARKER/VARIANT falls within. + elseif ($entity->chado_table == 'feature') { - if (!empty($feature_ids)) { + // First find the position of this marker. + $marker_pos = chado_query(' + SELECT pos.mappos + FROM chado.feature m + LEFT JOIN chado.feature_relationship mrl ON mrl.object_id=m.feature_id AND mrl.type_id=:instance_of + LEFT JOIN chado.feature l ON l.feature_id=mrl.subject_id + LEFT JOIN chado.featurepos pos ON l.feature_id = pos.feature_id + WHERE m.feature_id=:id', [ + ':id' => $entity->chado_record_id, + ':instance_of' => $type_id['instance_of'], + ])->fetchField(); - // Retrieve the type_ids we'll need for our query. - $type_id_obj = [ - 'start' => chado_get_cvterm(['id' => 'MAIN:start']), - 'end' => chado_get_cvterm(['id' => 'MAIN:end']), - 'lod' => chado_get_cvterm(['id' => 'MAIN:lod']), - 'addt_effect' => chado_get_cvterm(['id' => 'MAIN:additive_effect']), - 'parent' => chado_get_cvterm(['id' => 'MAIN:direction']), - ]; - $type_id = []; - foreach ($type_id_obj as $key => $obj) { - $type_id[$key] = 0; - if (is_object($obj)) { - $type_id[$key] = $obj->cvterm_id; - } - } + // Now grab all QTL spanning this position. + $feature_ids = chado_query(' + SELECT pos.feature_id as qtl + FROM chado.featurepos pos + INNER JOIN chado.featureposprop pstart + ON pstart.featurepos_id=pos.featurepos_id AND pstart.type_id=:start + INNER JOIN chado.featureposprop pend + ON pend.featurepos_id=pos.featurepos_id AND pend.type_id=:end + WHERE cast(pstart.value as float) <= :pos AND cast(pend.value as float) >= :pos', + [':pos' => $marker_pos, ':start' => $type_id['start'], ':end' => $type_id['end']])->fetchCol(); + // @debug dpm($feature_ids, 'feature_ids'); + } + + if (!empty($feature_ids)) { // Now get the generic information for each QTL. $entity->{$field_name}['und'] = []; diff --git a/includes/TripalFields/so__qtl/so__qtl_widget.inc b/includes/TripalFields/so__qtl/so__qtl_widget.inc index 72cb30d..9e3082a 100644 --- a/includes/TripalFields/so__qtl/so__qtl_widget.inc +++ b/includes/TripalFields/so__qtl/so__qtl_widget.inc @@ -20,9 +20,13 @@ class so__qtl_widget extends ChadoFieldWidget { * @see ChadoFieldWidget::form() * **/ - public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) { parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element); + + $widget['msg'] = [ + '#type' => 'markup', + '#markup' => '

The QTL List field retrieves data from the database for display but does not provide a way to edit it. To load QTL data use the importer provided.

', + ]; } /** @@ -39,4 +43,4 @@ class so__qtl_widget extends ChadoFieldWidget { public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) { } -} \ No newline at end of file +} diff --git a/includes/tripal_qtl.fields.inc b/includes/tripal_qtl.fields.inc index 98dfc6e..e9bd331 100644 --- a/includes/tripal_qtl.fields.inc +++ b/includes/tripal_qtl.fields.inc @@ -103,7 +103,7 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) { 'term_accession' => '0000771', 'auto_attach' => FALSE, 'chado_table' => $bundle->data_table, - 'chado_column' => 'organism_id', + 'chado_column' => 'cvterm_id', 'base_table' => $bundle->data_table, ), 'widget' => array( @@ -143,7 +143,7 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) { 'term_accession' => '0000771', 'auto_attach' => FALSE, 'chado_table' => $bundle->data_table, - 'chado_column' => 'organism_id', + 'chado_column' => 'featuremap_id', 'base_table' => $bundle->data_table, ), 'widget' => array( @@ -163,8 +163,7 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) { ), ); } - // Feature-based Pages (e.g. genetic map, gene, etc.) - /* + // Feature-based Pages (e.g. genetic marker, gene, etc.) elseif (isset($bundle->data_table) AND ($bundle->data_table == 'feature')) { // Specifically, only genetic markers. @@ -187,7 +186,7 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) { 'term_accession' => '0000771', 'auto_attach' => FALSE, 'chado_table' => $bundle->data_table, - 'chado_column' => 'organism_id', + 'chado_column' => 'feature_id', 'base_table' => $bundle->data_table, ), 'widget' => array( @@ -208,7 +207,6 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) { ); } } - */ return $instances; }