Skip to content

Commit

Permalink
Merge pull request #73 from sanctuuary/integrate-pubmetric
Browse files Browse the repository at this point in the history
Add code that calls pubmetric
  • Loading branch information
kretep authored Oct 30, 2024
2 parents 8ec5903 + 5430db8 commit d8707c0
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>nl.esciencecenter</groupId>
<artifactId>restape</artifactId>
<version>0.3.3</version>
<version>0.4.0</version>
<name>restape</name>
<description>RESTful API for the APE library</description>
<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String index() {
parameters = {
@Parameter(name = "config_path",
description = "URL to the APE configuration file.",
example = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json")
example = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json")
},
externalDocs = @ExternalDocumentation(description = "More information about the APE configuration file can be found here.",
url = "https://ape-framework.readthedocs.io/en/latest/docs/specifications/setup.html#configuration-file"),
Expand Down Expand Up @@ -110,7 +110,7 @@ public ResponseEntity<String> getData(
parameters = {
@Parameter(name = "config_path",
description = "URL to the APE configuration file.",
example = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json")
example = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json")
},
externalDocs = @ExternalDocumentation(description = "More information about the APE configuration file can be found here.",
url = "https://ape-framework.readthedocs.io/en/latest/docs/specifications/setup.html#configuration-file"),
Expand Down Expand Up @@ -144,7 +144,7 @@ public ResponseEntity<String> getTools(
parameters = {
@Parameter(name = "config_path",
description = "URL to the APE configuration file.",
example = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json")
example = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json")
},
externalDocs = @ExternalDocumentation(description = "More information about the APE configuration file can be found here.",
url = "https://ape-framework.readthedocs.io/en/latest/docs/specifications/setup.html#configuration-file"),
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/nl/esciencecenter/restape/ApeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,19 @@ public static JSONArray getConstraints(String configFileURL) throws OWLOntologyC
APE apeFramework = setupApe(configFileURL);
Collection<ConstraintTemplate> constraints = apeFramework.getConstraintTemplates();
JSONArray arrayConstraints = new JSONArray();
constraints.forEach(constraint -> arrayConstraints.put(constraint.toJSON()));
constraints.forEach(constraint -> {
JSONObject constraintJson = constraint.toJSON();
if (constraint.getConstraintID().equals("connected_op")) {
constraintJson.remove("label");
constraintJson.put("label", "Use operations sequentially.");
} else if (constraint.getConstraintID().equals("not_connected_op")) {
constraintJson.remove("label");
constraintJson.put("label", "Do not use operations sequentially.");
}

arrayConstraints.put(constraintJson);

});

return arrayConstraints;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nl/esciencecenter/restape/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class IOUtils {
/**
* URL to the README file containing instructions on how to run the workflows.
*/
private static final String README_URL = "https://raw.githubusercontent.com/Workflomics/containers/add_instructions/instructions.txt";
private static final String README_URL = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/add_instructions/instructions.txt";

/**
* Get the CWL content of the file at the given path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import java.util.List;

import okhttp3.OkHttpClient;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -23,6 +31,7 @@
import nl.esciencecenter.models.benchmarks.BenchmarkBase;
import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow;
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;
import nl.uu.cs.ape.solver.solutionStructure.cwl.DefaultCWLCreator;
import nl.uu.cs.ape.utils.APEFiles;

/**
Expand Down Expand Up @@ -63,7 +72,14 @@ static boolean computeBenchmarks(SolutionsList candidateSolutions, String runID)
* Compute the benchmarks for the workflow and save them in a JSON file.
*/
JSONObject workflowBenchmarks = computeWorkflowSpecificFields(workflow, runID);
workflowBenchmarks.put("benchmarks", computeWorkflowBenchmarks(workflow));
JSONArray benchmarks = computeWorkflowBenchmarks(workflow);
JSONObject additionalBenchmarks = getPubmetricBenchmarks(workflow);

if (!additionalBenchmarks.isEmpty() && additionalBenchmarks.has("benchmarks")) {
additionalBenchmarks.getJSONArray("benchmarks").forEach(benchmark -> benchmarks.put(benchmark));
}

workflowBenchmarks.put("benchmarks", benchmarks);

String titleBenchmark = workflow.getFileName() + ".json";
Path solFolder = candidateSolutions.getRunConfiguration().getSolutionDirPath2CWL();
Expand All @@ -79,6 +95,65 @@ static boolean computeBenchmarks(SolutionsList candidateSolutions, String runID)
return true;
}

/**
* Get the Pubmetric benchmarks for the workflow.
* @param workflow
* @return
*/
public static JSONObject getPubmetricBenchmarks(SolutionWorkflow workflow) {
// Generate the CWL file content
DefaultCWLCreator cwlCreator = new DefaultCWLCreator(workflow);
String cwlFileContent = cwlCreator.generate();

// Convert the CWL content to a byte array
byte[] cwlFileBytes = cwlFileContent.getBytes();

return sendPostToPubmetric(cwlFileBytes);
}


/**
* Send a POST request to the Pubmetric API to get the benchmarks for the CWL file.
* @param cwlFileBytes
* @return
*/
public static JSONObject sendPostToPubmetric(byte[] cwlFileBytes) {
// Create the HTTP client
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost("http://pubmetric:8000/score_workflow/");

// Create a multipart entity with the CWL file
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("cwl_file", cwlFileBytes, org.apache.http.entity.ContentType.DEFAULT_BINARY,
"workflow.cwl");

HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);

// Execute the request
CloseableHttpResponse response;
try {
response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();

// Print the response
if (responseEntity != null) {
String responseString = EntityUtils.toString(responseEntity);
return new JSONObject(responseString);
}

// Close resources
response.close();
httpClient.close();
} catch (IOException e) {
log.error("Error while fetching the Pubmetric benchmarks");
} catch (JSONException e) {
log.error("Error while parsing the Pubmetric benchmarks");
}

return new JSONObject();
}

/**
* Compute the benchmarks (based on bio.tools and OpenEBench APIs) for the
* workflows and return it in JSON format.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/data.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
INSERT INTO DOMAIN VALUES (1, 'Proteomics', "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/MassSpectometry/config.json");
INSERT INTO DOMAIN VALUES (2, 'Wombat-P', "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json");
INSERT INTO DOMAIN VALUES (2, 'Wombat-P', "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json");

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testGetDataFail() throws Exception {
*/
@Test
void testGetData() throws Exception {
String path = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String path = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";

mvc.perform(MockMvcRequestBuilders.get("/data_taxonomy?config_path=" + path).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
Expand All @@ -83,7 +83,7 @@ void testGetToolsFail() throws Exception {
*/
@Test
void testGetTools() throws Exception {
String path = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String path = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";

mvc.perform(
MockMvcRequestBuilders.get("/tools_taxonomy?config_path=" + path).accept(MediaType.APPLICATION_JSON))
Expand Down Expand Up @@ -121,7 +121,7 @@ void testRunSynthesisFail() throws Exception {
@Test
void testRunSynthesisPass() throws Exception {

String configPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String configPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String jsonContent = FileUtils.readFileToString(APEFiles.readPathToFile(configPath),
StandardCharsets.UTF_8);

Expand All @@ -134,7 +134,7 @@ void testRunSynthesisPass() throws Exception {
@Test
void testPostZipCWLs() throws Exception {

String path = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String path = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String content = FileUtils.readFileToString(APEFiles.readPathToFile(path),
StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(content);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/nl/esciencecenter/restape/ApeAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ApeAPITest {
*/
@Test
void runSynthesisFail() throws IOException, OWLOntologyCreationException {
String configPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String configPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String content = FileUtils.readFileToString(APEFiles.readPathToFile(configPath),
StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(content);
Expand All @@ -45,7 +45,7 @@ void runSynthesisFail() throws IOException, OWLOntologyCreationException {
*/
@Test
void runSynthesisPass() throws IOException, OWLOntologyCreationException {
String configPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String configPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String content = FileUtils.readFileToString(APEFiles.readPathToFile(configPath),
StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(content);
Expand All @@ -63,7 +63,7 @@ void runSynthesisPass() throws IOException, OWLOntologyCreationException {
*/
@Test
void runSynthesisAndBenchmarkPass() throws IOException, OWLOntologyCreationException {
String configPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String configPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String content = FileUtils.readFileToString(APEFiles.readPathToFile(configPath),
StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(content);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/nl/esciencecenter/restape/IOUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IOUtilsTest {
@Test
void testZipFilesForLocalExecution() throws Exception {

String path = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String path = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";
String content = FileUtils.readFileToString(APEFiles.readPathToFile(path),
StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(content);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/nl/esciencecenter/restape/RestApeUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RestApeUtilsTest {
*/
@Test
void loadURLPath() {
String urlPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String urlPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";

assertDoesNotThrow(() -> ApeAPI.setupApe(urlPath));

Expand All @@ -31,7 +31,7 @@ void loadLocalPath() {

assertDoesNotThrow(() -> {
File config = APEFiles.readPathToFile(
"https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json");
"https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json");
ApeAPI.setupApe(config.getAbsolutePath());
});

Expand All @@ -43,7 +43,7 @@ void loadLocalPath() {
*/
@Test
void getTypesFromURLPath() {
String urlPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String urlPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";

assertDoesNotThrow(() -> ApeAPI.getData(urlPath));

Expand All @@ -55,7 +55,7 @@ void getTypesFromURLPath() {
*/
@Test
void getToolsFromURLPath() {
String urlPath = "https://raw.githubusercontent.com/Workflomics/domain-annotations/main/WombatP_tools/config.json";
String urlPath = "https://raw.githubusercontent.com/Workflomics/tools-and-domains/refs/heads/main/domains/proteomics/config.json";

assertDoesNotThrow(() -> ApeAPI.getTools(urlPath));

Expand Down

0 comments on commit d8707c0

Please sign in to comment.