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();
}
});
}
}
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);
}
}
}
}
}
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));
}
}
}
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));
}
}
}
Aggregations