function tripal_feature_add_dbxref
2.x tripal_feature.DEPRECATED.inc | tripal_feature_add_dbxref($feature_id, $dbname, $accession) |
3.x tripal_feature.DEPRECATED.inc | tripal_feature_add_dbxref($feature_id, $dbname, $accession) |
1.x tripal_feature.api.inc | tripal_feature_add_dbxref($feature_id, $dbname, $accession) |
File
- tripal_feature/
api/ tripal_feature.api.inc, line 1031 - Provides an application programming interface (API) for working with features
Code
function tripal_feature_add_dbxref($feature_id, $dbname, $accession) {
// make sure the db exists. If it doesn't, then add it
$values = array('name' => $dbname);
$options = array('statement_name' => 'sel_db_na');
$db = tripal_core_chado_select('db', array('db_id'), $values, $options);
if (!$db or count($db) == 0) {
$options = array('statement_name' => 'ins_db_na');
$success = tripal_core_chado_insert('db', $values, $options);
if (!$success) {
watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, ".
"could not be added because the database, %dbname, does not exist and cannot be added.',
array('%feature_id' => $feature_id, '%dbname' => $dbname), WATCHDOG_WARNING);
return FALSE;
}
}
// first make sure that the record doesn't already exist
$values = array(
'dbxref_id' => array(
'accession' => $accession,
'db_id' => array(
'name' => $dbname
),
),
'feature_id' => $feature_id,
);
$options = array('statement_name' => 'sel_featuredbxref_dbfe');
$xref = tripal_core_chado_select('feature_dbxref', array('feature_dbxref_id'), $values, $options);
if (count($xref) == 0) {
// if the record doesn't exist then add it.
$options = array('statement_name' => 'ins_featuredbxref_dbfe');
$success = tripal_core_chado_insert('feature_dbxref', $values, $options);
if (!$success) {
watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, ' .
'could not be added: %db:%accession.', array('%feature_id' => $feature_id, '%db' => $dbname,
'%accession' => $accession), WATCHDOG_WARNING);
return FALSE;
}
}
return TRUE;
}