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) |
Related topics
1 call to tripal_feature_load_gff3_ontology()
- tripal_feature_load_gff3 in tripal_feature/
includes/ gff_loader.inc
File
- tripal_feature/
includes/ gff_loader.inc, line 1184 - @todo Add file header description
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 = $ref[0];
$accession = $ref[1];
// first look for the database name
$options = array('statement_name' => 'sel_db_name');
$db = tripal_core_chado_select('db', array('db_id'), array('name' => "DB:$dbname"), $options);
if (sizeof($db) == 0) {
// now look for the name without the 'DB:' prefix.
$db = tripal_core_chado_select('db', array('db_id'), array('name' => "$dbname"), $options);
if (sizeof($db) == 0) {
watchdog("T_gff3_loader", "Database, $dbname, is not present. Cannot associate term: $dbname:$accession", array(), WATCHDOG_WARNING);
return 0;
}
}
$db = $db[0];
// now check to see if the accession exists
$options = array('statement_name' => 'sel_dbxref_accession_dbid');
$dbxref = tripal_core_chado_select('dbxref', array('dbxref_id'),
array('accession' => $accession, 'db_id' => $db->db_id), $options);
if (sizeof($dbxref) == 0) {
watchdog("T_gff3_loader", "Accession, $accession is missing for reference: $dbname:$accession", array(), WATCHDOG_WARNING);
return 0;
}
$dbxref = $dbxref[0];
// now check to see if the cvterm exists
$options = array('statement_name' => 'sel_cvterm_dbxrefid');
$cvterm = tripal_core_chado_select('cvterm', array('cvterm_id'), array(
'dbxref_id' => $dbxref->dbxref_id), $options);
// if it doesn't exist in the cvterm table, look for an alternate id
if (sizeof($cvterm) == 0) {
$options = array('statement_name' => 'sel_cvtermdbxref_dbxrefid');
$cvterm = tripal_core_chado_select('cvterm_dbxref', array('cvterm_id'), array(
'dbxref_id' => $dbxref->dbxref_id), $options);
if (sizeof($cvterm) == 0) {
watchdog("T_gff3_loader", "CV Term is missing for reference: $dbname:$accession", array(), WATCHDOG_WARNING);
return 0;
}
}
$cvterm = $cvterm[0];
// check to see if this feature cvterm already exists
$options = array('statement_name' => 'sel_featurecvterm_cvtermid_featureid');
$fcvt = tripal_core_chado_select('feature_cvterm', array('feature_cvterm_id'),
array('cvterm_id' => $cvterm->cvterm_id, 'feature_id' => $feature->feature_id),
$options);
// 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',
),
);
$options = array('statement_name' => 'ins_featurecvterm_cvtermid_featureid_pubid');
$success = tripal_core_chado_insert('feature_cvterm', $values, $options);
if (!$success) {
watchdog("T_gff3_loader", "Failed to insert ontology term: $dbname:$accession", array(), WATCHDOG_WARNING);
return 0;
}
}
}
return 1;
}