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());
}
}
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());
}
// }
}
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();
}
}
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());
}
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.");
}
}
Aggregations