From f6ffb8830454957eda58d3cf1f7376fb03e4601c Mon Sep 17 00:00:00 2001 From: anishajauhari Date: Wed, 25 Aug 2021 14:49:21 -0500 Subject: [PATCH] Javaloadable api --- README.md | 12 +++ pom.xml | 91 +++++++++++++++++++ src/.idea/.gitignore | 3 + src/main/java/Main.java | 6 ++ .../predictors/BioTransformerAPIs.java | 8 ++ src/main/java/utils/Validator.java | 67 ++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 pom.xml create mode 100644 src/.idea/.gitignore create mode 100644 src/main/java/Main.java create mode 100644 src/main/java/biotransformerapis/predictors/BioTransformerAPIs.java create mode 100644 src/main/java/utils/Validator.java diff --git a/README.md b/README.md index e088481..ed80557 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # biotransformer-apis A library that provides APIs to facilitate the integration of various libraries into BioTransformer. +This repository contains the Predictor Model Interface which every Java Loadable prediction application should implement. + +
+ +To add this to your project - +1. Build the project. +2. Create a lib/ folder outside of src/ in your application. +3. Put the biotransformer-api.jar in the the lib/ folder. +4. Run Maven Goal - + mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=lib/biotransformer-api.jar -DgroupId=biotransformer -DartifactId=biotransformer-api -Dversion=1.0.0 -Dpackaging=jar +5. This would install the jar in your local .m2 directory. +6. Implement the interface now. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..db30f33 --- /dev/null +++ b/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + biotransformer + biotransformer-apis + 1.0.0 + + + 8 + ${jdk.version} + ${jdk.version} + UTF-8 + Main.java + + + + org.kie.modules + org-apache-commons-lang3 + 6.5.0.Final + pom + + + + biotransformer-apis + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.1 + + + false + + jar-with-dependencies + + + + + executable.BiotransformerExecutable + + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + + \ No newline at end of file diff --git a/src/.idea/.gitignore b/src/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/src/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..2c75dd0 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,6 @@ + +public class Main { + public static void main(String[] args) { + + } +} diff --git a/src/main/java/biotransformerapis/predictors/BioTransformerAPIs.java b/src/main/java/biotransformerapis/predictors/BioTransformerAPIs.java new file mode 100644 index 0000000..f7eb65d --- /dev/null +++ b/src/main/java/biotransformerapis/predictors/BioTransformerAPIs.java @@ -0,0 +1,8 @@ +package biotransformerapis.predictors; + +import java.util.LinkedHashMap; + +public interface BioTransformerAPIs { + + public Object predict (LinkedHashMap inputParameters) throws Exception; +} diff --git a/src/main/java/utils/Validator.java b/src/main/java/utils/Validator.java new file mode 100644 index 0000000..9291a49 --- /dev/null +++ b/src/main/java/utils/Validator.java @@ -0,0 +1,67 @@ +package utils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import org.apache.commons.lang3.StringUtils; + +public class Validator { + + public enum ioFormats{ + SDFILE, IATOMCONTAINERSET + } + LinkedHashMap> validParams = new LinkedHashMap>(); + + public Validator() { + ArrayList required = new ArrayList(); + ArrayList optional = new ArrayList(); + required.add("input"); + required.add("inputFormat"); + required.add("outputFormat"); + optional.add("output"); + this.validParams.put("required", required); + this.validParams.put("optional", required); + } + + public Boolean validateParameters(LinkedHashMap parameters) throws Exception { + Boolean isValid = true; + + for(String requiredParam : validParams.get("required")) { + if(!parameters.containsKey(requiredParam)) { + throw new IOException("The required parameter \'" + requiredParam + "\' is missing. Please provide an adequate value."); + } + } + + + ioFormats inputFormat = ioFormats.valueOf( StringUtils.upperCase( (String) parameters.get("inputFormat") )) ; + ioFormats outputFormat = ioFormats.valueOf( StringUtils.upperCase( (String) parameters.get("outputFormat") )) ; + + + if(!Arrays.asList(ioFormats.values()).contains(inputFormat)) { + isValid = false; + throw new IOException("The provided input \'" + inputFormat + "\' format is not support by PhaseIIFilter"); + } + if(!Arrays.asList(ioFormats.values()).contains(outputFormat)) { + isValid = false; + throw new IOException("The provided output \'" + inputFormat + "\' format is not support by PhaseIIFilter"); + } + + if(inputFormat == ioFormats.SDFILE) { + File inputFile = new File((String) parameters.get("input")); + if((!inputFile.exists()) || inputFile.isDirectory()) { + isValid = false; + throw new IOException("A pathname to the input file is missing. Please provide a pathname to the input file"); + + } + } + + if(outputFormat == ioFormats.SDFILE && !parameters.containsKey("output")) { + isValid = false; + throw new IOException("A pathname to the output file is missing. Please provide a pathname to the output file"); + } + + return isValid; + } +}