view dbAnnotRestClient.php @ 1:5af6f6e0a0da draft

Uploaded
author cheanney
date Thu, 16 Jul 2015 09:17:56 -0400
parents 8129ff2290dd
children
line wrap: on
line source

<?php
$restApiCall = "";
$restParams = "";

foreach ($argv as $val)
{
	$arr = preg_split("/=/", $val);
	if (strcmp('inputValues', $arr[0]) == 0){
		$inputvalues = $arr[1];
		$restParams = $restParams . "&inputValues=$inputvalues";
	}
	if (strcmp('annotations', $arr[0]) == 0){
		$annotations = $arr[1];
		$restParams = $restParams . "&annotations=$annotations";
	}
	if (strcmp('TaxonId', $arr[0]) == 0){
		$taxonid = $arr[1];
		$restParams = $restParams . "&taxonId=$taxonid";
	}
	else if (strcmp('fileType', $arr[0]) == 0){
		$fileType = $arr[1];
		if ($fileType == 'xml'){
			$biodbnetRestApiCallCore = "http://biodbnet.abcc.ncifcrf.gov/webServices/rest.php/biodbnetRestApi.xml?method=dbannot&format=row";
		}
		else{
			$biodbnetRestApiCallCore = "http://biodbnet.abcc.ncifcrf.gov/webServices/rest.php/biodbnetRestApi.json?method=dbannot&format=row";
		}
	}
}

$restApiCall = $biodbnetRestApiCallCore . $restParams;
$response = file_get_contents($restApiCall);

if ($fileType == 'xml' || $fileType == 'json'){
	print_r($response);
}elseif ($fileType == 'table'){
	$formattedResponse = json_decode($response, true);
	echo "<html>\n";
	echo "<br/><br/><b>bioDBnet: dbAnnot Result</b><br/>";
	echo "<table border=1>\n";
	$fields = array_keys($formattedResponse[0]);
	echo "<tr>";
	foreach ($fields as $f){
		echo "<th>$f</th>";
	}
	echo "</tr>\n";
	foreach ($formattedResponse as $key => $value){
		echo "<tr>";
		foreach ($value as $v){
			echo "<td>$v</td>";
		}
		echo "</tr>\n";
	}
	echo "</table>\n";
	echo "</html>\n";
}
?>