function tripal_feature_load_featureloc_sequences
2.x tripal_feature.theme.inc | tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) |
3.x tripal_feature.theme.inc | tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) |
1.x tripal_feature.module | tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) |
Related topics
File
- tripal_feature/
tripal_feature.module, line 1226 - @todo Add file header description
Code
function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
// if we don't have any featurelocs then no point in continuing
if (!$featurelocs) {
return array();
}
// get the list of relationships (including any aggregators) and iterate
// through each one to find information needed to color-code the reference sequence
$relationships = tripal_feature_get_aggregate_relationships($feature_id);
if (!$relationships) {
return array();
}
// iterate through each of the realtionships features and get their
// locations
foreach ($relationships as $rindex => $rel) {
// get the featurelocs for each of the relationship features
$rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
// keep track of this unique source feature
$src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
// copy over the results to the relationship object. Since there can
// be more than one feature location for each relationship feature we
// use the '$src' variable to keep track of these.
$rel->featurelocs = new stdClass();
$rel->featurelocs->$src = new stdClass();
$rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
$rel->featurelocs->$src->src_cvterm_id = $rel_featureloc->src_cvterm_id;
$rel->featurelocs->$src->src_cvname = $rel_featureloc->src_cvname;
$rel->featurelocs->$src->fmin = $rel_featureloc->fmin;
$rel->featurelocs->$src->fmax = $rel_featureloc->fmax;
$rel->featurelocs->$src->src_name = $rel_featureloc->src_name;
// keep track of the individual parts for each relationship
$start = $rel->featurelocs->$src->fmin;
$end = $rel->featurelocs->$src->fmax;
$type = $rel->subject_type;
$rel_locs[$src]['parts'][$start][$type]['start'] = $start;
$rel_locs[$src]['parts'][$start][$type]['end'] = $end;
$rel_locs[$src]['parts'][$start][$type]['type'] = $type;
}
}
// the featurelocs array provided to the function contains the locations
// where this feature is found. We want to get the sequence for each
// location and then annotate it with the parts found from the relationships
// locations determiend above.
$sql = "SELECT substring(residues from %d for %d) as residues " .
"FROM {feature} " .
"WHERE feature_id = %d";
$floc_sequences = array();
foreach ($featurelocs as $featureloc) {
// build the src name so we can keep track of the different parts for each feature
$src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
// orient the parts to the beginning of the feature sequence
if (!empty($rel_locs[$src]['parts'])) {
$parts = $rel_locs[$src]['parts'];
$rparts = array(); // we will fill this up if we're on the reverse strand
foreach ($parts as $start => $types) {
foreach ($types as $type_name => $type) {
if ($featureloc->strand >= 0) {
// this is on the forward strand. We need to convert the start on the src feature to the
// start on this feature's sequence
$parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
$parts[$start][$type_name]['end'] = $parts[$start][$type_name]['end'] - $featureloc->fmin;
$parts[$start][$type_name]['type'] = $type_name;
}
else {
// this is on the reverse strand. We need to swap the start and stop and calculate from the
// begining of the reverse sequence
$size = ($featureloc->fmax - $featureloc->fmin);
$start_orig = $parts[$start][$type_name]['start'];
$end_orig = $parts[$start][$type_name]['end'];
$new_start = $size - ($end_orig - $featureloc->fmin);
$new_end = $size - ($start_orig - $featureloc->fmin);
$rparts[$new_start][$type_name]['start'] = $new_start;
$rparts[$new_start][$type_name]['end'] = $new_end;
$rparts[$new_start][$type_name]['type'] = $type_name;
}
}
}
// now sort the parts
// if we're on the reverse strand we need to resort
if ($featureloc->strand >= 0) {
usort($parts, 'tripal_feature_sort_rel_parts_by_start');
}
else {
usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
$parts = $rparts;
}
$floc_sequences[$src]['src'] = $src;
$floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
$sequence = db_fetch_object(chado_query($sql, $featureloc->fmin + 1, ($featureloc->fmax - $featureloc->fmin), $featureloc->srcfeature_id->feature_id));
$residues = $sequence->residues;
if ($featureloc->strand < 0) {
$residues = tripal_feature_reverse_complement($residues);
}
$strand = '.';
if ($featureloc->strand == 1) {
$strand = '+';
}
elseif ($featureloc->strand == -1) {
$strand = '-';
}
$defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
$floc_sequences[$src]['formatted_seq'] = tripal_feature_color_sequence($residues, $parts, $defline);
}
}
return $floc_sequences;
}