Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated KiSAO OBO and added parsing for KiSAO_694 #1393

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vcell-core/src/main/java/cbit/util/kisao/KisaoOntology.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class KisaoOntology {

private List<KisaoTerm> terms = new ArrayList<>();
private final List<KisaoTerm> terms = new ArrayList<>();
private static KisaoOntology instance;


Expand Down Expand Up @@ -61,7 +61,7 @@ public static List<KisaoTerm> makeDescendantList(KisaoTerm root) {
if(tmpList.size() > 1) {
System.err.println("Each kisao term must have no more than 1 descendant");
}
if(tmpList.size() == 0) { // we seldom get here
if(tmpList.isEmpty()) { // we seldom get here
if(root.getId().equals("KISAO_0000000")) {
throw new RuntimeException("Error reaching KISAO_0000000");
} else {
Expand Down
23 changes: 13 additions & 10 deletions vcell-core/src/main/java/cbit/util/kisao/KisaoTermParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.StreamSupport;


public class KisaoTermParser {
Expand All @@ -22,16 +24,15 @@ public class KisaoTermParser {
final Pattern ISA_PATTERN = Pattern.compile("is_a:\\s*(\\S+)");

KisaoOntology parse() {
InputStream is = KisaoTermParser.class.getClassLoader().getResourceAsStream(Kisao_OBO);
BufferedReader isr = new BufferedReader(new InputStreamReader(is));
String line = null;
boolean inState = false;
KisaoOntology ontology = new KisaoOntology();
KisaoTerm curr = null;
boolean inState = false;

InputStream is = KisaoTermParser.class.getClassLoader().getResourceAsStream(Kisao_OBO);
assert is != null;
CodeByDrescher marked this conversation as resolved.
Show resolved Hide resolved

try {
while ((line = isr.readLine()) != null) {

for (String line : (new BufferedReader(new InputStreamReader(is))).lines().toList()){
if (line.matches(TERM_PATTERN)) {
inState = true;
curr = new KisaoTerm();
Expand All @@ -41,11 +42,12 @@ KisaoOntology parse() {
ontology.addTerm(curr);
curr = null;
}

if(inState) {
Matcher matcher = ID_PATTERN.matcher(line);
if (matcher.find()) {
curr.setId(matcher.group(1));
String group1 = matcher.group(1);
curr.setId(group1.startsWith("kisao:") ? group1.substring(6) : group1);
}

matcher = NAME_PATTERN.matcher(line);
Expand All @@ -54,11 +56,12 @@ KisaoOntology parse() {
}
matcher = ISA_PATTERN.matcher(line);
if (matcher.find()) {
curr.addIsaRef(matcher.group(1));
String group1 = matcher.group(1);
curr.addIsaRef(group1.startsWith("kisao:") ? group1.substring(6) : group1);
}
}
}
} catch(Exception e) {
} catch (Exception e) {
lg.error(e.getMessage(), e);
}

Expand Down
56 changes: 26 additions & 30 deletions vcell-core/src/main/java/cbit/vcell/solver/SolverUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ public static boolean isPowerOf2(int n) {

/**
* Ensure solvers extracted from resources and registered as property
* @param cf
* @param sd the solver description
* @return array of exes used by provided solver
* @throws IOException, {@link UnsupportedOperationException} if no exe for this solver
*/
public static File[] getExes(SolverDescription sd) throws IOException {
SolverExecutable se = sd.getSolverExecutable();
if (se != null) {
SolverExecutable.NameInfo nameInfos[] = se.getNameInfo();
SolverExecutable.NameInfo[] nameInfos = se.getNameInfo();
File files[] = new File[nameInfos.length];
for (int i = 0; i < nameInfos.length; ++i) {
SolverExecutable.NameInfo ni = nameInfos[i];
Expand All @@ -106,7 +106,7 @@ public static File[] getExes(SolverDescription sd) throws IOException {
}

/**
* calls {@link #getExes(SolverConfig)} if solver requires executables,
* calls {@link #getExes(SolverDescription)} if solver requires executables,
* no-op otherwise
*/
public static void prepareSolverExecutable(SolverDescription solverDescription) throws IOException {
Expand Down Expand Up @@ -179,33 +179,29 @@ private static List<SolverDescription> matchByKisaoId(KisaoTerm candidate) {
}

private static SolverDescription attemptLastResortMatch(KisaoTerm last) {
switch(last.getId()) {
case "KISAO_0000433":
return SolverDescription.CVODE;
case "KISAO_0000094":
return SolverDescription.CVODE;
case "KISAO_0000284":
return SolverDescription.CVODE;
case "KISAO_0000319":
return SolverDescription.StochGibson;
case "KISAO_0000408":
return SolverDescription.IDA;
case "KISAO_0000056":
return SolverDescription.Smoldyn;
case "KISAO_0000352":
return SolverDescription.HybridMilstein;
case "KISAO_0000398":
return SolverDescription.SundialsPDE;
case "KISAO_0000369":
return SolverDescription.SundialsPDE;
case "KISAO_0000281":
return SolverDescription.AdamsMoulton;
case "KISAO_0000377":
return SolverDescription.RungeKuttaFehlberg;
default:
logger.error("Failed last resort match for descendant " + last.getId());
return null;
}
return switch (last.getId()) {
case "KISAO_0000056" -> SolverDescription.Smoldyn; // Livermore Solver
case "KISAO_0000094" /* Livermore Solver */, "KISAO_0000284" /* ? missing ? */,
"KISAO_0000433" /* CVODE-like method */, "KISAO_0000694" /* ODE-solver */ ->
SolverDescription.CVODE;
case "KISAO_0000281" /*multi-step method*/ ->
SolverDescription.AdamsMoulton;
case "KISAO_0000319" /*Monte-carlo*/ ->
SolverDescription.StochGibson;
case "KISAO_0000352" /* Hybrid-method */ ->
SolverDescription.HybridMilstein;
case "KISAO_0000369" /* partial differential equation discretization method */,
"KISAO_0000398" /* iterative method for solving a system of equations */ ->
SolverDescription.SundialsPDE;
case "KISAO_0000377" /* one-step method */ ->
SolverDescription.RungeKuttaFehlberg;
case "KISAO_0000408" /* Newton type method */ ->
SolverDescription.IDA;
default -> {
logger.error("Failed last resort match for descendant {}", last.getId());
yield null;
}
};
}

private static boolean needsExactMatch(boolean cmdRequestedMatch){
Expand Down
6 changes: 3 additions & 3 deletions vcell-core/src/main/java/org/vcell/sedml/SEDMLImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public List<BioModel> getBioModels() {
// try to find a match in the ontology tree
SolverDescription solverDescription = SolverUtilities.matchSolverWithKisaoId(kisaoID, this.exactMatchOnly);
if (solverDescription != null) {
logger.info("Task (id='"+selectedTask.getId()+"') is compatible, solver match found in ontology: '" + kisaoID + "' matched to " + solverDescription);
logger.info("Task (id='{}') is compatible, solver match found in ontology: '{}' matched to {}", selectedTask.getId(), kisaoID, solverDescription);
} else {
// give it a try anyway with our deterministic default solver
solverDescription = SolverDescription.CombinedSundials;
logger.error("Task (id='"+selectedTask.getId()+")' is not compatible, no equivalent solver found in ontology for requested algorithm '"+kisaoID + "'; trying with deterministic default solver "+solverDescription);
logger.error("Task (id='{})' is not compatible, no equivalent solver found in ontology for requested algorithm '{}'; trying with deterministic default solver {}", selectedTask.getId(), kisaoID, solverDescription);
}
// find out everything else we need about the application we're going to use,
// as some more info will be needed when we parse the sbml file
Expand Down Expand Up @@ -1010,7 +1010,7 @@ private void translateAlgorithmParams(SolverTaskDescription simTaskDesc, org.jli
String kisaoID = algorithm.getKisaoID();
ErrorTolerance errorTolerance = new ErrorTolerance();
List<AlgorithmParameter> sedmlAlgorithmParameters = algorithm.getListOfAlgorithmParameters();
for(AlgorithmParameter sedmlAlgorithmParameter : sedmlAlgorithmParameters) {
for (AlgorithmParameter sedmlAlgorithmParameter : sedmlAlgorithmParameters) {

String apKisaoID = sedmlAlgorithmParameter.getKisaoID();
String apValue = sedmlAlgorithmParameter.getValue();
Expand Down
6,001 changes: 4,237 additions & 1,764 deletions vcell-core/src/main/resources/kisao_algs.obo

Large diffs are not rendered by default.

2,847 changes: 2,847 additions & 0 deletions vcell-core/src/main/resources/kisao_algs_old_replaced_22Nov2024.obo

Large diffs are not rendered by default.