Search in sources :

Example 36 with XMLSource

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

the class BiomodelDiagramServerResource method get_png.

@Override
@Get("image/png")
public ByteArrayRepresentation get_png() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    String vcml = getBiomodelVCML(vcellUser);
    if (vcml == null) {
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "BioModel not found");
    }
    try {
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(vcml));
        Integer imageWidthInPixels = 1000;
        BufferedImage bufferedImage = ITextWriter.generateDocReactionsImage(bioModel.getModel(), imageWidthInPixels);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "png", outputStream);
        byte[] imageBytes = outputStream.toByteArray();
        return new ByteArrayRepresentation(imageBytes, MediaType.IMAGE_PNG, imageBytes.length);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) VCellApiApplication(org.vcell.rest.VCellApiApplication) ByteArrayRepresentation(org.restlet.representation.ByteArrayRepresentation) ResourceException(org.restlet.resource.ResourceException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSource(cbit.vcell.xml.XMLSource) BufferedImage(java.awt.image.BufferedImage) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) Get(org.restlet.resource.Get)

Example 37 with XMLSource

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

the class BiomodelVCMLServerResource method getBiomodelVCML.

private String getBiomodelVCML(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        String cachedVcml = restDatabaseService.query(this, vcellUser);
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(cachedVcml));
        String latestVcml = XmlHelper.bioModelToXML(bioModel);
        return latestVcml;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "biomodel not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) BioModel(cbit.vcell.biomodel.BioModel) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) XMLSource(cbit.vcell.xml.XMLSource) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 38 with XMLSource

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

the class ProfileLikelihood method main.

// main
public static void main(String[] args) {
    try {
        File newXML = new File(args[0]);
        XMLSource source = new XMLSource(newXML);
        BioModel biomodel = XmlHelper.XMLToBioModel(source);
        SimulationContext app = biomodel.getSimulationContext("Deterministic");
        AnalysisTask[] task = app.getAnalysisTasks();
        // ParestRun.bFakeOptimization = true;
        final ProfileLikelihoodCallback callback = new ProfileLikelihoodCallback() {

            @Override
            public void report(String msg) {
                System.out.println(msg);
            }
        };
        ProfileLikelihood pl = new ProfileLikelihood(callback);
        pl.run((ParameterEstimationTask) task[0]);
    } catch (XmlParseException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContext(cbit.vcell.mapping.SimulationContext) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) MappingException(cbit.vcell.mapping.MappingException) XmlParseException(cbit.vcell.xml.XmlParseException) MathException(cbit.vcell.math.MathException)

Example 39 with XMLSource

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

the class SBMLStandaloneImporter method attemptImport.

private BioModel attemptImport(File sbmlFile) throws ExecutableException, IOException, ClassNotFoundException, XmlParseException {
    if (subProcess == null || subProcess.getStatus() != LiveProcessStatus.RUNNING) {
        subProcess = createProcess();
    }
    toChildProcess.writeObject(sbmlFile);
    Object back = fromChildProcess.readObject();
    if (back instanceof String) {
        String xml = (String) back;
        if (lg.isDebugEnabled()) {
            try (FileWriter fw = new FileWriter(sbmlFile.getAbsolutePath() + ".dump")) {
                fw.append(xml);
            }
        }
        XMLSource source = new XMLSource(xml);
        return XmlHelper.XMLToBioModel(source);
    }
    if (back instanceof Exception) {
        try {
            throw (Exception) back;
        } catch (SBMLImportException sie) {
            throw sie;
        } catch (Exception e) {
            throw new ExecutableException("child process exception", e);
        }
    }
    throw new ExecutableException("unexpected object from child process:  " + back.getClass().getName() + " " + back.toString());
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) FileWriter(java.io.FileWriter) XMLSource(cbit.vcell.xml.XMLSource) ExecutableException(org.vcell.util.exe.ExecutableException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException)

Example 40 with XMLSource

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

the class SEDMLExporter method main.

public static void main(String[] args) {
    // if (args.length != 1) {
    // System.out.println("Usage:\n\t path_of_vcml_file\n" );
    // System.exit(1);
    // }
    // String pathName = args[0];
    String pathName = "c:\\dan\\SEDML\\SEDML2.vcml";
    try {
        String biomodelXmlStr = XmlUtil.getXMLString(pathName);
        BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXmlStr.toString()));
        bioModel.refreshDependencies();
        // invoke the SEDMLEXporter
        SEDMLExporter sedmlExporter = new SEDMLExporter(bioModel, 1, 1);
        String absolutePath = "c:\\dan\\SEDML";
        String sedmlStr = sedmlExporter.getSEDMLFile(absolutePath);
        // String absolutePath = ResourceUtil.getUserHomeDir().getAbsolutePath();
        String outputName = absolutePath + "\\" + TokenMangler.mangleToSName(bioModel.getName()) + ".sedml";
        XmlUtil.writeXMLStringToFile(sedmlStr, outputName, true);
    } catch (IOException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Unable to read VCML file '" + pathName + "' into string.");
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Unable to convert VCML file '" + pathName + "' to a biomodel.");
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) IOException(java.io.IOException) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

XMLSource (cbit.vcell.xml.XMLSource)50 BioModel (cbit.vcell.biomodel.BioModel)37 XmlParseException (cbit.vcell.xml.XmlParseException)31 DataAccessException (org.vcell.util.DataAccessException)27 SimulationContext (cbit.vcell.mapping.SimulationContext)22 BigString (org.vcell.util.BigString)22 KeyValue (org.vcell.util.document.KeyValue)21 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)19 Simulation (cbit.vcell.solver.Simulation)18 SQLException (java.sql.SQLException)15 User (org.vcell.util.document.User)15 BioModelInfo (org.vcell.util.document.BioModelInfo)13 MathException (cbit.vcell.math.MathException)12 ExpressionException (cbit.vcell.parser.ExpressionException)12 PropertyVetoException (java.beans.PropertyVetoException)12 MappingException (cbit.vcell.mapping.MappingException)11 MathModel (cbit.vcell.mathmodel.MathModel)11 IOException (java.io.IOException)11 MathDescription (cbit.vcell.math.MathDescription)10 File (java.io.File)10