use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservableTableModel method bioModelChange.
@Override
protected void bioModelChange(PropertyChangeEvent evt) {
super.bioModelChange(evt);
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
RbmModelContainer rbmModelContainer = (RbmModelContainer) (oldValue.getModel().getRbmModelContainer());
// TODO: listen to something ??? rbmModelContainer.removePropertyChangeListener(this);
for (RbmObservable observable : rbmModelContainer.getObservableList()) {
observable.removePropertyChangeListener(this);
for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
RbmUtils.removePropertyChangeListener(speciesPattern, this);
}
}
}
BioModel newValue = (BioModel) evt.getNewValue();
if (newValue != null) {
RbmModelContainer rbmModelContainer = (RbmModelContainer) (newValue.getModel().getRbmModelContainer());
// TODO: rbmModelContainer.addPropertyChangeListener(this);
for (RbmObservable observable : rbmModelContainer.getObservableList()) {
observable.addPropertyChangeListener(this);
for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
RbmUtils.addPropertyChangeListener(speciesPattern, this);
}
}
}
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservableTableModel method checkInputValue.
public String checkInputValue(String inputValue, int row, int column) {
String errMsg = null;
final Column col = Column.values()[column];
RbmObservable selectedObservable = getValueAt(row);
switch(col) {
case name:
inputValue = inputValue.trim();
if (inputValue.length() > 0) {
String mangled = TokenMangler.fixTokenStrict(inputValue);
if (!mangled.equals(inputValue)) {
errMsg = RbmObservable.typeName + " '" + inputValue + "' not legal identifier, try '" + mangled + "'";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
RbmObservable o = getModel().getRbmModelContainer().getObservable(inputValue);
if (o != null && o != selectedObservable) {
errMsg = "Observable '" + inputValue + "' already exists!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
break;
case species_pattern:
try {
inputValue = inputValue.trim();
if (inputValue.length() > 0) {
StringTokenizer tokens = new StringTokenizer(inputValue);
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
// parsing will throw appropriate exception if molecular type or component don't exist
SpeciesPattern speciesPattern = RbmUtils.parseSpeciesPattern(token, bioModel.getModel());
}
}
} catch (Exception ex) {
errMsg = ex.getMessage();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
case type:
try {
inputValue = inputValue.trim();
RbmObservable.ObservableType ot = RbmObservable.ObservableType.valueOf((String) inputValue);
} catch (IllegalArgumentException e) {
e.printStackTrace(System.out);
errMsg = "";
for (int i = 0; i < RbmObservable.ObservableType.values().length; i++) {
errMsg += RbmObservable.ObservableType.values()[i].toString();
if (i < RbmObservable.ObservableType.values().length - 1) {
errMsg += " or ";
}
}
errMsg = "Type may only be " + errMsg;
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
} catch (Exception ex) {
errMsg = ex.getMessage();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
return null;
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ObservableTreeModel method setObservable.
public void setObservable(RbmObservable newValue) {
if (newValue == observable) {
return;
}
RbmObservable oldValue = observable;
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
for (SpeciesPattern speciesPattern : oldValue.getSpeciesPatternList()) {
RbmUtils.removePropertyChangeListener(speciesPattern, this);
}
}
observable = newValue;
if (newValue != null) {
newValue.addPropertyChangeListener(this);
for (SpeciesPattern speciesPattern : newValue.getSpeciesPatternList()) {
RbmUtils.addPropertyChangeListener(speciesPattern, this);
}
}
populateTree();
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class ClientRequestManager method createBioModelFromApplication.
public void createBioModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
if (simContext == null) {
PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding bio model");
return;
}
if (simContext.isRuleBased()) {
createRuleBasedBioModelFromApplication(requester, name, simContext);
return;
}
AsynchClientTask task1 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback dummyCallback = new MathMappingCallback() {
public void setProgressFraction(float percentDone) {
}
public void setMessage(String message) {
}
public boolean isInterrupted() {
return false;
}
};
MathMapping transformedMathMapping = simContext.createNewMathMapping(dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
BioModel newBioModel = new BioModel(null);
SimulationContext transformedSimContext = transformedMathMapping.getTransformation().transformedSimContext;
Model newModel = transformedSimContext.getModel();
newBioModel.setModel(newModel);
RbmModelContainer rbmmc = newModel.getRbmModelContainer();
for (RbmObservable o : rbmmc.getObservableList()) {
rbmmc.removeObservable(o);
}
for (ReactionRule r : rbmmc.getReactionRuleList()) {
rbmmc.removeReactionRule(r);
}
for (ReactionStep rs : newModel.getReactionSteps()) {
String oldName = rs.getName();
if (oldName.startsWith("_reverse_")) {
String newName = newModel.getReactionName("rev", oldName.substring("_reverse_".length()));
rs.setName(newName);
}
}
hashTable.put("newBioModel", newBioModel);
}
};
AsynchClientTask task2 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel newBioModel = (BioModel) hashTable.get("newBioModel");
DocumentWindowManager windowManager = createDocumentWindowManager(newBioModel);
// if(simContext.getBioModel().getVersion() != null){
// ((BioModelWindowManager)windowManager). setCopyFromBioModelAppVersionableTypeVersion(
// new VersionableTypeVersion(VersionableType.BioModelMetaData, simContext.getBioModel().getVersion()));
// }
getMdiManager().createNewDocumentWindow(windowManager);
}
};
ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.
the class BNGExecutorServiceMultipass method extractPolymerObservablesAsString.
private String extractPolymerObservablesAsString(String prefix, String sBngInputString) {
if (polymerEqualObservables.isEmpty() && polymerGreaterObservables.isEmpty()) {
return prefix;
}
String observablesString = "";
List<BNGSpecies> bngSpeciesList = BNGOutputFileParser.createBngSpeciesOutputSpec(sBngInputString);
// ordered by the network file index which is also key
Map<Integer, Map<String, Integer>> masterSignaturesMap = new LinkedHashMap<>();
// key = network file index, value = compartment of species
Map<Integer, String> masterCompartmentMap = new LinkedHashMap<>();
for (BNGSpecies species : bngSpeciesList) {
List<BNGSpecies> ourList = new ArrayList<>();
if (species instanceof BNGComplexSpecies) {
ourList.addAll(Arrays.asList(species.parseBNGSpeciesName()));
} else {
// if it's a simple species to begin with we'll only have one element in this list
ourList.add(species);
}
// key = name of molecules, value = number of occurrences
Map<String, Integer> signatureMap = new HashMap<>();
for (BNGSpecies mtp : ourList) {
if (!(mtp instanceof BNGMultiStateSpecies)) {
throw new RuntimeException("Species " + mtp.getName() + " must be instance of BNGMultiStateSpecies");
}
BNGMultiStateSpecies ss = (BNGMultiStateSpecies) mtp;
String mtpName = ss.extractMolecularTypeName();
if (signatureMap.containsKey(mtpName)) {
int value = signatureMap.get(mtpName);
value += 1;
signatureMap.put(mtpName, value);
} else {
signatureMap.put(mtpName, 1);
}
}
int networkFileIndex = species.getNetworkFileIndex();
masterSignaturesMap.put(networkFileIndex, signatureMap);
// we look in first mtp of this seed species, the compartment is the same in all
BNGMultiStateSpecies ss = (BNGMultiStateSpecies) ourList.get(0);
String compartment = ss.extractCompartment();
if (compartment == null) {
// single compartment, we get it from the model
if (model.getStructures().length > 1) {
throw new RuntimeException("BNGExecutorServiceMultipass: Unable to extract compartment");
}
compartment = model.getStructure(0).getName();
}
masterCompartmentMap.put(networkFileIndex, compartment);
}
// we need to find the next available index for observables
int nextAvailableIndex;
if (prefix != null) {
nextAvailableIndex = extractNextAvailableIndexFromObservables(prefix);
} else {
nextAvailableIndex = 1;
}
// we assume this is an observable made of only 1 sp that contains only one mtp, ex: A()=xx where xx is number of occurrences of A
for (RbmObservable oo : polymerEqualObservables) {
// for each polymer observable, here we build the string with the network indexes of the species that satisfy the criteria
String speciesFoundIndexes = "";
String mtpName = oo.getSpeciesPatternList().get(0).getMolecularTypePatterns().get(0).getMolecularType().getDisplayName();
int sequenceLength = oo.getSequenceLength();
System.out.println(mtpName + "=" + sequenceLength);
// comma counter
int i = 0;
boolean found = false;
// check all seed species for those that satisfy this observable and build comma delimited string of network file indexes
for (Map.Entry<Integer, Map<String, Integer>> entry : masterSignaturesMap.entrySet()) {
Integer networkFileIndex = entry.getKey();
// only interested if compartment is the same for both obs and seed species
String compartment = masterCompartmentMap.get(networkFileIndex);
if (!compartment.equals(oo.getStructure().getName())) {
// seed species in other compartment than our observable
continue;
}
Map<String, Integer> value = entry.getValue();
if (value.containsKey(mtpName)) {
int occurences = value.get(mtpName);
if (sequenceLength == occurences) {
if (i > 0) {
speciesFoundIndexes += ",";
}
speciesFoundIndexes += networkFileIndex;
found = true;
i++;
}
}
}
if (found == false) {
// desired number of occurrences for the polymer species has not been found in any seed species
continue;
}
// finished for this observable
System.out.println("Observable " + oo.getDisplayName() + ": " + mtpName + "()=" + sequenceLength + " found in species " + speciesFoundIndexes + ".");
observablesString += "\t" + nextAvailableIndex + " " + oo.getDisplayName() + "\t" + speciesFoundIndexes + "\n";
nextAvailableIndex++;
}
for (RbmObservable oo : polymerGreaterObservables) {
// same as above for the A()>xx polymer observables
String speciesFoundIndexes = "";
String mtpName = oo.getSpeciesPatternList().get(0).getMolecularTypePatterns().get(0).getMolecularType().getDisplayName();
int sequenceLength = oo.getSequenceLength();
System.out.println(mtpName + "=" + sequenceLength);
int i = 0;
boolean found = false;
// check all seed species for those that satisfy this observable and build comma delimited string of network file indexes
for (Map.Entry<Integer, Map<String, Integer>> entry : masterSignaturesMap.entrySet()) {
Integer networkFileIndex = entry.getKey();
String compartment = masterCompartmentMap.get(networkFileIndex);
if (!compartment.equals(oo.getStructure().getName())) {
// seed species in other compartment than our observable
continue;
}
Map<String, Integer> value = entry.getValue();
if (value.containsKey(mtpName)) {
int occurences = value.get(mtpName);
if (sequenceLength < occurences) {
if (i > 0) {
speciesFoundIndexes += ",";
}
speciesFoundIndexes += networkFileIndex;
found = true;
i++;
}
}
}
if (found == false) {
continue;
}
System.out.println("Observable " + oo.getDisplayName() + ": " + mtpName + "()>" + sequenceLength + " found in species " + speciesFoundIndexes + ".");
observablesString += "\t" + nextAvailableIndex + " " + oo.getDisplayName() + "\t" + speciesFoundIndexes + "\n";
nextAvailableIndex++;
}
if (observablesString.isEmpty()) {
// may be null
return prefix;
}
if (prefix != null) {
observablesString = prefix + observablesString;
}
return observablesString;
}
Aggregations