Search in sources :

Example 1 with ExportScheme

use of com.compomics.util.io.export.ExportScheme in project peptide-shaker by compomics.

the class ProteinFractionsPanel method copyTableContentToClipboardOrFile.

/**
 * Export the table contents to the file.
 *
 * @param index the table index
 */
private void copyTableContentToClipboardOrFile(TableIndex index) {
    final TableIndex tableIndex = index;
    if (tableIndex == TableIndex.PROTEIN_TABLE) {
        HashMap<String, ArrayList<ExportFeature>> exportFeatures = new HashMap<>();
        ArrayList<ExportFeature> sectionContent = new ArrayList<>();
        String textFileFilterDescription = "Tab separated text file (.txt)";
        String gzipFileFilterDescription = "Gzipped tab separated text file (.gz)";
        String excelFileFilterDescription = "Excel Workbook (.xls)";
        String lastSelectedFolderPath = peptideShakerGUI.getLastSelectedFolder().getLastSelectedFolder();
        FileAndFileFilter selectedFileAndFilter = FileChooserUtil.getUserSelectedFile(this, new String[] { ".xls", ".txt", ".gz" }, new String[] { excelFileFilterDescription, textFileFilterDescription, gzipFileFilterDescription }, "Export Report", lastSelectedFolderPath, "Protein table", false, true, false, 1);
        if (selectedFileAndFilter != null) {
            final File selectedFile = selectedFileAndFilter.getFile();
            final ExportFormat exportFormat;
            final boolean gzip;
            if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(textFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = false;
            } else if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(gzipFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = true;
            } else {
                exportFormat = ExportFormat.excel;
                gzip = false;
            }
            progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
            progressDialog.setTitle("Exporting Data. Please Wait...");
            final String filePath = selectedFile.getPath();
            new Thread(new Runnable() {

                public void run() {
                    try {
                        progressDialog.setVisible(true);
                    } catch (IndexOutOfBoundsException e) {
                    // ignore
                    }
                }
            }, "ProgressDialog").start();
            new Thread("ExportThread") {

                @Override
                public void run() {
                    try {
                        sectionContent.add(PsProteinFeature.starred);
                        sectionContent.add(PsProteinFeature.pi);
                        sectionContent.add(PsProteinFeature.accession);
                        sectionContent.add(PsProteinFeature.protein_description);
                        sectionContent.add(PsProteinFeature.protein_group);
                        sectionContent.add(PsProteinFeature.descriptions);
                        sectionContent.add(PsProteinFeature.other_proteins);
                        sectionContent.add(PsProteinFeature.chromosome);
                        sectionContent.add(PsProteinFeature.coverage);
                        sectionContent.add(PsProteinFeature.confident_coverage);
                        sectionContent.add(PsProteinFeature.all_coverage);
                        sectionContent.add(PsProteinFeature.possible_coverage);
                        sectionContent.add(PsProteinFeature.validated_peptides);
                        sectionContent.add(PsProteinFeature.peptides);
                        sectionContent.add(PsProteinFeature.unique_peptides);
                        sectionContent.add(PsProteinFeature.unique_validated_peptides);
                        sectionContent.add(PsProteinFeature.validated_psms);
                        sectionContent.add(PsProteinFeature.psms);
                        sectionContent.add(PsProteinFeature.spectrum_counting_nsaf);
                        sectionContent.add(PsProteinFeature.spectrum_counting_empai);
                        sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_percent);
                        sectionContent.add(PsProteinFeature.spectrum_counting_empai_percent);
                        sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_ppm);
                        sectionContent.add(PsProteinFeature.spectrum_counting_empai_ppm);
                        sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_fmol);
                        sectionContent.add(PsProteinFeature.spectrum_counting_empai_fmol);
                        sectionContent.add(PsProteinFeature.mw);
                        sectionContent.add(PsProteinFeature.confidence);
                        sectionContent.add(PsProteinFeature.validated);
                        exportFeatures.put(PsProteinFeature.type, sectionContent);
                        ExportScheme validatedProteinReport = new ExportScheme("Protein Table", false, exportFeatures, "\t", true, true, 0, false, false, false);
                        PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), getDisplayedProteins(), null, null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();
                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + filePath, "Data Exported", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (IllegalArgumentException e) {
                        if (e.getMessage().contains("Invalid row number (65536)")) {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, // @TODO: update the excel export library?
                            "An error occurred while generating the output. This format can contain only 65,535 lines.\n" + "Please use a text export instead.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        } else {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExportFormat(com.compomics.util.io.export.ExportFormat) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ExportScheme(com.compomics.util.io.export.ExportScheme) ExportFeature(com.compomics.util.io.export.ExportFeature) File(java.io.File) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter)

Example 2 with ExportScheme

use of com.compomics.util.io.export.ExportScheme in project peptide-shaker by compomics.

the class ProteinStructurePanel method copyTableContentToClipboardOrFile.

/**
 * Export the table contents to the clipboard.
 *
 * @param index the table index type
 */
private void copyTableContentToClipboardOrFile(TableIndex index) throws IOException {
    final TableIndex tableIndex = index;
    if (tableIndex == TableIndex.PROTEIN_TABLE || tableIndex == TableIndex.PEPTIDE_TABLE) {
        HashMap<String, ArrayList<ExportFeature>> exportFeatures = new HashMap<>();
        ArrayList<ExportFeature> sectionContent = new ArrayList<>();
        String textFileFilterDescription = "Tab separated text file (.txt)";
        String gzipFileFilterDescription = "Gzipped tab separated text file (.gz)";
        String excelFileFilterDescription = "Excel Workbook (.xls)";
        String lastSelectedFolderPath = peptideShakerGUI.getLastSelectedFolder().getLastSelectedFolder();
        String exportName = "Export";
        switch(tableIndex) {
            case PROTEIN_TABLE:
                exportName = "Protein table";
                break;
            case PEPTIDE_TABLE:
                exportName = "Peptide table";
                break;
            default:
                break;
        }
        FileAndFileFilter selectedFileAndFilter = FileChooserUtil.getUserSelectedFile(this, new String[] { ".xls", ".txt", ".gz" }, new String[] { excelFileFilterDescription, textFileFilterDescription, gzipFileFilterDescription }, "Export Report", lastSelectedFolderPath, exportName, false, true, false, 1);
        if (selectedFileAndFilter != null) {
            final File selectedFile = selectedFileAndFilter.getFile();
            final ExportFormat exportFormat;
            final boolean gzip;
            if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(textFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = false;
            } else if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(gzipFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = true;
            } else {
                exportFormat = ExportFormat.excel;
                gzip = false;
            }
            progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
            progressDialog.setTitle("Exporting Data. Please Wait...");
            final String filePath = selectedFile.getPath();
            new Thread(new Runnable() {

                public void run() {
                    try {
                        progressDialog.setVisible(true);
                    } catch (IndexOutOfBoundsException e) {
                    // ignore
                    }
                }
            }, "ProgressDialog").start();
            new Thread("ExportThread") {

                @Override
                public void run() {
                    try {
                        switch(tableIndex) {
                            case PROTEIN_TABLE:
                                sectionContent.add(PsProteinFeature.starred);
                                sectionContent.add(PsProteinFeature.pi);
                                sectionContent.add(PsProteinFeature.accession);
                                sectionContent.add(PsProteinFeature.protein_description);
                                sectionContent.add(PsProteinFeature.protein_group);
                                sectionContent.add(PsProteinFeature.descriptions);
                                sectionContent.add(PsProteinFeature.other_proteins);
                                sectionContent.add(PsProteinFeature.chromosome);
                                sectionContent.add(PsProteinFeature.coverage);
                                sectionContent.add(PsProteinFeature.confident_coverage);
                                sectionContent.add(PsProteinFeature.all_coverage);
                                sectionContent.add(PsProteinFeature.possible_coverage);
                                sectionContent.add(PsProteinFeature.validated_peptides);
                                sectionContent.add(PsProteinFeature.peptides);
                                sectionContent.add(PsProteinFeature.unique_peptides);
                                sectionContent.add(PsProteinFeature.unique_validated_peptides);
                                sectionContent.add(PsProteinFeature.validated_psms);
                                sectionContent.add(PsProteinFeature.psms);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_percent);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_percent);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_ppm);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_ppm);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_fmol);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_fmol);
                                sectionContent.add(PsProteinFeature.mw);
                                sectionContent.add(PsProteinFeature.confidence);
                                sectionContent.add(PsProteinFeature.validated);
                                exportFeatures.put(PsProteinFeature.type, sectionContent);
                                ExportScheme validatedProteinReport = new ExportScheme("Protein Table", false, exportFeatures, "\t", true, true, 0, false, false, false);
                                PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), getDisplayedProteins(), null, null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                break;
                            case PEPTIDE_TABLE:
                                sectionContent.add(PsPeptideFeature.starred);
                                sectionContent.add(PsPeptideFeature.pi);
                                sectionContent.add(PsPeptideFeature.accessions);
                                sectionContent.add(PsPeptideFeature.protein_description);
                                sectionContent.add(PsPeptideFeature.protein_groups);
                                sectionContent.add(PsPeptideFeature.sequence);
                                sectionContent.add(PsPeptideFeature.modified_sequence);
                                sectionContent.add(PsPeptideFeature.position);
                                sectionContent.add(PsPeptideFeature.aaBefore);
                                sectionContent.add(PsPeptideFeature.aaAfter);
                                sectionContent.add(PsPeptideFeature.missed_cleavages);
                                sectionContent.add(PsPeptideFeature.variable_ptms);
                                sectionContent.add(PsPeptideFeature.fixed_ptms);
                                sectionContent.add(PsPeptideFeature.psms);
                                sectionContent.add(PsPeptideFeature.validated_psms);
                                sectionContent.add(PsPeptideFeature.confidence);
                                sectionContent.add(PsPeptideFeature.validated);
                                exportFeatures.put(PsPeptideFeature.type, sectionContent);
                                validatedProteinReport = new ExportScheme("Peptide Table", false, exportFeatures, "\t", true, true, 0, false, false, false);
                                PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), null, getDisplayedPeptides(), null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                break;
                            default:
                                break;
                        }
                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();
                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + filePath, "Data Exported", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (FileNotFoundException e) {
                        progressDialog.setRunFinished();
                        JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output. Please make sure " + "that the destination file is not opened by another application.", "Output Error", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                        if (e.getMessage().contains("Invalid row number (65536)")) {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, // @TODO: update the excel export library?
                            "An error occurred while generating the output. This format can contain only 65,535 lines.\n" + "Please use a text export instead.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        } else {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    } else if (tableIndex == TableIndex.PDB_MATCHES || tableIndex == TableIndex.PDB_CHAINS) {
        // get the file to send the output to
        File selectedFile = peptideShakerGUI.getUserSelectedFile("pdb_details.txt", ".txt", "Tab separated text file (.txt)", "Export...", false);
        if (selectedFile != null) {
            if (tableIndex == TableIndex.PDB_CHAINS) {
                try (SimpleFileWriter writer = new SimpleFileWriter(selectedFile, false)) {
                    writer.writeLine("", "Chain", "PDB-Start", "PDB-End", "Coverage");
                    for (int i = 0; i < pdbChainsJTable.getRowCount(); i++) {
                        XYDataPoint pdbCoverage = (XYDataPoint) pdbChainsJTable.getValueAt(i, 2);
                        writer.writeLine(pdbChainsJTable.getValueAt(i, 0).toString(), pdbChainsJTable.getValueAt(i, 1).toString(), Double.toString(pdbCoverage.getX()), Double.toString(pdbCoverage.getY()), pdbChainsJTable.getValueAt(i, 3).toString());
                    }
                    JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + selectedFile.getPath(), "Data Exported", JOptionPane.INFORMATION_MESSAGE);
                }
            } else if (tableIndex == TableIndex.PDB_MATCHES) {
                try (BufferedWriter writer = new BufferedWriter(new FileWriter(selectedFile))) {
                    Util.tableToFile(pdbMatchesJTable, "\t", null, true, writer);
                    JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + selectedFile.getPath(), "Data Exported", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ExportFormat(com.compomics.util.io.export.ExportFormat) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ExportScheme(com.compomics.util.io.export.ExportScheme) ExportFeature(com.compomics.util.io.export.ExportFeature) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) File(java.io.File) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter)

Example 3 with ExportScheme

use of com.compomics.util.io.export.ExportScheme in project peptide-shaker by compomics.

the class OverviewPanel method copyTableContentToClipboardOrFile.

/**
 * Export the table contents to the clipboard.
 *
 * @param index the index type
 */
private void copyTableContentToClipboardOrFile(TableIndex index) {
    final TableIndex tableIndex = index;
    HashMap<String, ArrayList<ExportFeature>> exportFeatures = new HashMap<>();
    ArrayList<ExportFeature> sectionContent = new ArrayList<>();
    if (tableIndex == TableIndex.PROTEIN_TABLE || tableIndex == TableIndex.PEPTIDE_TABLE || tableIndex == TableIndex.PSM_TABLE) {
        String textFileFilterDescription = "Tab separated text file (.txt)";
        String gzipFileFilterDescription = "Gzipped tab separated text file (.gz)";
        String excelFileFilterDescription = "Excel Workbook (.xls)";
        String lastSelectedFolderPath = peptideShakerGUI.getLastSelectedFolder().getLastSelectedFolder();
        String exportName = "Export";
        switch(tableIndex) {
            case PROTEIN_TABLE:
                exportName = "Protein table";
                break;
            case PEPTIDE_TABLE:
                exportName = "Peptide table";
                break;
            case PSM_TABLE:
                exportName = "PSM table";
                break;
            default:
                break;
        }
        FileAndFileFilter selectedFileAndFilter = FileChooserUtil.getUserSelectedFile(this, new String[] { ".xls", ".txt", ".gz" }, new String[] { excelFileFilterDescription, textFileFilterDescription, gzipFileFilterDescription }, "Export Report", lastSelectedFolderPath, exportName, false, true, false, 1);
        if (selectedFileAndFilter != null) {
            final File selectedFile = selectedFileAndFilter.getFile();
            final ExportFormat exportFormat;
            final boolean gzip;
            if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(textFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = false;
            } else if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(gzipFileFilterDescription)) {
                exportFormat = ExportFormat.text;
                gzip = true;
            } else {
                exportFormat = ExportFormat.excel;
                gzip = false;
            }
            progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
            progressDialog.setTitle("Exporting Data. Please Wait...");
            final String filePath = selectedFile.getPath();
            new Thread(new Runnable() {

                public void run() {
                    try {
                        progressDialog.setVisible(true);
                    } catch (IndexOutOfBoundsException e) {
                    // ignore
                    }
                }
            }, "ProgressDialog").start();
            new Thread("ExportThread") {

                @Override
                public void run() {
                    try {
                        switch(tableIndex) {
                            case PROTEIN_TABLE:
                                sectionContent.add(PsProteinFeature.starred);
                                sectionContent.add(PsProteinFeature.pi);
                                sectionContent.add(PsProteinFeature.accession);
                                sectionContent.add(PsProteinFeature.protein_description);
                                sectionContent.add(PsProteinFeature.protein_group);
                                sectionContent.add(PsProteinFeature.descriptions);
                                sectionContent.add(PsProteinFeature.other_proteins);
                                sectionContent.add(PsProteinFeature.chromosome);
                                sectionContent.add(PsProteinFeature.coverage);
                                sectionContent.add(PsProteinFeature.confident_coverage);
                                sectionContent.add(PsProteinFeature.all_coverage);
                                sectionContent.add(PsProteinFeature.possible_coverage);
                                sectionContent.add(PsProteinFeature.validated_peptides);
                                sectionContent.add(PsProteinFeature.peptides);
                                sectionContent.add(PsProteinFeature.unique_peptides);
                                sectionContent.add(PsProteinFeature.unique_validated_peptides);
                                sectionContent.add(PsProteinFeature.validated_psms);
                                sectionContent.add(PsProteinFeature.psms);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_percent);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_percent);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_ppm);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_ppm);
                                sectionContent.add(PsProteinFeature.spectrum_counting_nsaf_fmol);
                                sectionContent.add(PsProteinFeature.spectrum_counting_empai_fmol);
                                sectionContent.add(PsProteinFeature.mw);
                                sectionContent.add(PsProteinFeature.confidence);
                                sectionContent.add(PsProteinFeature.validated);
                                exportFeatures.put(PsProteinFeature.type, sectionContent);
                                ExportScheme validatedProteinReport = new ExportScheme("Protein Table", false, exportFeatures, "\t", true, true, 0, false, false, false);
                                PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), getDisplayedProteins(), null, null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                break;
                            case PEPTIDE_TABLE:
                                sectionContent.add(PsPeptideFeature.starred);
                                sectionContent.add(PsPeptideFeature.pi);
                                sectionContent.add(PsPeptideFeature.accessions);
                                sectionContent.add(PsPeptideFeature.protein_description);
                                sectionContent.add(PsPeptideFeature.protein_groups);
                                sectionContent.add(PsPeptideFeature.sequence);
                                sectionContent.add(PsPeptideFeature.modified_sequence);
                                sectionContent.add(PsPeptideFeature.position);
                                sectionContent.add(PsPeptideFeature.aaBefore);
                                sectionContent.add(PsPeptideFeature.aaAfter);
                                sectionContent.add(PsPeptideFeature.missed_cleavages);
                                sectionContent.add(PsPeptideFeature.variable_ptms);
                                sectionContent.add(PsPeptideFeature.fixed_ptms);
                                sectionContent.add(PsPeptideFeature.psms);
                                sectionContent.add(PsPeptideFeature.validated_psms);
                                sectionContent.add(PsPeptideFeature.confidence);
                                sectionContent.add(PsPeptideFeature.validated);
                                exportFeatures.put(PsPeptideFeature.type, sectionContent);
                                validatedProteinReport = new ExportScheme("Peptide Table", false, exportFeatures, "\t", true, true, 0, false, false, false);
                                PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), null, getDisplayedPeptides(), null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                break;
                            case PSM_TABLE:
                                // @TODO: replace by the PSExportFactory when all of the missing values are supported
                                BufferedWriter writer = new BufferedWriter(new FileWriter(selectedFile));
                                Util.tableToFile(psmTable, "\t", progressDialog, true, writer);
                                writer.close();
                                // peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                break;
                            default:
                                break;
                        }
                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();
                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + filePath, "Data Exported", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (FileNotFoundException e) {
                        progressDialog.setRunFinished();
                        JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output. Please make sure " + "that the destination file is not opened by another application.", "Output Error", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                        if (e.getMessage().contains("Invalid row number (65536)")) {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, // @TODO: update the excel export library?
                            "An error occurred while generating the output. This format can contain only 65,535 lines.\n" + "Please use a text export instead.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        } else {
                            progressDialog.setRunFinished();
                            JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error", JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) ExportFormat(com.compomics.util.io.export.ExportFormat) FileNotFoundException(java.io.FileNotFoundException) BufferedWriter(java.io.BufferedWriter) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ExportScheme(com.compomics.util.io.export.ExportScheme) ExportFeature(com.compomics.util.io.export.ExportFeature) File(java.io.File) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter)

Example 4 with ExportScheme

use of com.compomics.util.io.export.ExportScheme in project peptide-shaker by compomics.

the class AnnotationPanel method helpEditorPaneHyperlinkUpdate.

// GEN-LAST:event_webIntActLabelMouseExited
/**
 * Enable the hyperlinks in the help panel.
 *
 * @param evt
 */
private void helpEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
    // GEN-FIRST:event_helpEditorPaneHyperlinkUpdate
    if (evt.getEventType().toString().equalsIgnoreCase(javax.swing.event.HyperlinkEvent.EventType.ACTIVATED.toString())) {
        if (evt.getDescription().equalsIgnoreCase("validated_proteins")) {
            if (peptideShakerGUI.getIdentification() != null) {
                String textFileFilterDescription = "Tab separated text file (.txt)";
                String gzipFileFilterDescription = "Gzipped tab separated text file (.gz)";
                String excelFileFilterDescription = "Excel Workbook (.xls)";
                String lastSelectedFolderPath = peptideShakerGUI.getLastSelectedFolder().getLastSelectedFolder();
                FileAndFileFilter selectedFileAndFilter = FileChooserUtil.getUserSelectedFile(this, new String[] { ".xls", ".txt", ".gz" }, new String[] { excelFileFilterDescription, textFileFilterDescription, gzipFileFilterDescription }, "Export Report", lastSelectedFolderPath, "All Validated Proteins", false, true, false, 1);
                if (selectedFileAndFilter != null) {
                    final File selectedFile = selectedFileAndFilter.getFile();
                    final ExportFormat exportFormat;
                    final boolean gzip;
                    if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(textFileFilterDescription)) {
                        exportFormat = ExportFormat.text;
                        gzip = false;
                    } else if (selectedFileAndFilter.getFileFilter().getDescription().equalsIgnoreCase(gzipFileFilterDescription)) {
                        exportFormat = ExportFormat.text;
                        gzip = true;
                    } else {
                        exportFormat = ExportFormat.excel;
                        gzip = false;
                    }
                    progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
                    progressDialog.setTitle("Exporting Data. Please Wait...");
                    final String filePath = selectedFile.getPath();
                    new Thread(new Runnable() {

                        public void run() {
                            try {
                                progressDialog.setVisible(true);
                            } catch (IndexOutOfBoundsException e) {
                            // ignore
                            }
                        }
                    }, "ProgressDialog").start();
                    new Thread("ExportThread") {

                        @Override
                        public void run() {
                            try {
                                HashMap<String, ArrayList<ExportFeature>> exportFeatures = new HashMap<>();
                                ArrayList<ExportFeature> sectionContent = new ArrayList<>();
                                sectionContent.add(PsProteinFeature.accession);
                                exportFeatures.put(PsProteinFeature.type, sectionContent);
                                ExportScheme validatedProteinReport = new ExportScheme("Validated Proteins", false, exportFeatures, "\t", false, false, 0, false, true, false);
                                PSExportFactory.writeExport(validatedProteinReport, selectedFile, exportFormat, gzip, peptideShakerGUI.getProjectParameters().getProjectUniqueName(), peptideShakerGUI.getProjectDetails(), peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getGeneMaps(), null, null, null, peptideShakerGUI.getDisplayParameters().getnAASurroundingPeptides(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getSpectrumCountingParameters(), progressDialog);
                                boolean processCancelled = progressDialog.isRunCanceled();
                                progressDialog.setRunFinished();
                                if (!processCancelled) {
                                    JOptionPane.showMessageDialog(peptideShakerGUI, "Data copied to file:\n" + filePath, "Data Exported.", JOptionPane.INFORMATION_MESSAGE);
                                }
                            } catch (IllegalArgumentException e) {
                                if (e.getMessage().contains("Invalid row number (65536)")) {
                                    progressDialog.setRunFinished();
                                    JOptionPane.showMessageDialog(peptideShakerGUI, // @TODO: update the excel export library?
                                    "An error occurred while generating the output. This format can contain only 65,535 lines.\n" + "Please use a text export instead.", "Output Error.", JOptionPane.ERROR_MESSAGE);
                                    e.printStackTrace();
                                } else {
                                    progressDialog.setRunFinished();
                                    JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error.", JOptionPane.ERROR_MESSAGE);
                                    e.printStackTrace();
                                }
                            } catch (Exception e) {
                                progressDialog.setRunFinished();
                                JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while generating the output.", "Output Error.", JOptionPane.ERROR_MESSAGE);
                                e.printStackTrace();
                            }
                        }
                    }.start();
                }
            } else {
                JOptionPane.showMessageDialog(peptideShakerGUI, "You have to load a project first!", "No Project", JOptionPane.WARNING_MESSAGE);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExportFormat(com.compomics.util.io.export.ExportFormat) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ExportScheme(com.compomics.util.io.export.ExportScheme) ExportFeature(com.compomics.util.io.export.ExportFeature) File(java.io.File) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter)

Example 5 with ExportScheme

use of com.compomics.util.io.export.ExportScheme in project peptide-shaker by compomics.

the class CLIExportMethods method exportReport.

/**
 * Writes an export according to the command line settings contained in the
 * reportCLIInputBean.
 *
 * @param reportCLIInputBean the command line settings
 * @param reportType the report type
 * @param experiment the experiment of the project
 * @param projectDetails the project details of the project
 * @param identification the identification of the project
 * @param geneMaps the gene maps
 * @param identificationFeaturesGenerator the identification features
 * generator
 * @param identificationParameters the identification parameters used
 * @param sequenceProvider the sequence provider
 * @param proteinDetailsProvider the protein details provider
 * @param spectrumProvider The spectrum provider.
 * @param nSurroundingAA the number of amino acids to export on the side of
 * peptide sequences
 * @param spectrumCountingPreferences the spectrum counting preferences
 * @param waitingHandler waiting handler displaying feedback to the user
 * @return File file containing the exported report
 *
 * @throws IOException exception thrown whenever an IO exception occurred
 * while reading or writing to a file
 */
public static File exportReport(ReportCLIInputBean reportCLIInputBean, String reportType, String experiment, ProjectDetails projectDetails, Identification identification, GeneMaps geneMaps, IdentificationFeaturesGenerator identificationFeaturesGenerator, IdentificationParameters identificationParameters, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, int nSurroundingAA, SpectrumCountingParameters spectrumCountingPreferences, WaitingHandler waitingHandler) throws IOException {
    PSExportFactory exportFactory = PSExportFactory.getInstance();
    ExportScheme exportScheme = exportFactory.getExportScheme(reportType);
    String reportName = reportType.replaceAll(" ", "_");
    reportName = PSExportFactory.getDefaultReportName(experiment, reportName);
    if (reportCLIInputBean.getReportNamePrefix() != null) {
        reportName = reportCLIInputBean.getReportNamePrefix() + reportName;
    }
    File reportFile = new File(reportCLIInputBean.getReportOutputFolder(), reportName);
    // @TODO: allow format selection
    PSExportFactory.writeExport(exportScheme, reportFile, ExportFormat.text, reportCLIInputBean.isGzip(), experiment, projectDetails, identification, identificationFeaturesGenerator, geneMaps, null, null, null, nSurroundingAA, identificationParameters, sequenceProvider, proteinDetailsProvider, spectrumProvider, spectrumCountingPreferences, waitingHandler);
    return reportFile;
}
Also used : PSExportFactory(eu.isas.peptideshaker.export.PSExportFactory) ExportScheme(com.compomics.util.io.export.ExportScheme) File(java.io.File)

Aggregations

ExportScheme (com.compomics.util.io.export.ExportScheme)11 File (java.io.File)9 FileAndFileFilter (com.compomics.util.gui.file_handling.FileAndFileFilter)7 ProgressDialogX (com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX)7 ExportFormat (com.compomics.util.io.export.ExportFormat)7 ExportFeature (com.compomics.util.io.export.ExportFeature)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 PSExportFactory (eu.isas.peptideshaker.export.PSExportFactory)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 SimpleFileWriter (com.compomics.util.io.flat.SimpleFileWriter)1 TreeMap (java.util.TreeMap)1 XYDataPoint (no.uib.jsparklines.data.XYDataPoint)1