use of com.compomics.util.parameters.identification.advanced.PsmScoringParameters in project peptide-shaker by compomics.
the class PsmScorer method scorePsms.
/**
* Attaches a score to the PSMs.
*
* @param identification the object containing the identification matches
* @param inputMap the input map scores
* @param processingPreferences the processing preferences
* @param identificationParameters the identification parameters
* @param waitingHandler the handler displaying feedback to the user
*/
public void scorePsms(Identification identification, InputMap inputMap, ProcessingParameters processingPreferences, IdentificationParameters identificationParameters, WaitingHandler waitingHandler) {
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
PsmScoringParameters psmScoringPreferences = identificationParameters.getPsmScoringParameters();
PSParameter psParameter = new PSParameter();
SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
SpectrumMatch spectrumMatch;
while ((spectrumMatch = psmIterator.next()) != null) {
String spectrumFile = spectrumMatch.getSpectrumFile();
HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> assumptions = spectrumMatch.getPeptideAssumptionsMap();
for (Entry<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> entry1 : assumptions.entrySet()) {
int advocateIndex = entry1.getKey();
if (psmScoringPreferences.isScoringNeeded(advocateIndex)) {
HashSet<Integer> scoresForAdvocate = psmScoringPreferences.getScoreForAlgorithm(advocateIndex);
if (!scoresForAdvocate.isEmpty()) {
TreeMap<Double, ArrayList<PeptideAssumption>> advocateAssumptions = entry1.getValue();
for (double eValue : advocateAssumptions.keySet()) {
for (SpectrumIdentificationAssumption assumption : advocateAssumptions.get(eValue)) {
if (assumption instanceof PeptideAssumption) {
psParameter = (PSParameter) assumption.getUrParam(psParameter);
double score = 1.0;
if (scoresForAdvocate.size() == 1 || !fastaParameters.isTargetDecoy()) {
score = psParameter.getIntermediateScore(scoresForAdvocate.iterator().next());
} else {
for (int scoreIndex : scoresForAdvocate) {
TargetDecoyMap targetDecoyMap = inputMap.getIntermediateScoreMap(spectrumFile, advocateIndex, scoreIndex);
Double intermediateScore = psParameter.getIntermediateScore(scoreIndex);
if (intermediateScore != null) {
double p = targetDecoyMap.getProbability(intermediateScore);
score *= (1.0 - p);
}
}
score = 1 - score;
}
assumption.setScore(score);
PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
Peptide peptide = peptideAssumption.getPeptide();
boolean decoy = PeptideUtils.isDecoy(peptide, sequenceProvider);
inputMap.addEntry(advocateIndex, spectrumFile, assumption.getScore(), decoy);
}
}
}
}
}
}
if (waitingHandler.isRunCanceled()) {
return;
}
waitingHandler.increaseSecondaryProgressCounter();
identification.updateObject(spectrumMatch.getKey(), spectrumMatch);
}
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
use of com.compomics.util.parameters.identification.advanced.PsmScoringParameters in project peptide-shaker by compomics.
the class PeptideShaker method createProject.
/**
* Creates a PeptideShaker project.
*
* @param waitingHandler the handler displaying feedback to the user
* @param exceptionHandler handler for exceptions
* @param identificationParameters the identification parameters
* @param processingParameters the processing parameters
* @param projectType the project type
* @param spectrumCountingParameters the spectrum counting parameters
* @param spectrumProvider the spectrum provider
* @param setWaitingHandlerFinshedWhenDone if true, the waiting handler is
* set to finished when the project is created
* @param projectDetails the project details
*
* @throws java.lang.InterruptedException exception thrown if a thread gets
* interrupted
* @throws java.util.concurrent.TimeoutException exception thrown if a
* process times out
* @throws java.io.IOException if an exception occurs when parsing files
*/
public void createProject(IdentificationParameters identificationParameters, ProcessingParameters processingParameters, SpectrumCountingParameters spectrumCountingParameters, SpectrumProvider spectrumProvider, ProjectDetails projectDetails, ProjectType projectType, WaitingHandler waitingHandler, boolean setWaitingHandlerFinshedWhenDone, ExceptionHandler exceptionHandler) throws InterruptedException, TimeoutException, IOException {
identification.getObjectsDB().commit();
identificationFeaturesGenerator = new IdentificationFeaturesGenerator(identification, identificationParameters, sequenceProvider, spectrumProvider, metrics, spectrumCountingParameters);
matchesValidator = new MatchesValidator(new TargetDecoyMap(), new TargetDecoyMap(), new TargetDecoyMap());
if (waitingHandler.isRunCanceled()) {
return;
}
PsmScoringParameters psmScoringPreferences = identificationParameters.getPsmScoringParameters();
FastaParameters fastaParameters = identificationParameters.getFastaParameters();
FastaSummary fastaSummary = FastaSummary.getSummary(projectDetails.getFastaFile(), fastaParameters, waitingHandler);
// set the background species
identificationParameters.getGeneParameters().setBackgroundSpeciesFromFastaSummary(fastaSummary);
ArrayList<Integer> usedAlgorithms = projectDetails.getIdentificationAlgorithms();
if (psmScoringPreferences.isScoringNeeded(usedAlgorithms)) {
waitingHandler.appendReport("Estimating PSM scores.", true, true);
PsmScorer psmScorer = new PsmScorer(fastaParameters, sequenceProvider, spectrumProvider);
psmScorer.estimateIntermediateScores(identification, inputMap, processingParameters, identificationParameters, waitingHandler, exceptionHandler);
if (psmScoringPreferences.isTargetDecoyNeededForPsmScoring(usedAlgorithms)) {
if (fastaParameters.isTargetDecoy()) {
waitingHandler.appendReport("Estimating intermediate scores probabilities.", true, true);
psmScorer.estimateIntermediateScoreProbabilities(identification, inputMap, processingParameters, waitingHandler);
} else {
waitingHandler.appendReport("No decoy sequences found. Impossible to " + "estimate intermediate scores probabilities.", true, true);
}
}
waitingHandler.appendReport("Scoring PSMs.", true, true);
psmScorer.scorePsms(identification, inputMap, processingParameters, identificationParameters, waitingHandler);
}
identification.getObjectsDB().commit();
System.gc();
if (fastaParameters.isTargetDecoy()) {
waitingHandler.appendReport("Computing assumptions probabilities.", true, true);
} else {
waitingHandler.appendReport("Importing assumptions scores.", true, true);
}
inputMap.estimateProbabilities(waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving assumptions probabilities, selecting best match, scoring modification localization.", true, true);
PsmProcessor psmProcessor = new PsmProcessor(identification);
psmProcessor.processPsms(inputMap, identificationParameters, matchesValidator, modificationLocalizationScorer, sequenceProvider, spectrumProvider, modificationFactory, proteinCount, processingParameters.getnThreads(), waitingHandler, exceptionHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing PSM probabilities.", true, true);
matchesValidator.getPsmMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
PeptideInference peptideInference = new PeptideInference();
ModificationLocalizationParameters modificationScoringPreferences = identificationParameters.getModificationLocalizationParameters();
if (modificationScoringPreferences.getAlignNonConfidentModifications()) {
waitingHandler.appendReport("Resolving peptide inference issues.", true, true);
peptideInference.peptideInference(identification, identificationParameters, sequenceProvider, modificationFactory, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
identification.getObjectsDB().commit();
System.gc();
}
String reportTxt = "Saving probabilities";
String waitingTitle = "Saving Probabilities.";
;
switch(projectType) {
case psm:
reportTxt += ".";
break;
case peptide:
reportTxt += ", building peptides.";
waitingTitle += " Building Peptides.";
break;
default:
reportTxt += ", building peptides and proteins.";
waitingTitle += " Building Peptides and Proteins.";
}
waitingHandler.appendReport(reportTxt, true, true);
waitingHandler.setWaitingText(waitingTitle + " Please Wait...");
attachSpectrumProbabilitiesAndBuildPeptidesAndProteins(sequenceProvider, identificationParameters.getSequenceMatchingParameters(), projectType, fastaParameters, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
waitingHandler.appendReport("Generating peptide map.", true, true);
matchesValidator.fillPeptideMaps(identification, metrics, waitingHandler, identificationParameters, sequenceProvider, spectrumProvider);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing peptide probabilities.", true, true);
matchesValidator.getPeptideMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving peptide probabilities.", true, true);
matchesValidator.attachPeptideProbabilities(identification, fastaParameters, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.protein) {
if (identificationParameters.getProteinInferenceParameters().getSimplifyGroups()) {
waitingHandler.appendReport("Simplifying protein groups.", true, true);
GroupSimplification groupSimplification = new GroupSimplification();
groupSimplification.removeRedundantGroups(identification, identificationParameters, sequenceProvider, proteinDetailsProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
identification.getObjectsDB().commit();
System.gc();
ProteinInference proteinInference = new ProteinInference();
waitingHandler.appendReport("Mapping shared peptides.", true, true);
proteinInference.distributeSharedPeptides(identification, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Generating protein map.", true, true);
matchesValidator.fillProteinMap(identification, spectrumProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Selecting leading proteins, inferring peptide and protein inference status.", true, true);
proteinInference.inferPiStatus(identification, metrics, matchesValidator.getProteinMap(), identificationParameters, sequenceProvider, proteinDetailsProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing protein probabilities.", true, true);
matchesValidator.getProteinMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving protein probabilities.", true, true);
matchesValidator.attachProteinProbabilities(identification, sequenceProvider, fastaParameters, metrics, waitingHandler, identificationParameters.getFractionParameters());
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
}
}
if (fastaParameters.isTargetDecoy()) {
IdMatchValidationParameters idMatchValidationParameters = identificationParameters.getIdValidationParameters();
if (idMatchValidationParameters.getDefaultPsmFDR() == 1 && idMatchValidationParameters.getDefaultPeptideFDR() == 1 && idMatchValidationParameters.getDefaultProteinFDR() == 1) {
waitingHandler.appendReport("Validating identifications at 1% FDR, quality control of matches.", true, true);
} else {
waitingHandler.appendReport("Validating identifications, quality control of matches.", true, true);
}
} else {
waitingHandler.appendReport("Quality control of matches.", true, true);
}
matchesValidator.validateIdentifications(identification, metrics, inputMap, waitingHandler, exceptionHandler, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, projectType, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
waitingHandler.appendReport("Scoring PTMs in peptides.", true, true);
modificationLocalizationScorer.scorePeptidePtms(identification, modificationFactory, waitingHandler, identificationParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.protein) {
waitingHandler.appendReport("Estimating spectrum counting scaling values.", true, true);
ScalingFactorsEstimators scalingFactors = new ScalingFactorsEstimators(spectrumCountingParameters);
scalingFactors.estimateScalingFactors(identification, metrics, sequenceProvider, identificationFeaturesGenerator, waitingHandler, exceptionHandler, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Scoring PTMs in proteins, gathering summary metrics.", true, true);
ProteinProcessor proteinProcessor = new ProteinProcessor(identification, identificationParameters, identificationFeaturesGenerator, sequenceProvider);
proteinProcessor.processProteins(modificationLocalizationScorer, metrics, modificationFactory, waitingHandler, exceptionHandler, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
}
}
projectCreationDuration.end();
String report = "Identification processing completed (" + projectCreationDuration.toString() + ").";
waitingHandler.appendReport(report, true, true);
waitingHandler.appendReportEndLine();
waitingHandler.appendReportEndLine();
identification.addUrParam(new PSMaps(inputMap, matchesValidator.getPsmMap(), matchesValidator.getPeptideMap(), matchesValidator.getProteinMap()));
if (setWaitingHandlerFinshedWhenDone) {
waitingHandler.setRunFinished();
}
}
use of com.compomics.util.parameters.identification.advanced.PsmScoringParameters in project peptide-shaker by compomics.
the class PsmScorer method estimateIntermediateScores.
/**
* Scores the PSMs contained in an identification object.
*
* @param identification the object containing the identification matches
* @param spectrumMatch a spectrum match containing the peptides and
* spectrum to score
* @param inputMap the input map scores
* @param identificationParameters identification parameters used
* @param peptideSpectrumAnnotator the spectrum annotator to use
* @param hyperScore the object to use to compute the hyperscore
* @param waitingHandler the handler displaying feedback to the user
*
* @return a list of advocates where no e-values could be found
*/
public ArrayList<Integer> estimateIntermediateScores(Identification identification, SpectrumMatch spectrumMatch, InputMap inputMap, IdentificationParameters identificationParameters, PeptideSpectrumAnnotator peptideSpectrumAnnotator, HyperScore hyperScore, WaitingHandler waitingHandler) {
AnnotationParameters annotationPreferences = identificationParameters.getAnnotationParameters();
PsmScoringParameters psmScoringPreferences = identificationParameters.getPsmScoringParameters();
String spectrumFile = spectrumMatch.getSpectrumFile();
String spectrumTitle = spectrumMatch.getSpectrumTitle();
HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> assumptions = spectrumMatch.getPeptideAssumptionsMap();
ArrayList<Integer> missingEvalue = new ArrayList<>(0);
for (Entry<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> entry1 : assumptions.entrySet()) {
int advocateIndex = entry1.getKey();
if (psmScoringPreferences.isScoringNeeded(advocateIndex)) {
HashSet<Integer> scoresForAdvocate = psmScoringPreferences.getScoreForAlgorithm(advocateIndex);
TreeMap<Double, ArrayList<PeptideAssumption>> algorthmAssumptions = entry1.getValue();
// the hyperscore requires a second pass for the e-value estimation
ArrayList<Double> hyperScores = null;
ArrayList<PSParameter> hyperScoreParameters = null;
ArrayList<Boolean> hyperScoreDecoys = null;
if (scoresForAdvocate.contains(PsmScore.hyperScore.index)) {
hyperScores = new ArrayList<>(algorthmAssumptions.size());
hyperScoreParameters = new ArrayList<>(algorthmAssumptions.size());
hyperScoreDecoys = new ArrayList<>(algorthmAssumptions.size());
}
for (Entry<Double, ArrayList<PeptideAssumption>> entry2 : algorthmAssumptions.entrySet()) {
for (PeptideAssumption peptideAssumption : entry2.getValue()) {
PSParameter assumptionParameter = new PSParameter();
Peptide peptide = peptideAssumption.getPeptide();
boolean decoy = PeptideUtils.isDecoy(peptide, sequenceProvider);
Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
for (Integer scoreIndex : scoresForAdvocate) {
double score;
if (scoreIndex.equals(PsmScore.native_score.index)) {
score = peptideAssumption.getScore();
} else {
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
SpecificAnnotationParameters specificAnnotationPreferences = annotationPreferences.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
score = psmScoresEstimator.getDecreasingScore(peptide, peptideAssumption.getIdentificationCharge(), spectrumFile, spectrumTitle, spectrum, identificationParameters, specificAnnotationPreferences, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator, scoreIndex);
}
assumptionParameter.setIntermediateScore(scoreIndex, score);
if (scoreIndex.equals(PsmScore.hyperScore.index)) {
hyperScores.add(-score);
hyperScoreParameters.add(assumptionParameter);
hyperScoreDecoys.add(decoy);
} else {
inputMap.setIntermediateScore(spectrumFile, advocateIndex, scoreIndex, score, decoy, psmScoringPreferences);
}
}
peptideAssumption.addUrParam(assumptionParameter);
}
}
if (scoresForAdvocate.contains(PsmScore.hyperScore.index)) {
HashMap<Double, Double> eValuesMap = hyperScore.getEValueMap(hyperScores);
if (eValuesMap != null) {
for (int i = 0; i < hyperScores.size(); i++) {
double score = hyperScores.get(i);
PSParameter psParameter = hyperScoreParameters.get(i);
boolean decoy = hyperScoreDecoys.get(i);
double eValue = eValuesMap.get(score);
psParameter.setIntermediateScore(PsmScore.hyperScore.index, eValue);
inputMap.setIntermediateScore(spectrumFile, advocateIndex, PsmScore.hyperScore.index, score, decoy, psmScoringPreferences);
}
} else {
missingEvalue.add(advocateIndex);
}
}
}
}
identification.updateObject(spectrumMatch.getKey(), spectrumMatch);
return missingEvalue;
}
Aggregations