function tripal_cv_obo_add_cvterm_dbxref
2.x tripal_cv.obo_loader.inc | tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) |
1.x obo_loader.inc | tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) |
Adds a database reference to a cvterm
Parameters
cvterm: The database object of the cvterm to which the synonym will be added.
xref: The cross refernce. It should be of the form from the OBO specification
Related topics
1 call to tripal_cv_obo_add_cvterm_dbxref()
- tripal_cv_obo_process_term in tripal_cv/
includes/ tripal_cv.obo_loader.inc - Uses the provided term array to add/update information to Chado about the term including the term, dbxref, synonyms, properties, and relationships.
File
- tripal_cv/
includes/ tripal_cv.obo_loader.inc, line 1265 - Functions to aid in loading ontologies into the chado cv module
Code
function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
$dbname = preg_replace('/^(.+?):.*$/', '$1', $xref);
$accession = preg_replace('/^.+?:\s*(.*?)(\{.+$|\[.+$|\s.+$|\".+$|$)/', '$1', $xref);
$description = preg_replace('/^.+?\"(.+?)\".*?$/', '$1', $xref);
$dbxrefs = preg_replace('/^.+?\[(.+?)\].*?$/', '$1', $xref);
if (!$accession) {
tripal_cv_obo_quiterror();
tripal_report_error("T_obo_loader", TRIPAL_WARNING, "Cannot add a dbxref without an accession: '$xref'", NULL);
return FALSE;
}
// if the xref is a database link, handle that specially
if (strcmp($dbname, 'http') == 0) {
$accession = $xref;
$dbname = 'URL';
}
// add the database
$db = tripal_insert_db(array('name' => $dbname));
if (!$db) {
tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
}
// now add the dbxref
$dbxref = tripal_cv_obo_add_dbxref($db->db_id, $accession, '', $description);
if (!$dbxref) {
tripal_cv_obo_quiterror("Cannot find or add the database reference (dbxref)");
}
// finally add the cvterm_dbxref but first check to make sure it exists
$values = array(
'cvterm_id' => $cvterm->cvterm_id,
'dbxref_id' => $dbxref->dbxref_id,
);
$result = chado_select_record('cvterm_dbxref', array('*'), $values);
if (count($result) == 0) {
$ins_options = array('return_record' => FALSE);
$result = chado_insert_record('cvterm_dbxref', $values, $ins_options);
if (!$result) {
tripal_cv_obo_quiterror("Cannot add cvterm_dbxref: $xref");
return FALSE;
}
}
return TRUE;
}