Entering edit mode
6.7 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).
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.
Hello,
is the method get() defined? How does it looks like?
fin swimmer
It is just to merge the query. The resulting query should look like 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
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:
fin swimmer
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";
Fine if you could solve your problem.
Please upvote posts that you find helpful.
fin swimmer