123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365 |
- <?php
- function chado_get_publication($identifiers, $options = []) {
-
- if (!is_array($identifiers)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The identifier passed in is expected to be an array with the key
- matching a column name in the pub table (ie: pub_id or name). You passed in %identifier.",
- ['%identifier' => print_r($identifiers, TRUE)]
- );
- }
- elseif (empty($identifiers)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: You did not pass in anything to identify the publication you want. The identifier
- is expected to be an array with the key matching a column name in the pub table
- (ie: pub_id or name). You passed in %identifier.",
- ['%identifier' => print_r($identifiers, TRUE)]
- );
- }
-
-
- if (array_key_exists('property', $identifiers)) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $pub = chado_get_record_with_property(
- ['table' => 'pub', 'base_records' => $identifiers],
- ['type_name' => $property],
- $options
- );
- }
- elseif (array_key_exists('dbxref', $identifiers)) {
- if (preg_match('/^(.*?):(.*?)$/', $identifiers['dbxref'], $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
-
- $values = [
- 'accession' => $accession,
- 'db_id' => [
- 'name' => $dbname,
- ],
- ];
- $dbxref = chado_select_record('dbxref', ['dbxref_id'], $values);
- if (count($dbxref) == 0) {
- return FALSE;
- }
- $pub_dbxref = chado_select_record('pub_dbxref', ['pub_id'], ['dbxref_id' => $dbxref[0]->dbxref_id]);
- if (count($pub_dbxref) == 0) {
- return FALSE;
- }
- $pub = chado_generate_var('pub', ['pub_id' => $pub_dbxref[0]->pub_id], $options);
- }
- else {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The dbxref identifier is not correctly formatted. Identifiers passed: %identifier.",
- ['%identifier' => print_r($identifiers, TRUE)]
- );
- }
- }
- elseif (array_key_exists('dbxref_id', $identifiers)) {
-
- $values = ['dbxref_id' => $identifiers['dbxref_id']];
- $pub_dbxref = chado_select_record('pub_dbxref', ['pub_id'], $values);
-
- if (count($pub_dbxref) > 0) {
- $pub = chado_generate_var('pub', ['pub_id' => $pub_dbxref[0]->pub_id], $options);
- }
- else {
- return FALSE;
- }
- }
-
-
- else {
-
- $pub = chado_generate_var('pub', $identifiers, $options);
- }
-
- if (is_array($pub)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The identifiers did not find a single unique record. Identifiers passed: %identifier.",
- ['%identifier' => print_r($identifiers, TRUE)]
- );
- }
-
- elseif ($pub === FALSE) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: Could not find a publication using the identifiers
- provided. Check that the identifiers are correct. Identifiers passed: %identifier.",
- ['%identifier' => print_r($identifiers, TRUE)]
- );
- }
-
- else {
- return $pub;
- }
- }
- function chado_publication_exists($pub_details) {
-
-
- if (array_key_exists('Publication Dbxref', $pub_details)) {
- $pub = chado_get_publication(['dbxref' => $pub_details['Publication Dbxref']]);
- if ($pub) {
- return [$pub->pub_id];
- }
- }
-
- if (array_key_exists('Citation', $pub_details)) {
- $pub = chado_get_publication(['uniquename' => $pub_details['Citation']]);
- if ($pub) {
- return [$pub->pub_id];
- }
- }
-
- 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 = [
- 'name' => $type_name,
- 'cv_id' => [
- '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", []);
- return [];
- }
- if (!$pub_type) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR,
- "chado_publication_exists(): Cannot find publication type: '%type'",
- ['%type' => $pub_details['Publication Type'][0]]);
- return [];
- }
-
-
- $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);
- }
-
-
- $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
- $pubs = [];
- switch ($import_dups_check) {
- case 'title_year':
- $identifiers = [
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year'],
- ];
- $pubs = chado_select_record('pub', ['pub_id'], $identifiers);
- break;
- case 'title_year_type':
- $identifiers = [
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year'],
- 'type_id' => $pub_type->cvterm_id,
- ];
- $pubs = chado_select_record('pub', ['pub_id'], $identifiers);
- break;
- case 'title_year_media':
- $identifiers = [
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year'],
- 'series_name' => $series_name,
- ];
- $pubs = chado_select_record('pub', ['pub_id'], $identifiers);
- break;
- }
- $return = [];
- foreach ($pubs as $pub) {
- $return[] = $pub->pub_id;
- }
- return $return;
- }
- function chado_autocomplete_pub($string = '') {
- $items = [];
- $sql = "
- SELECT pub_id, title, uniquename
- FROM {pub}
- WHERE lower(title) like lower(:str)
- ORDER by title
- LIMIT 25 OFFSET 0
- ";
- $pubs = chado_query($sql, [':str' => $string . '%']);
- while ($pub = $pubs->fetchObject()) {
- $val = $pub->title . " [id: " . $pub->pub_id . "]";
- $items[$val] = $pub->title;
- }
- drupal_json_output($items);
- }
- function chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE,
- $publish = TRUE, $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');
-
-
-
- $message_type = 'pub_import';
- $message_opts = [
- 'watchdog' => FALSE,
- 'print' => TRUE,
- ];
- $message = "Importing of publications is performed using a database transaction. " .
- "If the load fails or is terminated prematurely then the entire set of " .
- "insertions/updates is rolled back and will not be found in the database";
- tripal_report_error($message_type, TRIPAL_INFO, $message, [], $message_opts);
- $transaction = db_transaction();
- try {
- if (preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
- $criteria = [
- 'num_criteria' => 1,
- 'remote_db' => $dbname,
- 'criteria' => [
- '1' => [
- '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);
- }
-
- _chado_execute_pub_importer_publish($publish, NULL, $message_type, $message_opts);
- } catch (Exception $e) {
- $transaction->rollback();
- print "\n";
- watchdog_exception('T_pub_import', $e);
- print "FAILED: Rolling back database changes...\n";
- return;
- }
- }
- function chado_execute_active_pub_importers($report_email = FALSE,
- $publish = TRUE, $do_update = FALSE) {
- $report = [];
- $report['error'] = [];
- $report['inserted'] = [];
- $report['skipped'] = [];
- $report['updated'] = [];
-
- $args = [];
- $sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
- $importers = db_query($sql, $args);
- $do_contact = FALSE;
- while ($import = $importers->fetchObject()) {
- $importer_report = chado_execute_pub_importer($import->pub_import_id, $publish, $do_update);
- foreach ($importer_report as $action => $pubs) {
- $report[$action] = array_merge($report[$action], $pubs);
- }
- }
- $site_email = variable_get('site_mail', '');
- $params = [
- 'report' => $report,
- ];
- drupal_mail('tripal_chado', 'import_report', $report_email, language_default(), $params, $site_email, TRUE);
- print "Done.\n";
- }
- function chado_execute_pub_importer($import_id, $publish = TRUE,
- $do_update = FALSE, $job = NULL) {
-
- $report = [];
- $report['error'] = [];
- $report['inserted'] = [];
- $report['skipped'] = [];
- $report['updated'] = [];
-
-
-
- $message_type = 'pub_import';
- $message_opts = [
- 'watchdog' => FALSE,
- 'job' => $job,
- 'print' => TRUE,
- ];
- $message = "Importing of publications for this importer is performed using a database transaction. " .
- "If the load fails or is terminated prematurely then the entire set of " .
- "insertions/updates is rolled back and will not be found in the database";
- tripal_report_error($message_type, TRIPAL_INFO, $message, [], $message_opts);
-
- $transaction = db_transaction();
- try {
- $page = 0;
- $do_contact = FALSE;
- $num_to_retrieve = 100;
-
- $args = [':import_id' => $import_id];
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
- $import = db_query($sql, $args)->fetchObject();
- tripal_report_error($message_type, TRIPAL_INFO,
- "Executing Importer: !name.", ['!name' => $import->name], $message_opts);
- $criteria = unserialize($import->criteria);
- $remote_db = $criteria['remote_db'];
- $total_pubs = 0;
-
-
- do {
-
- $npages = isset($num_pubs)?(intval($num_pubs/$num_to_retrieve)+1):'?';
- tripal_report_error($message_type, TRIPAL_INFO,
- "Page ".($page+1)." of $npages. Querying !remote_db for up to !num pubs that match the criteria.",
- [
- '!num' => $num_to_retrieve,
- '!remote_db' => $remote_db,
- ], $message_opts);
- $results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
- $pubs = $results['pubs'];
- $num_pubs = $results['total_records'];
- $total_pubs += $num_pubs;
- tripal_report_error($message_type, TRIPAL_INFO,
- "Found %num publications.",
- ['%num' => $num_pubs], $message_opts);
- $subset_report = tripal_pub_add_publications($pubs, $import->do_contact, $do_update, $job);
- $countpubs = count($pubs);
- foreach ($subset_report as $action => $pubs) {
- $report[$action] = array_merge($report[$action], $pubs);
- }
- $page++;
- } while ($countpubs == $num_to_retrieve);
-
- _chado_execute_pub_importer_publish($publish, $job, $message_type, $message_opts);
- if ($job) {
- $job->setProgress(100);
- }
- } catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('T_pub_import', $e);
- tripal_report_error($message_type, TRIPAL_ERROR,
- "Rolling back database changes... !message",
- ['!message' => $e->getMessage()], $message_opts);
- return FALSE;
- }
- tripal_report_error($message_type, TRIPAL_INFO,
- "Done.", [], $message_opts);
- return $report;
- }
- function _chado_execute_pub_importer_publish($publish, $job, $message_type, $message_opts) {
-
- if ($publish === TRUE or $publish === 'both') {
-
- $bundle_term = tripal_load_term_entity([
- 'vocabulary' => 'TPUB',
- 'accession' => '0000002',
- ]);
- $bundle = tripal_load_bundle_entity(['term_id' => $bundle_term->id]);
- if ($bundle) {
- tripal_report_error($message_type, TRIPAL_INFO,
- "Publishing publications with Drupal...", [], $message_opts);
- chado_publish_records(['bundle_name' => $bundle->name], $job);
- }
-
-
-
-
- }
-
- if ($publish === 'sync' or $publish === 'both') {
- if (module_exists('tripal_pub')) {
- tripal_report_error($message_type, TRIPAL_INFO,
- "Syncing publications with Drupal...", [], $message_opts);
- chado_node_sync_records('pub');
- if ($import->do_contact) {
- tripal_report_error($message_type, TRIPAL_INFO,
- "Syncing contacts with Drupal...", [], $message_opts);
- chado_node_sync_records('contact');
- }
- }
- }
- }
- function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL,
- $db = NULL, $publish = TRUE) {
-
-
-
- $message_type = 'pub_import';
- $message_opts = [
- 'watchdog' => FALSE,
- 'print' => TRUE,
- ];
- $message = "Importing of publications for this importer is performed using a database transaction. " .
- "If the load fails or is terminated prematurely then the entire set of " .
- "insertions/updates is rolled back and will not be found in the database";
- tripal_report_error($message_type, TRIPAL_INFO, $message, [], $message_opts);
- $transaction = db_transaction();
- try {
-
-
- $sql = "
- SELECT DB.name as db_name, DBX.accession
- FROM {pub} P
- INNER JOIN {pub_dbxref} PDBX ON P.pub_id = PDBX.pub_id
- INNER JOIN {dbxref} DBX ON DBX.dbxref_id = PDBX.dbxref_id
- INNER JOIN {db} DB ON DB.db_id = DBX.db_id
- ";
- $args = [];
- if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
- $sql .= "WHERE DBX.accession = :accession and DB.name = :dbname ";
- $args[':accession'] = $accession;
- $args[':dbname'] = $dbname;
- }
- elseif ($db) {
- $sql .= " WHERE DB.name = :dbname ";
- $args[':dbname'] = $db;
- }
- $sql .= "ORDER BY DB.name, P.pub_id";
- $results = chado_query($sql, $args);
- $num_to_retrieve = 100;
- $i = 0;
- $curr_db = '';
- $ids = [];
- $search = [];
-
- while ($pub = $results->fetchObject()) {
- $accession = $pub->accession;
- $remote_db = $pub->db_name;
-
- $supported_dbs = variable_get('tripal_pub_supported_dbs', []);
- if (!in_array($remote_db, $supported_dbs)) {
- continue;
- }
- $search = [
- 'num_criteria' => 1,
- 'remote_db' => $remote_db,
- 'criteria' => [
- '1' => [
- 'search_terms' => "$remote_db:$accession",
- 'scope' => 'id',
- 'operation' => '',
- 'is_phrase' => 0,
- ],
- ],
- ];
- $qresults = tripal_get_remote_pubs($remote_db, $search, 1, 0);
- $pubs = $qresults['pubs'];
- tripal_pub_add_publications($pubs, $do_contact, TRUE);
- $i++;
- }
-
- _chado_execute_pub_importer_publish($publish, NULL, $message_type, $message_opts);
- } catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('T_pub_import', $e);
- tripal_report_error($message_type, TRIPAL_ERROR,
- "Rolling back database changes... !message",
- ['!message' => $e->getMessage()], $message_opts);
- return;
- }
- print "Done.\n";
- }
- function chado_pub_create_citations($options) {
- $skip_existing = TRUE;
- $sql = "
- SELECT cvterm_id
- FROM {cvterm}
- WHERE
- name = 'Citation' AND
- cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
- ";
- $citation_type_id = chado_query($sql)->fetchField();
-
- if ($options == 'all') {
- $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
- $skip_existing = FALSE;
- }
-
- else {
- if ($options == 'new') {
- $sql = "
- SELECT pub_id
- FROM {pub} P
- WHERE
- (SELECT value
- FROM {pubprop} PB
- WHERE type_id = :type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL
- AND pub_id <> 1
- ";
- $skip_existing = TRUE;
- }
- }
- $result = chado_query($sql, [':type_id' => $citation_type_id]);
- $counter_updated = 0;
- $counter_generated = 0;
- while ($pub = $result->fetchObject()) {
- $pub_arr = tripal_pub_get_publication_array($pub->pub_id, $skip_existing);
- if ($pub_arr) {
- $citation = chado_pub_create_citation($pub_arr);
- print $citation . "\n\n";
-
-
- if ($pub_arr['Citation']) {
- $sql = "
- UPDATE {pubprop} SET value = :value
- WHERE pub_id = :pub_id AND type_id = :type_id AND rank = :rank
- ";
- chado_query($sql, [
- ':value' => $citation,
- ':pub_id' => $pub->pub_id,
- ':type_id' => $citation_type_id,
- ':rank' => 0,
- ]);
- $counter_updated++;
-
- }
- else {
- $sql = "
- INSERT INTO {pubprop} (pub_id, type_id, value, rank)
- VALUES (:pub_id, :type_id, :value, :rank)
- ";
- chado_query($sql, [
- ':pub_id' => $pub->pub_id,
- ':type_id' => $citation_type_id,
- ':value' => $citation,
- ':rank' => 0,
- ]);
- $counter_generated++;
- }
- }
- }
- print "$counter_generated citations generated. $counter_updated citations updated.\n";
- }
- function chado_pub_create_citation($pub) {
- $citation = '';
- $pub_type = '';
-
-
-
-
-
- if (is_array($pub['Publication Type'])) {
- foreach ($pub['Publication Type'] as $ptype) {
- if ($ptype == 'Journal Article') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == 'Conference Proceedings') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == 'Review') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == 'Book') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == 'Letter') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == 'Book Chapter') {
- $pub_type = $ptype;
- break;
- }
- else {
- if ($ptype == "Research Support, Non-U.S. Gov't") {
- $pub_type = $ptype;
-
-
- }
- }
- }
- }
- }
- }
- }
- }
-
-
- if (!$pub_type) {
- $pub_type = $pub['Publication Type'][0];
- }
- }
- else {
- $pub_type = $pub['Publication Type'];
- }
-
-
-
- if ($pub_type == 'Journal Article') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages', $pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- else {
- if ($pub_type == 'Review') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages', $pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == 'Letter') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages', $pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == 'Conference Proceedings') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Conference Name', $pub)) {
- $citation .= $pub['Conference Name'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages', $pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- else {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages', $pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
- }
- return $citation;
- }
- function chado_get_pub_dbxrefs($pub_id) {
- $fkey = 'pub_id';
- $options = ['return_array' => 1];
- $sql = "SELECT REF.accession, REF.version, REF.description, DB.name, DB.url, DB.urlprefix "
- . "FROM {pub_dbxref} LINK "
- . "INNER JOIN {dbxref} REF on LINK.dbxref_id = REF.dbxref_id "
- . "INNER JOIN {db} DB on REF.db_id = DB.db_id "
- . "WHERE LINK.$fkey = :pub_id";
- $args = [':pub_id' => $pub_id];
- $records = chado_query($sql, $args);
- $results = [];
- $delta = 0;
- while($record = $records->fetchObject()) {
- $results[$delta]['accession'] = $record->accession;
- $results[$delta]['version'] = $record->version;
- $results[$delta]['description'] = $record->description;
- $results[$delta]['name'] = $record->name;
- $results[$delta]['url'] = $record->url;
- $results[$delta]['urlprefix'] = $record->urlprefix;
- $delta++;
- }
- return $results;
- }
- function chado_get_minimal_pub_info($pub) {
- if (!$pub) {
- return [];
- }
-
- if (isset($pub->uniquename) && $pub->uniquename == 'null') {
- return [];
- }
-
- $pub = chado_expand_var($pub, 'field', 'pub.title');
- $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
-
- $values = [
- 'pub_id' => $pub->pub_id,
- 'type_id' => [
- 'name' => 'Abstract',
- ],
- ];
- $options = [
- 'include_fk' => [
- ],
- ];
- $abstract = chado_generate_var('pubprop', $values, $options);
- $abstract_text = '';
- if($abstract) {
- $abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
- if ($abstract) {
- $abstract_text = htmlspecialchars($abstract->value);
- }
- }
-
- $values = [
- 'pub_id' => $pub->pub_id,
- 'type_id' => [
- 'name' => 'Authors',
- ],
- ];
- $options = [
- 'include_fk' => [
- ],
- ];
- $authors = chado_generate_var('pubprop', $values, $options);
- $authors_list = 'N/A';
- if($authors) {
- $authors = chado_expand_var($authors, 'field', 'pubprop.value');
- if ($authors) {
- $authors_list = $authors->value;
- }
- }
-
- $pub_dbxrefs = chado_get_pub_dbxrefs($pub->pub_id);
-
-
- $values = [
- 'pub_id' => $pub->pub_id,
- 'type_id' => [
- 'name' => 'URL',
- ],
- ];
- $options = [
- 'return_array' => 1,
- 'include_fk' => [],
- ];
- $url = '';
- $urls = chado_generate_var('pubprop', $values, $options);
- if ($urls) {
- $urls = chado_expand_var($urls, 'field', 'pubprop.value');
- if (count($urls) > 0) {
- $url = $urls[0]->value;
- }
- }
-
- $dbxrefs = [];
- foreach ($pub_dbxrefs as $pub_dbxref) {
- $dbxrefs[] = $pub_dbxref['name'] . ':' . $pub_dbxref['accession'];
- }
-
- $values = [
- 'pub_id' => $pub->pub_id,
- 'type_id' => [
- 'name' => 'Citation',
- ],
- ];
- $options = [
- 'include_fk' => [
- ],
- ];
- $citation = chado_generate_var('pubprop', $values, $options);
- if ($citation) {
- $citation = chado_expand_var($citation, 'field', 'pubprop.value');
- $citation = $citation->value;
- }
- else {
- $pub_info = [
- 'Title' => $pub->title,
- 'Publication Type' => $pub->type_id->name,
- 'Authors' => $authors_list,
- 'Series Name' => $pub->series_name,
- 'Volume' => $pub->volume,
- 'Issue' => $pub->issue,
- 'Pages' => $pub->pages,
- 'Publication Date' => $pub->pyear,
- ];
- $citation = chado_pub_create_citation($pub_info);
- }
- return [
- 'TPUB:0000039' => $pub->title,
- 'TPUB:0000003' => $citation,
- 'TPUB:0000050' => $abstract_text,
- 'TPUB:0000047' => $authors_list,
- 'TPUB:0000052' => $url,
- 'SBO:0000554' => $dbxrefs,
- ];
- }
|