use of com.compomics.util.gui.file_handling.FileAndFileFilter 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();
}
}
}
use of com.compomics.util.gui.file_handling.FileAndFileFilter 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);
}
}
}
}
}
use of com.compomics.util.gui.file_handling.FileAndFileFilter 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();
}
}
}
use of com.compomics.util.gui.file_handling.FileAndFileFilter 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);
}
}
}
}
use of com.compomics.util.gui.file_handling.FileAndFileFilter in project peptide-shaker by compomics.
the class PeptideShakerGUI method openJMenuItemActionPerformed.
// GEN-LAST:event_scoresJCheckBoxMenuItemActionPerformed
/**
* Open a file chooser to open an existing PeptideShaker project.
*
* @param evt
*/
private void openJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
if (!dataSaved && getProjectParameters() != null) {
int value = JOptionPane.showConfirmDialog(this, "Do you want to save the changes to " + getProjectParameters().getProjectUniqueName() + "?", "Unsaved Changes", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (value == JOptionPane.YES_OPTION) {
saveMenuItemActionPerformed(null);
} else if (value == JOptionPane.CANCEL_OPTION || value == JOptionPane.CLOSED_OPTION) {
return;
} else {
// no option
// do nothing
}
}
String lastSelectedFolderPath = lastSelectedFolder.getLastSelectedFolder();
String psdbFileFilterDescription = "PeptideShaker (.psdb)";
String zipFileFilterDescription = "Zipped PeptideShaker (.zip)";
FileAndFileFilter selectedFileAndFilter = FileChooserUtil.getUserSelectedFile(this, new String[] { ".psdb", ".zip" }, new String[] { psdbFileFilterDescription, zipFileFilterDescription }, "Open PeptideShaker Project", lastSelectedFolderPath, null, true, false, false, 0);
if (selectedFileAndFilter != null) {
File selectedFile = selectedFileAndFilter.getFile();
lastSelectedFolder.setLastSelectedFolder(selectedFile.getParent());
if (selectedFile.getName().endsWith(".zip")) {
importPeptideShakerZipFile(selectedFile);
} else if (selectedFile.getName().endsWith(".psdb")) {
exceptionHandler.setIgnoreExceptions(true);
clearData(true, true);
exceptionHandler.setIgnoreExceptions(false);
clearParameters();
getUserParameters().addRecentProject(selectedFile);
updateRecentProjectsList();
importPeptideShakerFile(selectedFile, false);
lastSelectedFolder.setLastSelectedFolder(selectedFile.getAbsolutePath());
} else {
JOptionPane.showMessageDialog(this, "Not a PeptideShaker file (.psdb).", "Unsupported File.", JOptionPane.WARNING_MESSAGE);
}
}
}
Aggregations