Skip to content

Commit

Permalink
Started on refactor to switch from python to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Nov 22, 2023
1 parent c82f4f2 commit 3ea800e
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package nl.esciencecenter.e3dchem.sygma;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.knime.chem.types.SmilesCell;
Expand Down Expand Up @@ -54,6 +57,29 @@ protected DataTableSpec[] configure(DataTableSpec[] inSpecs) throws InvalidSetti
return super.configure(inSpecs);
}

public List<String> generateForSingleParent(String parent) {
PredictMetabolitesConfig config = getConfig();
// TODO add path to sygma cli to config
String cliPath = "sygma";

ProcessBuilder processBuilder = new ProcessBuilder(cliPath,
cliPath,
"--phase1_cycles", Integer.toString(config.getPhase1cycles().getIntValue()),
"--phase2_cycles", Integer.toString(config.getPhase2cycles().getIntValue()),
parent
);
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder output = new StringBuilder();
int read;
char[] buffer = new char[4096];
while ((read = reader.read(buffer)) != -1) {
output.append(buffer, 0, read);
}
List<String> records = Arrays.asList(output.toString().split("\\$\\$\\$\\$"));
return records;
}

@Override
public BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec) throws Exception {
// When copying inData to output table using a Python pandas dataframe
Expand Down

0 comments on commit 3ea800e

Please sign in to comment.