12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286 |
- <?php
- function chado_get_publication($identifiers, $options = array()) {
-
- 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.",
- array('%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.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
-
-
- if (array_key_exists('property', $identifiers)) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $pub = chado_get_record_with_property(
- array('table' => 'pub', 'base_records' => $identifiers),
- array('type_name' => $property),
- $options
- );
- }
- elseif (array_key_exists('dbxref', $identifiers)) {
- if(preg_match('/^(.*?):(.*?)$/', $identifiers['dbxref'], $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
-
- $values = array(
- 'accession' => $accession,
- 'db_id' => array(
- 'name' => $dbname
- ),
- );
- $dbxref = chado_select_record('dbxref', array('dbxref_id'), $values);
- if (count($dbxref) == 0) {
- return FALSE;
- }
- $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), array('dbxref_id' => $dbxref[0]->dbxref_id));
- if (count($pub_dbxref) == 0) {
- return FALSE;
- }
- $pub = chado_generate_var('pub', array('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.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
- }
- elseif (array_key_exists('dbxref_id', $identifiers)) {
-
- $values = array('dbxref_id' => $identifiers['dbxref_id']);
- $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), $values);
-
- if (count($pub_dbxref) > 0) {
- $pub = chado_generate_var('pub', array('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.",
- array('%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.",
- array('%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(array('dbxref' => $pub_details['Publication Dbxref']));
- if($pub) {
- return array($pub->pub_id);
- }
- }
-
- if (array_key_exists('Citation', $pub_details)) {
- $pub = chado_get_publication(array('uniquename' => $pub_details['Citation']));
- if($pub) {
- return array($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 = 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();
- }
-
-
- $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 = 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;
- }
- function chado_autocomplete_pub($string = '') {
- $items = array();
- $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, array(':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 " .
- "deletions 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 = 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);
- }
-
- _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 = array();
- $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 = array(
- '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 " .
- "deletions 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 = array(':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 {
-
- tripal_report_error($message_type, TRIPAL_INFO,
- "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);
- foreach ($subset_report as $action => $pubs) {
- $report[$action] = array_merge($report[$action], $pubs);
- }
- $page++;
- }
- while (count($pubs) == $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 " .
- "deletions 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 = array();
- 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 = array();
- $search = array();
-
- while ($pub = $results->fetchObject()) {
- $accession = $pub->accession;
- $remote_db = $pub->db_name;
-
- $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
- if(!in_array($remote_db, $supported_dbs)) {
- continue;
- }
- $search = array(
- 'num_criteria' => 1,
- 'remote_db' => $remote_db,
- 'criteria' => array(
- '1' => array(
- '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, array(':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, array(':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, array(':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_minimal_pub_info($pub) {
- if (!$pub) {
- return array();
- }
-
- if (isset($pub->uniquename) && $pub->uniquename == 'null') {
- return array();
- }
-
- $pub = chado_expand_var($pub, 'field', 'pub.title');
- $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Abstract',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $abstract = chado_generate_var('pubprop', $values, $options);
- $abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
- $abstract_text = '';
- if ($abstract) {
- $abstract_text = htmlspecialchars($abstract->value);
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Authors',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $authors = chado_generate_var('pubprop', $values, $options);
- $authors = chado_expand_var($authors, 'field', 'pubprop.value');
- $authors_list = 'N/A';
- if ($authors) {
- $authors_list = $authors->value;
- }
-
- $options = array('return_array' => 1);
- $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
- $dbxref = NULL;
- if ($pub->pub_dbxref) {
- foreach ($pub->pub_dbxref as $index => $pub_dbxref) {
- if ($pub_dbxref->dbxref_id->db_id->urlprefix) {
- $dbxref = $pub_dbxref->dbxref_id;
- }
- }
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'URL',
- ),
- );
- $options = array(
- 'return_array' => 1,
- 'include_fk' => array(),
- );
- $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;
- }
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- );
- $options = array(
- 'return_array' => 1,
- );
- $pub_dbxrefs = chado_generate_var('pub_dbxref', $values, $options);
- $dbxrefs = array();
- foreach ($pub_dbxrefs as $pub_dbxref) {
- $dbxrefs[] = $pub_dbxref->dbxref_id->db_id->name . ':' . $pub_dbxref->dbxref_id->accession;
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Citation',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $citation = chado_generate_var('pubprop', $values, $options);
- if ($citation) {
- $citation = chado_expand_var($citation, 'field', 'pubprop.value');
- $citation = $citation->value;
- }
- else {
- $pub_info = array(
- '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 array(
- 'TPUB:0000039' => $pub->title,
- 'TPUB:0000003' => $citation,
- 'TPUB:0000050' => $abstract_text,
- 'TPUB:0000047' => $authors_list,
- 'TPUB:0000052' => $url,
- 'SBO:0000554' => $dbxrefs,
- );
- }
|