use of de.ipbhalle.metfragweb.datatype.Fragment in project MetFragRelaunched by ipb-halle.
the class MetFragWebBean method generateFragmentImages.
protected void generateFragmentImages(MetFragResult molecule) throws IOException {
// first remove last generated fragments
java.io.File imageFolderFragments = new java.io.File(this.getRootSessionFolder() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "images/fragments");
if (imageFolderFragments.exists())
FileUtils.deleteDirectory(imageFolderFragments);
imageFolderFragments.mkdirs();
// start creating the fragments
this.currentFragments = new java.util.Vector<Fragment>();
String sessionId = this.getSessionId();
ICandidate candidate = molecule.getRoot().getCandidate();
try {
candidate.initialisePrecursorCandidate();
} catch (Exception e1) {
System.err.println("error when initialising precursor for fragment generation");
e1.printStackTrace();
return;
}
for (int i = 0; i < molecule.getMatchList().getNumberElements(); i++) {
try {
HighlightSubStructureImageGenerator imageGenerator = new HighlightSubStructureImageGenerator();
int size = 300;
if (Double.parseDouble(this.beanSettingsContainer.getNeutralMonoisotopicMass()) > 500)
size = 400;
if (Double.parseDouble(this.beanSettingsContainer.getNeutralMonoisotopicMass()) > 700)
size = 500;
imageGenerator.setImageHeight(size);
imageGenerator.setImageWidth(size);
RenderedImage image;
java.io.File imageFile = new java.io.File(imageFolderFragments.getAbsolutePath() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "fragment_" + i + ".png");
try {
image = imageGenerator.generateImage(candidate.getPrecursorMolecule(), molecule.getMatchList().getElement(i).getBestMatchedFragment());
ImageIO.write(image, "png", imageFile);
} catch (Exception e) {
System.err.println("error generating fragment image");
}
FragmentMassToPeakMatch match = (FragmentMassToPeakMatch) molecule.getMatchList().getElement(i);
match.getBestMatchedFragment();
this.currentFragments.add(new Fragment(match.getModifiedFormulaHtmlStringOfBestMatchedFragment(candidate.getPrecursorMolecule()), MathTools.round(match.getBestMatchFragmentMass()), "/files/" + sessionId + "/images/fragments/fragment_" + i + ".png", match.getMatchedPeak().getMass(), this.currentFragments.size() + 1));
} catch (Exception e) {
e.printStackTrace();
System.err.println("error generating fragment image for " + molecule.getIdentifier() + " " + i);
continue;
}
}
try {
candidate.resetPrecursorMolecule();
} catch (Exception e1) {
System.err.println("error when initialising precursor for fragment generation");
e1.printStackTrace();
return;
}
}
Aggregations