Sample Codes for web API useYour script may receive map image file by sending request with map configuration to anatomography API.
Calling map API from perl scriptsIn the following sections, we show example Perl scripts that generate an output file (image or animation) in the same directory as the scrpt when executed.
example.plScript files named example.pl is a concatenation of four segments.
Seg1
#!/usr/bin/env perl use strict; use LWP::UserAgent; my $serverURL = "http://lifesciencedb.jp/bp3d/API/"; Seg2
$json = <<JSON;
{
"Common":{
"Version":"4.0",
"TreeName":"partof"
},
"Part":[
{
"PartName":"human body", # Some common names are allowed (list), better be FMA_ID in the list (list)
"PartColor":"F0D2A0", #Hexadecimal color code
"PartOpacity":0.1
},
{
"PartName":"skeletal system",
"PartColor":"FFFFFF"
},
{
"PartName":"heart",
"PartColor":"FF0000"
}
]
}
JSON
Seg3 for still image
sub getImage () { # Define subroutine name
my $json = shift;
my $userAgent = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET', $serverURL."image?".$json); # Specify which method of API you use by this subroutine
my $response = $userAgent->request($request);
return $response->content;
}
Seg3 for rotating animation in GIF
sub getAnimation () {
my $json = shift;
my $userAgent = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET', $serverURL."animation?".$json);
my $response = $userAgent->request($request);
return $response->content;
}
Seg4 for still image
open OUT, ">result.png"; # The name of result file binmode(OUT); print OUT &getImage($json); # The name of subroutine you choose close OUT; Seg4 for animation GIFopen OUT, ">gifanimation.gif"; binmode(OUT); print OUT &getAnimation($json); # 作成したJSONを利用して描画リクエスト close OUT; result.pngBy executing the file example.pl "', you will have the "'result.png"' as below. Making anatomical address encoder
http://lifesciencedb.jp/bp3d/API/animation?
{"Part":[{"PartID":"FMA16586"}],"Common":{"Version":"4.1","TreeName":"partof"},"Pin":[{"PinY":-69,"PinUpVectorX":0,"PinArrowVectorY":17,"PinDescription":"","PinCoordinateSystemName":"bp3d",
"PinArrowVectorX":-11,"PinUpVectorZ":1,"PinUpVectorY":0,"PinZ":911,"PinX":-98,"PinPartID":"FMA16586","PinArrowVectorZ":-5}]}
API/pick function
Constracting JSON object for API/pick request
Pick parameters
A process to put a pin on the map
Processing response returned from API/pick
{
Pin:[
{
PinX:nnn,
PinY:nnn,
PinZ:nnn,
PinArrowVectorX:nnn,
PinArrowVectorY:nnn,
PinArrowVectorZ:nnn,
PinUpVectorX:nnn,
PinUpVectorY:nnn,
PinUpVectorZ:nnn,
PinPartID:"xxx",
PinCoordinateSystemName:"xxx"
},
...
{
Repeat the above for all pins
}
}
}
|