Search in sources :

Example 6 with SBMLExporter

use of org.vcell.sbml.vcell.SBMLExporter in project vcell by virtualcell.

the class BiomodelSBMLServerResource method getBiomodelSBML.

private String getBiomodelSBML(User vcellUser) {
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        // Make temporary resource compatible with restDatabaseService so we can re-use
        BiomodelVCMLServerResource bmsr = new BiomodelVCMLServerResource() {

            @Override
            public Map<String, Object> getRequestAttributes() {
                HashMap<String, Object> hashMap = new HashMap<String, Object>();
                hashMap.put(VCellApiApplication.BIOMODELID, BiomodelSBMLServerResource.this.biomodelid);
                return hashMap;
            }

            @Override
            public Request getRequest() {
                // TODO Auto-generated method stub
                return BiomodelSBMLServerResource.this.getRequest();
            }
        };
        String biomodelVCML = restDatabaseService.query(bmsr, vcellUser);
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelVCML));
        // public SBMLExporter(BioModel argBioModel, int argSbmlLevel, int argSbmlVersion, boolean isSpatial) {
        SimulationContext simulationContext = null;
        if (appName != null) {
            simulationContext = bioModel.getSimulationContext(appName);
        } else {
            simulationContext = bioModel.getSimulationContext(0);
        }
        SBMLExporter sbmlExporter = new SBMLExporter(simulationContext, 3, 1, simulationContext.getGeometryContext().getGeometry().getDimension() > 0);
        return sbmlExporter.getSBMLString();
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) HashMap(java.util.HashMap) SBMLExporter(org.vcell.sbml.vcell.SBMLExporter) SimulationContext(cbit.vcell.mapping.SimulationContext) PermissionException(org.vcell.util.PermissionException) ResourceException(org.restlet.resource.ResourceException) BioModel(cbit.vcell.biomodel.BioModel) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)6 SimulationContext (cbit.vcell.mapping.SimulationContext)6 SBMLExporter (org.vcell.sbml.vcell.SBMLExporter)6 SbmlException (org.vcell.sbml.SbmlException)4 XMLSource (cbit.vcell.xml.XMLSource)3 XmlParseException (cbit.vcell.xml.XmlParseException)3 HashMap (java.util.HashMap)3 MathMapping (cbit.vcell.mapping.MathMapping)2 MathSymbolMapping (cbit.vcell.mapping.MathSymbolMapping)2 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)2 Function (cbit.vcell.math.Function)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 ModelParameter (cbit.vcell.model.Model.ModelParameter)2 ReservedSymbol (cbit.vcell.model.Model.ReservedSymbol)2 ProxyParameter (cbit.vcell.model.ProxyParameter)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 Structure (cbit.vcell.model.Structure)2 Expression (cbit.vcell.parser.Expression)2