我正在尝试编写一个 PHP 脚本以利用 NCBI(国家生物技术信息中心)的 E-utilities 服务。
我可以提供一个带有搜索词的 url(在本例中为“alaS”)并毫无问题地检索 XML 结果,代码如下:
<?php
$startUrl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&term=alaS&retmax=10000&usehistory=y";
$xml1=simplexml_load_file($startUrl) or die("Error: Cannot create object");
foreach ($xml1->IdList->children() as $child1)
{
$newUrl1="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?dbfrom=gene&db=protein&id=" . $child1;
echo $newUrl1 . "<br>";
};
?>
这工作正常(结果可以在http://djcamenares.x10.mx/testing/parse1.php
但是,当我尝试获取结果链接并让脚本检索其结果时,我什么也得不到。这是以下代码:
<?php
$startUrl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&term=alaS&retmax=10000&usehistory=y";
$xml1=simplexml_load_file($startUrl) or die("Error: Cannot create object");
$geneIDa=array();
foreach ($xml1->IdList->children() as $child1)
{
$newUrl1="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?dbfrom=gene&db=protein&id=" . $child1;
array_push($geneIDa, $newUrl1);
};
foreach ($geneIDa as $x1)
{
$xml2=simplexml_load_file($x1) or die("Error: Cannot create object");
echo $xml2->LinkSet->LinkSetDb[1]->Link->Id . "<br>";
};
?>
可在http://djcamenares.x10.mx/testing/parse3.php 获得
有什么建议么?也许我应该以更好的方式来构建我的整体程序?我需要将变量/结果来回传递给该实用程序服务器 3 次(一次搜索基因 ID,然后将每个基因 ID 与蛋白质 ID 链接,最后检索蛋白质序列)。
感谢您的帮助;对不起,如果这个问题是多余的或已经回答;我对 PHP 比较陌生。