Skip to content

Commit

Permalink
Merge branch 'master' into biosimulators_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalshaikh42 authored Jun 26, 2021
2 parents 88c5146 + c8169af commit 7fd7b17
Show file tree
Hide file tree
Showing 10 changed files with 1,634 additions and 160 deletions.
24 changes: 18 additions & 6 deletions vcell-client/src/main/java/org/vcell/imagej/ImageJHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;

import javax.print.attribute.standard.Finishings;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -46,7 +47,6 @@
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DebugHandler;
import org.jdom.Namespace;
import org.vcell.imagej.ImageJHelper.ApiSolverHandler.IJGeom;
import org.vcell.util.BeanUtils;
Expand Down Expand Up @@ -140,6 +140,7 @@
import cbit.vcell.solver.SimulationOwner;
import cbit.vcell.solver.SolverDescription;
import cbit.vcell.solver.SolverUtilities;
import cbit.vcell.solver.TempSimulation;
import cbit.vcell.solver.VCSimulationDataIdentifier;
import cbit.vcell.solver.VCSimulationIdentifier;
import cbit.vcell.solver.ode.ODESimData;
Expand Down Expand Up @@ -1400,6 +1401,14 @@ private static void addSimToIJContextInfo(ArrayList<IJContextInfo>ijContextInfos
ArrayList<IJSimInfo> ijSimInfos = new ArrayList<>();
for(Simulation sim:sims) {
ijSimInfos.add(new IJSimInfo(true, false, sim.getSimulationID(), sim.getName()));
final Iterator<Entry<String, String>> iterator = TempSimulation.mapTempSimIDToModelAppSim.entrySet().iterator();
String modelAppSim = TempSimulation.createModelAppSimName(sim);
while(iterator.hasNext()) {
final Entry<String, String> next = iterator.next();
if(next.getValue().equals(modelAppSim)) {
ijSimInfos.add(new IJSimInfo(true, false, next.getKey().toString(), sim.getName()+" (quickrun_"+next.getKey().toString()+")"));
}
}
}
ijContextInfos.add(new IJContextInfo(contextName,mathType,geomDim,geomName, ijSimInfos));
}
Expand All @@ -1421,11 +1430,11 @@ private static void populateDesktopIJModelInfos(IJDocType docType,ArrayList<KeyV
for(SimulationContext simulationContext:((BioModelWindowManager)documentWindowManager).getBioModel().getSimulationContexts()) {
addSimToIJContextInfo(ijContextInfos, simulationContext.getName(), simulationContext.getMathType(),simulationContext.getGeometryContext().getGeometry().getDimension(),simulationContext.getGeometry().getName(),simulationContext.getSimulations());
}
modelInfos.add(new IJModelInfo(documentWindowManager.getVCDocument().getName(), null, IJDocType.bm, true,documentWindowManager.getUser().getName(),null, ijContextInfos));
modelInfos.add(new IJModelInfo(documentWindowManager.getVCDocument().getName(), null, IJDocType.bm, true,(documentWindowManager.getUser()==null?null:documentWindowManager.getUser().getName()),null, ijContextInfos));
}else if(documentWindowManager instanceof MathModelWindowManager) {
MathModel mathModel = ((MathModelWindowManager)documentWindowManager).getMathModel();
addSimToIJContextInfo(ijContextInfos, null,mathModel.getMathDescription().getMathType(),mathModel.getGeometry().getDimension(),mathModel.getGeometry().getName(),((MathModelWindowManager)documentWindowManager).getSimulationWorkspace().getSimulations());
modelInfos.add(new IJModelInfo(documentWindowManager.getVCDocument().getName(), null, IJDocType.mm, true,documentWindowManager.getUser().getName(),null, ijContextInfos));
modelInfos.add(new IJModelInfo(documentWindowManager.getVCDocument().getName(), null, IJDocType.mm, true,(documentWindowManager.getUser()==null?null:documentWindowManager.getUser().getName()),null, ijContextInfos));
}
}
}
Expand Down Expand Up @@ -1629,7 +1638,7 @@ public static ArrayList<IJModelInfo> refreshIJModelInfoCache(IJDocType ijDocType
if(bOpenOnly == null || bOpenOnly.booleanValue() == false || (bOpenOnly.booleanValue() == true && bOpenOnDesktop == true)){
ArrayList<IJContextInfo> contInfos = new ArrayList<>();
ArrayList<IJSimInfo> ijsimfos= new ArrayList<>();
ijsimfos.add(new IJSimInfo(bOpenOnDesktop, false,Simulation.createSimulationID(new KeyValue(quickrunKey)), parentSimName));
ijsimfos.add(new IJSimInfo(bOpenOnDesktop, false,quickrunKey/*Simulation.createSimulationID(new KeyValue(quickrunKey))*/, parentSimName));
// ijsimfos.add(new IJSimInfo(quickrunKey, parentSimName));
contInfos.add(new IJContextInfo(parentContextName, parentMathType, parentGeomDim, parentGeomName, ijsimfos));
modelInfos.add(new IJModelInfo(parentModelName, parentDate, docType, (docType != IJDocType.quick?true:false), parentUser,parentModelKey,contInfos));
Expand Down Expand Up @@ -2430,7 +2439,9 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
StringTokenizer st = new StringTokenizer(file.getName(), "_");
st.nextToken();
String quickrunKey = st.nextToken();
if(Simulation.createSimulationID(new KeyValue(quickrunKey)).equals(ijSimInfo.simId)) {
// if(TempSimulation.mapTempSimIDToOriginalSimID.get(quickrunKey) != null && TempSimulation.mapTempSimIDToOriginalSimID.get(quickrunKey).equals(ijSimInfo.simId)) {
// if(Simulation.createSimulationID(new KeyValue(quickrunKey)).equals(ijSimInfo.simId)) {
if(quickrunKey.equals(ijSimInfo.simId)) {
ijDataResponder = IJDataResponder.create(new KeyValue(quickrunKey),file.getParentFile().getParentFile(), jobIndex);
break fileloop;
}
Expand Down Expand Up @@ -2494,6 +2505,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
response.setContentType("text/plain; charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write("VCellApi");
//response.getWriter().write("VCellApi:"+VCellClientTest.getVCellClient().getRequestManager().getDocumentManager().getUser().getName());
baseRequest.setHandled(true);

}
Expand Down
18 changes: 18 additions & 0 deletions vcell-core/src/main/java/cbit/vcell/solver/TempSimulation.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
package cbit.vcell.solver;

import java.util.TreeMap;

import org.vcell.util.document.SimulationVersion;
import org.vcell.util.document.VCellSoftwareVersion;
import org.vcell.util.document.Version;

import cbit.vcell.mapping.SimulationContext;

@SuppressWarnings("serial")
public class TempSimulation extends Simulation {
//Store association of tempSimID to originalSimID for use in ImageJHelper
public static final TreeMap<String,String> mapTempSimIDToOriginalSimID = new TreeMap<String,String>();
public static final TreeMap<String,String> mapTempSimIDToModelAppSim = new TreeMap<String,String>();
final private SimulationVersion tempSimVersion = SimulationVersion.createTempSimulationVersion();
public TempSimulation(Simulation simulation, boolean bCloneMath) {
super(simulation, bCloneMath);
mapTempSimIDToModelAppSim.put(tempSimVersion.getVersionKey().toString(), createModelAppSimName(simulation));
mapTempSimIDToOriginalSimID.put(tempSimVersion.getVersionKey().toString(), (simulation.getVersion()==null || simulation.getVersion().getVersionKey()==null?"":simulation.getVersion().getVersionKey().toString()));
}

public static String createModelAppSimName(Simulation simulation) {
String modelAppSim = simulation.getName();
if(simulation.getSimulationOwner() instanceof SimulationContext) {//biomodel
modelAppSim = ((SimulationContext)simulation.getSimulationOwner()).getBioModel().getName()+"_"+simulation.getSimulationOwner().getName()+"_"+modelAppSim;
}else {//mathmodel
modelAppSim = simulation.getSimulationOwner().getName()+"_"+modelAppSim;
}
return modelAppSim;
}
@Override
public Version getVersion() {
return tempSimVersion;
Expand Down
26 changes: 21 additions & 5 deletions vcell-core/src/main/java/cbit/vcell/xml/XmlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.jlibsedml.execution.ModelResolver;
import org.jlibsedml.modelsupport.KisaoOntology;
import org.jlibsedml.modelsupport.KisaoTerm;
import org.jlibsedml.modelsupport.SUPPORTED_LANGUAGE;
import org.sbml.jsbml.SBMLException;
import org.vcell.cellml.CellQuanVCTranslator;
import org.vcell.sbml.SbmlException;
Expand Down Expand Up @@ -591,6 +592,7 @@ public static List<VCDocument> sedmlToBioModel(VCLogger transLogger, ExternalDoc
org.jlibsedml.Simulation sedmlSimulation = null; // this will become the vCell simulation
org.jlibsedml.Model sedmlOriginalModel = null; // the "original" model referred to by the task
String sedmlOriginalModelName = null; // this will be used in the BioModel name
String sedmlOriginalModelLanguage = null; // can be sbml or vcml
ArchiveComponents ac = null;
if(externalDocInfo.getFile().getPath().toLowerCase().endsWith("sedx") || externalDocInfo.getFile().getPath().toLowerCase().endsWith("omex")) {
ac = Libsedml.readSEDMLArchive(new FileInputStream(externalDocInfo.getFile().getPath()));
Expand Down Expand Up @@ -626,6 +628,7 @@ public static List<VCDocument> sedmlToBioModel(VCLogger transLogger, ExternalDoc
throw new RuntimeException("Unexpected task " + selectedTask);
}
sedmlOriginalModelName = sedmlOriginalModel.getId();
sedmlOriginalModelLanguage = sedmlOriginalModel.getLanguage();

// at this point we assume that the sedml simulation, algorithm and kisaoID are all valid
Algorithm algorithm = sedmlSimulation.getAlgorithm();
Expand Down Expand Up @@ -681,11 +684,24 @@ public static List<VCDocument> sedmlToBioModel(VCLogger transLogger, ExternalDoc
}
// make it if we didn't and mark it as fresh
if (bioModel == null) {
XMLSource sbmlSource = new XMLSource(newMdl); // sbmlSource with all the changes applied
bioModel = (BioModel)XmlHelper.importSBML(transLogger, sbmlSource, bSpatial);
bioModel.setName(bioModelName);
docs.add(bioModel);
justMade = true;
if(sedmlOriginalModelLanguage.contentEquals(SUPPORTED_LANGUAGE.VCELL_GENERIC.getURN())) { // vcml
XMLSource vcmlSource = new XMLSource(newMdl);
bioModel = (BioModel)XmlHelper.XMLToBioModel(vcmlSource);
bioModel.setName(bioModelName);
docs.add(bioModel);
justMade = true;
try {
bioModel.getVCMetaData().createBioPaxObjects(bioModel);
} catch (Exception e) {
e.printStackTrace();
}
} else { // we assume it's sbml, if it's neither import will fail
XMLSource sbmlSource = new XMLSource(newMdl); // sbmlSource with all the changes applied
bioModel = (BioModel)XmlHelper.importSBML(transLogger, sbmlSource, bSpatial);
bioModel.setName(bioModelName);
docs.add(bioModel);
justMade = true;
}
}
// even if we just created the biomodel from the sbml file we have at least one application with initial conditions and stuff
// see if there is a suitable application type for the sedml kisao
Expand Down
7 changes: 7 additions & 0 deletions vcell-imagej-helper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,12 @@
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jfree/jfreechart -->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<!-- <version>1.5.0</version> -->
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ public ArrayList<VCellModelSearchResults> getSearchedModelSimCacheKey(Boolean bO
Node node = si.item(i);
String currentUser = (node.getAttributes().getNamedItem("user")==null?null:node.getAttributes().getNamedItem("user").getNodeValue());
boolean bUserMatch = vcCellModelSearch.getUserId() == null || vcCellModelSearch.getUserId().equals(currentUser);
if(node.getAttributes().getNamedItem("name")==null) {
continue;
}
String currentModel = node.getAttributes().getNamedItem("name").getNodeValue();
Long longDate = (node.getAttributes().getNamedItem("date")==null?null:Long.parseLong(node.getAttributes().getNamedItem("date").getNodeValue()));
if(longDate != null && vcellModelVersionTimeRange != null && (longDate < vcellModelVersionTimeRange.getEarliest().getTime() || longDate > vcellModelVersionTimeRange.getLatest().getTime())) {
Expand Down
Loading

0 comments on commit 7fd7b17

Please sign in to comment.