Skip to content

Commit

Permalink
Merge pull request #7 from UofS-Pulse-Binfo/4-qtl_lists
Browse files Browse the repository at this point in the history
4 qtl lists
  • Loading branch information
laceysanderson authored Apr 21, 2020
2 parents 2b6c7db + b271561 commit 8d1f52b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
71 changes: 51 additions & 20 deletions includes/TripalFields/so__qtl/so__qtl.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
/**
* @class
* Purpose:
* Purpose: List QTL on various Tripal Content Pages including Genetic Maps,
* Traits, Genetic Markers and Sequence Variants.
*
* Data:
* Assumptions:
* Data: See https://tripal-qtl.readthedocs.io/en/latest/QTLimporter.html#data-storage
* Assumptions: Assumes QTL are imported by this module.
*/
class so__qtl extends ChadoField {

Expand Down Expand Up @@ -109,12 +110,31 @@ class so__qtl extends ChadoField {
// @debug dpm($entity, 'entity');
$field_name = $this->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
Expand All @@ -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'] = [];
Expand Down
8 changes: 6 additions & 2 deletions includes/TripalFields/so__qtl/so__qtl_widget.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<p>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.</p>',
];
}

/**
Expand All @@ -39,4 +43,4 @@ class so__qtl_widget extends ChadoFieldWidget {
public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
}

}
}
10 changes: 4 additions & 6 deletions includes/tripal_qtl.fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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(
Expand All @@ -208,7 +207,6 @@ function tripal_qtl_bundle_instances_info($entity_type, $bundle) {
);
}
}
*/

return $instances;
}

0 comments on commit 8d1f52b

Please sign in to comment.