function tripal_feature_load_gff3_ontology
2.x tripal_feature.gff_loader.inc | tripal_feature_load_gff3_ontology($feature, $dbxrefs) |
1.x gff_loader.inc | tripal_feature_load_gff3_ontology($feature, $dbxrefs) |
Load the cvterms for a feature. Assumes there is a dbxref.accession matching a cvterm.name
Parameters
$feature:
$dbxrefs:
Related topics
1 call to tripal_feature_load_gff3_ontology()
- 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 1469 - Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.
Code
function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
// iterate through each of the dbxrefs
foreach ($dbxrefs as $dbxref) {
// get the database name from the reference. If it doesn't exist then create one.
$ref = explode(":", $dbxref);
$dbname = trim($ref[0]);
$accession = trim($ref[1]);
// first look for the database name
$db = chado_select_record('db', array('db_id'), array('name' => "DB:$dbname"));
if (sizeof($db) == 0) {
// now look for the name without the 'DB:' prefix.
$db = chado_select_record('db', array('db_id'), array('name' => "$dbname"));
if (sizeof($db) == 0) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Database, $dbname, is not present. Cannot associate term: $dbname:$accession", array());
return 0;
}
}
$db = $db[0];
// now check to see if the accession exists
$dbxref = chado_select_record('dbxref', array('dbxref_id'),
array('accession' => $accession, 'db_id' => $db->db_id));
if (sizeof($dbxref) == 0) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Accession, $accession is missing for reference: $dbname:$accession", array());
return 0;
}
$dbxref = $dbxref[0];
// now check to see if the cvterm exists
$cvterm = chado_select_record('cvterm', array('cvterm_id'), array(
'dbxref_id' => $dbxref->dbxref_id));
// if it doesn't exist in the cvterm table, look for an alternate id
if (sizeof($cvterm) == 0) {
$cvterm = chado_select_record('cvterm_dbxref', array('cvterm_id'), array(
'dbxref_id' => $dbxref->dbxref_id));
if (sizeof($cvterm) == 0) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "CV Term is missing for reference: $dbname:$accession", array());
return 0;
}
}
$cvterm = $cvterm[0];
// check to see if this feature cvterm already exists
$fcvt = chado_select_record('feature_cvterm', array('feature_cvterm_id'),
array('cvterm_id' => $cvterm->cvterm_id, 'feature_id' => $feature->feature_id));
// now associate this feature with the cvterm if it doesn't already exist
if (sizeof($fcvt) == 0) {
$values = array(
'cvterm_id' => $cvterm->cvterm_id,
'feature_id' => $feature->feature_id,
'pub_id' => array(
'uniquename' => 'null',
),
);
$success = chado_insert_record('feature_cvterm', $values);
if (!$success) {
tripal_report_error("tripal_feature", TRIPAL_WARNING, "Failed to insert ontology term: $dbname:$accession", array());
return 0;
}
}
}
return 1;
}