function chado_publication_exists

3.x tripal_chado.pub.api.inc chado_publication_exists($pub_details)

The publication table of Chado only has a unique constraint for the uniquename of the publiation, but in reality a publication can be considered unique by a combination of the title, publication type, published year and series name (e.g. journal name or conference name). The site administrator can configure how publications are determined to be unique. This function uses the configuration specified by the administrator to look for publications that match the details specified by the $pub_details argument and indicates if one ore more publications match the criteria.

Parameters

$pub_details: An associative array with details about the publications. The expected keys are: 'Title': The title of the publication. 'Year': The published year of the publication. 'Publication Type': An array of publication types. A publication can have more than one type. 'Series Name': The series name of the publication. 'Journal Name': An alternative to 'Series Name'. 'Conference Name': An alternative to 'Series Name'. 'Citation': The publication citation (this is the value saved in the pub.uniquename field and must be unique).

If this key is present it will also be checked 'Publication Dbxref': A database cross reference of the form DB:ACCESSION where DB is the name of the database and ACCESSION is the unique identifier (e.g PMID:3483139).

Return value

An array containing the pub_id's of matching publications. Returns an empty array if no pubs match.

Related topics

2 calls to chado_publication_exists()
tripal_publication_exists in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
The publication table of Chado only has a unique constraint for the uniquename of the publiation, but in reality a publication can be considered unique by a combination of the title, publication type, published year and series name (e.g. journal name…
tripal_pub_add_publication in tripal_chado/includes/loaders/tripal_chado.pub_importers.inc
Adds a new publication to the Chado, along with all properties and database cross-references. If the publication does not already exist in Chado then it is added. If it does exist nothing is done. If the $update parameter is TRUE then the…

File

tripal_chado/api/modules/tripal_chado.pub.api.inc, line 190
Provides API functions specificially for managing publication records in Chado.

Code

function chado_publication_exists($pub_details) {

  // First try to find the publication using the accession number if that key 
  // exists in the details array.
  if (array_key_exists('Publication Dbxref', $pub_details)) {
    $pub = chado_get_publication(array('dbxref' => $pub_details['Publication Dbxref']));
    if ($pub) {
      return array($pub->pub_id);
    }
  }

  // Make sure the citation is unique.
  if (array_key_exists('Citation', $pub_details)) {
    $pub = chado_get_publication(array('uniquename' => $pub_details['Citation']));
    if ($pub) {
      return array($pub->pub_id);
    }
  }

  // Get the publication type (use the first publication type).
  if (array_key_exists('Publication Type', $pub_details)) {
    $type_name = '';
    if (is_array($pub_details['Publication Type'])) {
      $type_name = $pub_details['Publication Type'][0];
    }
    else {
      $type_name = $pub_details['Publication Type'];
    }
    $identifiers = array(
      'name' => $type_name,
      'cv_id' => array(
        'name' => 'tripal_pub',
      ),
    );
    $pub_type = chado_get_cvterm($identifiers);
  }
  else {
    tripal_report_error('tripal_pub', TRIPAL_ERROR, 
    "chado_publication_exists(): The Publication Type is a " .
      "required property but is missing", array());
    return array();
  }
  if (!$pub_type) {
    tripal_report_error('tripal_pub', TRIPAL_ERROR, 
    "chado_publication_exists(): Cannot find publication type: '%type'", 
    array('%type' => $pub_details['Publication Type'][0]));
    return array();
  }

  // Get the series name.  The pub.series_name field is only 255 chars so we 
  // must truncate to be safe.
  $series_name = '';
  if (array_key_exists('Series Name', $pub_details)) {
    $series_name = substr($pub_details['Series Name'], 0, 255);
  }
  if (array_key_exists('Journal Name', $pub_details)) {
    $series_name = substr($pub_details['Journal Name'], 0, 255);
  }
  if (array_key_exists('Conference Name', $pub_details)) {
    $series_name = substr($pub_details['Conference Name'], 0, 255);
  }

  // Make sure the publication is unique using the prefereed import 
  // duplication check.
  $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
  $pubs = array();
  switch ($import_dups_check) {
    case 'title_year':
      $identifiers = array(
        'title' => $pub_details['Title'],
        'pyear' => $pub_details['Year']
      );
      $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
      break;
    case 'title_year_type':
      $identifiers = array(
        'title' => $pub_details['Title'],
        'pyear' => $pub_details['Year'],
        'type_id' => $pub_type->cvterm_id,
      );
      $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
      break;
    case 'title_year_media':
      $identifiers = array(
        'title' => $pub_details['Title'],
        'pyear' => $pub_details['Year'],
        'series_name' => $series_name,
      );
      $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
      break;
  }

  $return = array();
  foreach ($pubs as $pub) {
    $return[] = $pub->pub_id;
  }

  return $return;
}