Search in sources :

Example 6 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class RbmNetworkGenerator method generateModel.

public static void generateModel(BioModel bioModel, String netfile) throws Exception {
    Model model = bioModel.getModel();
    Map<String, SpeciesContext> speciesMap = new HashMap<String, SpeciesContext>();
    Map<String, ReactionStep> reactionMap = new HashMap<String, ReactionStep>();
    List<ReactionLine> reactionLineList = new ArrayList<ReactionLine>();
    BufferedReader br = new BufferedReader(new StringReader(netfile));
    int reversibleCount = 0;
    int reactionCount = 0;
    while (true) {
        String line = br.readLine();
        if (line == null) {
            break;
        }
        line = line.trim();
        if (line.equals(BEGIN_PARAMETERS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_PARAMETERS)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                String token2 = st.nextToken();
                String token3 = st.nextToken();
                ModelParameter mp = model.new ModelParameter(token2, new Expression(token3), Model.ROLE_UserDefined, bioModel.getModel().getUnitSystem().getInstance_TBD());
                model.addModelParameter(mp);
            }
        } else if (line.equals(BEGIN_SPECIES)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_SPECIES)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                // no
                String token1 = st.nextToken();
                // pattern
                String token2 = st.nextToken();
                // initial condition
                String token3 = st.nextToken();
                String newname = token2.replaceAll("\\.", "_");
                newname = newname.replaceAll("[\\(,][a-zA-Z]\\w*", "");
                newname = newname.replaceAll("~|!\\d*", "");
                newname = newname.replaceAll("\\(\\)", "");
                newname = newname.replaceAll("\\)", "");
                SpeciesContext sc = model.createSpeciesContext(model.getStructure(0));
                sc.setName(newname);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc, token2);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc.getSpecies(), token2);
                speciesMap.put(token1, sc);
            }
        } else if (line.equals(BEGIN_REACTIONS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_REACTIONS)) {
                    break;
                }
                ++reactionCount;
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                // reactants
                String token2 = st.nextToken();
                // products
                String token3 = st.nextToken();
                // rate
                String token4 = st.nextToken();
                String token5 = st.nextToken();
                boolean bFoundReversible = false;
                Expression rate = new Expression(token4);
                for (ReactionLine rl : reactionLineList) {
                    if (token2.equals(rl.products) && token3.equals(rl.reactants) && token5.equals(rl.ruleLabel + "r")) {
                        ReactionStep rs = reactionMap.get(rl.no);
                        ((MassActionKinetics) rs.getKinetics()).getReverseRateParameter().setExpression(rate);
                        reactionLineList.remove(rl);
                        bFoundReversible = true;
                        break;
                    }
                }
                if (bFoundReversible) {
                    ++reversibleCount;
                    continue;
                }
                ReactionLine rl = new ReactionLine(token1, token2, token3, token5);
                reactionLineList.add(rl);
                SimpleReaction reaction = model.createSimpleReaction(model.getStructure(0));
                reactionMap.put(token1, reaction);
                reaction.setModel(model);
                bioModel.getVCMetaData().setFreeTextAnnotation(reaction, line2);
                MassActionKinetics kinetics = new MassActionKinetics(reaction);
                reaction.setKinetics(kinetics);
                st = new StringTokenizer(token2, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Reactant && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addReactant(sc, 1);
                        }
                    }
                }
                st = new StringTokenizer(token3, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Product && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addProduct(sc, 1);
                        }
                    }
                }
                kinetics.getForwardRateParameter().setExpression(rate);
            }
        }
    }
    System.out.println(model.getNumSpecies() + " species added");
    System.out.println(model.getNumReactions() + " reactions added");
    System.out.println(reversibleCount + " reversible reactions found");
    if (reactionCount != model.getNumReactions() + reversibleCount) {
        throw new RuntimeException("Reactions are not imported correctly!");
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) ModelParameter(cbit.vcell.model.Model.ModelParameter) StringTokenizer(java.util.StringTokenizer) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) MassActionKinetics(cbit.vcell.model.MassActionKinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 7 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class XmlReader method getModelParams.

public ModelParameter[] getModelParams(Element globalParams, Model model) throws XmlParseException {
    Iterator<Element> globalsIterator = globalParams.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
    Vector<ModelParameter> modelParamsVector = new Vector<ModelParameter>();
    while (globalsIterator.hasNext()) {
        org.jdom.Element paramElement = (Element) globalsIterator.next();
        modelParamsVector.add(getModelParameter(paramElement, model));
    }
    return ((ModelParameter[]) BeanUtils.getArray(modelParamsVector, ModelParameter.class));
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) Element(org.jdom.Element) Vector(java.util.Vector) Element(org.jdom.Element)

Example 8 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class KineticContext method getParameter.

public ModelParameter getParameter(SBOSet sboSet) {
    ModelParameter param = sboSetToParam.get(sboSet);
    if (param == null) {
        for (Map.Entry<SBOTerm, ModelParameter> entry : termToParam.entrySet()) {
            SBOTerm sboTerm = entry.getKey();
            if (sboSet.includes(sboTerm)) {
                param = entry.getValue();
                sboSetToParam.put(sboSet, param);
                break;
            }
        }
    }
    return param;
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) SBOTerm(org.vcell.pathway.sbo.SBOTerm) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class SBPAXHMMIrrevLawBuilder method addKinetics.

public void addKinetics(KineticContext context) {
    try {
        ReactionStep reaction = context.getReaction();
        HMM_IRRKinetics kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
        NameScope modelScope = reaction.getModel().getNameScope();
        ModelParameter kMichaelis = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
        if (kMichaelis != null) {
            KineticsParameter kmParameter = kinetics.getKmParameter();
            kmParameter.setExpression(new Expression(kMichaelis, modelScope));
            kmParameter.setUnitDefinition(kMichaelis.getUnitDefinition());
        }
        ModelParameter kcat = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcat != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxParameter.setExpression(Expression.mult(new Expression(kcat, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMax = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
            if (vMax != null) {
                KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
                vmaxParameter.setExpression(new Expression(vMax, modelScope));
                vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
            }
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) NameScope(cbit.vcell.parser.NameScope) Expression(cbit.vcell.parser.Expression) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) ReactionStep(cbit.vcell.model.ReactionStep) Catalyst(cbit.vcell.model.Catalyst) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 10 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class SBPAXParameterExtractor method extractParameter.

public static Map<SBOTerm, ModelParameter> extractParameter(ReactionStep reaction, SBMeasurable measurable) throws PropertyVetoException {
    Map<SBOTerm, ModelParameter> sboToParameters = new HashMap<SBOTerm, ModelParameter>();
    Set<SBOTerm> sboTerms = SBPAXSBOExtractor.extractSBOTerms(measurable);
    String symbol = null;
    VCUnitDefinition targetUnit = null;
    Model model = reaction.getModel();
    ModelUnitSystem modelUnitSystem = model.getUnitSystem();
    Set<SBOTerm> termsWithUnituM = SetUtil.newSet(SBOList.sbo0000027MichaelisConstant, SBOList.sbo0000322MichaelisConstantForSubstrate);
    for (SBOTerm sboTerm : sboTerms) {
        if (termsWithUnituM.contains(sboTerm)) {
            targetUnit = modelUnitSystem.getVolumeConcentrationUnit();
        // targetUnit = VCUnitDefinition.UNIT_uM;
        }
        if (StringUtil.notEmpty(sboTerm.getSymbol())) {
            symbol = sboTerm.getSymbol();
        }
        for (int i = 0; i < symbol.length(); ++i) {
            char charAt = symbol.charAt(i);
            if (!Character.isJavaIdentifierPart(charAt)) {
                symbol = symbol.replace(charAt, '_');
            }
        }
    }
    VCUnitDefinition unit = UOMEUnitExtractor.extractVCUnitDefinition(measurable, modelUnitSystem);
    double conversionFactor = 1.0;
    if (targetUnit != null && unit != null && unit != modelUnitSystem.getInstance_TBD() && !targetUnit.equals(unit)) {
        // if(unit.equals(VCUnitDefinition.UNIT_M) && targetUnit.equals(VCUnitDefinition.UNIT_uM)) {
        if (unit.isCompatible(targetUnit)) {
            conversionFactor = unit.convertTo(conversionFactor, targetUnit);
            unit = targetUnit;
        }
    }
    ArrayList<Double> numbers = measurable.getNumber();
    if (StringUtil.isEmpty(symbol)) {
        symbol = "p" + (++nParameter);
    }
    for (Double number : numbers) {
        String parameterName = symbol + "_" + reaction.getName();
        if (model.getModelParameter(parameterName) != null) {
            int count = 0;
            while (model.getModelParameter(parameterName + "_" + count) != null) {
                ++count;
            }
            parameterName = parameterName + "_" + count;
        }
        ModelParameter parameter = model.new ModelParameter(parameterName, new Expression(conversionFactor * number.doubleValue()), Model.ROLE_UserDefined, unit);
        model.addModelParameter(parameter);
        for (SBOTerm sboTerm : sboTerms) {
            sboToParameters.put(sboTerm, parameter);
        }
    }
    return sboToParameters;
}
Also used : HashMap(java.util.HashMap) SBOTerm(org.vcell.pathway.sbo.SBOTerm) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

ModelParameter (cbit.vcell.model.Model.ModelParameter)46 Expression (cbit.vcell.parser.Expression)28 SpeciesContext (cbit.vcell.model.SpeciesContext)25 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)24 Model (cbit.vcell.model.Model)19 ReactionStep (cbit.vcell.model.ReactionStep)19 ExpressionException (cbit.vcell.parser.ExpressionException)16 Structure (cbit.vcell.model.Structure)15 PropertyVetoException (java.beans.PropertyVetoException)14 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)13 Parameter (cbit.vcell.model.Parameter)12 ArrayList (java.util.ArrayList)12 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)11 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)11 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)10 Vector (java.util.Vector)10 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 BioModel (cbit.vcell.biomodel.BioModel)8 StructureMapping (cbit.vcell.mapping.StructureMapping)8 Kinetics (cbit.vcell.model.Kinetics)8