Search in sources :

Example 1 with ExceptionHandler

use of com.compomics.util.exceptions.ExceptionHandler in project peptide-shaker by compomics.

the class ProteinProcessor method processProteins.

/**
 * Scores the PTMs of all protein matches contained in an identification
 * object, estimates spectrum counting and summary statistics.
 *
 * @param modificationLocalizationScorer The modification localization
 * scorer to use.
 * @param metrics If provided, metrics on proteins will be saved while
 * iterating the matches.
 * @param modificationProvider The modification provider to use.
 * @param waitingHandler The handler displaying feedback to the user.
 * @param exceptionHandler The exception handler to use.
 * @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 processProteins(ModificationLocalizationScorer modificationLocalizationScorer, Metrics metrics, ModificationProvider modificationProvider, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler, ProcessingParameters processingParameters) throws InterruptedException, TimeoutException {
    waitingHandler.setWaitingText("Scoring Protein Modification Localization. Please Wait...");
    int max = identification.getProteinIdentification().size();
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.setMaxSecondaryProgressCounter(max);
    // validate the proteins
    ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(waitingHandler);
    ArrayList<ProteinRunnable> runnables = new ArrayList<>(processingParameters.getnThreads());
    for (int i = 1; i <= processingParameters.getnThreads(); i++) {
        ProteinRunnable runnable = new ProteinRunnable(proteinMatchesIterator, modificationLocalizationScorer, modificationProvider, waitingHandler, exceptionHandler);
        pool.submit(runnable);
        runnables.add(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getProteinIdentification().size(), TimeUnit.MINUTES)) {
        throw new InterruptedException("Protein matches validation timed out. Please contact the developers.");
    }
    waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    if (metrics != null) {
        metrics.setMaxSpectrumCounting(runnables.stream().mapToDouble(ProteinRunnable::getMaxSpectrumCounting).sum());
        metrics.setnValidatedProteins(runnables.stream().mapToInt(ProteinRunnable::getnValidatedProteins).sum());
        metrics.setnConfidentProteins(runnables.stream().mapToInt(ProteinRunnable::getnConfidentProteins).sum());
        metrics.setMaxNPeptides(runnables.stream().mapToInt(ProteinRunnable::getMaxPeptides).max().orElse(0));
        metrics.setMaxNPsms(runnables.stream().mapToInt(ProteinRunnable::getMaxPsms).max().orElse(0));
        metrics.setMaxMW(runnables.stream().mapToDouble(ProteinRunnable::getMaxMW).max().orElse(0.0));
        metrics.setMaxProteinAccessionLength(runnables.stream().mapToInt(ProteinRunnable::getMaxProteinAccessionLength).max().orElse(0));
        TreeMap<Double, TreeMap<Integer, TreeMap<Integer, TreeSet<Long>>>> orderMap1 = new TreeMap<>();
        for (int i = 0; i < runnables.size(); i++) {
            HashMap<Double, HashMap<Integer, HashMap<Integer, HashSet<Long>>>> threadMap1 = runnables.get(i).getOrderMap();
            for (Entry<Double, HashMap<Integer, HashMap<Integer, HashSet<Long>>>> entry1 : threadMap1.entrySet()) {
                double key1 = entry1.getKey();
                HashMap<Integer, HashMap<Integer, HashSet<Long>>> threadMap2 = entry1.getValue();
                TreeMap<Integer, TreeMap<Integer, TreeSet<Long>>> orderMap2 = orderMap1.get(key1);
                if (orderMap2 == null) {
                    orderMap2 = new TreeMap<>();
                    orderMap1.put(key1, orderMap2);
                }
                for (Entry<Integer, HashMap<Integer, HashSet<Long>>> entry2 : threadMap2.entrySet()) {
                    int key2 = entry2.getKey();
                    HashMap<Integer, HashSet<Long>> threadMap3 = entry2.getValue();
                    TreeMap<Integer, TreeSet<Long>> orderMap3 = orderMap2.get(key2);
                    if (orderMap3 == null) {
                        orderMap3 = new TreeMap<>();
                        orderMap2.put(key2, orderMap3);
                    }
                    for (Entry<Integer, HashSet<Long>> entry3 : threadMap3.entrySet()) {
                        int key3 = entry3.getKey();
                        HashSet<Long> threadSet = entry3.getValue();
                        TreeSet<Long> orderedSet = orderMap3.get(key3);
                        if (orderedSet == null) {
                            orderedSet = new TreeSet<>();
                            orderMap3.put(key3, orderedSet);
                        }
                        orderedSet.addAll(threadSet);
                    }
                }
            }
        }
        long[] proteinKeys = orderMap1.values().stream().flatMap(map -> map.values().stream()).flatMap(map -> map.values().stream()).flatMap(set -> set.stream()).mapToLong(a -> a).toArray();
        metrics.setProteinKeys(proteinKeys);
    }
}
Also used : Arrays(java.util.Arrays) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) ProcessingParameters(com.compomics.util.parameters.tools.ProcessingParameters) ModificationProvider(com.compomics.util.experiment.biology.modifications.ModificationProvider) ExecutorService(java.util.concurrent.ExecutorService) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) ModificationLocalizationScorer(eu.isas.peptideshaker.ptm.ModificationLocalizationScorer) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) ProteinUtils(com.compomics.util.experiment.identification.utils.ProteinUtils) ExceptionHandler(com.compomics.util.exceptions.ExceptionHandler) Metrics(com.compomics.util.experiment.identification.peptide_shaker.Metrics) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) HashSet(java.util.HashSet) TreeMap(java.util.TreeMap) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with ExceptionHandler

use of com.compomics.util.exceptions.ExceptionHandler in project peptide-shaker by compomics.

the class NewDialog method loadButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
/**
 * Tries to process the identification files, closes the dialog and then
 * opens the results in the main frame.
 *
 * @param evt
 */
private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (validateUserInput()) {
        if (welcomeDialog != null) {
            welcomeDialog.setVisible(false);
        }
        this.setVisible(false);
        peptideShakerGUI.setVisible(true);
        ProjectType projectType = ProjectType.getProjectType(typeCmb.getSelectedItem().toString());
        peptideShakerGUI.setIdentificationParameters(identificationParameters);
        peptideShakerGUI.setProcessingParameters(processingParameters);
        peptideShakerGUI.setDisplayParameters(displayPreferences);
        projectDetails = new ProjectDetails();
        projectDetails.setCreationDate(new Date());
        projectDetails.setPeptideShakerVersion(new eu.isas.peptideshaker.utils.Properties().getVersion());
        projectDetails.setFastaFile(fastaFile);
        peptideShakerGUI.setProjectDetails(projectDetails);
        peptideShakerGUI.setCurentNotes(new ArrayList<>());
        peptideShakerGUI.updateNotesNotificationCounter();
        peptideShakerGUI.resetDisplayFeaturesGenerator();
        peptideShakerGUI.setSpectrumCountingParameters(spectrumCountingPreferences);
        peptideShakerGUI.setMsFileHandler(msFileHandler);
        ProjectParameters projectParameters = new ProjectParameters(projectNameIdTxt.getText().trim());
        // incrementing the counter for a new PeptideShaker start run via GUI
        if (peptideShakerGUI.getUtilitiesUserParameters().isAutoUpdate()) {
            Util.sendGAUpdate("UA-36198780-1", "startrun-gui", "peptide-shaker-" + PeptideShaker.getVersion());
        }
        peptideShaker = new PeptideShaker(projectParameters);
        ArrayList<String> tips;
        try {
            tips = Tips.getTips();
        } catch (Exception e) {
            tips = new ArrayList<>();
        // Do something here?
        }
        WaitingDialog waitingDialog = new WaitingDialog(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true, tips, "Importing Data", "PeptideShaker", PeptideShaker.getVersion(), true);
        waitingDialog.setCloseDialogWhenImportCompletes(true, true);
        int progressCounter = idFiles.size() + spectrumFiles.size();
        // establishing the database connection
        progressCounter++;
        // the FASTA file
        progressCounter++;
        // the peptide to protein map
        progressCounter++;
        // computing probabilities etc
        progressCounter += 6;
        if (identificationParameters.getProteinInferenceParameters().getSimplifyGroups()) {
            // simplify protein groups
            progressCounter++;
        }
        // resolving protein inference
        progressCounter++;
        // Correcting protein probabilities, Validating identifications at 1% FDR, Scoring PTMs in peptides, Scoring PTMs in proteins.
        progressCounter += 4;
        // Scoring PTMs in PSMs. Estimating PTM FLR.
        progressCounter += 2;
        if (identificationParameters.getModificationLocalizationParameters().getAlignNonConfidentModifications()) {
            // Peptide inference
            progressCounter++;
        }
        // add one more just to not start at 0%
        progressCounter++;
        waitingDialog.setMaxPrimaryProgressCounter(progressCounter);
        // just to not start at 0%
        waitingDialog.increasePrimaryProgressCounter();
        boolean needDialog = false;
        // load the identification files
        if (idFiles.size() > 0) {
            needDialog = true;
            new Thread(new Runnable() {

                public void run() {
                    ExceptionHandler exceptionHandler = new WaitingDialogExceptionHandler((WaitingDialog) waitingDialog, "https://github.com/compomics/peptide-shaker/issues");
                    try {
                        int outcome = peptideShaker.importFiles(waitingDialog, idFiles, msFileHandler, identificationParameters, projectDetails, processingParameters, exceptionHandler);
                        if (outcome == 0) {
                            peptideShaker.createProject(identificationParameters, processingParameters, spectrumCountingPreferences, msFileHandler, projectDetails, projectType, waitingDialog, true, exceptionHandler);
                        } else {
                            waitingDialog.setRunCanceled();
                        }
                    } catch (Exception e) {
                        exceptionHandler.catchException(e);
                        waitingDialog.setRunCanceled();
                        waitingDialog.setWaitingText("Failed to import data or create the project!");
                    }
                }
            }, "Import data and create project").start();
        }
        if (needDialog) {
            try {
                waitingDialog.setVisible(true);
            } catch (IndexOutOfBoundsException e) {
            // ignore
            }
            this.dispose();
        }
        if (!needDialog || !waitingDialog.isRunCanceled()) {
            peptideShakerGUI.setProject(projectParameters);
            peptideShakerGUI.setIdentification(peptideShaker.getIdentification());
            peptideShakerGUI.setMetrics(peptideShaker.getMetrics());
            peptideShakerGUI.setGeneMaps(peptideShaker.getGeneMaps());
            peptideShakerGUI.setProjectType(projectType);
            peptideShakerGUI.setSequenceProvider(peptideShaker.getSequenceProvider());
            peptideShakerGUI.setProteinDetailsProvider(peptideShaker.getProteinDetailsProvider());
            peptideShakerGUI.resetDisplayFeaturesGenerator();
            peptideShakerGUI.setIdentificationFeaturesGenerator(peptideShaker.getIdentificationFeaturesGenerator());
            peptideShakerGUI.displayResults();
            // display the overview tab
            peptideShakerGUI.initiateDisplay();
            peptideShakerGUI.getProjectDetails().setReport(waitingDialog.getReport(null));
            this.dispose();
        } else if (waitingDialog.isRunCanceled()) {
            // close the database
            try {
                peptideShaker.getIdentification().close(false);
            } catch (Exception e) {
                System.out.println("Failed to close the database!");
                e.printStackTrace();
            }
        }
    }
}
Also used : ProjectDetails(eu.isas.peptideshaker.preferences.ProjectDetails) ArrayList(java.util.ArrayList) WaitingDialog(com.compomics.util.gui.waiting.waitinghandlers.WaitingDialog) WaitingDialogExceptionHandler(com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler) Date(java.util.Date) WaitingDialogExceptionHandler(com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler) ExceptionHandler(com.compomics.util.exceptions.ExceptionHandler) ProjectParameters(com.compomics.util.experiment.ProjectParameters) ProjectType(com.compomics.util.parameters.peptide_shaker.ProjectType) PeptideShaker(eu.isas.peptideshaker.PeptideShaker)

Example 3 with ExceptionHandler

use of com.compomics.util.exceptions.ExceptionHandler 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

ExceptionHandler (com.compomics.util.exceptions.ExceptionHandler)3 ArrayList (java.util.ArrayList)3 Identification (com.compomics.util.experiment.identification.Identification)2 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)2 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)2 ProteinMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator)2 Metrics (com.compomics.util.experiment.identification.peptide_shaker.Metrics)2 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)2 ProteinUtils (com.compomics.util.experiment.identification.utils.ProteinUtils)2 MatchValidationLevel (com.compomics.util.experiment.identification.validation.MatchValidationLevel)2 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)2 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)2 ProjectType (com.compomics.util.parameters.peptide_shaker.ProjectType)2 WaitingDialogExceptionHandler (com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler)1 ProjectParameters (com.compomics.util.experiment.ProjectParameters)1 GeneMaps (com.compomics.util.experiment.biology.genes.GeneMaps)1 ModificationProvider (com.compomics.util.experiment.biology.modifications.ModificationProvider)1 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)1 Filter (com.compomics.util.experiment.filtering.Filter)1 FilterItemComparator (com.compomics.util.experiment.filtering.FilterItemComparator)1