use of eu.isas.peptideshaker.ptm.ModificationLocalizationScorer 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);
}
}
use of eu.isas.peptideshaker.ptm.ModificationLocalizationScorer in project peptide-shaker by compomics.
the class PeptideShakerGUI method updateMainMatch.
/**
* Update the protein match in the different tabs.
*
* @param mainMatch the protein match to use
* @param proteinInferenceType the protein inference group type
*/
public void updateMainMatch(String mainMatch, int proteinInferenceType) {
try {
ModificationLocalizationScorer ptmScorer = new ModificationLocalizationScorer();
Identification identification = getIdentification();
ProteinMatch proteinMatch = identification.getProteinMatch(selectedProteinKey);
ptmScorer.scorePTMs(identification, proteinMatch, getIdentificationParameters(), false, modificationFactory, null);
} catch (Exception e) {
catchException(e);
}
overviewPanel.updateProteinTable();
proteinStructurePanel.updateMainMatch(mainMatch, proteinInferenceType);
}
use of eu.isas.peptideshaker.ptm.ModificationLocalizationScorer in project peptide-shaker by compomics.
the class ModificationSiteInferenceDialog method okButtonActionPerformed.
// GEN-LAST:event_cancelButtonActionPerformed
/**
* Updates the data and then closes the dialog.
*
* @param evt
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_okButtonActionPerformed
boolean changed = false;
if (changed) {
try {
// save changes in the peptide match
Identification identification = peptideShakerGUI.getIdentification();
// update protein level PTM scoring
ModificationLocalizationScorer ptmScorer = new ModificationLocalizationScorer();
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
identification.getProteinMatches(peptideMatch.getKey()).stream().map(key -> identification.getProteinMatch(key)).forEach(proteinMatch -> ptmScorer.scorePTMs(identification, proteinMatch, identificationParameters, false, modificationFactory, null));
} catch (Exception e) {
peptideShakerGUI.catchException(e);
}
}
dispose();
}
use of eu.isas.peptideshaker.ptm.ModificationLocalizationScorer in project peptide-shaker by compomics.
the class PeptideShakerGUI method validationQcMenuItemActionPerformed.
// GEN-LAST:event_configurationFilesSettingsActionPerformed
/**
* Open the ValidationQCPreferencesDialog.
*
* @param evt
*/
private void validationQcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_validationQcMenuItemActionPerformed
final IdMatchValidationParameters idValidationParameters = getIdentificationParameters().getIdValidationParameters();
final ValidationQcParameters validationQCParameters = idValidationParameters.getValidationQCParameters();
ValidationQCParametersDialog validationQCParametersDialog = new ValidationQCParametersDialog(this, validationQCParameters, getIdentificationParameters().getSearchParameters().getModificationParameters().getAllModifications(), true);
if (!validationQCParametersDialog.isCanceled()) {
ValidationQcParameters newParameters = validationQCParametersDialog.getValidationQCParameters();
if (!newParameters.isSameAs(validationQCParameters)) {
idValidationParameters.setValidationQCParameters(newParameters);
// Update the assumptions QC filters
for (Filter filter : newParameters.getPsmFilters()) {
PsmFilter psmFilter = (PsmFilter) filter;
AssumptionFilter assumptionFilter = psmFilter.getAssumptionFilter();
assumptionFilter.clear();
for (String itemName : psmFilter.getItemsNames()) {
assumptionFilter.setFilterItem(itemName, psmFilter.getComparatorForItem(itemName), psmFilter.getValue(itemName));
}
}
progressDialog = new ProgressDialogX(PeptideShakerGUI.this, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setTitle("Validating. Please Wait...");
progressDialog.setPrimaryProgressCounterIndeterminate(false);
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("RecalculateThread") {
@Override
public void run() {
PeptideShakerGUI peptideShakerGUI = PeptideShakerGUI.this;
try {
PSMaps pSMaps = new PSMaps();
pSMaps = (PSMaps) peptideShakerGUI.getIdentification().getUrParam(pSMaps);
MatchesValidator matchesValidator = new MatchesValidator(pSMaps.getPsmMap(), pSMaps.getPeptideMap(), pSMaps.getProteinMap());
matchesValidator.validateIdentifications(peptideShakerGUI.getIdentification(), peptideShakerGUI.getMetrics(), pSMaps.getInputMap(), progressDialog, exceptionHandler, peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getGeneMaps(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getProjectType(), peptideShakerGUI.getProcessingParameters());
progressDialog.setPrimaryProgressCounterIndeterminate(true);
ProteinProcessor proteinProcessor = new ProteinProcessor(peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getSequenceProvider());
proteinProcessor.processProteins(new ModificationLocalizationScorer(), peptideShakerGUI.getMetrics(), modificationFactory, progressDialog, peptideShakerGUI.getExceptionHandler(), peptideShakerGUI.getProcessingParameters());
if (!progressDialog.isRunCanceled()) {
// update the other tabs
peptideShakerGUI.getMetrics().setnValidatedProteins(-1);
peptideShakerGUI.getMetrics().setnConfidentProteins(-1);
peptideShakerGUI.setUpdated(PeptideShakerGUI.OVER_VIEW_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.PROTEIN_FRACTIONS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.STRUCTURES_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.MODIFICATIONS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.QC_PLOTS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.SPECTRUM_ID_TAB_INDEX, false);
peptideShakerGUI.setDataSaved(false);
} else {
idValidationParameters.setValidationQCParameters(validationQCParameters);
}
} catch (Exception e) {
peptideShakerGUI.catchException(e);
}
progressDialog.setRunFinished();
PeptideShakerGUI.this.repaintPanels();
}
}.start();
}
}
}
use of eu.isas.peptideshaker.ptm.ModificationLocalizationScorer in project peptide-shaker by compomics.
the class ValidationPanel method validateButtonActionPerformed.
// GEN-LAST:event_formComponentResized
/**
* Validate the data using the current settings.
*
* @param evt
*/
private void validateButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_validateButtonActionPerformed
double lastThreshold = Double.valueOf(thresholdInput.getText());
thresholdInputActionPerformed(null);
if (lastThreshold < 0 || lastThreshold > 100) {
JOptionPane.showMessageDialog(this, "Please verify the given threshold. Interval: [0, 100].", "Threshold Error", JOptionPane.WARNING_MESSAGE);
} else {
progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setTitle("Recalculating. Please Wait...");
progressDialog.setPrimaryProgressCounterIndeterminate(false);
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("RecalculateThread") {
@Override
public void run() {
try {
PSMaps pSMaps = new PSMaps();
pSMaps = (PSMaps) peptideShakerGUI.getIdentification().getUrParam(pSMaps);
MatchesValidator matchesValidator = new MatchesValidator(pSMaps.getPsmMap(), pSMaps.getPeptideMap(), pSMaps.getProteinMap());
matchesValidator.validateIdentifications(peptideShakerGUI.getIdentification(), peptideShakerGUI.getMetrics(), pSMaps.getInputMap(), progressDialog, peptideShakerGUI.getExceptionHandler(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), peptideShakerGUI.getGeneMaps(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getProjectType(), peptideShakerGUI.getProcessingParameters());
progressDialog.setPrimaryProgressCounterIndeterminate(true);
if (peptideShakerGUI.getProjectType() == ProjectType.protein) {
ProteinProcessor proteinProcessor = new ProteinProcessor(peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationParameters(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getSequenceProvider());
proteinProcessor.processProteins(new ModificationLocalizationScorer(), peptideShakerGUI.getMetrics(), modificationFactory, progressDialog, peptideShakerGUI.getExceptionHandler(), peptideShakerGUI.getProcessingParameters());
}
if (!progressDialog.isRunCanceled()) {
// update the other tabs
peptideShakerGUI.getMetrics().setnValidatedProteins(-1);
peptideShakerGUI.getMetrics().setnConfidentProteins(-1);
peptideShakerGUI.setUpdated(PeptideShakerGUI.OVER_VIEW_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.PROTEIN_FRACTIONS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.STRUCTURES_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.MODIFICATIONS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.QC_PLOTS_TAB_INDEX, false);
peptideShakerGUI.setUpdated(PeptideShakerGUI.SPECTRUM_ID_TAB_INDEX, false);
dataValidated = true;
validateButton.setEnabled(false);
double input = Double.valueOf(thresholdInput.getText());
int inputType = thresholdTypeCmb.getSelectedIndex();
TargetDecoyResults currentResults = currentTargetDecoyMap.getTargetDecoyResults();
currentResults.setUserInput(input);
currentResults.setInputType(inputType);
String selectedGroup = (String) groupSelectionTable.getValueAt(groupSelectionTable.getSelectedRow(), 1);
originalThresholds.put(selectedGroup, input);
originalThresholdTypes.put(selectedGroup, inputType);
peptideShakerGUI.setDataSaved(false);
} else {
// @TODO: ideally the validation settings ought to be reset as well..?
}
} catch (Exception e) {
peptideShakerGUI.catchException(e);
}
progressDialog.setRunFinished();
}
}.start();
}
}
Aggregations