Search in sources :

Example 6 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class VFrapXmlHelper method VFRAPToBioModel.

public static BioModel VFRAPToBioModel(Hashtable<String, Object> hashTable, XMLSource xmlSource, DocumentManager documentManager, final TopLevelWindowManager requester) throws XmlParseException, IOException, DataAccessException, MathException, DivideByZeroException, ExpressionException, ImageException, UtilCancelException {
    Component requesterComponent = requester.getComponent();
    File vFrapFile = xmlSource.getXmlFile();
    // ---
    // ex  ccc8.vfrap
    String vFrapFileNameExtended = vFrapFile.getName();
    {
        // we want to make sure to reload these strings from the hash later on
        String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
        // we'll save here the "special" vFrap images (prebleach_avg, ...)
        String mixedFieldDataName = initialFieldDataName + "Mx";
        hashTable.put("mixedFieldDataName", mixedFieldDataName);
        hashTable.put("initialFieldDataName", initialFieldDataName);
    }
    if (vFrapFileNameExtended.indexOf(".vfrap") < 0) {
        throw new RuntimeException("File extension must be .vfrap");
    }
    // VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
    checkNameAvailability(hashTable, true, documentManager, requesterComponent);
    System.out.println("Loading " + vFrapFileNameExtended + " ...");
    String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
    MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
    Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
    // ----- read the biomodel from Virtual FRAP xml file ----------
    BioModel bioModel = null;
    XmlReader vcellXMLReader = new XmlReader(true);
    Element bioModelElement = vFrapRoot.getChild(XMLTags.BioModelTag);
    if (bioModelElement == null) {
        throw new RuntimeException("Unable to load biomodel.");
    }
    String docSoftwareVersion = vFrapRoot.getAttributeValue(XMLTags.SoftwareVersionAttrTag);
    bioModel = vcellXMLReader.getBioModel(bioModelElement, (docSoftwareVersion == null ? null : VCellSoftwareVersion.fromString(docSoftwareVersion)));
    // ------ locate the special images within the vFrap files and load them in memory
    if (!LoadVFrapSpecialImages(hashTable, vFrapRoot)) {
        // just return the biomodel if image loading fails for some reason
        return bioModel;
    }
    // ------- save the special images in the database as field data ------------
    ExternalDataIdentifier vfrapMisc = SaveVFrapSpecialImagesAsFieldData(hashTable, documentManager);
    // ------- create and save data symbols for the vFrap "special" images -----------
    CreateSaveVFrapDataSymbols(hashTable, bioModel, vfrapMisc);
    // -------- replace vFrap default names in field function arguments with data symbol names -----
    ReplaceVFrapNamesWithSymbolNames(bioModel);
    return bioModel;
}
Also used : Element(org.jdom.Element) BioModel(cbit.vcell.biomodel.BioModel) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) XmlReader(cbit.vcell.xml.XmlReader) Component(java.awt.Component) File(java.io.File)

Example 7 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class GlobalModelParameterTable method setModelParameters.

public void setModelParameters(Connection con, Model model) throws SQLException, DataAccessException {
    String sql = " SELECT " + GlobalModelParameterTable.table.xmlFragment.getQualifiedColName() + " FROM " + GlobalModelParameterTable.table.getTableName() + " WHERE " + GlobalModelParameterTable.table.modelRef.getQualifiedColName() + " = " + model.getVersion().getVersionKey() + " ORDER BY " + GlobalModelParameterTable.table.id.getUnqualifiedColName();
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        StringBuffer modelParameeterXMLSB = new StringBuffer();
        while (rset.next()) {
            String modelParameeterXMLS = rset.getString(GlobalModelParameterTable.table.xmlFragment.toString());
            if (!rset.wasNull()) {
                modelParameeterXMLS = org.vcell.util.TokenMangler.getSQLRestoredString(modelParameeterXMLS);
                modelParameeterXMLSB.append(modelParameeterXMLS);
            }
        }
        if (modelParameeterXMLSB.length() > 0) {
            XmlReader xmlReader = new XmlReader(true);
            Element modelParameeterXMLElement = XmlUtil.stringToXML(modelParameeterXMLSB.toString(), null).getRootElement();
            try {
                Model.ModelParameter[] modelParameterArr = xmlReader.getModelParams(modelParameeterXMLElement, model);
                model.setModelParameters(modelParameterArr);
            } catch (Exception e) {
                throw new DataAccessException("error reading ModelParameters for model " + model.getName(), e);
            }
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
}
Also used : Statement(java.sql.Statement) Element(org.jdom.Element) ResultSet(java.sql.ResultSet) XmlReader(cbit.vcell.xml.XmlReader) DataAccessException(org.vcell.util.DataAccessException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException)

Example 8 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class ApplicationMathTable method convertOutputFunctionXMLToFuncList.

private ArrayList<AnnotatedFunction> convertOutputFunctionXMLToFuncList(String outputFunctionsXML) throws XmlParseException {
    Element outputFunctionElement = XmlUtil.stringToXML(outputFunctionsXML, null).getRootElement();
    ArrayList<AnnotatedFunction> outputFunctionList = (new XmlReader(false)).getOutputFunctions(outputFunctionElement);
    return outputFunctionList;
}
Also used : Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

XmlReader (cbit.vcell.xml.XmlReader)8 Element (org.jdom.Element)7 DataAccessException (org.vcell.util.DataAccessException)4 SQLException (java.sql.SQLException)3 XmlParseException (cbit.vcell.xml.XmlParseException)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 BioModel (cbit.vcell.biomodel.BioModel)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)1 BioEvent (cbit.vcell.mapping.BioEvent)1 RateRule (cbit.vcell.mapping.RateRule)1 ReactionRuleSpec (cbit.vcell.mapping.ReactionRuleSpec)1 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)1 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)1 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)1 Model (cbit.vcell.model.Model)1 ModelException (cbit.vcell.model.ModelException)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1