use of com.compomics.util.io.export.ExportFeature 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.io.export.ExportFeature 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.io.export.ExportFeature 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.io.export.ExportFeature 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.io.export.ExportFeature in project peptide-shaker by compomics.
the class PsAnnotationSection method writeSection.
/**
* Writes the desired section.
*
* @param annotationPreferences the annotation preferences of the project
* @param waitingHandler the waiting handler
*
* @throws IOException exception thrown whenever an error occurred while
* writing the file.
*/
public void writeSection(AnnotationParameters annotationPreferences, WaitingHandler waitingHandler) throws IOException {
if (waitingHandler != null) {
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
if (header) {
if (indexes) {
writer.writeHeaderText("");
writer.addSeparator();
}
writer.writeHeaderText("Parameter");
writer.addSeparator();
writer.writeHeaderText("Value");
writer.newLine();
}
int line = 1;
for (ExportFeature exportFeature : annotationFeatures) {
if (indexes) {
writer.write(Integer.toString(line));
writer.addSeparator();
}
writer.write(exportFeature.getTitle());
writer.addSeparator();
PsAnnotationFeature annotationFeature = (PsAnnotationFeature) exportFeature;
switch(annotationFeature) {
case automatic_annotation:
if (annotationPreferences.isAutomaticAnnotation()) {
writer.write("Yes");
} else {
writer.write("No");
}
break;
case fragment_ion_accuracy:
writer.write(Double.toString(annotationPreferences.getFragmentIonAccuracy()));
break;
case intensity_limit:
writer.write(Double.toString(annotationPreferences.getAnnotationIntensityLimit()));
break;
case neutral_losses:
String neutralLosses = annotationPreferences.getNeutralLosses().stream().map(neutralLoss -> neutralLoss.name).collect(Collectors.joining(", "));
writer.write(neutralLosses);
break;
case neutral_losses_sequence_dependence:
String value = annotationPreferences.areNeutralLossesSequenceAuto() ? "Yes" : "No";
writer.write(value);
break;
case selected_ions:
String ions = annotationPreferences.getFragmentIonTypes().stream().map(fragmentType -> PeptideFragmentIon.getSubTypeAsString(fragmentType)).collect(Collectors.joining(", "));
writer.write(ions);
break;
default:
writer.write("Not implemented");
}
writer.newLine();
line++;
}
}
Aggregations