Generating multiple NCBI URLs with eutils
0
0
Entering edit mode
6.0 years ago
nemo ▴ 40

I would like to create a URL that takes input from different arrays to generate a search. The data I would like to retrieve is from NCBI ins xml formats. Below you can find the code I wrote. But I can't get it to work; I am stuck. Thank you in advance.

I should have something like this as result but i got nothing.

https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmode=xml&retmax=10&sort=relevance&term=A20%20AND%20Homo%20sapiens%20%5borgn%5d%20AND%20alive%5bprop%5d

 

    $eutils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils";
    $db = "gene";
    $gene_symbols = array("A20","HBB","ABO");
    $species = array("homo sapiens", "Escherichia coli","Saccharomyces cerevisiae");
    $links = array();

    foreach ($gene_symbols as $key => $GS){ 
       $SP = $species[$key];
       $query = "$GS AND $SP [orgn] AND alive";

       $esearch = "$eutils/esearch.fcgi?db=$db&retmode=xml&retmax=10&sort=relevance&term=";

       #echo $esearch; 
       $links[] = get($esearch.$query);  
    }

   foreach($links as $lk){
      $xml = simplexml_load_file($lk) or die("feed not loading");    
    }

       var_dump($xml);

For some reason it put them all after each other and the foreach loop doesn't seem to work. I got no errors.

Added from SE Post (missing here):

I run this code in php using visual studio code. The result should be visualised in the webbrowser (http://localhost/test.php).

bio-informatics utilities • 1.3k views
ADD COMMENT
0
Entering edit mode

Hello nemo!

It appears that your post has been cross-posted to another site: https://bioinformatics.stackexchange.com/questions/4160

This is typically not recommended as it runs the risk of annoying people in both communities.

ADD REPLY
0
Entering edit mode

Hello,

is the method get() defined? How does it looks like?

fin swimmer

ADD REPLY
0
Entering edit mode

It is just to merge the query. The resulting query should look like

And that's the point. "It should". Have you tested it? In the code you gave us, there is not definition of the method get and so php give up and throw an error because it doesn't know what to do with get().

Have you turned on the error_reporting? Just add these two line add the beginning of your document:

error_reporting(-1);
ini_set("display_errors", 1);

fin swimmer

ADD REPLY
0
Entering edit mode

Thanks for the error reporting that very useful. I wish I knew earlier. I solved the problem. $links[] = "$eutils/esearch.fcgi?db=$db&retmode=xml&retmax=10&sort=relevance&term=$query";

ADD REPLY
0
Entering edit mode

Fine if you could solve your problem.

Please upvote posts that you find helpful.

fin swimmer

ADD REPLY

Login before adding your answer.

Traffic: 1740 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6