}
// check if we should narrow the mass accuracy window, if yes, do a second pass validation
if (!precursorMzDeviations.isEmpty()) {
NonSymmetricalNormalDistribution precDeviationDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(precursorMzDeviations);
Double minDeviation = precDeviationDistribution.getMinValueForProbability(0.0001);
Double maxDeviation = precDeviationDistribution.getMaxValueForProbability(0.0001);
boolean needSecondPass = false;
if (minDeviation < maxDeviation) {
String unit = "ppm";
if (!searchParameters.isPrecursorAccuracyTypePpm()) {
unit = "Da";
}
if (minDeviation != Double.NaN && minDeviation > -searchParameters.getPrecursorAccuracy()) {
needSecondPass = true;
PsmFilter psmFilter = new PsmFilter("Precursor m/z deviation > " + Util.roundDouble(minDeviation, 2) + " " + unit);
psmFilter.setDescription("Precursor m/z deviation < " + Util.roundDouble(minDeviation, 2) + " " + unit);
psmFilter.setMinPrecursorMzError(minDeviation);
psmFilter.setPrecursorMinMzErrorComparison(RowFilter.ComparisonType.AFTER);
for (int charge : charges) {
psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
}
}
if (minDeviation != Double.NaN && maxDeviation < searchParameters.getPrecursorAccuracy()) {
needSecondPass = true;
PsmFilter psmFilter = new PsmFilter("Precursor m/z deviation < " + Util.roundDouble(maxDeviation, 2) + " " + unit);
psmFilter.setDescription("Precursor m/z deviation > " + Util.roundDouble(maxDeviation, 2) + " " + unit);
psmFilter.setMaxPrecursorMzError(maxDeviation);
psmFilter.setPrecursorMaxMzErrorComparison(RowFilter.ComparisonType.BEFORE);
for (int charge : charges) {
psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
}
}
}
if (needSecondPass) {
if (inputMap != null) {
inputMap.resetAdvocateContributions(spectrumFileName);
}
for (String spectrumKey : identification.getSpectrumIdentification(spectrumFileName)) {
updateSpectrumMatchValidationLevel(identification, identificationFeaturesGenerator, searchParameters, sequenceMatchingPreferences, annotationPreferences, peptideSpectrumAnnotator, psmMap, spectrumKey);
psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
if (psParameter.getMatchValidationLevel().isValidated()) {
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
if (peptideAssumption != null) {
if (inputMap != null) {
Peptide bestPeptide = peptideAssumption.getPeptide();
ArrayList<Integer> agreementAdvocates = new ArrayList<Integer>();
for (int advocateId : spectrumMatch.getAdvocates()) {
for (SpectrumIdentificationAssumption spectrumIdentificationAssumption : spectrumMatch.getFirstHits(advocateId)) {
if (spectrumIdentificationAssumption instanceof PeptideAssumption) {
Peptide advocatePeptide = ((PeptideAssumption) spectrumIdentificationAssumption).getPeptide();
if (bestPeptide.isSameSequenceAndModificationStatus(advocatePeptide, sequenceMatchingPreferences)) {
agreementAdvocates.add(advocateId);
break;
}
}
}
}
boolean unique = agreementAdvocates.size() == 1;
for (int advocateId : agreementAdvocates) {
inputMap.addAdvocateContribution(advocateId, spectrumFileName, unique);
}
inputMap.addAdvocateContribution(Advocate.peptideShaker.getIndex(), spectrumFileName, agreementAdvocates.isEmpty());
}
}
}
if (waitingHandler != null) {
waitingHandler.increaseSecondaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
}
} else if (waitingHandler != null) {
waitingHandler.increaseSecondaryProgressCounter(identification.getSpectrumIdentification(spectrumFileName).size());
}
}
}
HashMap<String, Integer> validatedTotalPeptidesPerFraction = new HashMap<String, Integer>();
identification.loadPeptideMatches(null);
identification.loadPeptideMatchParameters(new PSParameter(), null);
ArrayList<Double> validatedPeptideLengths = new ArrayList<Double>();
// validate the peptides
for (String peptideKey : identification.getPeptideIdentification()) {
updatePeptideMatchValidationLevel(identification, identificationFeaturesGenerator, searchParameters, peptideMap, peptideKey);
// set the fraction details
psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
if (psParameter.getMatchValidationLevel().isValidated()) {
double length = Peptide.getSequence(peptideKey).length();
validatedPeptideLengths.add(length);
}
// @TODO: could be a better more elegant way of doing this?
HashMap<String, Integer> validatedPsmsPerFraction = new HashMap<String, Integer>();
HashMap<String, ArrayList<Double>> precursorIntensitesPerFractionPeptideLevel = new HashMap<String, ArrayList<Double>>();
for (String fraction : psParameter.getFractions()) {
ArrayList<Double> precursorIntensities = new ArrayList<Double>();
if (metrics.getFractionPsmMatches().get(fraction + "_" + peptideKey) != null) {
ArrayList<String> spectrumKeys = metrics.getFractionPsmMatches().get(fraction + "_" + peptideKey);
for (int k = 0; k < spectrumKeys.size(); k++) {
psParameter2 = (PSParameter) identification.getSpectrumMatchParameter(spectrumKeys.get(k), psParameter2);
if (psParameter2.getMatchValidationLevel().isValidated()) {
if (validatedPsmsPerFraction.containsKey(fraction)) {
Integer value = validatedPsmsPerFraction.get(fraction);
validatedPsmsPerFraction.put(fraction, value + 1);
} else {
validatedPsmsPerFraction.put(fraction, 1);
}
if (SpectrumFactory.getInstance().getPrecursor(spectrumKeys.get(k)).getIntensity() > 0) {
precursorIntensities.add(SpectrumFactory.getInstance().getPrecursor(spectrumKeys.get(k)).getIntensity());
}
}
if (waitingHandler != null) {
if (waitingHandler.isRunCanceled()) {
return;
}
}
}
}
precursorIntensitesPerFractionPeptideLevel.put(fraction, precursorIntensities);
// save the total number of peptides per fraction
if (psParameter.getMatchValidationLevel().isValidated()) {
if (validatedTotalPeptidesPerFraction.containsKey(fraction)) {
Integer value = validatedTotalPeptidesPerFraction.get(fraction);
validatedTotalPeptidesPerFraction.put(fraction, value + 1);
} else {
validatedTotalPeptidesPerFraction.put(fraction, 1);
}
}
}
// set the number of validated spectra per fraction for each peptide
psParameter.setFractionValidatedSpectra(validatedPsmsPerFraction);
psParameter.setPrecursorIntensityPerFraction(precursorIntensitesPerFractionPeptideLevel);
identification.updatePeptideMatchParameter(peptideKey, psParameter);
if (waitingHandler != null) {
waitingHandler.increaseSecondaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
}
if (validatedPeptideLengths.size() >= 100) {
NonSymmetricalNormalDistribution lengthDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(validatedPeptideLengths);
metrics.setPeptideLengthDistribution(lengthDistribution);
}
// validate the proteins
TargetDecoyMap targetDecoyMap = proteinMap.getTargetDecoyMap();