. * * * User defined settings * ~~~~~~~~~~~~~~~~~~~~~ */ $ncbi_Tool = "AssEd"; // Default display settings: $ps_ShowCounts = true; // make a table of search counts in pubmed and PMC $ps_ShowAuDetails = true; // make an AuthorProfile (if search is for an author) $ps_ShowJournals = true; // make a list of most popular journals $ps_ShowPublishers = true; // make a list of most popular publishers $ps_ShowLanguages = true; // make a list of languages $ps_ShowTrends = true; // make a bar chart of publishing trends by year $ps_ShowAuthors = true; // make a list of (co)authors $ps_ShowCloud = true; // make a tag cloud from abstracts // Ignore list for the word cloud $CloudIgnore = array("and","from","that","the","this","was","for","with","has","have","are","both","but","been","not","these","than","those","thus","which","were","any","their","had","its","there","our","they"); /* * You will also need to edit 'lib/Variables.php' * * * Changelog * ~~~~~~~~~ * - v0.3b - 2009-03-07 * - Completely rearranged code so that various items can be switched on and off as desired, and the file can be adapted for external use * - Added a world cloud option * - Added IsAuthor switch so that the tool can be used for things other than just AuthorProfiles * - v0.2b - 2008-11-02 * - Added languages to highlight tool * - v0.1b - 2008-10-25 * * * ********************************************************************************************************************************************/ error_reporting(E_ERROR); ini_set('display_errors', '1'); require_once("lib/Variables.php"); require_once("lib/SupportFunctions.php"); require_once("lib/DoiResolve.php"); include_once("lib/eSearch.php"); include_once("lib/eSummary.php"); include_once("lib/eFetch.php"); @include_once("lib/BioMedCentral.php"); session_start(); $PhpEntrezTool = new PubmedSearch(); // Run the object class PubmedSearch { var $SearchTerm; // string - our search term var $PostData; // array - posted input var $IsAuthor; // t/f - whether we are searching for an author var $ShowCounts; // t/f - make a table of search counts in pubmed and PMC var $ShowAuDetails; // t/f - make an AuthorProfile var $ShowJournals; // t/f - make a list of most popular journals var $ShowPublishers; // t/f - make a list of most popular publishers var $ShowLanguages; // t/f - make a list of languages var $ShowTrends; // t/f - make a bar chart of publishing trends by year var $ShowAuthors; // t/f - make a list of (co)authors var $ShowCloud; // t/f - make a tag cloud from abstracts var $OrderBy; // string - order by 'score' or 'date' var $HighLight; // array - strings to HighLight and score var $QueryKey; // string - pubmed session query number var $WebEnv; // string - pubmed session variable var $IdLists; // array - PMIDs for HighLight terms var $Weight; // array - weights for HighLight Terms var $Title; // string - page title var $Html; // string - page html var $Publications; // array - details of each pub needed for making the HTML, associated to PMIDs var $Abstracts; // array - abstracts associated to PMIDs var $Scores; var $Counts; // array - counts for publications in pubmed and PMC over various timescales var $Journals; // array - count for each journal var $Dois; // array - count for each top-level DOI, to turn into publishers var $Languages; // array - count for each language var $CoAuthors; // array - count for each (co)author var $Years; // array - count for each year published var $Cloud; // array - counts for each abstract word var $OaIdList; var $FullName; // array - list of full names found, if IsAuthor is switched on var $Emails; // array - list of emails, if IsAuthor is switched on var $Affiliations; // array - list of affiliations, if IsAuthor is switched on function PubmedSearch($SearchTerm = null, $Auto = true) { // Find the SearchTerm if (isset($SearchTerm)) $this->SearchTerm = $SearchTerm; // look for the term in the input variables elseif (isset($_GET['SearchTerm'])) $this->SearchTerm = $_GET['SearchTerm']; // look for the term in the postdata elseif (isset($_SESSION['SearchTerm'])) $this->SearchTerm = $_SESSION['SearchTerm']; // look for the term in the saved session variables // If no SearchTerm is found, return an error message else { $this->Title = "PET: Error"; $this->Html = "

Error: No search term specified.

\n"; $this->OutputHtml(); } $this->SearchTerm = str_replace("%20", " ", str_replace("_", " ", $this->SearchTerm)); // clean up SearchTerm // Extract other variables // Order by 'date' or 'score' - postdata needs to be given priority here if (isset($_GET['OrderBy'])) $this->OrderBy = $_GET['OrderBy']; else $this->OrderBy = 'guess'; // Layout variables -- load the defaults, then overrule Global $ps_ShowCounts, $ps_ShowJournals, $ps_ShowPublishers, $ps_ShowLanguages, $ps_ShowTrends, $ps_ShowAuthors, $ps_ShowCloud, $ps_ShowAuDetails; // Global defaults $this->ShowCounts = $ps_ShowCounts; $this->ShowJournals = $ps_ShowJournals; $this->ShowPublishers = $ps_ShowPublishers; $this->ShowLanguages = $ps_ShowLanguages; $this->ShowTrends = $ps_ShowTrends; $this->ShowAuthors = $ps_ShowAuthors; $this->ShowCloud = $ps_ShowCloud; $this->ShowAuDetails = $ps_ShowAuDetails; if (!empty($_GET['IsAuthor'])) $this->IsAuthor = true; if (isset($_SESSION['PostData'])) { $this->PostData = $_SESSION['PostData']; // Get the session data from other PET services if (isset($this->PostData['Searches'])) $this->HighLight = $this->PostData['Searches']; // extract the highlight terms if (empty($this->OrderBy) or ($this->OrderBy == "guess")) $this->OrderBy = "score"; // automatically assign OrderBy } if (empty($this->OrderBy) or ($this->OrderBy == "guess")) $this->OrderBy = "year"; // automatically assign OrderBy /*********************/ // If we're in automatic mode, run the functions if ($Auto) { if ($this->ShowCounts) $this->GetBasicCounts(); // Make a table of search counts if (isset($this->HighLight)) $this->MakeIdLists(); // Get PubMed IDs matching HighLight $this->RunSearch(); // Run the PubMed Search if (!empty($this->FullName)) $this->GetFullNameCounts(); // Add to this->Counts the counts for full author names if (!empty($this->ShowCloud)) $this->MakeCloud(); // Make a word cloud $this->PrintResults(); // Return the HTML } } /********************************************************************** * Function: GetBasicCounts( ) * - Get counts for various timescales from PubMed and PMC * - Runs automatically when $ShowCounts is 'true' */ function GetBasicCounts() { try { $eSearch = new eSearch( 'pubmed', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->Run(2); $this->Counts['PubMed (all)'] = $eSearch->Count; $this->QueryKey = $eSearch->QueryKey; $this->WebEnv = $eSearch->WebEnv; $eSearch = new eSearch( 'pubmed', "\"" . $this->SearchTerm . "\" AND (free full text[sb])", null, null, 20 ); $eSearch->Run(2); $this->Counts['Open Access'] = $eSearch->Count; $this->OaIdList = $eSearch->IdList; $eSearch = new eSearch( 'pubmed', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 3652; $eSearch->Run(2); $this->Counts['PubMed (10yr)'] = $eSearch->Count; $eSearch = new eSearch( 'pubmed', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 1826; $eSearch->Run(2); $this->Counts['PubMed (5yr)'] = $eSearch->Count; $eSearch = new eSearch( 'pubmed', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 365; $eSearch->Run(2); $this->Counts['PubMed (1yr)'] = $eSearch->Count; $eSearch = new eSearch( 'pmc', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->Run(2); $this->Counts['PMC (all)'] = $eSearch->Count; $eSearch = new eSearch( 'pmc', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 3652; $eSearch->Run(2); $this->Counts['PMC (10yr)'] = $eSearch->Count; $eSearch = new eSearch( 'pmc', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 1826; $eSearch->Run(2); $this->Counts['PMC (5yr)'] = $eSearch->Count; $eSearch = new eSearch( 'pmc', "\"" . $this->SearchTerm . "\"", null, null, 20, 'count'); $eSearch->RelDate = 365; $eSearch->Run(2); $this->Counts['PMC (1yr)'] = $eSearch->Count; } catch (Exception $e) { $this->Html = "

Caught an exception while trying to fetch document summaries (".$e->getMessage()."). Reloading the page to try again...

\n"; $this->OutputHtml(true); } } /********************************************************************** * Function: MakeIdLists( ) * - Fill $IdLists with arrays of PubMed IDs for the $HighLight terms; * - Fill $Weight with weights for each HighLight term; * - Fill $Counts with counts for each HighLight term; * - Runs automatically when $HighLight is not empty */ /****** CLEANUP NEEDED: extract SearchStrings somewhere before running anything that relies on them *********/ function MakeIdLists() { foreach ($this->HighLight as $Search) { $SearchTerm = "\"" . $this->SearchTerm . "\" (" . $Search['SearchString'] . ")"; try { $eSearch = new eSearch( "pubmed", $SearchTerm, "1900/01/01", date('Y/m/01'), $Search['AtMost'] ); $eSearch->Run(2); } catch (Exception $e) { $this->Html .= "

Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "

\n"; $this->SaveReload(); exit; } if (is_array($eSearch->IdList)) $this->IdLists[$Search['SearchString']] = $eSearch->IdList; elseif (is_string($eSearch->IdList)) $this->IdLists[$Search['SearchString']][] = $eSearch->IdList; // Calculate the weight to be given to each search -- the weight diminishes logarithmically thus giving additional weight to rare terms $weight[$Search['SearchString']] = 2; if ($Search['Count'] < 1000000) $this->Weight[$Search['SearchString']] = 3; if ($Search['Count'] < 100000) $this->Weight[$Search['SearchString']] = 4; if ($Search['Count'] < 10000) $this->Weight[$Search['SearchString']] = 6; if ($Search['Count'] < 1000) $this->Weight[$Search['SearchString']] = 9; if ($Search['Count'] < 100) $this->Weight[$Search['SearchString']] = 13; $this->Counts[$Search['SearchString']] = $eSearch->Count; } } /********************************************************************** * Function: RunSearch( ) * - Gets the array of PubMed results and processes them */ function RunSearch() { // Run the Search, and extract some info from the results $SearchTerm = "\"" . $this->SearchTerm . "\""; //if ($this->IsAuthor) $SearchTerm .= "[Author]"; // this breaks things $eSearch = new eSearch( 'pubmed', $SearchTerm, null, null, 20 ); $eSearch->Run(2); if (isset($_SESSION['ps_Publications'])) $this->Publications = $_SESSION['ps_Publications']; // check to see if we already have some processed publications saved $CutOff = $eSearch->Count; if ($CutOff > 250) $CutOff = 250; for ($eFs = (isset($this->Publications) ? count($this->Publications) : 0); $eFs < $CutOff; $eFs += 50) { try{ $eFetch = new eFetch( 'pubmed', $eSearch->QueryKey, $eSearch->WebEnv, $eSearch->Translation, $eFs, 50 ); $eFetch->Run(1); $eSummary = new eSummary( 'pubmed', $eSearch->QueryKey, $eSearch->WebEnv, $eFs, 50 ); $eSummary->Run(1); } catch (Exception $e) { $eSearch->DeleteCache(); $eSummary->DeleteCache(); unset($eSearch); try{ $eSearch = new eSearch( 'pubmed', $SearchTerm, null, null, 20 ); $eSearch->Run(2); $eFetch = new eFetch( 'pubmed', $eSearch->QueryKey, $eSearch->WebEnv, $eSearch->Translation, $eFs, 50); $eFetch->Run(1); $eSummary = new eSummary( 'pubmed', $eSearch->QueryKey, $eSearch->WebEnv, $eFs, 50 ); $eSummary->Run(1); } catch (Exception $f) { $this->Html = "

Caught an exception while trying to fetch document summaries (".$e->getMessage()."). Reloading the page to try again...

\n"; $this->SaveReload(); } } foreach ($eFetch->Array['PubmedArticle'] as &$Pub) { // Merge the eSummary into the eFetch // - unfortunately, there are a few details in eSummary which aren't available in eFetch if (!empty($eSummary->Array['DocSum'][$Pub['MedlineCitation']['PMID']])) $Pub = array_merge($Pub, $eSummary->Array['DocSum'][$Pub['MedlineCitation']['PMID']]); unset($eSummary->Array['DocSum'][$Pub['MedlineCitation']['PMID']]); // Send it off to ExtractPaper for processing $this->ExtractPaper($Pub); unset($Pub); } } } /********************************************************************** * Function: ExtractPaper( Pub - merged array of eSummary and eFetch ) * - Gets the array of PubMed results and processes them */ function ExtractPaper($Pub) { /*************************/ // Make sure we have the correct associations $Pub['Id'] = $Pub['MedlineCitation']['PMID']; // PubMed ID if (empty($Pub['Source'])) { // Journal if (!empty($Pub['MedlineCitation']['Article']['Journal']['ISOAbbreviation'])) $Pub['Source'] = $Pub['MedlineCitation']['Article']['Journal']['ISOAbbreviation']; else $Pub['Source'] = $Pub['MedlineCitation']['Article']['Journal']['Title']; } /*************************/ // Counts: Journals, Publishers, Languages, Years, (co)Authors // Journals if ($this->ShowJournals) { if (isset($this->Journals[$Pub['Source']])) $this->Journals[$Pub['Source']] += 1; else $this->Journals[$Pub['Source']] = 1; $Pub['Classes'][] = str_replace(" ", "_", $Pub['Source']); } // Publishers if ($this->ShowPublishers and isset($Pub['PubmedData']['ArticleIdList']['doi'])) { $Doi = explode("/", $Pub['PubmedData']['ArticleIdList']['doi']); if (isset($this->Dois[$Doi[0]])) $this->Dois[$Doi[0]] += 1; else $this->Dois[$Doi[0]] = 1; $Pub['Classes'][] = str_replace(".","", $Doi[0]); } // Languages if ($this->ShowLanguages and isset($Pub['LangList']['Lang'])) { if (isset($this->Languages[$Pub['LangList']['Lang']])) $this->Languages[$Pub['LangList']['Lang']] += 1; else $this->Languages[$Pub['LangList']['Lang']] = 1; $Pub['Classes'][] = 'lang-' . $Pub['LangList']['Lang']; } // Years if ($this->ShowTrends and isset($Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate']['Year'])) { if (!empty($this->Years[$Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate']['Year']])) $this->Years[$Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate']['Year']] += 1; else $this->Years[$Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate']['Year']] = 1; } /*************************/ // AuthorProfile // - if the search is for an author, build their profile if ($this->IsAuthor) { if (count($Pub['MedlineCitation']['Article']['AuthorList']) == 1) { $Pub['FirstAu'] = true; $Pub['LastAu'] = true; } // If this is a single author publication, our author must be the first author! else { $i = 1; foreach ($Pub['MedlineCitation']['Article']['AuthorList'] as $k => $v) { unset($l, $m); if (isset($l)) unset($l); if (($i == 1) and ($k == $this->SearchTerm)) $Pub['FirstAu'] = true; if (isset($v['Initials'])) $l = $v['LastName'] . ' ' . substr($v['Initials'], 0, 1); if (isset($v['Initials'])) $m = $v['LastName'] . ' ' . substr($v['ForeName'], 0, 1); // Find some fullnames... if (($k == $this->SearchTerm) OR (isset($l) and ($l == $this->SearchTerm)) OR (isset($m) and ($m == $this->SearchTerm))) { $FullName = (isset($v['ForeName']) ? $v['ForeName'] : (isset($v['Initials']) ? $v['Initials'] : 'Anon')) . (isset($v['MiddleName']) ? " " . $v['MiddleName'] : '') . " " . $v['LastName']; if (isset($this->FullName[$FullName])) $this->FullName[$FullName] += 1; else $this->FullName[$FullName] = 1; } // Make a list of (co)Authors elseif ($this->ShowAuthors) { if (!empty($this->CoAuthors[$k])) $this->CoAuthors[$k] += 1; else $this->CoAuthors[$k] = 1; } $i++; } if ($k == $this->SearchTerm) $Pub['LastAu'] = true; } // If we're keeping counts, build them for first/last authorship if ($this->ShowCounts) { // Count for first author if (!empty($Pub['FirstAu'])) { if (!empty($this->Counts['First Author'])) $this->Counts['First Author'] += 1; else $this->Counts['First Author'] = 1; $Pub['Classes'][] = "FirstAu"; } // Count for last author if (!empty($Pub['LastAu'])) { if (!empty($this->Counts['Last Author'])) $this->Counts['Last Author'] += 1; else $this->Counts['Last Author'] = 1; $Pub['Classes'][] = "LastAu"; } } // If we're going to be building an AuthorProfile, keep a record of affiliations and email addresses if ($this->ShowAuDetails) { // Affiliations if (isset($Pub['MedlineCitation']['Article']['Affiliation']) and (empty($this->Affiliations[$FullName]) OR !in_array($Pub['MedlineCitation']['Article']['Affiliation'], $this->Affiliations[$FullName]))) $this->Affiliations[$FullName][] = $Pub['MedlineCitation']['Article']['Affiliation']; // Email addresses if (!empty($Pub['FirstAu']) and !empty($Pub['MedlineCitation']['Article']['Affiliation'])) { if (strpos($Pub['MedlineCitation']['Article']['Affiliation'], '@', 0)) { $email = strtolower(substr($Pub['MedlineCitation']['Article']['Affiliation'], strrpos($Pub['MedlineCitation']['Article']['Affiliation'], ' '))); if (empty($this->Emails[$FullName]) OR !in_array($email, $this->Emails[$FullName])) $this->Emails[$FullName][] = $email; } } // If BMC module is installed, we can also try and get email addresses from BioMedCentral if (class_exists("BioMedCentral")) $this->GetDetailsFromBmc($Doi[1]); } } // Otherwise, just make the list of all authors elseif ($this->ShowAuthors) { foreach ($Pub['MedlineCitation']['Article']['AuthorList'] as $k => $v) { if (!empty($this->CoAuthors[$k])) $this->CoAuthors[$k] += 1; else $this->CoAuthors[$k] = 1; } } /*********** SCORES ***********/ if (!empty($Pub['FirstAu']) and !empty($this->PostData['ScoreFirstAu'])) $this->Scores[$Pub['MedlineCitation']['PMID']] = $this->PostData['ScoreFirstAu']; elseif (!empty($Pub['LastAu']) and !empty($this->PostData['ScoreLastAu'])) $this->Scores[$Pub['MedlineCitation']['PMID']] = $this->PostData['ScoreLastAu']; else $this->Scores[$Pub['MedlineCitation']['PMID']] = 1; if (!empty($this->PostData['WeightJournal']) and (in_array($Pub['MedlineCitation']['Article']['Journal']['ISOAbbreviation'], $this->PostData['ScoreJournal']) OR in_array($Pub['MedlineCitation']['Article']['Journal']['ISSN'], $this->PostData['ScoreJournal']) OR in_array($Pub['MedlineCitation']['Article']['Journal']['ISOAbbreviation'], $this->PostData['FullJournalName']))) $this->Scores[$Pub['MedlineCitation']['PMID']] = $this->Scores[$Pub['MedlineCitation']['PMID']] * $this->PostData['WeightJournal']; if (!empty($this->PostData['ScoreDoi']) and isset($Doi) and in_array($Doi[0], $this->PostData['ScoreDoi'])) $this->Scores[$$Pub['MedlineCitation']['PMID']] = $this->Scores[$Pub['MedlineCitation']['PMID']] * $this->PostData['WeightDoi']; // Weight the score by age if (isset($this->PostData['ScoreAge']) and $this->PostData['ScoreAge']) { $Timestamp = strtotime(implode("/", $Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate'])); $Age = time() - $Timestamp; $Age = $Age / 31570560; if ($Age < 1) $Weight = 2; // If the publication is less than a year old, double the score else $Weight = 0.5 + (1 / $Age); // Otherwise, weight it by 0.5 + (1 / Age) $this->Scores[$Pub['MedlineCitation']['PMID']] = $this->Scores[$Pub['MedlineCitation']['PMID']] * $Weight; } // Weight the score by search matches if (!empty($this->IdLists)) { foreach ($this->IdLists as $String => $IdList) { if (in_array($Pub['MedlineCitation']['PMID'], $IdList)) { $this->Scores[$Pub['MedlineCitation']['PMID']] = $this->Scores[$Pub['MedlineCitation']['PMID']] * $this->Weight[$String]; $Pub['Classes'][] = str_replace(" ", "_", $String); } } } /*************************/ // Make stripped array $this->Publications[$Pub['Id']] = array( "Title" => $Pub['MedlineCitation']['Article']['ArticleTitle'], "Authors" => $Pub['MedlineCitation']['Article']['AuthorList'], "Source" => $Pub['Source'], "PubDate" => implode("-", $Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate']), "Citation" => "" . $Pub['Source'] . " ". (isset($Pub['SO']) ? $Pub['SO'] : implode("-", $Pub['MedlineCitation']['Article']['Journal']['JournalIssue']['PubDate'])), "Doi" => $Pub['PubmedData']['ArticleIdList']['doi'], "Classes" => $Pub['Classes'], ); // Save abstract for mining and HTML things $this->Abstracts[$Pub['Id']] = $Pub['MedlineCitation']['Article']['Abstract']['AbstractText']; } /********************************************************************** * Function: ExtractPaper( Pub - merged array of eSummary and eFetch ) * - Gets the array of PubMed results and processes them */ function GetDetailsFromBmc($Doi) { $Bmc = new BioMedCentral( "10.1186/" . $Doi ); $Bmc->GetXmlFile(); if (isset($Bmc->Error)) return 0; $Bmc->XmlToArray(); if (isset($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm])) { if (!empty($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['mi'])) $FullName = array($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['fnm'], $Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['mi'], $Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['snm']); else $FullName = array($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['fnm'], $Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['snm']); $FullName = implode(" ", $FullName); if (isset($this->FullName[$FullName])) $this->FullName[$FullName] += 1; else $this->FullName[$FullName] = 1; if (!empty($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['email'])) { $email = strtolower($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['email']); if (empty($this->Emails[$FullName]) OR !in_array($email, $this->Emails[$FullName])) $this->Emails[$FullName][] = $email; } if (!empty($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['insr'])) { if (isset($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['insr']['iid'])) { if (is_array($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['insr']['iid'])) { foreach ($Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['insr']['iid'] as $v) { $AffiliationId = $v; if (!empty($Bmc->Array['fm']['bibl']['insg']['ins'][$AffiliationId])) $Affiliation = $Bmc->Array['fm']['bibl']['insg']['ins'][$AffiliationId]; if (empty($this->Affiliations[$FullName]) OR !in_array($Affiliation, $this->Affiliations[$FullName])) $this->Affiliations[$FullName][] = $Affiliation; } } else { $AffiliationId = $Bmc->Array['fm']['bibl']['aug'][$this->SearchTerm]['insr']['iid']; if (!empty($Bmc->Array['fm']['bibl']['insg']['ins'][$AffiliationId])) $Affiliation = $Bmc->Array['fm']['bibl']['insg']['ins'][$AffiliationId]; if (empty($this->Affiliations[$FullName]) OR !in_array($Affiliation, $this->Affiliations[$FullName])) $this->Affiliations[$FullName][] = $Affiliation; } } } } unset($Bmc); return 1; } /********************************************************************** * Function: GetFullNameCounts( ) * - if this is an AuthorProfile, get the counts for each fullname found */ function GetFullNameCounts() { // Full name counts foreach ($this->FullName as $Fn => $Count) { $this->Counts[$Fn] = $Count; $eSearch = new eSearch( 'pubmed', $Fn, null, null, 20 ); $eSearch->Run(2); if (!empty($eSearch->Count)) { //$this->Counts[$Fn] = $eSearch->Count; foreach ($eSearch->IdList as $Id) { if (!empty($this->Publications[$Id])) $this->Publications[$Id]['Classes'][] = str_replace(" ", "_", $Fn); } } unset($eSearch); } } /********************************************************************** * Function: MakeCloud( ) * - make a tag cloud from abstracts */ function MakeCloud($Max = 200, $Min = 60, $Div = " · ", $CutOff = 60) { Global $CloudIgnore; // Count the number of words foreach ($this->Abstracts as $Abstract) { $Abstract = strtolower(strip_chars(array(".",",","-","/",";",":","(",")","[","]"), $Abstract)); $Words = explode(" ",$Abstract); foreach ($Words as $Word) { if (in_array($Word, $CloudIgnore) or (strlen($Word) < 3)) continue; if (isset($Counts[$Word])) $Counts[$Word] += 1; else $Counts[$Word] = 1; } } // Count the number of values arsort($Counts); $Vals = 0; $i = 0; foreach ($Counts as $Count) { $i += 1; if (isset($PrevCount) and ($Count == $PrevCount)) continue; $Vals += 1; if ($i >= $CutOff) break; $PrevCount = $Count; } // Assign sizes unset($PrevCount); $Step = ($Max - $Min) / $Vals; $Size = $Max; $i = 1; foreach ($Counts as $Word => $Count) { if (isset($PrevCount) and ($Count != $PrevCount)) $Size -= $Step; $Sizes[$Word] = $Size; if ($i >= $CutOff) break; $PrevCount = $Count; $i += 1; } ksort($Sizes); // Make HTML $this->Cloud = ""; $i = 1; foreach ($Sizes as $Word => $Size) { $this->Cloud .= "SearchTerm . ") AND " . $Word . "\">" . $Word . "\n"; if ($i < count($Sizes)) $this->Cloud .= $Div; $i += 1; } } /************************************************************************************************************************************************************ HTML FUNCTIONS - Lists - Author Profile - World Cloud - Counts - Journals - Publishers - Languages - Trends - Authors - Default unified HTML - Page maker - SaveReload *************************************************************************************************************************************************************/ /********************************************************************** * Function: PrintResults( ) * - make the HTML for the results */ function PrintResults() { $this->Title = $this->SearchTerm; $this->Html = ""; // > begin layout table $this->Html .= "\n
"; // > begin left colum if ($this->IsAuthor and $this->ShowAuDetails) $this->Html .= $this->HtmlProfiles() . "
\n"; // Author profile if ($this->ShowCloud) { // Word cloud $this->Html .= "
Cloud

" . $this->Cloud . "


\n"; } $this->Html .= $this->HtmlPubLists(); // Publication lists $this->Html .= "
"; // > end left column; begin right column if ($this->ShowCounts) $this->Html .= $this->HtmlCounts(); // Counts if ($this->ShowJournals) $this->Html .= $this->HtmlJournals(); // Journals if ($this->ShowPublishers) $this->Html .= $this->HtmlPublishers(); // Publishers if ($this->ShowLanguages) $this->Html .= $this->HtmlLanguages(); // Languages if ($this->ShowAuthors) $this->Html .= $this->HtmlAuthors(); // (Co)Authors if ($this->ShowTrends) $this->Html .= $this->HtmlTrends(); // Trends $this->Html .= "
\n"; // > end layout table $this->OutputHtml(); } /********************************************************************** * Function: HtmlPubLists( ) * - make the HTML for the publication lists * - this function makes two lists: one ordered by date, the other by score */ function HtmlPubLists() { // By date $DateTable = "\n"; foreach ($this->Publications as $Pmid => $Pub) { unset($AuList); // Highlight text if (isset($this->HighLight)) { foreach ($this->HighLight as $Search) { $NewTerms = explode(" ", $Search['SearchString']); if (!empty($NewTerms)) $HighlightTerms = array_merge($HighlightTerms, $NewTerms); } foreach ($HighlightTerms as $Term) { $Pub['Title'] = str_replace($Term, "" . $Term . "", $Pub['Title']); } } $Doi = explode("/", $Pub['Doi']); if (!empty($Pub['Authors'])) { foreach ($Pub['Authors'] as $Short => $Full) { if (empty($Full['LastName'])) $Au = "" . $Full['CollectiveName'] . ""; else { if ($Short == $this->SearchTerm) $Au = "" . (isset($Full['ForeName']) ? $Full['ForeName'] : $Full['Initials']) . (isset($Full['MiddleName']) ? " " . $Full['MiddleName'] : '') . " " . $Full['LastName'] . ""; else $Au = "" . (isset($Full['ForeName']) ? $Full['ForeName'] : (isset($Full['Initials']) ? $Full['Initials'] : 'Anon')) . (isset($Full['MiddleName']) ? " " . $Full['MiddleName'] : '') . " " . $Full['LastName'] . ""; } $AuList[] = $Au; } $AuList = implode(", ", $AuList); } else $AuList = "Error - could not extract author list."; $DateTable .= "\n"; } $DateTable .= "
Publication list (order by: date | score)

Date: " . $Pub['PubDate'] . "

" . $Pub['Title'] . "

" . $AuList . "

" . ((!empty($this->OaIdList) and in_array($Pmid, $this->OaIdList)) ? "\"[Open" : "") . $Pub['Citation'] . " " . (isset($Pub['Doi']) ? "[doi:" . $Pub['Doi'] . "]" : "") . " [pmid:" . $Pmid . "]

\n"; // By score arsort($this->Scores); $ScoreTable = "\n"; foreach ($this->Scores as $Pmid => $Score) { unset($AuList); $Pub = $this->Publications[$Pmid]; // Highlight text if (isset($this->HighLight)) { foreach ($this->HighLight as $Search) { $NewTerms = explode(" ", $Search['SearchString']); if (!empty($NewTerms)) $HighlightTerms = array_merge($HighlightTerms, $NewTerms); } foreach ($HighlightTerms as $Term) { $Pub['Title'] = str_replace($Term, "" . $Term . "", $Pub['Title']); } } $Doi = explode("/", $Pub['Doi']); if (!empty($Pub['Authors'])) { foreach ($Pub['Authors'] as $Short => $Full) { if (empty($Full['LastName'])) $Au = "" . $Full['CollectiveName'] . ""; else { if ($Short == $this->SearchTerm) $Au = "" . (isset($Full['ForeName']) ? $Full['ForeName'] : $Full['Initials']) . (isset($Full['MiddleName']) ? " " . $Full['MiddleName'] : '') . " " . $Full['LastName'] . ""; else $Au = "" . (isset($Full['ForeName']) ? $Full['ForeName'] : (isset($Full['Initials']) ? $Full['Initials'] : 'Anon')) . (isset($Full['MiddleName']) ? " " . $Full['MiddleName'] : '') . " " . $Full['LastName'] . ""; } $AuList[] = $Au; } $AuList = implode(", ", $AuList); } else $AuList = "Error - could not extract author list."; $ScoreTable .= "\n"; } $ScoreTable .= "
Publication list (order by: date | score)

Score: " . $Score . "

" . $Pub['Title'] . "

" . $AuList . "

" . ((!empty($this->OaIdList) and in_array($Pmid, $this->OaIdList)) ? "\"[Open" : "") . $Pub['Citation'] . " " . (isset($Pub['Doi']) ? "[doi:" . $Pub['Doi'] . "]" : "") . " [pmid:" . $Pmid . "]

\n"; if ($this->OrderBy == "score") { $Html = "
" . $ScoreTable . "
\n"; $Html .= "
" . $DateTable . "
\n"; } else { $Html = "
" . $ScoreTable . "
\n"; $Html .= "
" . $DateTable . "
\n"; } return $Html; } /********************************************************************** * Function: HtmlProfiles( ) * - make the HTML for the publication lists * - this function makes two lists: one ordered by date, the other by score */ function HtmlProfiles() { $Html = "\n"; if (!empty($this->FullName)) { foreach ($this->FullName as $k => $v) { $Html .= "\n"; $Html .= "\n"; $Html .= "\n"; } } else $Html .= ""; $Html .= "
Suggested names
" . $k . "

" . (isset($this->Emails[$k]) ? implode("

", $this->Emails[$k]) : '') . "

\n"; $Html .= "\n"; $Html .= "
Affiliations[$k]) and (count($this->Affiliations[$k]) > 3)) ? "style=\"display:none;\"" : "") . ">

Hide affiliations.

" . (!empty($this->Affiliations[$k]) ? implode("

", $this->Affiliations[$k]) : "No affiliations found.") . "

None found.

\n"; return $Html; } /********************************************************************** * Function: HtmlCounts( ) * - make the HTML for the counts */ function HtmlCounts() { $Html .= "\n"; $SearchLinks = array( "PubMed (all)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22" . $this->Author . "%22", "Open Access" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22" . $this->Author . "%22 AND (free full text[sb])", "PubMed (10yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 10 years"[PDat])", "PubMed (5yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 5 years"[PDat]", "PubMed (1yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 1 years"[PDat]", "PMC (all)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pmc&Cmd=Search&Term=%22" . $this->Author . "%22", "PMC (10yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pmc&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 10 years"[PDat]", "PMC (5yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pmc&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 5 years"[PDat]", "PMC (1yr)" => "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pmc&Cmd=Search&Term=%22" . $this->Author . "%22 AND ("last 1 years"[PDat]", "First Author" => "javascript:highLight('FirstAu')", "Last Author" => "javascript:highLight('LastAu')", ); foreach ($this->Counts as $k => $v) { $Html .= ""; } $Html .= "
Search counts
" . ((strlen($k) > 26) ? substr($k, 0, 23) . '...' : $k) . "" . (isset($SearchLinks[$k]) ? "" . $v . "" : "" . $v . "") . "

"; return $Html; } /********************************************************************** * Function: HtmlLanguages( ) * - make the HTML for the languages */ function HtmlLanguages() { $Html = "\n"; arsort($this->Languages); $i = 0; foreach ($this->Languages as $k => $v) { $Html .= "\n"; $i += 1; if ($i > 20) break; } $Html .= "
Languages
" . $k . "" . $v . "

\n"; return $Html; } /********************************************************************** * Function: HtmlJournals( ) * - make the HTML for the journals */ function HtmlJournals() { $Html = "\n"; arsort($this->Journals); $i = 0; foreach ($this->Journals as $k => $v) { $Html .= "\n"; $i += 1; if ($i > 20) break; } $Html .= "
Favourite journals
" . $k . "Author . "%22 AND ("" . $k . ""[TA])\">" . $v . "

\n"; return $Html; } /********************************************************************** * Function: HtmlPublishers( ) * - make the HTML for the publishers */ function HtmlPublishers() { Global $PublisherTranslation; $Html = "\n"; arsort($this->Dois); $i = 0; foreach ($this->Dois as $k => $v) { $Html .= "\n"; $i += 1; if ($i > 20) break; } $Html .= "
Favourite publishers
" . (isset($PublisherTranslation[$k]) ? $PublisherTranslation[$k] : $k) . "". $v . "

\n"; return $Html; } /********************************************************************** * Function: HtmlAuthors( ) * - make the HTML for the authors */ function HtmlAuthors() { $Html = "\n"; arsort($this->CoAuthors); $i = 0; foreach ($this->CoAuthors as $k => $v) { $Html .= "\n"; $i += 1; if ($i > 20) break; } $Html .= "
Co-authors
" . $k . "". $v . "

\n"; return $Html; } /********************************************************************** * Function: HtmlTrends( ) * - make the HTML for trends */ function HtmlTrends() { $Html = "\n"; $h = 0; for ($y = date('Y'); $y > 1970; $y--) { if (empty($this->Years[$y])) { $Years[$y] = 0; continue; } if ($this->Years[$y] > $h) $h = $this->Years[$y]; $Years[$y] = $this->Years[$y]; $CutOff = $y; unset($this->Years[$y]); } $i = 0; foreach ($Years as $y => $c) { if ($y < $CutOff) break; $width = (135 / $h) * $c; $Html .= "\n"; } $Html .= "
History
" . $y . "
" . (!empty($c) ? $c : " ") . "

\n"; return $Html; } /******************************************************************************************************************************************** * Function: OutputHtml( Reload ) * Formats the page as HTML */ function OutputHtml($Reload = false) { $Title = $this->Title; $Html = $this->Html; $SearchTerm = $this->SearchTerm; if ($Reload) $Reload = "\n"; else $Reload = ""; $NavBar = file_get_contents("NavBar.php"); $Time = round((microtime(true) - $_SESSION['began']), 2); // Calculate the time elapsed echo << $Title $Reload $NavBar

PubMed Search: $SearchTerm

$Html

... time elapsed: $Time seconds.

Content from pubmed used under NLM terms of use (NLM disclaimer). Content from BioMed Central and the Open-Access padlock (PLoS) used under the terms of the Creative Commons Attribution license.

END; exit; } /******************************************************************************************************************************************** * Function: SaveReload( ) * Saves session variables and reloads the page */ function SaveReload() { $_SESSION['ps_Publications'] = $this->Publications; $this->OutputHtml(true); } } ?>