Search in sources :

Example 1 with HyperScore

use of com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore in project peptide-shaker by compomics.

the class PsmScorer method estimateIntermediateScores.

/**
 * Scores the PSMs contained in an identification object.
 *
 * @param identification the object containing the identification matches
 * @param inputMap the input map scores
 * @param processingParameters the processing preferences
 * @param identificationParameters identification parameters used
 * @param waitingHandler the handler displaying feedback to the user
 * @param exceptionHandler a handler for exceptions
 *
 * @throws java.lang.InterruptedException exception thrown if a thread is
 * interrupted
 * @throws java.util.concurrent.TimeoutException exception thrown if the
 * process times out
 */
public void estimateIntermediateScores(Identification identification, InputMap inputMap, ProcessingParameters processingParameters, IdentificationParameters identificationParameters, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler) throws InterruptedException, TimeoutException {
    // Remove the intensity filter during scoring
    AnnotationParameters annotationSettings = identificationParameters.getAnnotationParameters();
    double intensityThreshold = annotationSettings.getAnnotationIntensityLimit();
    annotationSettings.setIntensityLimit(0);
    waitingHandler.setWaitingText("Scoring PSMs. Please Wait...");
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
    ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(null);
    ArrayList<PsmScorerRunnable> psmScorerRunnables = new ArrayList<>(processingParameters.getnThreads());
    for (int i = 1; i <= processingParameters.getnThreads() && !waitingHandler.isRunCanceled(); i++) {
        PsmScorerRunnable runnable = new PsmScorerRunnable(psmIterator, identification, inputMap, identificationParameters, waitingHandler, exceptionHandler);
        psmScorerRunnables.add(runnable);
        pool.submit(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("PSM scoring timed out. Please contact the developers.");
    }
    ArrayList<HashMap<Double, Integer>> aHistograms = new ArrayList<>(processingParameters.getnThreads());
    ArrayList<HashMap<Double, Integer>> bHistograms = new ArrayList<>(processingParameters.getnThreads());
    HashMap<Long, ArrayList<Integer>> missingValuesMap = new HashMap<>();
    for (PsmScorerRunnable runnable : psmScorerRunnables) {
        HashMap<Long, ArrayList<Integer>> currentMissingValuesMap = runnable.getMissingEValues();
        missingValuesMap.putAll(currentMissingValuesMap);
        HyperScore hyperScore = runnable.getHyperScore();
        aHistograms.add(hyperScore.getAs());
        bHistograms.add(hyperScore.getBs());
    }
    if (!missingValuesMap.isEmpty()) {
        HashMap<Double, Integer> aHistogram = HistogramUtils.mergeHistograms(aHistograms);
        HashMap<Double, Integer> bHistogram = HistogramUtils.mergeHistograms(bHistograms);
        double defaultA = aHistogram.isEmpty() ? Double.NaN : HistogramUtils.getMedianValue(aHistogram);
        double defaultB = bHistogram.isEmpty() ? Double.NaN : HistogramUtils.getMedianValue(bHistogram);
        long[] spectrumKeys = missingValuesMap.keySet().stream().mapToLong(Long::longValue).toArray();
        psmIterator = identification.getSpectrumMatchesIterator(spectrumKeys, null);
        pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
        for (int i = 1; i <= processingParameters.getnThreads() && !waitingHandler.isRunCanceled(); i++) {
            MissingEValueEstimatorRunnable runnable = new MissingEValueEstimatorRunnable(missingValuesMap, defaultA, defaultB, psmIterator, inputMap, identificationParameters, waitingHandler, exceptionHandler);
            pool.submit(runnable);
        }
        if (waitingHandler.isRunCanceled()) {
            pool.shutdownNow();
            return;
        }
        pool.shutdown();
        if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
            throw new TimeoutException("PSM scoring timed out. Please contact the developers.");
        }
    }
    waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    // Restaure intensity threshold
    annotationSettings.setIntensityLimit(intensityThreshold);
}
Also used : HyperScore(com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore) HashMap(java.util.HashMap) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) ExecutorService(java.util.concurrent.ExecutorService) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

SpectrumMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator)1 HyperScore (com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore)1 AnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)1 SpecificAnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1