function chado_import_pub_by_dbxref
3.x tripal_chado.pub.api.inc | chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update = TRUE) |
Imports a singe publication specified by a remote database cross reference.
Parameters
$pub_dbxref: The unique database ID for the record to update. This value must be of the format DB_NAME:ACCESSION where DB_NAME is the name of the database (e.g. PMID or AGL) and the ACCESSION is the unique identifier for the record in the database.
$do_contact: Set to TRUE if authors should automatically have a contact record added to Chado.
$do_update: If set to TRUE then the publication will be updated if it already exists in the database.
Related topics
3 calls to chado_import_pub_by_dbxref()
- drush_tripal_chado_trp_import_pubs in tripal_chado/
tripal_chado.drush.inc - Imports publications into Chado
- tripal_chado_prepare_chado in tripal_chado/
includes/ setup/ tripal_chado.setup.inc - Prepares Chado for use by Tripal.
- tripal_import_pub_by_dbxref in tripal_chado/
api/ modules/ tripal_chado.module.DEPRECATED.api.inc - Imports a singe publication specified by a remote database cross reference.
File
- tripal_chado/
api/ modules/ tripal_chado.pub.api.inc, line 340 - Provides API functions specificially for managing publication records in Chado.
Code
function chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update = TRUE) {
$num_to_retrieve = 1;
$pager_id = 0;
$page = 0;
$num_pubs = 0;
$pub_id = NULL;
module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');
print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
"If the load fails or is terminated prematurely then the entire set of \n" .
"insertions/updates is rolled back and will not be found in the database\n\n";
$transaction = db_transaction();
try {
if (preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
$dbname = $matches[1];
$accession = $matches[2];
$criteria = array(
'num_criteria' => 1,
'remote_db' => $dbname,
'criteria' => array(
'1' => array(
'search_terms' => "$dbname:$accession",
'scope' => 'id',
'operation' => '',
'is_phrase' => 0,
),
),
);
$remote_db = $criteria['remote_db'];
$results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
$pubs = $results['pubs'];
$search_str = $results['search_str'];
$total_records = $results['total_records'];
tripal_pub_add_publications($pubs, $do_contact, $do_update);
}
// For backwards compatibility check to see if the legacy pub module
// is enabled. If so, then sync the nodes.
if (module_exists('tripal_pub')) {
// Sync the newly added publications with Drupal.
print "Syncing publications with Drupal...\n";
chado_node_sync_records('pub');
// If any of the importers wanted to create contacts from the authors
// then sync them.
if ($do_contact) {
print "Syncing contacts with Drupal...\n";
chado_node_sync_records('contact');
}
}
}
catch (Exception $e) {
$transaction->rollback();
print "\n"; // make sure we start errors on new line
watchdog_exception('T_pub_import', $e);
print "FAILED: Rolling back database changes...\n";
return;
}
}