use of de.unijena.cheminf.mortar.model.data.FragmentDataModel in project MORTAR by FelixBaensch.
the class GuiUtil method setImageStructureHeight.
//
/**
* Sets the height for structure images to each MoleculeDataModel object of the items list of the tableView.
* If image height is too small it will be set to GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT (50.0)
*
* @param aTableView TableView
* @param aHeight double
* @param aSettingsContainer SettingsContainer
*/
public static void setImageStructureHeight(TableView aTableView, double aHeight, SettingsContainer aSettingsContainer) {
double tmpHeight = (aHeight - GuiDefinitions.GUI_TABLE_VIEW_HEADER_HEIGHT - GuiDefinitions.GUI_PAGINATION_CONTROL_PANEL_HEIGHT) / aSettingsContainer.getRowsPerPageSetting();
if (aTableView.getClass().equals(ItemizationDataTableView.class)) {
tmpHeight = (aHeight - 2 * GuiDefinitions.GUI_TABLE_VIEW_HEADER_HEIGHT - GuiDefinitions.GUI_PAGINATION_CONTROL_PANEL_HEIGHT) / aSettingsContainer.getRowsPerPageSetting();
}
if (tmpHeight < GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT) {
tmpHeight = GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT;
}
if (aTableView.getClass().equals(ItemizationDataTableView.class)) {
for (MoleculeDataModel tmpMoleculeDataModel : ((IDataTableView) aTableView).getItemsList()) {
tmpMoleculeDataModel.setStructureImageHeight(tmpHeight);
String tmpFragmentationName = ((ItemizationDataTableView) aTableView).getFragmentationName();
if (!tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(tmpFragmentationName)) {
continue;
}
for (FragmentDataModel tmpFragmentDataModel : tmpMoleculeDataModel.getFragmentsOfSpecificAlgorithm(tmpFragmentationName)) {
tmpFragmentDataModel.setStructureImageHeight(tmpHeight);
}
}
} else {
for (MoleculeDataModel tmpMoleculeDataModel : ((IDataTableView) aTableView).getItemsList()) {
tmpMoleculeDataModel.setStructureImageHeight(tmpHeight);
}
}
}
use of de.unijena.cheminf.mortar.model.data.FragmentDataModel in project MORTAR by FelixBaensch.
the class Exporter method createFragmentationTabPdfFile.
//
/**
* Exports the fragmentation results as they are displayed on the fragments tab as a PDF file. Opens a file chooser
* dialog for the user to determine a directory and file for the exported data.
*
* @param aFragmentDataModelList a list of FragmentDataModel instances to export
* @param aMoleculeDataModelList a list MoleculeDataModel needed for the fragmentation report at the head of the exported document
* @param aFragmentationName fragmentation name to be displayed in the header of the PDF file
* @return PDF file which contains the results of the fragmentation
* @throws FileNotFoundException
* @throws DocumentException
* @author Betül Sevindik
*/
private List<String> createFragmentationTabPdfFile(File aPdfFile, List<MoleculeDataModel> aFragmentDataModelList, ObservableList<MoleculeDataModel> aMoleculeDataModelList, String aFragmentationName) throws FileNotFoundException, DocumentException {
if (aPdfFile == null || aFragmentDataModelList == null || aMoleculeDataModelList == null || aFragmentationName == null) {
return null;
}
List<String> tmpFailedExportFragments = new LinkedList<>();
this.document = new Document(PageSize.A4);
this.document.setPageSize(this.document.getPageSize().rotate());
PdfWriter.getInstance(this.document, new FileOutputStream(aPdfFile.getPath()));
this.document.open();
// relative sizes
float[] tmpCellLength = { 70f, 120f, 50f, 50f, 55f, 55f };
PdfPTable tmpFragmentationTable = new PdfPTable(tmpCellLength);
PdfPCell tmpSmilesStringCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.smiles"), fontFactory));
PdfPCell tmpFrequencyCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.frequency"), this.fontFactory));
PdfPCell tmpPercentageCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.percentage"), this.fontFactory));
PdfPCell tmpMolFrequencyCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.moleculeFrequency"), this.fontFactory));
PdfPCell tmpMolPercentageCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.moleculePercentage"), this.fontFactory));
PdfPCell tmpFragmentCell = new PdfPCell(new Paragraph(Message.get("Exporter.fragmentationTab.pdfCellHeader.fragment"), this.fontFactory));
Chunk tmpHeader = new Chunk(Message.get("Exporter.fragmentationTab.pdfCellHeader.header"), FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.UNDERLINE));
Paragraph tmpSpace = new Paragraph(" ");
tmpFragmentationTable.addCell(tmpFragmentCell);
tmpFragmentationTable.addCell(tmpSmilesStringCell);
tmpFragmentationTable.addCell(tmpFrequencyCell);
tmpFragmentationTable.addCell(tmpPercentageCell);
tmpFragmentationTable.addCell(tmpMolFrequencyCell);
tmpFragmentationTable.addCell(tmpMolPercentageCell);
for (MoleculeDataModel tmpModel : aFragmentDataModelList) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
FragmentDataModel tmpFragmentDataModel = (FragmentDataModel) tmpModel;
int tmpAbsoluteFrequency = tmpFragmentDataModel.getAbsoluteFrequency();
String tmpStringAbsoluteFrequency = String.format("%d", tmpAbsoluteFrequency);
double tmpAbsolutePercentage = tmpFragmentDataModel.getAbsolutePercentage();
int tmpMoleculeFrequency = tmpFragmentDataModel.getMoleculeFrequency();
String tmpStringMoleculeFrequency = String.format("%d", tmpMoleculeFrequency);
String tmpStringAbsolutePercentage = String.format("%.3f", tmpAbsolutePercentage);
double tmpMoleculePercentage = tmpFragmentDataModel.getMoleculePercentage();
String tmpStringMoleculePercentage = String.format("%.2f", tmpMoleculePercentage);
// creates an image of the fragment
PdfPCell tmpImageFragmentCell = new PdfPCell();
tmpImageFragmentCell.setFixedHeight(85f);
IAtomContainer tmpStructureOfFragment;
try {
tmpStructureOfFragment = tmpFragmentDataModel.getAtomContainer();
} catch (CDKException anException) {
Exporter.LOGGER.getLogger(MoleculeDataModel.class.getName()).log(Level.SEVERE, anException.toString() + "_" + tmpFragmentDataModel.getName(), anException);
tmpFailedExportFragments.add(tmpFragmentDataModel.getUniqueSmiles());
continue;
}
javafx.scene.image.Image tmpImageStructureOfFragment = DepictionUtil.depictImageWithZoom(tmpStructureOfFragment, 4.0);
BufferedImage tmpBufferedImageFragment = SwingFXUtils.fromFXImage(tmpImageStructureOfFragment, null);
Image tmpImageFragment = this.getITextImage(tmpBufferedImageFragment);
// inserts the data into the table
PdfPCell tmpCellOfFrequency = new PdfPCell(new Paragraph(tmpStringAbsoluteFrequency));
tmpCellOfFrequency.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell tmpCellOfPercentage = new PdfPCell(new Paragraph(tmpStringAbsolutePercentage));
tmpCellOfPercentage.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell tmpCellOfMolFrequency = new PdfPCell(new Paragraph(tmpStringMoleculeFrequency));
tmpCellOfMolFrequency.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell tmpCellOfMolPercentage = new PdfPCell(new Paragraph(tmpStringMoleculePercentage));
tmpCellOfMolPercentage.setHorizontalAlignment(Element.ALIGN_RIGHT);
tmpImageFragmentCell.addElement(tmpImageFragment);
tmpFragmentationTable.addCell(tmpImageFragmentCell);
tmpFragmentationTable.addCell(tmpFragmentDataModel.getUniqueSmiles());
tmpFragmentationTable.addCell(tmpCellOfFrequency);
tmpFragmentationTable.addCell(tmpCellOfPercentage);
tmpFragmentationTable.addCell(tmpCellOfMolFrequency);
tmpFragmentationTable.addCell(tmpCellOfMolPercentage);
}
this.document.add(tmpHeader);
this.document.add(tmpSpace);
this.document.add(this.createHeaderTable(aFragmentDataModelList.size(), aMoleculeDataModelList.size(), aFragmentationName));
this.document.add(tmpSpace);
this.document.add(tmpFragmentationTable);
this.document.close();
return tmpFailedExportFragments;
}
use of de.unijena.cheminf.mortar.model.data.FragmentDataModel in project MORTAR by FelixBaensch.
the class Exporter method createFragmentationTabCsvFile.
//
/**
* Exports the fragmentation results as they are displayed on the fragments tab as a CSV file.
*
* @param aList a list of FragmentDataModel instances to export
* @param aSeparator the separator for the csv file
* @throws FileNotFoundException
* @author Betül Sevindik
*/
private void createFragmentationTabCsvFile(File aCsvFile, List<MoleculeDataModel> aList, String aSeparator) throws FileNotFoundException {
if (aCsvFile == null || aList == null) {
return;
}
PrintWriter tmpWriter = new PrintWriter(aCsvFile.getPath());
StringBuilder tmpFragmentationCsvHeader = new StringBuilder();
tmpFragmentationCsvHeader.append(Message.get("Exporter.fragmentationTab.csvHeader.smiles") + aSeparator + Message.get("Exporter.fragmentationTab.csvHeader.frequency") + aSeparator + Message.get("Exporter.fragmentationTab.csvHeader.percentage") + aSeparator + Message.get("Exporter.fragmentationTab.csvHeader.moleculeFrequency") + aSeparator + Message.get("Exporter.fragmentationTab.csvHeader.moleculePercentage") + ("\n"));
tmpWriter.write(tmpFragmentationCsvHeader.toString());
for (MoleculeDataModel tmpDataModel : aList) {
if (Thread.currentThread().isInterrupted()) {
return;
}
FragmentDataModel tmpFragmentDataModel = (FragmentDataModel) tmpDataModel;
tmpWriter.printf("%s" + aSeparator + "%d" + aSeparator + "%.3f" + aSeparator + "%d" + aSeparator + "%.2f\n", tmpFragmentDataModel.getUniqueSmiles(), tmpFragmentDataModel.getAbsoluteFrequency(), tmpFragmentDataModel.getAbsolutePercentage(), tmpFragmentDataModel.getMoleculeFrequency(), tmpFragmentDataModel.getMoleculePercentage());
}
tmpWriter.close();
}
use of de.unijena.cheminf.mortar.model.data.FragmentDataModel in project MORTAR by FelixBaensch.
the class Exporter method createItemizationTabCsvFile.
// </editor-fold>
//
// <editor-fold desc="private methods" defaultstate="collapsed">
/**
* Exports the fragmentation results as they are displayed on the itemization tab as a CSV file.
*
* @param aMoleculeDataModelList a list of MoleculeDataModel instances to export along with their fragments
* @param aFragmentationName fragmentation name to retrieve the specific set of fragments from the molecule data models
* @param aSeparator the separator for the csv file
* @throws FileNotFoundException
* @author Betül Sevindik
*/
private void createItemizationTabCsvFile(File aCsvFile, List<MoleculeDataModel> aMoleculeDataModelList, String aFragmentationName, String aSeparator) throws FileNotFoundException {
if (aCsvFile == null || aMoleculeDataModelList == null || aFragmentationName == null) {
return;
}
PrintWriter tmpWriter = new PrintWriter(aCsvFile.getPath());
StringBuilder tmpCsvHeader = new StringBuilder();
tmpCsvHeader.append(Message.get("Exporter.itemsTab.csvHeader.moleculeName") + aSeparator + Message.get("Exporter.itemsTab.csvHeader.smilesOfStructure") + aSeparator + Message.get("Exporter.itemsTab.csvHeader.smilesOfFragmentsAndFrequency") + "\n");
tmpWriter.write(tmpCsvHeader.toString());
for (MoleculeDataModel tmpMoleculeDataModel : aMoleculeDataModelList) {
if (Thread.currentThread().isInterrupted()) {
return;
}
tmpWriter.printf("%s" + aSeparator + "%s", tmpMoleculeDataModel.getName(), tmpMoleculeDataModel.getUniqueSmiles());
if (!tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(aFragmentationName)) {
continue;
}
List<FragmentDataModel> tmpFragmentList = tmpMoleculeDataModel.getFragmentsOfSpecificAlgorithm(aFragmentationName);
for (FragmentDataModel tmpFragmentDataModel : tmpFragmentList) {
if (Thread.currentThread().isInterrupted() || !tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(aFragmentationName)) {
return;
}
tmpWriter.append(aSeparator);
tmpWriter.printf("%s" + aSeparator + "%s", tmpFragmentDataModel.getUniqueSmiles(), tmpMoleculeDataModel.getFragmentFrequencyOfSpecificAlgorithm(aFragmentationName).get(tmpFragmentDataModel.getUniqueSmiles()).toString());
}
tmpWriter.append("\n");
}
tmpWriter.close();
}
use of de.unijena.cheminf.mortar.model.data.FragmentDataModel in project MORTAR by FelixBaensch.
the class Exporter method createItemizationTabPdfFile.
//
/**
* Exports the fragmentation results as they are displayed on the itemization tab as a PDF file. Opens a file chooser
* dialog for the user to determine a directory and file for the exported data.
*
* @param aFragmentDataModelListSize size of list of FragmentDataModel instances to export
* @param aMoleculeDataModelList a list MoleculeDataModel needed for the fragmentation report at the head of the exported document
* @param aFragmentationName fragmentation name to retrieve the specific set of fragments from the molecule data models
* @throws FileNotFoundException
* @throws DocumentException
* @author Betül Sevindik
*/
private List<String> createItemizationTabPdfFile(File aPdfFile, int aFragmentDataModelListSize, ObservableList<MoleculeDataModel> aMoleculeDataModelList, String aFragmentationName) throws FileNotFoundException, DocumentException {
if (aPdfFile == null || aFragmentDataModelListSize == 0 || aMoleculeDataModelList == null || aMoleculeDataModelList.size() == 0 || aFragmentationName == null || aFragmentationName.isEmpty()) {
return null;
}
List<String> tmpFailedExportFragments = new LinkedList<>();
this.document = new Document(PageSize.A4);
PdfWriter.getInstance(this.document, new FileOutputStream(aPdfFile.getPath()));
this.document.open();
// creates the pdf table
Chunk tmpItemizationTabHeader = new Chunk(Message.get("Exporter.itemsTab.pdfCellHeader.header"), FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.UNDERLINE));
Paragraph tmpSpace = new Paragraph(" ");
this.document.add(tmpItemizationTabHeader);
this.document.add(tmpSpace);
this.document.add(this.createHeaderTable(aFragmentDataModelListSize, aMoleculeDataModelList.size(), aFragmentationName));
this.document.add(tmpSpace);
for (MoleculeDataModel tmpMoleculeDataModel : aMoleculeDataModelList) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
PdfPTable tmpTable = new PdfPTable(2);
PdfPTable tmpFragmentTable = new PdfPTable(1);
tmpTable.setWidths(new int[] { 40, 80 });
PdfPCell tmpNameCell = new PdfPCell(new Paragraph(Message.get("Exporter.itemsTab.pdfCellHeader.name"), this.fontFactory));
tmpNameCell.setFixedHeight(55f);
PdfPCell tmpStructureCell = new PdfPCell(new Paragraph(Message.get("Exporter.itemsTab.pdfCellHeader.structure"), this.fontFactory));
tmpStructureCell.setFixedHeight(120f);
tmpTable.addCell(tmpNameCell);
String tmpName = tmpMoleculeDataModel.getName();
tmpTable.addCell(tmpName);
tmpTable.addCell(tmpStructureCell);
// Image of molecule
IAtomContainer tmpMoleculeStructure;
try {
tmpMoleculeStructure = tmpMoleculeDataModel.getAtomContainer();
} catch (CDKException anException) {
Exporter.LOGGER.getLogger(MoleculeDataModel.class.getName()).log(Level.SEVERE, anException.toString() + "_" + tmpMoleculeDataModel.getName(), anException);
tmpFailedExportFragments.add(tmpMoleculeDataModel.getUniqueSmiles());
continue;
}
PdfPCell tmpMoleculeStructureCell = new PdfPCell();
tmpMoleculeStructureCell.setFixedHeight(120f);
javafx.scene.image.Image tmpMoleculeImage = DepictionUtil.depictImageWithZoom(tmpMoleculeStructure, 3.0);
BufferedImage tmpBufferedImageOfMolecule = SwingFXUtils.fromFXImage(tmpMoleculeImage, null);
Image tmpMolecule = this.getITextImage(tmpBufferedImageOfMolecule);
tmpMoleculeStructureCell.addElement(tmpMolecule);
tmpTable.addCell(tmpMoleculeStructureCell);
PdfPCell tmpCellOfFragment = new PdfPCell(new Paragraph(Message.get("Exporter.itemsTab.pdfCellHeader.fragments"), this.fontFactory));
tmpCellOfFragment.setHorizontalAlignment(Element.ALIGN_CENTER);
tmpFragmentTable.addCell(tmpCellOfFragment);
this.document.add(tmpTable);
this.document.add(tmpFragmentTable);
if (!tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(aFragmentationName)) {
continue;
}
List<FragmentDataModel> tmpFragmentList = tmpMoleculeDataModel.getFragmentsOfSpecificAlgorithm(aFragmentationName);
PdfPTable tmpFragmentationTable2 = new PdfPTable(3);
for (int tmpFragmentNumber = 0; tmpFragmentNumber < tmpFragmentList.size(); ) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
// magic number, see line 487 (loop below): "for (; tmpImagesNumbers < 3; tmpImagesNumbers++){"
ArrayList<PdfPCell> tmpCell = new ArrayList<PdfPCell>(3);
int tmpImagesNumbers = 0;
for (; tmpImagesNumbers < 3; tmpImagesNumbers++) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
if (tmpFragmentNumber >= tmpFragmentList.size()) {
break;
}
FragmentDataModel tmpFragmentDatModel = tmpFragmentList.get(tmpFragmentNumber);
IAtomContainer tmpFragmentStructure;
try {
tmpFragmentStructure = tmpFragmentDatModel.getAtomContainer();
} catch (CDKException anException) {
Exporter.LOGGER.getLogger(MoleculeDataModel.class.getName()).log(Level.SEVERE, anException.toString() + "_" + tmpFragmentDatModel.getName(), anException);
tmpFailedExportFragments.add(tmpFragmentDatModel.getUniqueSmiles());
continue;
}
if (!tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(aFragmentationName)) {
continue;
}
String tmpFrequency = tmpMoleculeDataModel.getFragmentFrequencyOfSpecificAlgorithm(aFragmentationName).get(tmpFragmentDatModel.getUniqueSmiles()).toString();
javafx.scene.image.Image tmpFragmentImage = DepictionUtil.depictImageWithText(tmpFragmentStructure, 3.0, BasicDefinitions.DEFAULT_IMAGE_WIDTH_DEFAULT, BasicDefinitions.DEFAULT_IMAGE_HEIGHT_DEFAULT, tmpFrequency);
BufferedImage tmpBufferedImageOfFragment = SwingFXUtils.fromFXImage(tmpFragmentImage, null);
Image tmpFragment = this.getITextImage(tmpBufferedImageOfFragment);
PdfPCell cell = new PdfPCell();
cell.addElement(tmpFragment);
tmpCell.add(cell);
tmpFragmentNumber++;
}
for (int tmpCellIterator = 0; tmpCellIterator < 3; tmpCellIterator++) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
if (tmpCellIterator < tmpImagesNumbers) {
tmpFragmentationTable2.addCell(tmpCell.get(tmpCellIterator));
} else {
tmpFragmentationTable2.addCell(new Paragraph(""));
}
}
}
this.document.add(tmpFragmentationTable2);
this.document.newPage();
}
this.document.close();
return tmpFailedExportFragments;
}
Aggregations