Search in sources :

Example 46 with RbmObservable

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);
            }
        }
    }
}
Also used : RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 47 with RbmObservable

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) ObservableType(cbit.vcell.model.RbmObservable.ObservableType) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 48 with RbmObservable

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();
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 49 with RbmObservable

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) ReactionRule(cbit.vcell.model.ReactionRule) Hashtable(java.util.Hashtable) RbmObservable(cbit.vcell.model.RbmObservable) SimulationContext(cbit.vcell.mapping.SimulationContext) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) MathMapping(cbit.vcell.mapping.MathMapping) ASTModel(org.vcell.model.bngl.ASTModel) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) CSGObject(cbit.vcell.geometry.CSGObject)

Example 50 with RbmObservable

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) BNGComplexSpecies(cbit.vcell.bionetgen.BNGComplexSpecies) LinkedHashMap(java.util.LinkedHashMap) BNGMultiStateSpecies(cbit.vcell.bionetgen.BNGMultiStateSpecies) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Aggregations

RbmObservable (cbit.vcell.model.RbmObservable)50 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 ReactionRule (cbit.vcell.model.ReactionRule)20 SpeciesContext (cbit.vcell.model.SpeciesContext)18 Structure (cbit.vcell.model.Structure)16 ArrayList (java.util.ArrayList)15 MolecularType (org.vcell.model.rbm.MolecularType)14 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 ReactionStep (cbit.vcell.model.ReactionStep)9 PropertyVetoException (java.beans.PropertyVetoException)8 SimulationContext (cbit.vcell.mapping.SimulationContext)7 Model (cbit.vcell.model.Model)7 BioModel (cbit.vcell.biomodel.BioModel)6 ModelException (cbit.vcell.model.ModelException)6 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)5 ProductPattern (cbit.vcell.model.ProductPattern)5 ReactantPattern (cbit.vcell.model.ReactantPattern)5 BioModelNode (cbit.vcell.desktop.BioModelNode)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4 StructureToolShapeIcon (cbit.vcell.graph.gui.StructureToolShapeIcon)3