Menu

Search NCBI, import the reference by 1 click

Yizhou He
2009-01-09
2013-05-28
  • Yizhou He

    Yizhou He - 2009-01-09

    Hi, Matthias Steffens & Richard Karnesky:

    I'm a graduate student doing research in Genetics and molecular biology fields. I use NCBI PubMED a lot. Actually, everyone I know depend on NCBI PubMED for their references. However, It is not that easy to import NCBI reference to refbase.

    I write some code for refbase to search in NCBI, then it will list the search result and show title, author, journal, year. It list 100 result per page. Simply click the title, it will import select item to your refbase library. Or you can check the checkbox in front of the title and it will import all items you selected into your refbase library.

    It make reference selection and import much more easy. However, I'm not a php programmer. I know a lot about ASP but not PHP. I wrote these code by search php manual in google. So I think you must be able to improve the code very much.

    I don't know too much about your program flow in search.php, so I showed all htm head and foot and terminate the program when it is done. you may be able to integrate it better.

    Hope it is useful for you.

    Yizhou Jospeh He

    I altered three files.
    import_modify.php line 131.
    //treat checkbox transfered array with accession number as value.------------------------------------------------
        if (isset($formVars['sourceIDs']))
            {
            $SIDs=$HTTP_POST_VARS["sourceIDs"];
            if (is_array($SIDs))
                {
                $sourceIDs=implode(", ", $SIDs);
               
                }
            else
                {
                $sourceIDs = $formVars['sourceIDs'];
                }
            }
        else
            $sourceIDs = "";

    //----------------------------------------------

    New file NCBISearch.php
    //Just a form to send search terms--------------------------------------------
    <form action="search.php" method="GET" name="simpleSearch" align=center>
    <input type="hidden" name="formType" value="NCBISearch">
    <input type="hidden" name="showQuery" value="0">
    <table align="center" border="0" cellpadding="0" cellspacing="10" width="95%" summary="This table holds the search form">
    <tr>
        <td align=center>
        <br><br><br>
            <input type="text" id="SearchTerms" name="SearchTerms" size="42">
            <input type="submit" value="Search PubMED">
        <br><br><br>   
        </td>
    </tr>

    </table>
    </form>
    //-----------------------------------------------------

    code insert to search.php after line 552
    //treat data send by NCBISearch--------------------------------------------------

    elseif    ($formType="NCBISearch")
            {
                    connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'

        // If there's no stored message available:
        if (!isset($_SESSION['HeaderString']))
            $HeaderString = $loc["SearchMain"].":"; // Provide the default message
        else
        {
            $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)

            // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
            deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
        }

        // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
        // ('' will produce the default 'Web' output style)
        if (isset($_REQUEST['viewType']))
            $viewType = $_REQUEST['viewType'];
        else
            $viewType = "";

        // Get the default number of records per page preferred by the current user:
        $showRows = $_SESSION['userRecordsPerPage'];

        // Get the user's preference for displaying auto-completions:
        $showAutoCompletions = $_SESSION['userAutoCompletions'];

        // Show the login status:
        showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')

        // (2a) Display header:
        // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
        displayHTMLhead(encodeHTML($officialDatabaseName) . " -- " . $loc["SimpleSearch"], "index,follow", "Search the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array());
        showPageHeader($HeaderString);
           
            $SearchTerms=urlencode($_REQUEST['SearchTerms']);
           
            $RetStart=$_REQUEST['RetStart'];
            ?>
            <head><title>NCBI Search</title><link rel='stylesheet' href='css/style.css' type='text/css' title='CSS Definition'></head><body marginleft=50 marginright=50 margintop=50 marginbottom=50>
        <Script name=JavaScript>
            function checkall(val, formpart)
                {
                var x = 0;
                while(document.queryResults.elements[x]) {
                if(document.queryResults.elements[x].name == formpart) {
                    document.queryResults.elements[x].checked = val;
                }
                x++;
                }
                //toggleRadio('allRecs', 'selRecs', val);
    }
    </script>
            <center>
            <form action="search.php" method="GET" name="simpleSearch" align=center>
                <input type="hidden" name="formType" value="NCBISearch">
                <input type="hidden" name="showQuery" value="0">
                <a href="JavaScript:checkall(true,'sourceIDs[]');" title="select all records on this page">Select All</a>&nbsp;&nbsp;
                <a href="JavaScript:checkall(false,'sourceIDs[]');" title="deselect all records on this page">Deselect All</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="text" id="SearchTerms" name="SearchTerms" value="<?=$SearchTerms?>" size="42">
                <input type="submit" value="Search PubMED">
            <?
            $fh = fopen("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&usehistory=n&retmax=100&retstart=".$RetStart."&term=".$SearchTerms,"r");
            $Ids="";
            while(!feof($fh))
                {
                    $output = str_replace("/","",trim(fgets($fh, 4096)));
                    if (substr($output,0,7)=="<Count>" & $TotalCount=="")
                        {
                        $TotalCount=substr($output,7,strlen($output)-14);
                        echo "&nbsp;&nbsp;&nbsp;&nbsp; Page <select onchange=window.location.href='search.php?formType=NCBISearch&RetStart='+this.value+'&SearchTerms=".$SearchTerms."';>";
                        for ($i=0;$i<=((int)$TotalCount)/100+1;$i++)
                            {
                            echo "<option value=".$i*100;
                            if ($RetStart==$i*100)
                                {
                                echo " selected ";
                                }
                            echo ">".$i."</option>\n";
                            }
                            echo "</select> of ";
                            echo (int)((int)$TotalCount/100)+1;
                            echo " of ".$TotalCount." records</form> </center><br>";
                            ?>
                            <form action="import_modify.php" method="POST" target='_blank' name='queryResults' id='queryResults'>
                                <input type="hidden" name="formType" value="importID">
                                <input type="hidden" name="submit" value="Import">
                                <input type="hidden" name="showSource" value="1">
                               
                                <?
                        }
                    if (substr($output,0,8)=="<RetMax>")
                        {
                        $RetMax=$output ;
                        }
                    if (substr($output,0,9)=="<RetStart>")
                        {
                        $RetStart=$output;
                        }
                    if (substr($output,0,4)=="<Id>")
                        {
                        $output=str_replace("<Id>","",$output);
                       
                        $Ids=$Ids.$output.",";
                        }   
                }
                //echo $Ids;
                fclose($fh);
                $fh = fopen("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=".$Ids."&retmode=xml","r");
                $Ids="";
                echo "<center><table width=90%>";
                while(!feof($fh))
                    {
                    $output = str_replace("/","",trim(fgets($fh, 4096)));
                    if (substr($output,0,4)=="<Id>")
                        {
                        $CurId=str_replace("<Id>","",$output);
                        echo "<tr><td align=left><input name='sourceIDs[]' type='checkbox' value='".$CurId."' id='UidCheckBox'> ";
                        }
                    if (substr($output,12,7)=="PubDate")
                        {
                        $CurDate=substr($output,33,4);
                        }
                    if (substr($output,12,6)=="Source")
                        {
                        $CurJournal=substr($output,34,strlen($output)-6);
                        }
                    if (substr($output,12,10)=="AuthorList")
                        {
                        $CurAuthorList="";
                        }
                    if (substr($output,12,6)=="Author" & substr($output,12,10)!="AuthorList")
                        {
                        $CurAuthorList=$CurAuthorList.substr($output,34,strlen($output)-6).",";
                        }   
                    if (substr($output,12,5)=="Title")
                        {
                        $CurTitle=substr($output,33,strlen($output)-6);
                        echo "<a target=_blank href='import_modify.php?formType=importID&sourceIDs=".$CurId."'>".$CurTitle." </a>";
                        echo "<a target=_blank href='http://www.ncbi.nlm.nih.gov/pubmed/".$CurId."?ordinalpos=1&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DefaultReportPanel.Pubmed_RVDocSum'>[NCBI] </a><br>";
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$CurAuthorList."<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I>".$CurJournal."</I>.$CurDate.<br><br>\n";
                        echo "</td></tr>";
                        }
                   
                    }
                echo "</table><br><input type='submit' name='submit' value='Add to Library' title='press this button to add selected references to your library'></center></form>";
                fclose($fh);
       
                // (5) Close the database connection:
                disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
                // DISPLAY THE HTML FOOTER:
                // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php')
                showPageFooter($HeaderString);
                displayHTMLfoot();
                exit();
            }
    //---------------------------------------------------------------------

     
    • jaregi

      jaregi - 2009-01-30

      Hi Yizhou,

      This looks like a great addition. Could you post a screenshot to this forum to show us how it looks in practise on your modified refbase? That would be great. Thanks.

      Best, j

       
    • jaregi

      jaregi - 2009-01-30

      Hi Yizhou,

      I pasted the code you suggested but it didn't work for me. Using the search.php via the field on the homepage view gives me a blank page. I also called up the NCBIsearch.php page separately via the location bar. This produced the simple search page as intended but the search there didn't work.

      Any ideas on where things went astray. Did you test the code on your local setup?

      Best, j

       
    • Yizhou He

      Yizhou He - 2009-02-06

      You may insert the code in wrong place in Search.php.
      go ahead to test my version on
      http://152.19.87.44/refbase/index.php
      test username is test@refbase.net
      password is test.

      There is an NCBI search after Home | Show All |

      let me know if it works.

      Yizhou Joseph He

       
    • Yizhou He

      Yizhou He - 2009-02-06

      http://152.19.87.44/refbase/refbase.rar

      unpack with winrar and see what's the difference.

      Good luck!

       
  • wskwntei

    wskwntei - 2010-02-22

    I know what's the problem, add the following line after line 165 of  includes\header.inc.php so that the link will show up

    <a href="NCBIsearch.php">NCBI Search</a>&nbsp;|&nbsp;

    Also, to add head and foot to the search form, use this fancy version of NCBIsearch.php
    <?php
    // Project:    Web Reference Database (refbase) <http://www.refbase.net>
    // Copyright:  Matthias Steffens <mailto:refbase@extracts.de> and the file's
    //             original author(s).
    //
    //             This code is distributed in the hope that it will be useful,
    //             but WITHOUT ANY WARRANTY. Please see the GNU General Public
    //             License for more details.
    //
    // File:       ./simple_search.php
    // Repository: $HeadURL: https://refbase.svn.sourceforge.net/svnroot/refbase/trunk/simple_search.php $
    // Author(s):  Matthias Steffens <mailto:refbase@extracts.de>
    //
    // Created:    29-Jul-02, 16:39
    // Modified:   $Date: 2008-11-18 13:13:00 -0800 (Tue, 18 Nov 2008) $
    //             $Author: msteffens $
    //             $Revision: 1321 $

    // Search form providing access to the main fields of the database.
    // It offers some output options (like how many records to display per page)
    // and let's you specify the output sort order (up to three levels deep).

    // Incorporate some include files:
    include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
    include 'includes/header.inc.php'; // include header
    include 'includes/footer.inc.php'; // include footer
    include 'includes/include.inc.php'; // include common functions
    include 'initialize/ini.inc.php'; // include common variables

    // ---------------------------------------------

    // START A SESSION:
    // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
    start_session(true);

    // ---------------------------------------------

    // Initialize preferred display language:
    // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
    include 'includes/locales.inc.php'; // include the locales

    // ---------------------------------------------

    // (1) Open the database connection and use the literature database:
    connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'

    // If there's no stored message available:
    if (!isset($_SESSION))
    $HeaderString = $loc.":"; // Provide the default message
    else
    {
    $HeaderString = $_SESSION; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)

    // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
    deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
    }

    // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
    // ('' will produce the default 'Web' output style)
    if (isset($_REQUEST))
    $viewType = $_REQUEST;
    else
    $viewType = "";

    // Get the default number of records per page preferred by the current user:
    $showRows = $_SESSION;

    // Get the user's preference for displaying auto-completions:
    $showAutoCompletions = $_SESSION;

    // Show the login status:
    showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')

    // (2a) Display header:
    // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
    displayHTMLhead(encodeHTML($officialDatabaseName) . " - " . $loc, "index,follow", "Search the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array());
    showPageHeader($HeaderString);

    // Define variables holding common drop-down elements, i.e. build properly formatted <option> tag elements:
    $dropDownConditionals1Array = array("contains"         => $loc,
                                        "does not contain" => $loc,
                                        "is equal to"      => $loc,
                                        "is not equal to"  => $loc,
                                        "starts with"      => $loc,
                                        "ends with"        => $loc);

    $dropDownItems1 = buildSelectMenuOptions($dropDownConditionals1Array, "", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'

    $dropDownConditionals2Array = array("is greater than" => $loc,
                                        "is less than"    => $loc,
                                        "is within range" => $loc,
                                        "is within list"  => $loc);

    $dropDownItems2 = buildSelectMenuOptions($dropDownConditionals2Array, "", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'

    // TODO: if possible, we should use function 'mapFieldNames()' here
    $dropDownFieldNameArray = array("author"         => $loc,
                                    "title"          => $loc,
                                    "year"           => $loc,
                                    "publication"    => $loc,
                                    "volume_numeric" => $loc, // 'volume_numeric' is used instead of 'volume' in the sort dropdown menus
                                    "pages"          => $loc);

    $dropDownItems3 = buildSelectMenuOptions($dropDownFieldNameArray, "", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'

    // Build HTML elements that allow for search suggestions for text entered by the user:
    if (isset($_SESSION) AND ($_SESSION == "yes"))
    {
    $authorSuggestElements = buildSuggestElements("authorName", "authorSuggestions", "authorSuggestProgress", "col-author-"); // function 'buildSuggestElements()' is defined in 'include.inc.php'
    $titleSuggestElements = buildSuggestElements("titleName", "titleSuggestions", "titleSuggestProgress", "col-title-");
    $yearSuggestElements = buildSuggestElements("yearNo", "yearSuggestions", "yearSuggestProgress", "col-year-");
    $publicationSuggestElements = buildSuggestElements("publicationName2", "publicationSuggestions", "publicationSuggestProgress", "col-publication-");
    $volumeSuggestElements = buildSuggestElements("volumeNo", "volumeSuggestions", "volumeSuggestProgress", "col-volume-");
    $pagesSuggestElements = buildSuggestElements("pagesNo", "pagesSuggestions", "pagesSuggestProgress", "col-pages-");
    }
    else
    {
    $authorSuggestElements = "";
    $titleSuggestElements = "";
    $yearSuggestElements = "";
    $publicationSuggestElements = "";
    $volumeSuggestElements = "";
    $pagesSuggestElements = "";
    }

    // (2b) Start <form> and <table> holding the form elements:
    //Just a form to send search terms-----------------------------
    ?>

    <form action="search.php" method="GET" name="simpleSearch" align=center>
    <input type="hidden" name="formType" value="NCBISearch">
    <input type="hidden" name="showQuery" value="0">
    <table align="center" border="0" cellpadding="0" cellspacing="10" width="95%" summary="This table holds the search form">
    <tr>
    <td align=center>
    <br><br><br>
    <input type="text" id="SearchTerms" name="SearchTerms" size="42">
    <input type="submit" value="Search PubMED">
    <br><br><br>
    </td>
    </tr>

    </table>
    </form>

    <?php
    //-----------------------------------
    // (5) Close the database connection:
    disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'

    // ---------------------------------------------

    // DISPLAY THE HTML FOOTER:
    // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php')
    showPageFooter($HeaderString);

    displayHTMLfoot();

    // ---------------------------------------------
    ?>

     

Log in to post a comment.