Search in sources :

Example 1 with SimpleSemaphore

use of com.compomics.util.threading.SimpleSemaphore in project peptide-shaker by compomics.

the class GroupSimplification method removeRedundantGroups.

/**
 * Remove groups that can be explained by a simpler group.
 *
 * @param identification the identification class containing all
 * identification matches
 * @param identificationParameters the identification parameters
 * @param sequenceProvider the sequence provider
 * @param proteinDetailsProvider the protein details provider
 * @param waitingHandler the handler displaying feedback to the user
 */
public void removeRedundantGroups(Identification identification, IdentificationParameters identificationParameters, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, WaitingHandler waitingHandler) {
    int max = identification.getProteinIdentification().size();
    if (waitingHandler != null) {
        waitingHandler.setWaitingText("Symplifying Protein Groups. Please Wait...");
        waitingHandler.setSecondaryProgressCounterIndeterminate(false);
        waitingHandler.setMaxSecondaryProgressCounter(max);
    }
    HashSet<Long> proteinGroupKeys = identification.getProteinIdentification();
    HashSet<Long> toDelete = new HashSet<>();
    HashMap<Long, long[]> processedKeys = new HashMap<>();
    SimpleSemaphore mutex = new SimpleSemaphore(1);
    proteinGroupKeys.stream().filter(key -> !processedKeys.containsKey(key)).map(key -> identification.getProteinMatch(key)).filter(proteinMatch -> proteinMatch.getNProteins() > 1).forEach(proteinSharedGroup -> removeRedundantGroups(identification, identificationParameters, sequenceProvider, proteinDetailsProvider, proteinSharedGroup, processedKeys, toDelete, mutex, waitingHandler));
    int totalSimplified = Arrays.stream(nDeleted).sum();
    if (totalSimplified > 0) {
        if (waitingHandler != null) {
            waitingHandler.appendReport(toDelete.size() + " unlikely protein mappings found:", true, true);
            String padding = "    ";
            for (int i = 0; i < ProteinInference.GroupSimplificationOption.values().length; i++) {
                int iSimplified = nDeleted[i];
                if (iSimplified > 0) {
                    ProteinInference.GroupSimplificationOption option = ProteinInference.GroupSimplificationOption.values()[i];
                    waitingHandler.appendReport(padding + "- " + iSimplified + " " + option.description + ".", true, true);
                }
            }
            waitingHandler.setSecondaryProgressCounterIndeterminate(false);
            waitingHandler.setMaxSecondaryProgressCounter(toDelete.size());
        }
        toDelete.stream().forEach(key -> {
            identification.removeObject(key);
            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.increaseSecondaryProgressCounter();
            }
        });
    }
}
Also used : Arrays(java.util.Arrays) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) HashMap(java.util.HashMap) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) Collectors(java.util.stream.Collectors) ProteinInferenceParameters(com.compomics.util.parameters.identification.advanced.ProteinInferenceParameters) Sets(com.google.common.collect.Sets) KEYWORDS_UNCHARACTERIZED(eu.isas.peptideshaker.protein_inference.ProteinInference.KEYWORDS_UNCHARACTERIZED) HashSet(java.util.HashSet) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with SimpleSemaphore

use of com.compomics.util.threading.SimpleSemaphore in project peptide-shaker by compomics.

the class DeepLcExport method deepLcExport.

/**
 * Exports a DeepLC training file for the given spectrum file.
 *
 * @param destinationFile The file where to write the export.
 * @param confidentHitsDestinationFile The file where to write the export
 * for confident hits.
 * @param keys The keys of the spectrum matches.
 * @param identification The identification object containing the matches.
 * @param modificationParameters The modification parameters.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param sequenceProvider The sequence provider.
 * @param spectrumProvider The spectrum provider.
 * @param waitingHandler The waiting handler.
 */
public static void deepLcExport(File destinationFile, File confidentHitsDestinationFile, HashSet<Long> keys, Identification identification, ModificationParameters modificationParameters, SequenceMatchingParameters sequenceMatchingParameters, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, WaitingHandler waitingHandler) {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    HashSet<Long> processedPeptideKeys = new HashSet<>();
    SimpleSemaphore writingSemaphore = new SimpleSemaphore(1);
    try (SimpleFileWriter writer = new SimpleFileWriter(destinationFile, true)) {
        writer.writeLine("seq,modifications,tr");
        try (SimpleFileWriter writerConfident = new SimpleFileWriter(confidentHitsDestinationFile, true)) {
            writerConfident.writeLine("seq,modifications,tr");
            long[] spectrumKeys = keys.stream().mapToLong(a -> a).toArray();
            SpectrumMatchesIterator spectrumMatchesIterator = identification.getSpectrumMatchesIterator(spectrumKeys, waitingHandler);
            SpectrumMatch spectrumMatch;
            while ((spectrumMatch = spectrumMatchesIterator.next()) != null) {
                // Display progress
                if (waitingHandler != null) {
                    waitingHandler.increaseSecondaryProgressCounter();
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                }
                // Measured retention time
                String spectrumFile = spectrumMatch.getSpectrumFile();
                String spectrumTitle = spectrumMatch.getSpectrumTitle();
                Precursor precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
                double retentionTime = precursor.rt;
                // Export all candidate peptides
                spectrumMatch.getAllPeptideAssumptions().parallel().forEach(peptideAssumption -> writePeptideCandidate(peptideAssumption, retentionTime, modificationParameters, sequenceProvider, sequenceMatchingParameters, modificationFactory, processedPeptideKeys, writingSemaphore, writer));
                // Check whether the spectrum yielded a confident peptide
                if (spectrumMatch.getBestPeptideAssumption() != null && ((PSParameter) spectrumMatch.getUrParam(PSParameter.dummy)).getMatchValidationLevel().isValidated()) {
                    // Export the confident peptide to the confident peptides file
                    writePeptideCandidate(spectrumMatch.getBestPeptideAssumption(), retentionTime, modificationParameters, sequenceProvider, sequenceMatchingParameters, modificationFactory, processedPeptideKeys, writingSemaphore, writerConfident);
                }
            }
        }
    }
}
Also used : ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) DeepLcUtils(eu.isas.peptideshaker.utils.DeepLcUtils) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) HashMap(java.util.HashMap) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) Collectors(java.util.stream.Collectors) File(java.io.File) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WaitingHandler(com.compomics.util.waiting.WaitingHandler) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) HashSet(java.util.HashSet)

Example 3 with SimpleSemaphore

use of com.compomics.util.threading.SimpleSemaphore in project peptide-shaker by compomics.

the class Ms2PipExport method ms2pipExport.

/**
 * Exports a ms2pip training file for the given spectrum file.
 *
 * @param peprecFile The file where to write the export.
 * @param identification The identification object containing the matches.
 * @param modificationParameters The modification parameters.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param sequenceProvider The sequence provider.
 * @param spectrumProvider The spectrum provider.
 * @param waitingHandler The waiting handler.
 */
public static void ms2pipExport(File peprecFile, Identification identification, ModificationParameters modificationParameters, SequenceMatchingParameters sequenceMatchingParameters, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, WaitingHandler waitingHandler) {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    try (SimpleFileWriter writer = new SimpleFileWriter(peprecFile, true)) {
        writer.writeLine("spec_id modifications peptide charge");
        SpectrumMatchesIterator spectrumMatchesIterator = identification.getSpectrumMatchesIterator(waitingHandler);
        HashSet<Long> processedPeptideKeys = new HashSet<>();
        SimpleSemaphore writingSemaphore = new SimpleSemaphore(1);
        SpectrumMatch spectrumMatch;
        while ((spectrumMatch = spectrumMatchesIterator.next()) != null) {
            // Display progress
            if (waitingHandler != null) {
                waitingHandler.increaseSecondaryProgressCounter();
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
            }
            // Export all candidate peptides
            spectrumMatch.getAllPeptideAssumptions().parallel().forEach(peptideAssumption -> writePeptideCandidate(peptideAssumption, modificationParameters, sequenceProvider, sequenceMatchingParameters, modificationFactory, processedPeptideKeys, writingSemaphore, writer));
        }
    }
}
Also used : ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) HashSet(java.util.HashSet)

Example 4 with SimpleSemaphore

use of com.compomics.util.threading.SimpleSemaphore in project peptide-shaker by compomics.

the class PercolatorExport method percolatorExport.

/**
 * Exports a Percolator training file.
 *
 * @param destinationFile The file where to write the export.
 * @param rtPrediction The retention time prediction.
 * @param fragmentationPrediction The fragmentation prediction.
 * @param identification The identification object containing the matches.
 * @param searchParameters The search parameters.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param annotationParameters The annotation parameters.
 * @param modificationLocalizationParameters The modification localization
 * parameters.
 * @param sequenceProvider The sequence provider.
 * @param spectrumProvider The spectrum provider.
 * @param waitingHandler The waiting handler.
 */
public static void percolatorExport(File destinationFile, HashMap<String, ArrayList<Double>> rtPrediction, HashMap<String, ArrayList<Spectrum>> fragmentationPrediction, Identification identification, SearchParameters searchParameters, SequenceMatchingParameters sequenceMatchingParameters, AnnotationParameters annotationParameters, ModificationLocalizationParameters modificationLocalizationParameters, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, WaitingHandler waitingHandler) {
    // reset the progress bar
    waitingHandler.resetSecondaryProgressCounter();
    waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    SimpleSemaphore writingSemaphore = new SimpleSemaphore(1);
    try (SimpleFileWriter writer = new SimpleFileWriter(destinationFile, true)) {
        Boolean rtPredictionsAvailable = rtPrediction != null;
        String header = PercolatorUtils.getHeader(searchParameters, rtPredictionsAvailable);
        writer.writeLine(header);
        SpectrumMatchesIterator spectrumMatchesIterator = identification.getSpectrumMatchesIterator(waitingHandler);
        SpectrumMatch spectrumMatch;
        while ((spectrumMatch = spectrumMatchesIterator.next()) != null) {
            // Make sure that there is no duplicate in the export
            HashSet<Long> processedPeptideKeys = new HashSet<>();
            // Display progress
            if (waitingHandler != null) {
                waitingHandler.increaseSecondaryProgressCounter();
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
            }
            // Export all candidate peptides
            SpectrumMatch tempSpectrumMatch = spectrumMatch;
            tempSpectrumMatch.getAllPeptideAssumptions().parallel().forEach(peptideAssumption -> writePeptideCandidate(tempSpectrumMatch, peptideAssumption, rtPrediction, searchParameters, sequenceProvider, sequenceMatchingParameters, annotationParameters, modificationLocalizationParameters, modificationFactory, spectrumProvider, processedPeptideKeys, writingSemaphore, writer));
        }
    }
}
Also used : ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) HashSet(java.util.HashSet)

Aggregations

SimpleSemaphore (com.compomics.util.threading.SimpleSemaphore)4 HashSet (java.util.HashSet)4 ModificationFactory (com.compomics.util.experiment.biology.modifications.ModificationFactory)3 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)3 SpectrumMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator)3 SimpleFileWriter (com.compomics.util.io.flat.SimpleFileWriter)3 Identification (com.compomics.util.experiment.identification.Identification)2 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)2 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)2 WaitingHandler (com.compomics.util.waiting.WaitingHandler)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)1 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)1 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)1 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)1 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)1 Precursor (com.compomics.util.experiment.mass_spectrometry.spectra.Precursor)1 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)1 ProteinInferenceParameters (com.compomics.util.parameters.identification.advanced.ProteinInferenceParameters)1