Search in sources :

Example 11 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class OverviewPanel method updatePsmSelection.

/**
 * Update the PSM selection according to the currently selected peptide.
 *
 * @param row the row index of the selected peptide
 * @param forcePsmOrderUpdate if true, the sorted listed is recreated even
 * if not needed
 */
private void updatePsmSelection(int row, boolean forcePsmOrderUpdate) {
    if (row != -1) {
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        Identification identification = peptideShakerGUI.getIdentification();
        IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
        SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) peptideTable.getModel();
        int peptideIndex = tableModel.getViewIndex(row);
        long peptideKey = peptideKeys[peptideIndex];
        psmKeys = identificationFeaturesGenerator.getSortedPsmKeys(peptideKey, peptideShakerGUI.getUtilitiesUserParameters().getSortPsmsOnRt(), forcePsmOrderUpdate);
        // clear the selection in case more than one row was selected for the last peptide
        psmTable.clearSelection();
        // update the table model
        if (psmTable.getModel() instanceof PsmTableModel && ((PsmTableModel) psmTable.getModel()).isInstantiated()) {
            ((PsmTableModel) psmTable.getModel()).updateDataModel(identification, peptideShakerGUI.getDisplayFeaturesGenerator(), peptideShakerGUI.getIdentificationParameters(), psmKeys);
            ((PsmTableModel) psmTable.getModel()).setSelfUpdating(true);
            ((PsmTableModel) psmTable.getModel()).resetSorting(new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true));
        } else {
            PsmTableModel psmTableModel = new PsmTableModel(identification, peptideShakerGUI.getDisplayFeaturesGenerator(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getIdentificationParameters(), psmKeys, peptideShakerGUI.getDisplayParameters().showScores(), peptideShakerGUI.getExceptionHandler());
            psmTable.setModel(psmTableModel);
        }
        setPsmTableProperties();
        showSparkLines(peptideShakerGUI.showSparklines());
        int nValidatedPsms = identificationFeaturesGenerator.getNValidatedSpectraForPeptide(peptideKey);
        int nConfidentPsms = identificationFeaturesGenerator.getNConfidentSpectraForPeptide(peptideKey);
        int nPsms = psmTable.getRowCount();
        String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Peptide Spectrum Matches (";
        if (nConfidentPsms > 0) {
            title += nValidatedPsms + "/" + nPsms + " - " + nConfidentPsms + " confident, " + (nValidatedPsms - nConfidentPsms) + " doubtful";
        } else {
            title += nValidatedPsms + "/" + nPsms;
        }
        title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
        ((TitledBorder) psmsPanel.getBorder()).setTitle(title);
        psmsPanel.repaint();
        updateSelection(true);
        newItemSelection();
        // update the sequence coverage map
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    int proteinIndex, selectedProteinRow = proteinTable.getSelectedRow();
                    if (selectedProteinRow != -1) {
                        SelfUpdatingTableModel proteinTableModel = (SelfUpdatingTableModel) proteinTable.getModel();
                        proteinIndex = proteinTableModel.getViewIndex(selectedProteinRow);
                    } else {
                        proteinIndex = 0;
                    }
                    long proteinKey = proteinKeys[proteinIndex];
                    ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
                    updateSequenceCoverage(proteinKey, proteinMatch.getLeadingAccession());
                } catch (Exception e) {
                    peptideShakerGUI.catchException(e);
                }
            }
        });
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}
Also used : PsmTableModel(eu.isas.peptideshaker.gui.tablemodels.PsmTableModel) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) Identification(com.compomics.util.experiment.identification.Identification) TitledBorder(javax.swing.border.TitledBorder) FileNotFoundException(java.io.FileNotFoundException) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) SelfUpdatingTableModel(com.compomics.util.gui.tablemodels.SelfUpdatingTableModel) java.awt(java.awt)

Example 12 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class ProteinStructurePanel method updatedPeptideSelection.

/**
 * Updates the peptide selection according to the currently selected
 * protein.
 *
 * @param proteinIndex the row index of the protein
 */
private void updatedPeptideSelection(int proteinIndex) {
    if (proteinIndex != -1) {
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        DefaultTableModel dm = (DefaultTableModel) peptideTable.getModel();
        dm.getDataVector().removeAllElements();
        dm.fireTableDataChanged();
        long proteinMatchKey = proteinKeys[proteinIndex];
        ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinMatchKey);
        String proteinAccession = proteinMatch.getLeadingAccession();
        peptideTableMap = new HashMap<>();
        int index = 0;
        long[] peptideKeys = peptideShakerGUI.getIdentificationFeaturesGenerator().getSortedPeptideKeys(proteinMatchKey);
        for (long peptideKey : peptideKeys) {
            PeptideMatch peptideMatch = peptideShakerGUI.getIdentification().getPeptideMatch(peptideKey);
            PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            if (!psParameter.getHidden()) {
                // find and add the peptide start and end indexes
                StartIndexes startIndexes = new StartIndexes(Arrays.stream(peptideMatch.getPeptide().getProteinMapping().get(proteinAccession)).map(site -> site + 1).boxed().collect(Collectors.toCollection(ArrayList::new)));
                int proteinInferenceType = psParameter.getProteinInferenceGroupClass();
                // @TODO: should be replaced by a table model!!!
                ((DefaultTableModel) peptideTable.getModel()).addRow(new Object[] { index + 1, psParameter.getStarred(), proteinInferenceType, peptideShakerGUI.getDisplayFeaturesGenerator().getTaggedPeptideSequence(peptideMatch, true, true, true), startIndexes, false, psParameter.getMatchValidationLevel().getIndex() });
                peptideTableMap.put(index + 1, peptideKey);
                index++;
            }
        }
        ((DefaultTableModel) peptideTable.getModel()).fireTableDataChanged();
        String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Peptides (";
        IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
        int nValidatedPeptides = identificationFeaturesGenerator.getNValidatedPeptides(proteinMatchKey);
        int nConfidentPeptides = identificationFeaturesGenerator.getNConfidentPeptides(proteinMatchKey);
        int nPeptides = proteinMatch.getPeptideCount();
        if (nConfidentPeptides > 0) {
            title += nValidatedPeptides + "/" + nPeptides + " - " + nConfidentPeptides + " confident, " + (nValidatedPeptides - nConfidentPeptides) + " doubtful";
        } else {
            title += nValidatedPeptides + "/" + nPeptides;
        }
        title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
        ((TitledBorder) peptidesPanel.getBorder()).setTitle(title);
        peptidesPanel.repaint();
        String proteinSequence = peptideShakerGUI.getSequenceProvider().getSequence(proteinAccession);
        peptideTable.getColumn("Start").setCellRenderer(new JSparklinesMultiIntervalChartTableCellRenderer(PlotOrientation.HORIZONTAL, (double) proteinSequence.length(), ((double) proteinSequence.length()) / 50, peptideShakerGUI.getSparklineColor()));
        ((JSparklinesMultiIntervalChartTableCellRenderer) peptideTable.getColumn("Start").getCellRenderer()).showReferenceLine(true, 0.02, Color.BLACK);
        ((JSparklinesMultiIntervalChartTableCellRenderer) peptideTable.getColumn("Start").getCellRenderer()).showNumberAndChart(true, TableProperties.getLabelWidth() - 10);
        // select the peptide in the table
        if (peptideTable.getRowCount() > 0) {
            int peptideRow = 0;
            long peptideKey = peptideShakerGUI.getSelectedPeptideKey();
            if (peptideKey != NO_KEY) {
                peptideRow = getPeptideRow(peptideKey);
            }
            if (peptideRow != -1) {
                peptideTable.setRowSelectionInterval(peptideRow, peptideRow);
                peptideTable.scrollRectToVisible(peptideTable.getCellRect(peptideRow, 0, false));
                peptideTableKeyReleased(null);
            }
        }
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}
Also used : Color(java.awt.Color) PsPeptideFeature(com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature) PsProteinFeature(com.compomics.util.io.export.features.peptideshaker.PsProteinFeature) Arrays(java.util.Arrays) JSparklinesArrayListBarChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesArrayListBarChartTableCellRenderer) NO_KEY(com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter) BareBonesBrowserLaunch(com.compomics.util.examples.BareBonesBrowserLaunch) JSparklinesBarChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesBarChartTableCellRenderer) FileChooserUtil(com.compomics.util.gui.file_handling.FileChooserUtil) JTableHeader(javax.swing.table.JTableHeader) ProteinInferencePeptideLevelDialog(eu.isas.peptideshaker.gui.protein_inference.ProteinInferencePeptideLevelDialog) PeptideShakerGUI(eu.isas.peptideshaker.gui.PeptideShakerGUI) MouseAdapter(java.awt.event.MouseAdapter) TitledBorder(javax.swing.border.TitledBorder) JSparklinesIntegerIconTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntegerIconTableCellRenderer) TableProperties(com.compomics.util.gui.TableProperties) SpectrumCountingMethod(com.compomics.util.experiment.quantification.spectrumcounting.SpectrumCountingMethod) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) TableModelEvent(javax.swing.event.TableModelEvent) ExportScheme(com.compomics.util.io.export.ExportScheme) DefaultTableModel(javax.swing.table.DefaultTableModel) TrueFalseIconRenderer(no.uib.jsparklines.extra.TrueFalseIconRenderer) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PSExportFactory(eu.isas.peptideshaker.export.PSExportFactory) SelfUpdatingTableModel(com.compomics.util.gui.tablemodels.SelfUpdatingTableModel) Util(com.compomics.util.Util) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) GuiUtilities(com.compomics.util.gui.GuiUtilities) DisplayParameters(eu.isas.peptideshaker.preferences.DisplayParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) Dimension(java.awt.Dimension) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) Graphics(java.awt.Graphics) Toolkit(java.awt.Toolkit) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) FindPdbForUniprotAccessions(com.compomics.util.pdbfinder.FindPdbForUniprotAccessions) HelpDialog(com.compomics.util.gui.error_handlers.HelpDialog) PdbParameter(com.compomics.util.pdbfinder.pdb.PdbParameter) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) PlotOrientation(org.jfree.chart.plot.PlotOrientation) TableModelListener(javax.swing.event.TableModelListener) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) JSparklinesIntervalChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntervalChartTableCellRenderer) JSparklinesMultiIntervalChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesMultiIntervalChartTableCellRenderer) JSparklinesIntegerColorTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntegerColorTableCellRenderer) XYPlottingDialog(com.compomics.util.gui.XYPlottingDialog) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinTableModel(eu.isas.peptideshaker.gui.tablemodels.ProteinTableModel) JmolAdapter(org.jmol.api.JmolAdapter) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) ProteinInferenceDialog(eu.isas.peptideshaker.gui.protein_inference.ProteinInferenceDialog) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) ExportFeature(com.compomics.util.io.export.ExportFeature) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) JmolViewer(org.jmol.api.JmolViewer) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ExportGraphicsDialog(com.compomics.util.gui.export.graphics.ExportGraphicsDialog) PdbBlock(com.compomics.util.pdbfinder.pdb.PdbBlock) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ExportFormat(com.compomics.util.io.export.ExportFormat) HtmlLinksRenderer(no.uib.jsparklines.extra.HtmlLinksRenderer) SmarterJmolAdapter(org.jmol.adapter.smarter.SmarterJmolAdapter) GeneDetailsDialog(com.compomics.util.gui.genes.GeneDetailsDialog) StartIndexes(no.uib.jsparklines.data.StartIndexes) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) javax.swing(javax.swing) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) StartIndexes(no.uib.jsparklines.data.StartIndexes) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) TitledBorder(javax.swing.border.TitledBorder) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) JSparklinesMultiIntervalChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesMultiIntervalChartTableCellRenderer) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 13 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class PsdbParent method loadPsdbFile.

/**
 * Loads the information from a psdb file.
 *
 * @param dbFolder the folder where to untar the project
 * @param waitingHandler a waiting handler displaying feedback to the user.
 * Ignored if null
 * @param openFromZip flag determining if pdsb file was opened from a zip
 * file
 *
 * @throws IOException thrown of IOException occurs exception thrown
 * whenever an error occurred while reading or writing a file
 */
public void loadPsdbFile(File dbFolder, WaitingHandler waitingHandler, boolean openFromZip) throws IOException {
    // close any open connection to an identification database
    if (identification != null) {
        identification.close(false);
    }
    // create the matches folder if it does not exist
    if (!dbFolder.exists()) {
        if (!dbFolder.mkdirs()) {
            throw new IOException("Impossible to create folder " + dbFolder.getAbsolutePath() + ".");
        }
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String dbName = "tempDB-" + df.format(new Date()) + ".psdb";
    File destinationFile = new File(dbFolder.getAbsolutePath(), dbName);
    IoUtil.copyFile(psdbFile, destinationFile);
    // GzUtils.gunzipFile(psdbFile, destinationFile, false); // @TODO: re-add when the zipping works
    ObjectsDB objectsDB = new ObjectsDB(dbFolder.getAbsolutePath(), destinationFile.getName(), false);
    // get the PeptideShaker parameters
    PeptideShakerParameters psParameters = (PeptideShakerParameters) objectsDB.retrieveObject(PeptideShakerParameters.KEY);
    identificationParameters = psParameters.getIdentificationParameters();
    spectrumCountingParameters = psParameters.getSpectrumCountingPreferences();
    projectDetails = psParameters.getProjectDetails();
    metrics = psParameters.getMetrics();
    geneMaps = psParameters.getGeneMaps();
    filterParameters = psParameters.getFilterParameters();
    displayParameters = psParameters.getDisplayParameters();
    sequenceProvider = psParameters.getSequenceProvider();
    proteinDetailsProvider = psParameters.getProteinDetailsProvider();
    projectType = psParameters.getProjectType();
    // find or create the fm index
    FMIndex fmIndex = null;
    if (openFromZip) {
        File fmPath = new File(Paths.get(psdbFile.getParentFile().getAbsolutePath(), "data").toString());
        for (File file : fmPath.listFiles()) {
            if (file.getAbsoluteFile().toString().toLowerCase().endsWith(".fasta")) {
                fmIndex = new FMIndex(file, psParameters.getIdentificationParameters().getFastaParameters(), waitingHandler, true, psParameters.getIdentificationParameters().getPeptideVariantsParameters(), psParameters.getIdentificationParameters().getSearchParameters());
                break;
            }
        }
    } else {
        boolean fastaFileFound = false;
        try {
            FastaSummary fastaSummary = loadFastaFile(waitingHandler);
            if (fastaSummary != null) {
                fastaFileFound = true;
            }
        } catch (IOException e) {
            fastaFileFound = false;
        }
        if (fastaFileFound) {
            File fastaFile = new File(psParameters.getProjectDetails().getFastaFile());
            fmIndex = new FMIndex(fastaFile, psParameters.getIdentificationParameters().getFastaParameters(), waitingHandler, true, psParameters.getIdentificationParameters().getPeptideVariantsParameters(), psParameters.getIdentificationParameters().getSearchParameters());
        } else {
            throw new IOException("FASTA file not found " + psParameters.getProjectDetails().getFastaFile() + ".");
        }
    }
    psParameters.setSequenceProvider(fmIndex);
    psParameters.setProteinDetailsProvider(fmIndex);
    sequenceProvider = fmIndex;
    proteinDetailsProvider = fmIndex;
    objectsDB.updateObject(PeptideShakerParameters.KEY, psParameters);
    projectParameters = (ProjectParameters) objectsDB.retrieveObject(ProjectParameters.key);
    identification = new Identification(objectsDB);
    // load identification attributes
    IdentificationKeys identificationKeys = (IdentificationKeys) objectsDB.retrieveObject(IdentificationKeys.KEY);
    identification.setIdentificationKeys(identificationKeys);
    PSMaps psMaps = new PSMaps();
    psMaps = (PSMaps) objectsDB.retrieveObject(psMaps.getParameterKey());
    identification.addUrParam(psMaps);
    // set up the spectrum provider
    msFileHandler = new MsFileHandler();
    // set up caches
    identificationFeaturesGenerator = new IdentificationFeaturesGenerator(identification, identificationParameters, sequenceProvider, msFileHandler, metrics, spectrumCountingParameters);
    IdentificationFeaturesCache identificationFeaturesCache = psParameters.getIdentificationFeaturesCache();
    if (identificationFeaturesCache != null) {
        identificationFeaturesGenerator.setIdentificationFeaturesCache(psParameters.getIdentificationFeaturesCache());
        identificationFeaturesCache.setReadOnly(false);
    }
    if (waitingHandler != null && waitingHandler.isRunCanceled()) {
        waitingHandler.setRunFinished();
        return;
    }
    loadUserParameters();
    userPreferences.addRecentProject(psdbFile);
    saveUserParameters();
}
Also used : IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) IdentificationKeys(com.compomics.util.experiment.identification.IdentificationKeys) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) IdentificationFeaturesCache(com.compomics.util.experiment.identification.features.IdentificationFeaturesCache) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) Date(java.util.Date) ObjectsDB(com.compomics.util.db.object.ObjectsDB) FMIndex(com.compomics.util.experiment.identification.protein_inference.fm_index.FMIndex) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) PeptideShakerParameters(eu.isas.peptideshaker.parameters.PeptideShakerParameters) MsFileHandler(com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)

Example 14 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class MatchesValidator method validateIdentifications.

/**
 * This method validates the identification matches of an identification
 * object. Target Decoy thresholds must be set.
 *
 * @param identification The identification class containing the matches to
 * validate.
 * @param metrics If provided, metrics on fractions will be saved while
 * iterating the matches.
 * @param geneMaps The gene maps.
 * @param inputMap The target decoy map of all search engine scores.
 * @param waitingHandler The waiting handler displaying progress to the user
 * and allowing canceling the process.
 * @param exceptionHandler The handler for exceptions.
 * @param identificationFeaturesGenerator The identification features
 * generator computing information about the identification matches.
 * @param sequenceProvider The protein sequence provider.
 * @param proteinDetailsProvider The protein details provider.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param projectType The project type.
 * @param processingParameters The processing parameters.
 *
 * @throws java.lang.InterruptedException exception thrown if a thread gets
 * interrupted
 * @throws java.util.concurrent.TimeoutException exception thrown if the
 * operation times out
 */
public void validateIdentifications(Identification identification, Metrics metrics, InputMap inputMap, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, GeneMaps geneMaps, IdentificationParameters identificationParameters, ProjectType projectType, ProcessingParameters processingParameters) throws InterruptedException, TimeoutException {
    IdMatchValidationParameters validationParameters = identificationParameters.getIdValidationParameters();
    waitingHandler.setWaitingText("Finding FDR Thresholds. Please Wait...");
    for (int algorithm : inputMap.getInputAlgorithms()) {
        TargetDecoyMap targetDecoyMap = inputMap.getTargetDecoyMap(algorithm);
        TargetDecoyResults currentResults = targetDecoyMap.getTargetDecoyResults();
        currentResults.setInputType(1);
        currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
        currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
        targetDecoyMap.getTargetDecoySeries().getFDRResults(currentResults);
    }
    TargetDecoyResults currentResults = psmMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
    psmMap.getTargetDecoySeries().getFDRResults(currentResults);
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    currentResults = peptideMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultPeptideFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultPeptideFDR());
    peptideMap.getTargetDecoySeries().getFDRResults(currentResults);
    currentResults = proteinMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultProteinFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultProteinFDR());
    proteinMap.getTargetDecoySeries().getFDRResults(currentResults);
    ValidationQcParameters validationQCParameters = validationParameters.getValidationQCParameters();
    waitingHandler.setWaitingText("Match Validation and Quality Control. Please Wait...");
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.resetSecondaryProgressCounter();
    waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size() + identification.getPeptideIdentification().size() + 2 * identification.getSpectrumIdentificationSize());
    // validate the spectrum matches
    if (inputMap != null) {
        inputMap.resetAdvocateContributions();
    }
    AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
    double intensityLimit = annotationParameters.getAnnotationIntensityLimit();
    annotationParameters.setIntensityLimit(0);
    ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    ArrayList<PsmValidatorRunnable> psmRunnables = new ArrayList<>(processingParameters.getnThreads());
    for (int i = 1; i <= processingParameters.getnThreads(); i++) {
        PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, false, true);
        pool.submit(runnable);
        psmRunnables.add(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
    }
    // combine the precursor mz deviations from the different threads into one map
    HashMap<String, ArrayList<Double>> precursorMzDeviations = new HashMap<>(identification.getSpectrumIdentification().size());
    for (PsmValidatorRunnable runnable : psmRunnables) {
        for (String spectrumFileName : runnable.getThreadPrecursorMzDeviations().keySet()) {
            ArrayList<Double> threadPrecursorMzDeviations = runnable.getThreadPrecursorMzDeviations().get(spectrumFileName);
            ArrayList<Double> filePrecursorMzDeviations = precursorMzDeviations.get(spectrumFileName);
            if (filePrecursorMzDeviations != null) {
                filePrecursorMzDeviations.addAll(threadPrecursorMzDeviations);
            } else {
                precursorMzDeviations.put(spectrumFileName, threadPrecursorMzDeviations);
            }
        }
    }
    for (String spectrumFileName : precursorMzDeviations.keySet()) {
        double[] precursorMzDeviationsFile = precursorMzDeviations.get(spectrumFileName).stream().mapToDouble(a -> a).toArray();
        if (precursorMzDeviationsFile.length >= 100) {
            Arrays.sort(precursorMzDeviationsFile);
            identificationFeaturesGenerator.setMassErrorDistribution(spectrumFileName, precursorMzDeviationsFile);
        } else {
            // There are not enough precursors, disable probabilistic precursor filter
            if (validationQCParameters.getPsmFilters() != null) {
                for (Filter filter : validationQCParameters.getPsmFilters()) {
                    PsmFilter psmFilter = (PsmFilter) filter;
                    if (psmFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
                        psmFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
                        SearchParameters searchParameters = identificationParameters.getSearchParameters();
                        if (searchParameters.isPrecursorAccuracyTypePpm()) {
                            psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        } else {
                            psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        }
                    }
                    AssumptionFilter assumptionFilter = psmFilter.getAssumptionFilter();
                    if (assumptionFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
                        assumptionFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
                        SearchParameters searchParameters = identificationParameters.getSearchParameters();
                        if (searchParameters.isPrecursorAccuracyTypePpm()) {
                            assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        } else {
                            assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        }
                    }
                }
            }
        }
    }
    pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    for (int i = 1; i <= processingParameters.getnThreads(); i++) {
        PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, true, false);
        pool.submit(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
    }
    annotationParameters.setIntensityLimit(intensityLimit);
    if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
        // validate the peptides
        pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
        ArrayList<PeptideValidatorRunnable> peptideRunnables = new ArrayList<>(processingParameters.getnThreads());
        PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(waitingHandler);
        for (int i = 1; i <= processingParameters.getnThreads(); i++) {
            PeptideValidatorRunnable runnable = new PeptideValidatorRunnable(peptideMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, metrics);
            pool.submit(runnable);
            peptideRunnables.add(runnable);
        }
        if (waitingHandler.isRunCanceled()) {
            pool.shutdownNow();
            return;
        }
        pool.shutdown();
        if (!pool.awaitTermination(identification.getPeptideIdentification().size(), TimeUnit.MINUTES)) {
            throw new InterruptedException("Peptide matches validation timed out. Please contact the developers.");
        }
        HashMap<String, Integer> validatedTotalPeptidesPerFraction = new HashMap<>();
        ArrayList<Double> validatedPeptideLengths = new ArrayList<>();
        for (PeptideValidatorRunnable runnable : peptideRunnables) {
            HashMap<String, Integer> threadValidatedTotalPeptidesPerFraction = runnable.getValidatedTotalPeptidesPerFraction();
            for (String fraction : threadValidatedTotalPeptidesPerFraction.keySet()) {
                Integer nValidated = validatedTotalPeptidesPerFraction.get(fraction);
                if (nValidated == null) {
                    nValidated = 0;
                }
                nValidated += threadValidatedTotalPeptidesPerFraction.get(fraction);
                validatedTotalPeptidesPerFraction.put(fraction, nValidated);
            }
            validatedPeptideLengths.addAll(runnable.getValidatedPeptideLengths());
        }
        if (validatedPeptideLengths.size() >= 100) {
            NonSymmetricalNormalDistribution lengthDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(validatedPeptideLengths);
            metrics.setPeptideLengthDistribution(lengthDistribution);
        }
        metrics.setTotalPeptidesPerFraction(validatedTotalPeptidesPerFraction);
        if (projectType == ProjectType.protein) {
            // validate the proteins
            pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
            ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(waitingHandler);
            ArrayList<ProteinValidatorRunnable> proteinRunnables = new ArrayList<>(processingParameters.getnThreads());
            for (int i = 1; i <= processingParameters.getnThreads(); i++) {
                ProteinValidatorRunnable runnable = new ProteinValidatorRunnable(proteinMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, metrics, identificationParameters, waitingHandler, exceptionHandler);
                pool.submit(runnable);
                proteinRunnables.add(runnable);
            }
            if (waitingHandler.isRunCanceled()) {
                pool.shutdownNow();
                return;
            }
            pool.shutdown();
            if (!pool.awaitTermination(identification.getProteinIdentification().size(), TimeUnit.MINUTES)) {
                throw new InterruptedException("Protein matches validation timed out. Please contact the developers.");
            }
            long[] validatedTargetProteinKeys = proteinRunnables.stream().flatMap(runnable -> runnable.getValidatedProteinMatches().stream()).mapToLong(a -> a).toArray();
            metrics.setValidatedTargetProteinKeys(validatedTargetProteinKeys);
        }
    }
}
Also used : Arrays(java.util.Arrays) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) FractionParameters(com.compomics.util.parameters.identification.advanced.FractionParameters) TimeoutException(java.util.concurrent.TimeoutException) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinFilterItem(com.compomics.util.experiment.identification.filtering.items.ProteinFilterItem) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) Set(java.util.Set) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) Collectors(java.util.stream.Collectors) ProteinFilter(com.compomics.util.experiment.identification.filtering.ProteinFilter) Executors(java.util.concurrent.Executors) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) ExceptionHandler(com.compomics.util.exceptions.ExceptionHandler) Metrics(com.compomics.util.experiment.identification.peptide_shaker.Metrics) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) PeptideFilter(com.compomics.util.experiment.identification.filtering.PeptideFilter) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) NonSymmetricalNormalDistribution(com.compomics.util.math.statistics.distributions.NonSymmetricalNormalDistribution) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) InputMap(eu.isas.peptideshaker.scoring.maps.InputMap) ProjectType(com.compomics.util.parameters.peptide_shaker.ProjectType) ProcessingParameters(com.compomics.util.parameters.tools.ProcessingParameters) FilterItemComparator(com.compomics.util.experiment.filtering.FilterItemComparator) PeptideFilterItem(com.compomics.util.experiment.identification.filtering.items.PeptideFilterItem) ExecutorService(java.util.concurrent.ExecutorService) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) AssumptionFilterItem(com.compomics.util.experiment.identification.filtering.items.AssumptionFilterItem) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) TimeUnit(java.util.concurrent.TimeUnit) TreeMap(java.util.TreeMap) FastaParameters(com.compomics.util.experiment.io.biology.protein.FastaParameters) ProteinUtils(com.compomics.util.experiment.identification.utils.ProteinUtils) Filter(com.compomics.util.experiment.filtering.Filter) GeneMaps(com.compomics.util.experiment.biology.genes.GeneMaps) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) HashMap(java.util.HashMap) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) TimeoutException(java.util.concurrent.TimeoutException) NonSymmetricalNormalDistribution(com.compomics.util.math.statistics.distributions.NonSymmetricalNormalDistribution) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) ProteinFilter(com.compomics.util.experiment.identification.filtering.ProteinFilter) PeptideFilter(com.compomics.util.experiment.identification.filtering.PeptideFilter) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) Filter(com.compomics.util.experiment.filtering.Filter) ExecutorService(java.util.concurrent.ExecutorService) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter)

Aggregations

IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)14 Identification (com.compomics.util.experiment.identification.Identification)8 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)6 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)6 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)5 SelfUpdatingTableModel (com.compomics.util.gui.tablemodels.SelfUpdatingTableModel)5 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)5 Collectors (java.util.stream.Collectors)5 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)4 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)4 MatchValidationLevel (com.compomics.util.experiment.identification.validation.MatchValidationLevel)4 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)4 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)4 ProgressDialogX (com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX)4 ExportFeature (com.compomics.util.io.export.ExportFeature)4 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)4 WaitingHandler (com.compomics.util.waiting.WaitingHandler)4