Search in sources :

Example 86 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class SBMLImporter method addReactionParticipants.

/**
 * addReactionParticipant : Adds reactants and products and modifiers to a
 * reaction. Input args are the sbml reaction, vc reaction This method was
 * created mainly to handle reactions where there are reactants and/or
 * products that appear multiple times in a reaction. Virtual Cell now
 * allows the import of such reactions.
 */
private void addReactionParticipants(org.sbml.jsbml.Reaction sbmlRxn, ReactionStep vcRxn) throws Exception {
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    // if (!(vcRxn instanceof FluxReaction)) {
    if (true) {
        // reactants in sbmlRxn
        HashMap<String, Integer> sbmlReactantsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumReactants(); j++) {
            SpeciesReference spRef = sbmlRxn.getReactant(j);
            String sbmlReactantSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlReactantSpId) != null) {
                // check
                // if
                // spRef
                // is in
                // sbml
                // model
                // If stoichiometry of speciesRef is not an integer, it is
                // not handled in the VCell at this time; no point going
                // further
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for SBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the reactant '" + sbmlReactantSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the reactant '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlReactantsHash.get(sbmlReactantSpId) == null) {
                    // if sbmlReactantSpId is NOT in sbmlReactantsHash, add
                    // it with its stoichiometry
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlReactantSpId IS in sbmlReactantsHash, update
                    // its stoichiometry value to (existing-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlReactantsHash.get(sbmlReactantSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // sbmlReactionParticipantsHash as reactants to vcRxn
        for (Entry<String, Integer> es : sbmlReactantsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addReactant(speciesContext, stoich);
        }
        /*
			Iterator<String> sbmlReactantsIter = sbmlReactantsHash.keySet()
					.iterator();
			while (sbmlReactantsIter.hasNext()) {
				String sbmlReactantStr = sbmlReactantsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlReactantStr);
				int stoich = sbmlReactantsHash.get(sbmlReactantStr).intValue();
				((SimpleReaction) vcRxn).addReactant(speciesContext, stoich);
			}
			*/
        // products in sbmlRxn
        HashMap<String, Integer> sbmlProductsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumProducts(); j++) {
            SpeciesReference spRef = sbmlRxn.getProduct(j);
            String sbmlProductSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlProductSpId) != null) {
                /* check if spRef is in sbml model
					If stoichiometry of speciesRef is not an integer, it is
					not handled in the VCell at this time; no point going
					further */
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for sBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the product '" + sbmlProductSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the product '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlProductsHash.get(sbmlProductSpId) == null) {
                    // if sbmlProductSpId is NOT in sbmlProductsHash, add it
                    // with its stoichiometry
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlProductSpId IS in sbmlProductsHash, update its
                    // stoichiometry value to (existing-value-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlProductsHash.get(sbmlProductSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // as products to vcRxn
        for (Entry<String, Integer> es : sbmlProductsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addProduct(speciesContext, stoich);
        }
    /*
			Iterator<String> sbmlProductsIter = sbmlProductsHash.keySet()
					.iterator();
			while (sbmlProductsIter.hasNext()) {
				String sbmlProductStr = sbmlProductsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlProductStr);
				int stoich = sbmlProductsHash.get(sbmlProductStr).intValue();
				((SimpleReaction) vcRxn).addProduct(speciesContext, stoich);
			}
			*/
    // proxy.addProducts(sbmlProductsHash);
    }
    // modifiers
    for (int j = 0; j < (int) sbmlRxn.getNumModifiers(); j++) {
        ModifierSpeciesReference spRef = sbmlRxn.getModifier(j);
        String sbmlSpId = spRef.getSpecies();
        if (sbmlModel.getSpecies(sbmlSpId) != null) {
            // check if this modifier species is preesent in vcRxn (could
            // have been added as reactamt/product/catalyst).
            // If alreay a catalyst in vcRxn, do nothing
            ArrayList<ReactionParticipant> vcRxnParticipants = getVCReactionParticipantsFromSymbol(vcRxn, sbmlSpId);
            SpeciesContext speciesContext = vcModel.getSpeciesContext(sbmlSpId);
            if (vcRxnParticipants == null || vcRxnParticipants.size() == 0) {
                // If not in reactionParticipantList of vcRxn, add as
                // catalyst.
                vcRxn.addCatalyst(speciesContext);
            } else {
                for (ReactionParticipant rp : vcRxnParticipants) {
                    if (rp instanceof Reactant || rp instanceof Product) {
                        // If already a reactant or product in vcRxn, add
                        // warning to localIssuesList, don't do anything
                        localIssueList.add(new Issue(speciesContext, issueContext, IssueCategory.SBMLImport_Reaction, "Species " + speciesContext.getName() + " was already added as a reactant and/or product to " + vcRxn.getName() + "; Cannot add it as a catalyst also.", Issue.SEVERITY_INFO));
                        break;
                    }
                }
            }
        } else {
            // spRef is not in model, throw exception
            throw new SBMLImportException("Modifier '" + sbmlSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
        }
    // end - if (spRef is species in model)
    }
// end - for modifiers
}
Also used : Issue(org.vcell.util.Issue) HashMap(java.util.HashMap) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) SpeciesReference(org.sbml.jsbml.SpeciesReference) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 87 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class DocumentValidUtil method checkIssuesForErrors.

public static void checkIssuesForErrors(SimulationContext simulationContext, boolean bIgnoreMathDescription) {
    Vector<Issue> issueList = new Vector<Issue>();
    IssueContext issueContext = new IssueContext();
    simulationContext.getModel().gatherIssues(issueContext, issueList);
    simulationContext.gatherIssues(issueContext, issueList, bIgnoreMathDescription);
    checkIssuesForErrors(issueList);
}
Also used : Issue(org.vcell.util.Issue) IssueContext(org.vcell.util.IssueContext) Vector(java.util.Vector)

Example 88 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class KenworthyTest method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("expecting 2 arguments");
        System.out.println("usage: java " + Workflow.class.getSimpleName() + " workingdir workflowInputFile");
        System.out.println("workingdir example: " + "D:\\developer\\eclipse\\workspace\\VCell_5.4_vmicro\\datadir");
        System.out.println("workflowInputFile example: " + "D:\\developer\\eclipse\\workspace\\VCell_5.4_vmicro\\workflow1.txt");
        System.exit(1);
    }
    try {
        // PropertyLoader.loadProperties();
        // workflowInputFile "C:\\developer\\eclipse\\workspace\\VCell_5.3_vmicro\\workflow1.txt"
        File workingDirectory = new File(args[0]);
        LocalWorkspace localWorkspace = new LocalWorkspace(workingDirectory);
        Repository repository = new MemoryRepository();
        // String workflowLanguageText = BeanUtils.readBytesFromFile(new File(args[1]), null);
        // Workflow workflow = Workflow.parse(localWorkspace, workflowLanguageText);
        System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> using hard-coded example instead <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        File vfrapFile = new File("D:\\Developer\\eclipse\\workspace_refactor\\VCell_5.4_vmicro\\3D_FRAP_2_ZProjection_Simulation1.vfrap");
        // Workflow workflow = getVFrapSimpleExample(workingDirectory, vfrapFile);
        // Workflow workflow = getFakeDataExample(workingDirectory);
        Workflow workflow = getInteractiveModelWorkflow(repository, workingDirectory);
        TaskContext taskContext = new TaskContext(workflow, repository, localWorkspace);
        ArrayList<Issue> issues = new ArrayList<Issue>();
        IssueContext issueContext = new IssueContext();
        workflow.gatherIssues(issueContext, issues);
        // WorkflowJGraphProxy workflowJGraphProxy = new WorkflowJGraphProxy(workflow);
        // displayWorkflowGraphJGraphX(workflowJGraphProxy);
        WorkflowUtilities.displayWorkflowGraph(workflow);
        WorkflowUtilities.displayWorkflowTable(taskContext);
        workflow.reportIssues(issues, Issue.SEVERITY_INFO, true);
        // 
        // execute the workflow
        // 
        workflow.compute(taskContext, new WorkflowUtilities.Progress());
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : LocalWorkspace(org.vcell.vmicro.workflow.data.LocalWorkspace) TaskContext(org.vcell.workflow.TaskContext) Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) Workflow(org.vcell.workflow.Workflow) Repository(org.vcell.workflow.Repository) MemoryRepository(org.vcell.workflow.MemoryRepository) MemoryRepository(org.vcell.workflow.MemoryRepository) IssueContext(org.vcell.util.IssueContext) File(java.io.File)

Aggregations

Issue (org.vcell.util.Issue)88 ArrayList (java.util.ArrayList)18 IssueContext (org.vcell.util.IssueContext)14 Expression (cbit.vcell.parser.Expression)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 PropertyVetoException (java.beans.PropertyVetoException)9 MolecularType (org.vcell.model.rbm.MolecularType)9 Structure (cbit.vcell.model.Structure)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)7 Model (cbit.vcell.model.Model)6 ModelParameter (cbit.vcell.model.Model.ModelParameter)6 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)6 BioModel (cbit.vcell.biomodel.BioModel)5 ModelException (cbit.vcell.model.ModelException)5 Product (cbit.vcell.model.Product)5 Reactant (cbit.vcell.model.Reactant)5 ReactionParticipant (cbit.vcell.model.ReactionParticipant)5 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)5