*/
public static void updateSpectrumMatchValidationLevel(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator,
SearchParameters searchParameters, SequenceMatchingPreferences sequenceMatchingPreferences, AnnotationPreferences annotationPreferences, PeptideSpectrumAnnotator peptideSpectrumAnnotator,
PsmSpecificMap psmMap, String spectrumKey) throws SQLException, IOException, ClassNotFoundException, InterruptedException, MzMLUnmarshallerException {
SequenceFactory sequenceFactory = SequenceFactory.getInstance();
PSParameter psParameter = new PSParameter();
psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
psParameter.resetQcResults();
if (sequenceFactory.concatenatedTargetDecoy()) {
Integer charge = new Integer(psParameter.getSpecificMapKey());
String fileName = Spectrum.getSpectrumFile(spectrumKey);
TargetDecoyMap targetDecoyMap = psmMap.getTargetDecoyMap(charge, fileName);
double psmThreshold = 0;
double confidenceThreshold = 100;
boolean noValidated = true;
if (targetDecoyMap != null) {
TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
psmThreshold = targetDecoyResults.getScoreLimit();
confidenceThreshold = targetDecoyResults.getConfidenceLimit() + targetDecoyMap.getResolution();
if (confidenceThreshold > 100) {
confidenceThreshold = 100;
}
noValidated = targetDecoyResults.noValidated();
}
if (!noValidated && psParameter.getPsmProbabilityScore() <= psmThreshold) {
String spectrumFile = Spectrum.getSpectrumFile(spectrumKey);
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
if (spectrumMatch.getBestPeptideAssumption() != null) {
// update the annotation preferences for the new psm, mainly the charge
annotationPreferences.setCurrentSettings(spectrumMatch.getBestPeptideAssumption(), true, sequenceMatchingPreferences);
} else if (spectrumMatch.getBestTagAssumption() != null) {
charge = spectrumMatch.getBestTagAssumption().getIdentificationCharge().value;
} else {
throw new IllegalArgumentException("No best tag or peptide found for spectrum " + spectrumKey);
}
String reasonDoubtful = null;
boolean filterPassed = true;
for (PsmFilter filter : psmMap.getDoubtfulMatchesFilters(charge, spectrumFile)) {
boolean validated = filter.isValidated(spectrumKey, identification, searchParameters, annotationPreferences, peptideSpectrumAnnotator);
psParameter.setQcResult(filter.getName(), validated);
if (!validated) {
if (filter.getName().toLowerCase().contains("deviation")) {
filter.isValidated(spectrumKey, identification, searchParameters, annotationPreferences, peptideSpectrumAnnotator);
} else if (filter.getName().toLowerCase().contains("coverage")) {
filter.isValidated(spectrumKey, identification, searchParameters, annotationPreferences, peptideSpectrumAnnotator);
}
filterPassed = false;
if (reasonDoubtful == null) {
reasonDoubtful = "";
} else {
reasonDoubtful += ", ";
}
reasonDoubtful += filter.getDescription();
}
}
boolean confidenceThresholdPassed = psParameter.getPsmConfidence() >= confidenceThreshold; //@TODO: not sure whether we should include all 100% confidence hits by default?
if (!confidenceThresholdPassed) {
if (reasonDoubtful == null) {
reasonDoubtful = "";
} else {
reasonDoubtful += ", ";
}
reasonDoubtful += "Low confidence";
}
boolean enoughHits = targetDecoyMap.getnTargetOnly() > 100;
if (!enoughHits) {
if (reasonDoubtful == null) {
reasonDoubtful = "";
} else {
reasonDoubtful += ", ";
}
reasonDoubtful += "Low number of hits";
}
if (!sequenceFactory.hasEnoughSequences()) {
if (reasonDoubtful == null) {
reasonDoubtful = "";
} else {
reasonDoubtful += ", ";
}
reasonDoubtful += "Database too small";
}
if (filterPassed && confidenceThresholdPassed && enoughHits && sequenceFactory.hasEnoughSequences()) {
psParameter.setMatchValidationLevel(MatchValidationLevel.confident);
} else {
psParameter.setMatchValidationLevel(MatchValidationLevel.doubtful);
if (reasonDoubtful != null) {
psParameter.setReasonDoubtful(reasonDoubtful);