% Must be run with prova_axis.bat ex013.prova
% Test of a remote web service calls via Prova built-in
%     Apache Axis client framework.

:-eval(ws_uniparc()).
%:-eval(ws_gopubmed()).

% Analysis web service workflow example of Alan Robinson
%    (see http://industry.ebi.ac.uk/soaplab/)
ws_uniparc() :-
	Map = java.util.HashMap(),

	% Retrieve the starting DNA sequence.
	Map.put("sequence_usa","embl:xlrhodop"),
	doCall_uniparc("edit::seqret",Map,"outseq",Xlrhodop_dna),
	println([Xlrhodop_dna]),
	println([">>>>>>>>>>>"]),

	% Find the largest ORF in this DNA sequence
	%    (actually the only one over 400 nucleotides).
	Map.clear(),
	Map.put("sequence_direct_data",Xlrhodop_dna),
	Map.put("minsize","400"),
	Map.put("find","3"),
	doCall_uniparc("nucleic_gene_finding::getorf",Map,"outseq",Xlrhodop_orf),
	println([Xlrhodop_orf]),
	println([">>>>>>>>>>>"]),

	% Translate this ORF (N.B. the 'getorf' tool can do translation).
	Map.clear(),
	Map.put("sequence_direct_data",Xlrhodop_orf),
	doCall_uniparc("nucleic_translation::transeq",Map,"outseq",Xlrhodop_pep),
	println([Xlrhodop_pep]),
	println([">>>>>>>>>>>"]),

	% Retrieve a set of related opsin proteins from SWISS-PROT.
	Map.clear(),
	Map.put("sequence_usa","swallid:ops2_*"),
	doCall_uniparc("edit::seqret",Map,"outseq",Seqs),
	println([Seqs]),
	println([">>>>>>>>>>>"]),

	% Perform a multiple alignment of these proteins.
	Map.clear(),
	Map.put("sequence_direct_data",Seqs),
	doCall_uniparc("alignment_multiple::emma",Map,"outseq",Alignment),
	println([Alignment]),
	println([">>>>>>>>>>>"]),

	% Generate a profile for this multiple alignment.
	Map.clear(),
	Map.put("sequence_direct_data",Alignment),
	Map.put("type","G"),
	doCall_uniparc("nucleic_profiles::prophecy",Map,"outfile",Profile),
	println([Profile]),
	println([">>>>>>>>>>>"]),

	% Use the profile to identify a motif in the original peptide.
	Map.clear(),
	Map.put("sequence_direct_data",Xlrhodop_pep),
	Map.put("infile_direct_data",Profile),
	doCall_uniparc("nucleic_profiles::prophet",Map,"outfile",Motif),
	println([Motif]),
	println([">>>>>>>>>>>"]).

doCall_uniparc(Port,Input_list,Key,Result) :-
	concat(["http://industry.ebi.ac.uk/soap/soaplab/",Port],Target),
	concat(["http://globus.ebi.ac.uk:9080/axis/services/",Port],NS),
	% Call Analysis web service (see http://industry.ebi.ac.uk/soaplab/)
	ws_call(
		% endpoint
		Target,
		% namespace
		NS,
		% service
		"AnalysisWSAppLabImplService",
		% port
		Port,
		% operation
		"createAndRun",
		% response
		JobId,
		% parameters
		Input_list
	),
	ws_call(
		% endpoint
		Target,
		% namespace
		NS,
		% service
		"AnalysisWSAppLabImplService",
		% port
		Port,
		% operation
		"waitFor",
		% response
		Result1,
		% parameters
		JobId
	),
	ws_call(
		% endpoint
		Target,
		% namespace
		NS,
		% service
		"AnalysisWSAppLabImplService",
		% port
		Port,
		% operation
		"getResults",
		% response
		ResultMap,
		% parameters
		JobId
	),
	ws_call(
		% endpoint
		Target,
		% namespace
		NS,
		% service
		"AnalysisWSAppLabImplService",
		% port
		Port,
		% operation
		"destroy",
		% response
		Result2, % No response for this call
		% parameters
		JobId
	),
%println(["********",ResultMap]),
	Result = ResultMap.get(Key).

ws_gopubmed() :-
	% Call GoPubMed web service (see http://gopubmed.net)
	%	WSDL is at http://comas.soi.city.ac.uk/ws.prova/services/gopubmed?wsdl
	ws_call(
		% endpoint
		"http://comas.soi.city.ac.uk/ws.prova/services/gopubmed",
		% namespace
		"http://comas.soi.city.ac.uk:7777/ws.prova/services/gopubmed",
		% service
		"gopubmedService",
		% port
		"gopubmed",
		% operation
		"query",
		% response (note that it is typed for the right deserializing to occur)
		String.Result,
		% parameters: query string, maximum papers, and mode (non-strict mode)
		"tnap",2,0
	),
	println([String.Result]).
ws_local() :-
	% Call GoPubMed web service (see http://gopubmed.net)
	%	WSDL is at http://localhost:7777/ws.prova/services/gopubmed?wsdl
	ws_call(
		% endpoint
		"http://localhost:7777/ws.prova/services/gopubmed",
		% namespace
		"http://localhost:7777/ws.prova/services/gopubmed",
		% service
		"gopubmedService",
		% port
		"gopubmed",
		% operation
		"query",
		% response (note that it is typed for the right deserializing to occur)
		String.Result,
		% parameters: query string, maximum papers, and mode (non-strict mode)
		"tnap,xml",2,0
	),
	println([String.Result]).
ws_test_ms() :-
	ws_call("http://localhost/WebService1/Service1.asmx",
				"http://ws.prova/myservice/myInterface/2002/07/23",
				"Service1","Service1Soap","GetVideos",Result),
	println(["Result=",Result]).
