function tripal_feature_load_gff3_parents
2.x tripal_feature.gff_loader.inc | tripal_feature_load_gff3_parents($feature, $cvterm, $parents,
$organism_id, |
1.x gff_loader.inc | tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism_id, $fmin) |
Load the parents for a gff3 feature
Parameters
$feature:
$cvterm:
$parents:
$organism_id:
$fmin:
Related topics
1 call to tripal_feature_load_gff3_parents()
- tripal_feature_load_gff3 in tripal_feature/
includes/ tripal_feature.gff_loader.inc - Actually load a GFF3 file. This is the function called by tripal jobs
File
- tripal_feature/
includes/ tripal_feature.gff_loader.inc, line 1270 - Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.
Code
function tripal_feature_load_gff3_parents($feature, $cvterm, $parents,
$organism_id, $strand, $phase, $fmin, $fmax) {
$uname = $feature->uniquename;
$type = $cvterm->name;
$rel_type = 'part_of';
// Prepare these SQL statements that will be used repeatedly.
$cvterm_sql = "
SELECT CVT.cvterm_id
FROM {cvterm} CVT
INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
WHERE cv.name = :cvname and (CVT.name = :name or CVTS.synonym = :synonym)
";
// Iterate through the parents in the list.
foreach ($parents as $parent) {
// Get the parent cvterm.
$values = array(
'organism_id' => $organism_id,
'uniquename' => $parent,
);
$result = chado_select_record('tripal_gff_temp', array('type_name'), $values);
if (count($result) == 0) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot find parent: %parent", array('%parent' => $parent));
return '';
}
$parent_type = $result[0]->type_name;
// try to find the parent
$parentcvterm = chado_query($cvterm_sql, array(':cvname' => 'sequence', ':name' => $parent_type, ':synonym' => $parent_type))->fetchObject();
$relcvterm = chado_query($cvterm_sql, array(':cvname' => 'sequence', ':name' => $rel_type, ':synonym' => $rel_type))->fetchObject();
if (!$relcvterm) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot find the term, 'part_of', from the sequence ontology. This term is used for associating parent and children features. Please check that the ontology is fully imported.");
exit;
}
$values = array(
'organism_id' => $organism_id,
'uniquename' => $parent,
'type_id' => $parentcvterm->cvterm_id,
);
$result = chado_select_record('feature', array('feature_id'), $values);
$parent_feature = $result[0];
// if the parent exists then add the relationship otherwise print error and skip
if ($parent_feature) {
// check to see if the relationship already exists
$values = array(
'object_id' => $parent_feature->feature_id,
'subject_id' => $feature->feature_id,
'type_id' => $relcvterm->cvterm_id,
);
$rel = chado_select_record('feature_relationship', array('*'), $values);
if (count($rel) > 0) {
}
else {
// the relationship doesn't already exist, so add it.
$values = array(
'subject_id' => $feature->feature_id,
'object_id' => $parent_feature->feature_id,
'type_id' => $relcvterm->cvterm_id,
);
$result = chado_insert_record('feature_relationship', $values);
if (!$result) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)",
array());
}
}
// If this feature is a CDS and now that we know the parent we can
// add it to the tripal_gffcds_temp table for later lookup.
if ($type == 'CDS') {
$values = array(
'feature_id' => $feature->feature_id,
'parent_id' => $parent_feature->feature_id,
'fmin' => $fmin,
'fmax' => $fmax,
'strand' => $strand,
);
if ($phase) {
$values['phase'] = $phase;
}
$result = chado_insert_record('tripal_gffcds_temp', $values);
if (!$result) {
tripal_report_error('tripal_feature', TRIPAL_ERROR, "Cound not save record in temporary CDS table, Cannot continue.", array());
exit;
}
}
}
else {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent",
array());
}
}
}