Package eu.isas.peptideshaker.gui.exportdialogs

Source Code of eu.isas.peptideshaker.gui.exportdialogs.FollowupPreferencesDialog

package eu.isas.peptideshaker.gui.exportdialogs;

import com.compomics.util.Util;
import com.compomics.util.experiment.identification.SequenceFactory;
import com.compomics.util.experiment.identification.matches.PeptideMatch;
import com.compomics.util.experiment.identification.matches.ProteinMatch;
import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
import com.compomics.util.gui.JOptionEditorPane;
import com.compomics.util.gui.ptm.PtmChooser;
import com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX;
import com.compomics.util.gui.renderers.AlignedListCellRenderer;
import eu.isas.peptideshaker.followup.ProgenesisExcelExport;
import eu.isas.peptideshaker.followup.FastaExport;
import eu.isas.peptideshaker.followup.InclusionListExport;
import eu.isas.peptideshaker.followup.SpectrumExporter;
import eu.isas.peptideshaker.followup.ProgenesisExport;
import eu.isas.peptideshaker.followup.RecalibrationExporter;
import eu.isas.peptideshaker.followup.SwathExport;
import eu.isas.peptideshaker.gui.PeptideShakerGUI;
import eu.isas.peptideshaker.myparameters.PSParameter;
import eu.isas.peptideshaker.utils.IdentificationFeaturesGenerator;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import javax.swing.*;

/**
* This class will allow the user to generate spectrum information for follow up
* analysis.
*
* @author Marc Vaudel
* @author Harald Barsnes
*/
public class FollowupPreferencesDialog extends javax.swing.JDialog {

    /**
     * The main GUI.
     */
    private PeptideShakerGUI peptideShakerGUI;
    /**
     * A simple progress dialog.
     */
    private static ProgressDialogX progressDialog;

    /**
     * Creates a new FollowupPreferencesDialog.
     *
     * @param peptideShakerGUI
     */
    public FollowupPreferencesDialog(PeptideShakerGUI peptideShakerGUI) {
        super(peptideShakerGUI, true);
        this.peptideShakerGUI = peptideShakerGUI;
        initComponents();

        spectrumRecalibrationCmb.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        spectrumValidationCmb.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        inclusionListFormat.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        proteinExportCmb1.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        proteinExportCmb2.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        psmSelectionComboBox.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        graphDatabaseFormat.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));
        psmSelectionComboBoxSwath.setRenderer(new AlignedListCellRenderer(SwingConstants.CENTER));

        this.setLocationRelativeTo(peptideShakerGUI);

        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundPanel = new javax.swing.JPanel();
        spectraPanel = new javax.swing.JPanel();
        exportSpectraLabel = new javax.swing.JLabel();
        spectrumValidationCmb = new javax.swing.JComboBox();
        exportMgfButton = new javax.swing.JButton();
        recalibrateSpectraLabel = new javax.swing.JLabel();
        spectrumRecalibrationCmb = new javax.swing.JComboBox();
        recalibrateMgfButton = new javax.swing.JButton();
        inclusionListPanel = new javax.swing.JPanel();
        includeValidatedPsmsLabel = new javax.swing.JLabel();
        inclusionListFormat = new javax.swing.JComboBox();
        inclusionListButton = new javax.swing.JButton();
        progenesisPanel = new javax.swing.JPanel();
        exportProgenesisButton = new javax.swing.JButton();
        psmSelectionComboBox = new javax.swing.JComboBox();
        exportToProgenesisLinkLabel = new javax.swing.JLabel();
        proteinsPanel = new javax.swing.JPanel();
        exportAllIdentifiedProteinsAsFastaLabel = new javax.swing.JLabel();
        exportIdentifiedProteinsAsFastaButton = new javax.swing.JButton();
        exportAllIdentifiedProteinAccessionsLabel = new javax.swing.JLabel();
        exportIdentifiedProteinAccessionNumbersAsCsvButton = new javax.swing.JButton();
        proteinExportCmb1 = new javax.swing.JComboBox();
        proteinExportCmb2 = new javax.swing.JComboBox();
        graphDatabasesPanel = new javax.swing.JPanel();
        graphDatabasesLabel = new javax.swing.JLabel();
        graphDatabaseFormat = new javax.swing.JComboBox();
        graphDatabasetButton = new javax.swing.JButton();
        swathPanel = new javax.swing.JPanel();
        swathButton = new javax.swing.JButton();
        psmSelectionComboBoxSwath = new javax.swing.JComboBox();
        swathExportLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Export - Follow Up Analysis");
        setResizable(false);

        backgroundPanel.setBackground(new java.awt.Color(230, 230, 230));

        spectraPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Spectra"));
        spectraPanel.setOpaque(false);

        exportSpectraLabel.setText("Export Spectra");

        spectrumValidationCmb.setModel(new DefaultComboBoxModel(SpectrumExporter.ExportType.getPossibilities()));

        exportMgfButton.setText("Export as MGF");
        exportMgfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportMgfButtonActionPerformed(evt);
            }
        });

        recalibrateSpectraLabel.setText("Recalibrate Spectra (beta)");

        spectrumRecalibrationCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Precursor and Fragment Ions", "Precursor Ions", "Fragment Ions" }));

        recalibrateMgfButton.setText("Export as MGF");
        recalibrateMgfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recalibrateMgfButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout spectraPanelLayout = new javax.swing.GroupLayout(spectraPanel);
        spectraPanel.setLayout(spectraPanelLayout);
        spectraPanelLayout.setHorizontalGroup(
            spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(spectraPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(spectraPanelLayout.createSequentialGroup()
                        .addComponent(exportSpectraLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spectrumValidationCmb, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(spectraPanelLayout.createSequentialGroup()
                        .addComponent(recalibrateSpectraLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spectrumRecalibrationCmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(exportMgfButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(recalibrateMgfButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        spectraPanelLayout.setVerticalGroup(
            spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(spectraPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exportSpectraLabel)
                    .addComponent(spectrumValidationCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exportMgfButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(spectraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(recalibrateSpectraLabel)
                    .addComponent(spectrumRecalibrationCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(recalibrateMgfButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        inclusionListPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Inclusion List (beta)"));
        inclusionListPanel.setOpaque(false);

        includeValidatedPsmsLabel.setText("Instrument Format");

        inclusionListFormat.setModel(new DefaultComboBoxModel(InclusionListExport.ExportFormat.getPossibilities()));

        inclusionListButton.setText("Export as List");
        inclusionListButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inclusionListButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout inclusionListPanelLayout = new javax.swing.GroupLayout(inclusionListPanel);
        inclusionListPanel.setLayout(inclusionListPanelLayout);
        inclusionListPanelLayout.setHorizontalGroup(
            inclusionListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inclusionListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(includeValidatedPsmsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inclusionListFormat, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(inclusionListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        inclusionListPanelLayout.setVerticalGroup(
            inclusionListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inclusionListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(inclusionListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inclusionListFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(includeValidatedPsmsLabel)
                    .addComponent(inclusionListButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        progenesisPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Label Free Quantification"));
        progenesisPanel.setOpaque(false);

        exportProgenesisButton.setText("Export CSV");
        exportProgenesisButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportProgenesisButtonActionPerformed(evt);
            }
        });

        psmSelectionComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Validated PSMs of Validated Peptides of Validated Proteins", "Validated PSMs of Validated Peptides", "Validated PSMs", "Validated PSMs Containing Confidently Localized PTMs" }));

        exportToProgenesisLinkLabel.setText("<html><a href=\\\"http://www.nonlinear.com/products/progenesis/lc-ms/overview/\\\">Progenesis LC-MS</a></html>");
        exportToProgenesisLinkLabel.setToolTipText("Click for Progenesis LC-MS export help");
        exportToProgenesisLinkLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                exportToProgenesisLinkLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                exportToProgenesisLinkLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                exportToProgenesisLinkLabelMouseExited(evt);
            }
        });

        javax.swing.GroupLayout progenesisPanelLayout = new javax.swing.GroupLayout(progenesisPanel);
        progenesisPanel.setLayout(progenesisPanelLayout);
        progenesisPanelLayout.setHorizontalGroup(
            progenesisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, progenesisPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(exportToProgenesisLinkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(psmSelectionComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(exportProgenesisButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        progenesisPanelLayout.setVerticalGroup(
            progenesisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(progenesisPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(progenesisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(psmSelectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exportProgenesisButton)
                    .addComponent(exportToProgenesisLinkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        proteinsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Proteins"));
        proteinsPanel.setOpaque(false);

        exportAllIdentifiedProteinsAsFastaLabel.setText("Export Sequences");

        exportIdentifiedProteinsAsFastaButton.setText("Export as FASTA");
        exportIdentifiedProteinsAsFastaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportIdentifiedProteinsAsFastaButtonActionPerformed(evt);
            }
        });

        exportAllIdentifiedProteinAccessionsLabel.setText("Export Accession Numbers");

        exportIdentifiedProteinAccessionNumbersAsCsvButton.setText("Export as TXT");
        exportIdentifiedProteinAccessionNumbersAsCsvButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportIdentifiedProteinAccessionNumbersAsCsvButtonActionPerformed(evt);
            }
        });

        proteinExportCmb1.setModel(new DefaultComboBoxModel(FastaExport.ExportType.getPossibilities()));

        proteinExportCmb2.setModel(new DefaultComboBoxModel(FastaExport.ExportType.getPossibilities()));

        javax.swing.GroupLayout proteinsPanelLayout = new javax.swing.GroupLayout(proteinsPanel);
        proteinsPanel.setLayout(proteinsPanelLayout);
        proteinsPanelLayout.setHorizontalGroup(
            proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(proteinsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(exportAllIdentifiedProteinAccessionsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exportAllIdentifiedProteinsAsFastaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(proteinExportCmb2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(proteinExportCmb1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(exportIdentifiedProteinAccessionNumbersAsCsvButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(exportIdentifiedProteinsAsFastaButton, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                .addContainerGap())
        );
        proteinsPanelLayout.setVerticalGroup(
            proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(proteinsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exportAllIdentifiedProteinAccessionsLabel)
                    .addComponent(exportIdentifiedProteinAccessionNumbersAsCsvButton)
                    .addComponent(proteinExportCmb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(proteinsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exportAllIdentifiedProteinsAsFastaLabel)
                    .addComponent(exportIdentifiedProteinsAsFastaButton)
                    .addComponent(proteinExportCmb2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        graphDatabasesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Graph Databases"));
        graphDatabasesPanel.setOpaque(false);

        graphDatabasesLabel.setText("Database Format");

        graphDatabaseFormat.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cytoscape", "Gephi", "Neo4j" }));

        graphDatabasetButton.setText("Export Database");
        graphDatabasetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graphDatabasetButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout graphDatabasesPanelLayout = new javax.swing.GroupLayout(graphDatabasesPanel);
        graphDatabasesPanel.setLayout(graphDatabasesPanelLayout);
        graphDatabasesPanelLayout.setHorizontalGroup(
            graphDatabasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(graphDatabasesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(graphDatabasesLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graphDatabaseFormat, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(graphDatabasetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        graphDatabasesPanelLayout.setVerticalGroup(
            graphDatabasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(graphDatabasesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(graphDatabasesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(graphDatabaseFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(graphDatabasesLabel)
                    .addComponent(graphDatabasetButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        swathPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("SWATH Library (beta)"));
        swathPanel.setOpaque(false);

        swathButton.setText("Export as TXT");
        swathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                swathButtonActionPerformed(evt);
            }
        });

        psmSelectionComboBoxSwath.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Validated PSMs of Validated Peptides of Validated Proteins", "Validated PSMs of Validated Peptides", "Validated PSMs", "Validated PSMs Containing Confidently Localized PTMs" }));

        swathExportLabel.setText("Text Export");
        swathExportLabel.setToolTipText("Click for Progenesis LC-MS export help");

        javax.swing.GroupLayout swathPanelLayout = new javax.swing.GroupLayout(swathPanel);
        swathPanel.setLayout(swathPanelLayout);
        swathPanelLayout.setHorizontalGroup(
            swathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, swathPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swathExportLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(psmSelectionComboBoxSwath, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(swathButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        swathPanelLayout.setVerticalGroup(
            swathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swathPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(swathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(psmSelectionComboBoxSwath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(swathButton)
                    .addComponent(swathExportLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
        backgroundPanel.setLayout(backgroundPanelLayout);
        backgroundPanelLayout.setHorizontalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(inclusionListPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(progenesisPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(proteinsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(spectraPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(graphDatabasesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(swathPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        backgroundPanelLayout.setVerticalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(spectraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(proteinsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(progenesisPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graphDatabasesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inclusionListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(swathPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Export the given spectra as an mgf file.
     *
     * @param evt
     */
    private void exportMgfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportMgfButtonActionPerformed

        final File selectedFolder = Util.getUserSelectedFolder(this, "Select Output Folder", peptideShakerGUI.getLastSelectedFolder(), "Output Folder", "Select", false);

        if (selectedFolder != null) {

            peptideShakerGUI.setLastSelectedFolder(selectedFolder.getAbsolutePath());

            progressDialog = new ProgressDialogX(this, peptideShakerGUI,
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")),
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")),
                    true);
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting Spectra. Please Wait...");

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

            new Thread("SaveThread") {
                @Override
                public void run() {

                    try {
                        SpectrumExporter spectrumExporter = new SpectrumExporter(peptideShakerGUI.getIdentification());
                        spectrumExporter.exportSpectra(selectedFolder, progressDialog, SpectrumExporter.ExportType.getTypeFromIndex(spectrumValidationCmb.getSelectedIndex()), peptideShakerGUI.getSequenceMatchingPreferences());

                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();

                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "Spectra saved to " + selectedFolder.getAbsolutePath() + ".", "Save Complete", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "An error occurred when saving the file.", "Saving Failed", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }.start();
        }
    }//GEN-LAST:event_exportMgfButtonActionPerformed

    /**
     * Export the inclusion list to file.
     *
     * @param evt
     */
    private void inclusionListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inclusionListButtonActionPerformed
        new InclusionListExportDialog(this, InclusionListExport.ExportFormat.getTypeFromIndex(inclusionListFormat.getSelectedIndex()), true);
    }//GEN-LAST:event_inclusionListButtonActionPerformed

    /**
     * Export the Spectrum IDs as a Phenyx tab separated text file for input to
     * Progenesis. Only works if the mgf files came from Progenesis in the first
     * place.
     *
     * @param evt
     */
    private void exportProgenesisButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportProgenesisButtonActionPerformed

        final File finalOutputFile;

        if (psmSelectionComboBox.getSelectedIndex() == 4) {
            finalOutputFile = peptideShakerGUI.getUserSelectedFile(".xls", "(Excel Workbook) *.xls", "Select Destination File", false);
        } else {
            finalOutputFile = peptideShakerGUI.getUserSelectedFile(".txt", "(Tab Separated Text File) *.txt", "Select Destination File", false);
        }

        if (finalOutputFile != null) {

            progressDialog = new ProgressDialogX(this, peptideShakerGUI,
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")),
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")),
                    true);
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting PSMs. Please Wait...");

            final int userChoice = psmSelectionComboBox.getSelectedIndex();
            ArrayList<String> ptms = new ArrayList<String>();
            if (userChoice == 3) {
                PtmChooser ptmChooser = new PtmChooser(peptideShakerGUI, peptideShakerGUI.getSearchParameters().getModificationProfile().getAllNotFixedModifications(), ptms);
                if (ptmChooser.isCanceled()) {
                    return;
                }
                ptms = ptmChooser.getSelection();
            }
            final ArrayList<String> ptmSelection = ptms;

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

            new Thread("ProgenesisPsmThread") {
                @Override
                public void run() {
                    try {
                        if (psmSelectionComboBox.getSelectedIndex() == 4) {
                            ProgenesisExcelExport progenesisExcelExport = new ProgenesisExcelExport(
                                    progressDialog,
                                    peptideShakerGUI.getIdentification().getProteinIdentification(),
                                    peptideShakerGUI.getSearchParameters().getEnzyme(),
                                    peptideShakerGUI.getSequenceMatchingPreferences(),
                                    peptideShakerGUI.getIdentification(),
                                    finalOutputFile);
                            progenesisExcelExport.writeProgenesisExcelExport();
                        } else {
                            ProgenesisExport.writeProgenesisExport(finalOutputFile, peptideShakerGUI.getIdentification(),
                                    ProgenesisExport.ExportType.getTypeFromIndex(userChoice), progressDialog, ptmSelection,
                                    peptideShakerGUI.getSequenceMatchingPreferences());
                        }

                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();

                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "Results exported to \'"
                                    + finalOutputFile.getName() + "\'.", "Export Complete", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        peptideShakerGUI.catchException(e);
                    }
                }
            }.start();
        }
    }//GEN-LAST:event_exportProgenesisButtonActionPerformed

    /**
     * Export all the identified proteins to a FASTA file.
     *
     * @param evt
     */
    private void exportIdentifiedProteinsAsFastaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportIdentifiedProteinsAsFastaButtonActionPerformed
        exportFasta(false);
    }//GEN-LAST:event_exportIdentifiedProteinsAsFastaButtonActionPerformed

    /**
     * Export all the identified protein accession numbers to a tab separated
     * text file.
     *
     * @param evt
     */
    private void exportIdentifiedProteinAccessionNumbersAsCsvButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportIdentifiedProteinAccessionNumbersAsCsvButtonActionPerformed
        exportFasta(true);
    }//GEN-LAST:event_exportIdentifiedProteinAccessionNumbersAsCsvButtonActionPerformed

    /**
     * Recalibrate the spectra.
     *
     * @param evt
     */
    private void recalibrateMgfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recalibrateMgfButtonActionPerformed
        recalibrateSpectra();
    }//GEN-LAST:event_recalibrateMgfButtonActionPerformed

    /**
     * Change the cursor to a hand cursor.
     *
     * @param evt
     */
    private void exportToProgenesisLinkLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exportToProgenesisLinkLabelMouseEntered
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    }//GEN-LAST:event_exportToProgenesisLinkLabelMouseEntered

    /**
     * Change the cursor back to the default cursor.
     *
     * @param evt
     */
    private void exportToProgenesisLinkLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exportToProgenesisLinkLabelMouseExited
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_exportToProgenesisLinkLabelMouseExited

    /**
     * Open the Progenesis home page.
     *
     * @param evt
     */
    private void exportToProgenesisLinkLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exportToProgenesisLinkLabelMouseClicked
        JOptionPane.showMessageDialog(this, JOptionEditorPane.getJOptionEditorPane(
                "<a href=\"http://www.nonlinear.com/products/progenesis/lc-ms/overview/\">Progenesis</a> does not yet have a specific PeptideShaker import. In order to get the<br>"
                + "identifications back into Progenesis one therefore has to rely on the Phenyx import<br>"
                + "format, i.e., select 'Phenyx' when importing the results back into Progenesis.<br><br>"
                + "Note that converting to the 'Phenyx' format simplifies the identification results.<br><br>"
                + "If you would like to see a proper PeptideShaker import please contact <a href=\"http://www.nonlinear.com/products/progenesis/lc-ms/overview/\">Progenesis</a>."),
                "Progenesis Help", JOptionPane.WARNING_MESSAGE);
    }//GEN-LAST:event_exportToProgenesisLinkLabelMouseClicked

    /**
     * Export the data as a graph database.
     *
     * @param evt
     */
    private void graphDatabasetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphDatabasetButtonActionPerformed

        final File selectedFolder = Util.getUserSelectedFolder(this, "Select Result Folder", peptideShakerGUI.getLastSelectedFolder(), "Database Folder", "Save", false);

        if (selectedFolder != null) {

            peptideShakerGUI.setLastSelectedFolder(selectedFolder.getAbsolutePath());

            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.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting. Please Wait...");

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

            new Thread("ExportThread") {
                @Override
                public void run() {

                    // @TODO: move code below to a gui independent export option!
                    boolean exported = false;

                    // database graph formats info:
                    // cytoscape: http://cytoscape.org/manual/Cytoscape2_6Manual.html#Import Free-Format Table Files
                    // gephi: https://gephi.org/users/supported-graph-formats/spreadsheet/
                    // neo4j: http://blog.neo4j.org/2013/03/importing-data-into-neo4j-spreadsheet.html
                    // make a list of the proteins added as nodes, as to not add them more than once
                    HashSet<String> proteinsAdded = new HashSet<String>();

                    try {
                        // write the nodes
                        Writer nodeWriter = new BufferedWriter(new FileWriter(new File(selectedFolder, "nodes.txt")));
                        Writer edgeWriter = new BufferedWriter(new FileWriter(new File(selectedFolder, "edges.txt")));

                        // write the header
                        if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Cytoscape")) {
                            nodeWriter.write("id\tlabel\ttype\tvalidated\tdecoy\n");
                            edgeWriter.write("source\ttarget\tinteraction\n");
                        } else if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Gephi")) {
                            nodeWriter.write("id\tlabel\ttype\tvalidated\tdecoy\n");
                            edgeWriter.write("source\ttarget\tlabel\n");
                        } else if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                            nodeWriter.write("BEGIN\n");
                            edgeWriter.write("BEGIN\n");
                        }

                        // write the protein nodes
                        progressDialog.setTitle("Getting Protein Details. Please Wait...");
                        progressDialog.setPrimaryProgressCounterIndeterminate(true);
                        peptideShakerGUI.getIdentification().loadProteinMatches(progressDialog);
//
                        // @TODO: the below code couldn't be used as it deals with protein groups and not individual proteins
//                        progressDialog.setTitle("Writing Protein Details. Please Wait...");
//                        progressDialog.resetPrimaryProgressCounter();
//                        progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getProteinIdentification().size());
//
//                        for (String proteinKey : peptideShakerGUI.getIdentification().getProteinIdentification()) {
//                            PSParameter probabilities = new PSParameter();
//                            probabilities = (PSParameter) peptideShakerGUI.getIdentification().getProteinMatchParameter(proteinKey, probabilities);
//                            ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
//                            nodeWriter.write(proteinKey + "\t" + proteinMatch.getMainMatch() + "\tprotein" + "\t" + probabilities.isValidated() + "\t" + proteinMatch.isDecoy() + "\n"); // @TODO: add more information?
//                            progressDialog.increasePrimaryProgressCounter();
//                        }

                        // write the peptide nodes
                        progressDialog.setTitle("Getting Peptide Details. Please Wait...");
                        progressDialog.setPrimaryProgressCounterIndeterminate(true);
                        peptideShakerGUI.getIdentification().loadPeptideMatches(progressDialog);

                        progressDialog.setTitle("Writing Peptide Details. Please Wait...");
                        progressDialog.resetPrimaryProgressCounter();
                        progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getPeptideIdentification().size());

                        for (String peptideKey : peptideShakerGUI.getIdentification().getPeptideIdentification()) {

                            PeptideMatch peptideMatch = peptideShakerGUI.getIdentification().getPeptideMatch(peptideKey);
                            PSParameter probabilities = new PSParameter();
                            probabilities = (PSParameter) peptideShakerGUI.getIdentification().getPeptideMatchParameter(peptideKey, probabilities);

                            // write the peptide node
                            if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                                nodeWriter.write("create n={id:'" + peptideKey + "', name:'" + peptideMatch.getTheoreticPeptide().getTaggedModifiedSequence(peptideShakerGUI.getSearchParameters().getModificationProfile(), false, false, true, false) + "', type:'Peptide'};\n");
                            } else {
                                nodeWriter.write(peptideKey + "\t"
                                        + peptideMatch.getTheoreticPeptide().getTaggedModifiedSequence(peptideShakerGUI.getSearchParameters().getModificationProfile(), false, false, true, false)
                                        + "\tpeptide" + "\t" + probabilities.getMatchValidationLevel() + "\t" + peptideMatch.getTheoreticPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences()) + "\n"); // @TODO: add more information?
                            }

                            // write the peptide to protein edge and the protein nodes
                            for (String protein : peptideMatch.getTheoreticPeptide().getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences())) {

                                // write the protein node
                                if (!proteinsAdded.contains(protein)) {
                                    proteinsAdded.add(protein);
                                    ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(protein);
                                    if (proteinMatch != null) {
                                        probabilities = (PSParameter) peptideShakerGUI.getIdentification().getProteinMatchParameter(protein, probabilities);

                                        if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                                            nodeWriter.write("create n={id:'" + protein + "', name:'" + protein + "', type:'Protein'};\n");
                                        } else {
                                            nodeWriter.write(protein + "\t" + protein + "\tprotein" + "\t" + probabilities.getMatchValidationLevel() + "\t" + proteinMatch.isDecoy() + "\n"); // @TODO: add more information?
                                        }
                                    } else {
                                        if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                                            nodeWriter.write("create n={id:'" + protein + "', name:'" + protein + "', type:'Protein'};\n");
                                        } else {
                                            nodeWriter.write(protein + "\t" + protein + "\tprotein" + "\t" + "false" + "\t" + SequenceFactory.getInstance().isDecoyAccession(protein) + "\n"); // @TODO: add more information?
                                        }
                                    }
                                }

                                // write the peptide to protein edge
                                if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                                    edgeWriter.write("start n1=node:node_auto_index(id='" + peptideKey + "'),n2=node:node_auto_index(id='" + protein + "') create unique n1-[:MAPS_TO]->n2;\n");
                                } else {
                                    edgeWriter.write(peptideKey + "\t" + protein + "\tpeptide_to_protein\n");
                                }
                            }

                            progressDialog.increasePrimaryProgressCounter();
                        }

                        if (((String) graphDatabaseFormat.getSelectedItem()).equalsIgnoreCase("Neo4j")) {
                            nodeWriter.write("COMMIT");
                            edgeWriter.write("COMMIT");
                        }

                        // write the spectrum nodes
                        // @TODO: implement me
                        // @TODO: implement other node types
                        nodeWriter.close();
                        edgeWriter.close();

                        proteinsAdded.clear();

                        exported = true;
                    } catch (IOException e) {
                        progressDialog.setRunCanceled();
                        peptideShakerGUI.catchException(e);
                    } catch (ClassNotFoundException e) {
                        progressDialog.setRunCanceled();
                        peptideShakerGUI.catchException(e);
                    } catch (IllegalArgumentException e) {
                        progressDialog.setRunCanceled();
                        peptideShakerGUI.catchException(e);
                    } catch (SQLException e) {
                        progressDialog.setRunCanceled();
                        peptideShakerGUI.catchException(e);
                    } catch (InterruptedException e) {
                        progressDialog.setRunCanceled();
                        peptideShakerGUI.catchException(e);
                    }

                    boolean processCancelled = progressDialog.isRunCanceled();
                    progressDialog.setRunFinished();

                    if (!processCancelled) {

                        if (exported) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this,
                                    "Graph database saved to folder \'" + selectedFolder.getAbsolutePath() + "\'.",
                                    "Save Complete", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this,
                                    "An error occurred during exporting. See resources/PeptideShaker.log for details.",
                                    "Export Error", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            }.start();
        }
    }//GEN-LAST:event_graphDatabasetButtonActionPerformed

    /**
     * Exports a text file containing the information to create a swath library.
     *
     * @param evt
     */
    private void swathButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_swathButtonActionPerformed
        exportSwath();
    }//GEN-LAST:event_swathButtonActionPerformed

    /**
     * Exports a text file containing the information to create a swath library.
     */
    private void exportSwath() {

        final File finalOutputFile = peptideShakerGUI.getUserSelectedFile(".txt", "(Tab Separated Text File) *.txt", "Select Destination File", false);

        if (finalOutputFile != null) {

            progressDialog = new ProgressDialogX(this, peptideShakerGUI,
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")),
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")),
                    true);
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting PSMs. Please Wait...");

            final int userChoice = psmSelectionComboBoxSwath.getSelectedIndex();
            ArrayList<String> ptms = new ArrayList<String>();
            if (userChoice == 3) {
                PtmChooser ptmChooser = new PtmChooser(peptideShakerGUI, peptideShakerGUI.getSearchParameters().getModificationProfile().getAllNotFixedModifications(), ptms);
                if (ptmChooser.isCanceled()) {
                    return;
                }
                ptms = ptmChooser.getSelection();
            }
            final ArrayList<String> ptmSelection = ptms;

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

            new Thread("ProgenesisPsmThread") {
                @Override
                public void run() {
                    try {
                        SwathExport.writeSwathExport(finalOutputFile, peptideShakerGUI.getIdentification(), SwathExport.ExportType.getTypeFromIndex(userChoice),
                                progressDialog, ptmSelection, peptideShakerGUI.getAnnotationPreferences(), peptideShakerGUI.getSequenceMatchingPreferences());

                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();

                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "Results exported to \'"
                                    + finalOutputFile.getName() + "\'.", "Export Complete", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        peptideShakerGUI.catchException(e);
                    }
                }
            }.start();
        }
    }

    /**
     * Export proteins.
     *
     * @param accessionsOnly if true, only accession numbers are exported
     */
    private void exportFasta(boolean accessionsOnly) {

        // get the file to send the output to
        final File selectedFile;
        if (accessionsOnly) {
            selectedFile = peptideShakerGUI.getUserSelectedFile(".txt", "Supported formats: text format (.txt)", "Select Destination File", false);
        } else {
            selectedFile = peptideShakerGUI.getUserSelectedFile(".fasta", "Supported formats: FASTA format (.fasta)", "Select Destination File", false);
        }
        final boolean finalAccessionsOnly = accessionsOnly;

        if (selectedFile != null) {

            progressDialog = new ProgressDialogX(this, peptideShakerGUI,
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")),
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")),
                    true);
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting. Please Wait...");

            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 {
                        FastaExport.ExportType exportType;
                        if (finalAccessionsOnly) {
                            exportType = FastaExport.ExportType.getTypeFromIndex(proteinExportCmb1.getSelectedIndex());
                        } else {
                            exportType = FastaExport.ExportType.getTypeFromIndex(proteinExportCmb2.getSelectedIndex());
                        }
                        SequenceFactory sequenceFactory = SequenceFactory.getInstance();
                        IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();

                        progressDialog.setPrimaryProgressCounterIndeterminate(false);
                        if (exportType == FastaExport.ExportType.non_validated) {
                            progressDialog.setMaxPrimaryProgressCounter(sequenceFactory.getAccessions().size());
                        } else {
                            progressDialog.setMaxPrimaryProgressCounter(identificationFeaturesGenerator.getNValidatedProteins());
                        }

                        FastaExport.export(selectedFile, peptideShakerGUI.getIdentification(), identificationFeaturesGenerator, exportType, progressDialog, peptideShakerGUI.getFilterPreferences(), finalAccessionsOnly);

                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();

                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "Identified proteins exported to "
                                    + selectedFile.getPath() + ".", "Export Complete", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(FollowupPreferencesDialog.this, "An error occurred when exporting the data.", "Export Failed", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }.start();
        }
    }

    /**
     * Lets the user select an output folder and starts the recalibration of
     * spectra.
     */
    public void recalibrateSpectra() {

        final File selectedFolder = Util.getUserSelectedFolder(this, "Select Output Folder", peptideShakerGUI.getLastSelectedFolder(), "Output Folder", "Select", false);

        if (selectedFolder != null) {

            peptideShakerGUI.setLastSelectedFolder(selectedFolder.getAbsolutePath());

            SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
            for (String fileName : spectrumFactory.getMgfFileNames()) {
                String newName = RecalibrationExporter.getRecalibratedFileName(fileName);
                File testFile = new File(selectedFolder, newName);
                if (testFile.exists()) {
                    int outcome = JOptionPane.showConfirmDialog(this,
                            "File(s) already exist, shall it be overwritten?", "Selected File(s) Already Exists",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (outcome != JOptionPane.YES_OPTION) {
                        return;
                    } else {
                        break;
                    }
                }
            }

            progressDialog = new ProgressDialogX(this, peptideShakerGUI,
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")),
                    Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")),
                    true);
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            progressDialog.setTitle("Exporting. Please Wait...");

            int selection = spectrumRecalibrationCmb.getSelectedIndex();
            final boolean precursors = selection == 0 || selection == 1;
            final boolean fragments = selection == 0 || selection == 2;

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

            new Thread("SaveThread") {
                @Override
                public void run() {
                    try {
                        RecalibrationExporter.writeRecalibratedSpectra(precursors, fragments, selectedFolder,
                                peptideShakerGUI.getIdentification(), peptideShakerGUI.getAnnotationPreferences(), progressDialog);

                        boolean processCancelled = progressDialog.isRunCanceled();
                        progressDialog.setRunFinished();

                        if (!processCancelled) {
                            JOptionPane.showMessageDialog(FollowupPreferencesDialog.this,
                                    "Recalibrated spectra saved to " + selectedFolder.getAbsolutePath() + ".", "Save Complete", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        peptideShakerGUI.catchException(e);
                    } finally {
                        progressDialog.setRunFinished();
                    }
                }
            }.start();
        }
    }

    /**
     * Returns the references to the PeptideShakerGUI.
     *
     * @return the references to the PeptideShakerGUI
     */
    public PeptideShakerGUI getPeptideShakerGUI() {
        return peptideShakerGUI;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel backgroundPanel;
    private javax.swing.JLabel exportAllIdentifiedProteinAccessionsLabel;
    private javax.swing.JLabel exportAllIdentifiedProteinsAsFastaLabel;
    private javax.swing.JButton exportIdentifiedProteinAccessionNumbersAsCsvButton;
    private javax.swing.JButton exportIdentifiedProteinsAsFastaButton;
    private javax.swing.JButton exportMgfButton;
    private javax.swing.JButton exportProgenesisButton;
    private javax.swing.JLabel exportSpectraLabel;
    private javax.swing.JLabel exportToProgenesisLinkLabel;
    private javax.swing.JComboBox graphDatabaseFormat;
    private javax.swing.JLabel graphDatabasesLabel;
    private javax.swing.JPanel graphDatabasesPanel;
    private javax.swing.JButton graphDatabasetButton;
    private javax.swing.JLabel includeValidatedPsmsLabel;
    private javax.swing.JButton inclusionListButton;
    private javax.swing.JComboBox inclusionListFormat;
    private javax.swing.JPanel inclusionListPanel;
    private javax.swing.JPanel progenesisPanel;
    private javax.swing.JComboBox proteinExportCmb1;
    private javax.swing.JComboBox proteinExportCmb2;
    private javax.swing.JPanel proteinsPanel;
    private javax.swing.JComboBox psmSelectionComboBox;
    private javax.swing.JComboBox psmSelectionComboBoxSwath;
    private javax.swing.JButton recalibrateMgfButton;
    private javax.swing.JLabel recalibrateSpectraLabel;
    private javax.swing.JPanel spectraPanel;
    private javax.swing.JComboBox spectrumRecalibrationCmb;
    private javax.swing.JComboBox spectrumValidationCmb;
    private javax.swing.JButton swathButton;
    private javax.swing.JLabel swathExportLabel;
    private javax.swing.JPanel swathPanel;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of eu.isas.peptideshaker.gui.exportdialogs.FollowupPreferencesDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.