function tripal_pub_add_publications
2.x tripal_pub.pub_importers.inc | tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) |
3.x tripal_chado.pub_importers.inc | tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) |
1.x tripal_pub.api.inc | tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) |
Adds publications that have been retrieved from a remote database and consolidated into an array of details.
Parameters
$pubs: An array containing a list of publications to add to Chado. The array contains a set of details for the publication.
$do_contact: Set to TRUE if authors should automatically have a contact record added to Chado.
$update: If set to TRUE then publications that already exist in the Chado database will be updated, whereas if FALSE only new publications will be added
Return value
Returns an array containing the number of publications that were inserted, updated, skipped and which had an error during import.
Related topics
4 calls to tripal_pub_add_publications()
- tripal_execute_active_pub_importers in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Imports all publications for all active import setups.
- tripal_execute_pub_importer in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Imports all publications for a given publication import setup.
- tripal_import_pub_by_dbxref in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Imports a singe publication specified by a remote database cross reference.
- tripal_reimport_publications in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Updates publication records that currently exist in the Chado pub table with the most recent data in the remote database.
File
- tripal_pub/
includes/ tripal_pub.pub_importers.inc, line 873 - Management of importers
Code
function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) {
$report = array();
$report['error'] = 0;
$report['inserted'] = array();
$report['skipped'] = array();
$total_pubs = count($pubs);
// iterate through the publications and add each one
$i = 1;
foreach ($pubs as $pub) {
$memory = number_format(memory_get_usage()) . " bytes";
print "Processing $i of $total_pubs. Memory usage: $memory.\r";
// add the publication to Chado
$action = '';
$pub_id = tripal_pub_add_publication($pub, $action, $do_contact, $update);
if ($pub_id) {
// add the publication cross reference (e.g. to PubMed)
if ($pub_id and $pub['Publication Dbxref']) {
$dbxref = array();
if (preg_match('/^(.*?):(.*?)$/', trim($pub['Publication Dbxref']), $matches)) {
$dbxref['db_name'] = $matches[1];
$dbxref['accession'] = $matches[2];
}
else {
tripal_report_error(
'tripal_pub',
TRIPAL_ERROR,
'Unable to extract the dbxref to be associated with the publication (pub ID=@pub_id) from @dbxref. This reference should be [database-name]:[accession]',
array('@pub_id' => $pub_id, '@dbxref' => $pub['Publication Dbxref'])
);
}
$pub_dbxref = tripal_associate_dbxref('pub', $pub_id, $dbxref);
}
$pub['pub_id'] = $pub_id;
}
switch ($action) {
case 'error':
$report['error']++;
break;
case 'inserted':
$report['inserted'][] = $pub;
break;
case 'updated':
$report['updated'][] = $pub;
break;
case 'skipped':
$report['skipped'][] = $pub;
break;
}
$i++;
}
print "\n";
return $report;
}