function chado_feature_add_gbaccession
1.x tripal_feature.module | chado_feature_add_gbaccession($accession, $feature_id) |
Related topics
File
- tripal_feature/
tripal_feature.module, line 688 - @todo Add file header description
Code
function chado_feature_add_gbaccession($accession, $feature_id) {
// use chado database
// remove any old accession from genbank dbEST
$fdbxref_dsql = "DELETE FROM {feature_dbxref} " .
"WHERE feature_id = %d and dbxref_id IN " .
" (SELECT DBX.dbxref_id FROM {dbxref} DBX " .
" INNER JOIN DB ON DB.db_id = DBX.db_id " .
" INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id " .
" WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = %d)";
if (!chado_query($fdbxref_dsql, $feature_id, $feature_id)) {
$error .= "Could not remove accession from feature. ";
}
// if we don't have an accession number to add then just return
if (!$accession) {
return;
}
// get the db_id
$db_sql = "SELECT db_id FROM {DB} " .
"WHERE name = 'DB:Genbank_est'";
$db = db_fetch_object(chado_query($db_sql));
// check to see if we have this accession number already in the database
// if so then don't add it again. it messes up drupal if the insert fails.
// It is possible for the accession number to be present and not the feature
$dbxref_sql = "SELECT dbxref_id FROM {dbxref} " .
"WHERE db_id = %d and accession = '%s'";
$dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
if (!$dbxref) {
// add the accession number
$dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) " .
" VALUES (%d, '%s') ";
if (!chado_query($dbxref_isql, $db->db_id, $accession)) {
$error .= 'Could not add accession as a database reference ';
}
// get the dbxref_id for the just added accession number
$dbxref_sql = "SELECT dbxref_id FROM {dbxref} " .
"WHERE db_id = %d and accession = '%s'";
$dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
}
// associate the accession number with the feature
$feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) " .
" VALUES (%d, %d) ";
if (!chado_query($feature_dbxref_isql, $feature_id, $dbxref->dbxref_id)) {
$error .= 'Could not add feature database reference. ';
}
return $error;
}