Search in sources :

Example 1 with IdMatchValidationParameters

use of com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters 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();
    }
}
Also used : ProteinInference(eu.isas.peptideshaker.protein_inference.ProteinInference) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) PeptideInference(com.compomics.util.experiment.identification.peptide_inference.PeptideInference) MatchesValidator(eu.isas.peptideshaker.validation.MatchesValidator) ScalingFactorsEstimators(com.compomics.util.experiment.quantification.spectrumcounting.ScalingFactorsEstimators) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) PsmScorer(eu.isas.peptideshaker.scoring.psm_scoring.PsmScorer) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) PsmScoringParameters(com.compomics.util.parameters.identification.advanced.PsmScoringParameters) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) ProteinProcessor(eu.isas.peptideshaker.processing.ProteinProcessor) GroupSimplification(eu.isas.peptideshaker.protein_inference.GroupSimplification) FastaParameters(com.compomics.util.experiment.io.biology.protein.FastaParameters) PsmProcessor(eu.isas.peptideshaker.processing.PsmProcessor)

Example 2 with IdMatchValidationParameters

use of com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters in project peptide-shaker by compomics.

the class MzIdentMLExport method writeAnalysisProtocol.

/**
 * Write the analysis protocol.
 */
private void writeAnalysisProtocol() {
    writer.write(getCurrentTabSpace());
    writer.write("<AnalysisProtocolCollection>");
    writer.newLine();
    tabCounter++;
    // add spectrum identification protocol
    writer.write(getCurrentTabSpace());
    writer.write("<SpectrumIdentificationProtocol analysisSoftware_ref=\"ID_software\" id=\"SearchProtocol_1\">");
    writer.newLine();
    tabCounter++;
    // the search type
    writer.write(getCurrentTabSpace());
    writer.write("<SearchType>");
    writer.newLine();
    tabCounter++;
    writeCvTerm(new CvTerm("PSI-MS", "MS:1001083", "ms-ms search", null));
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</SearchType>");
    writer.newLine();
    // the search parameters
    SearchParameters searchParameters = identificationParameters.getSearchParameters();
    writer.write(getCurrentTabSpace());
    writer.write("<AdditionalSearchParams>");
    writer.newLine();
    tabCounter++;
    writeCvTerm(new CvTerm("PSI-MS", "MS:1001211", "parent mass type mono", null));
    writeCvTerm(new CvTerm("PSI-MS", "MS:1001256", "fragment mass type mono", null));
    switch(mzIdentMLVersion) {
        case v1_1:
            break;
        case v1_2:
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002492", "consensus scoring", null));
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002490", "peptide-level scoring", null));
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002497", "group PSMs by sequence with modifications", null));
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002491", "modification localization scoring", null));
            break;
        default:
            throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
    }
    // @TODO: list all search parameters from the search engines used?
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</AdditionalSearchParams>");
    writer.newLine();
    // the modifications
    writer.write(getCurrentTabSpace());
    writer.write("<ModificationParams>");
    writer.newLine();
    tabCounter++;
    // create the ptm index map
    switch(mzIdentMLVersion) {
        case v1_1:
            break;
        case v1_2:
            for (String modName : searchParameters.getModificationParameters().getAllModifications()) {
                Modification modification = modificationProvider.getModification(modName);
                Double modMass = modification.getMass();
                Integer index = modIndexMap.get(modMass);
                if (index == null) {
                    modIndexMap.put(modMass, modIndexMap.size());
                }
            }
            break;
        default:
            throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
    }
    // iterate and add the modifications
    for (String modName : searchParameters.getModificationParameters().getAllModifications()) {
        Modification modification = modificationProvider.getModification(modName);
        ModificationType modificationType = modification.getModificationType();
        double modMass = modification.getMass();
        String aminoAcidsAtTarget;
        if (modificationType == ModificationType.modaa || modificationType == ModificationType.modcaa_peptide || modificationType == ModificationType.modcaa_protein || modificationType == ModificationType.modnaa_peptide || modificationType == ModificationType.modnaa_protein) {
            StringBuilder sb = new StringBuilder();
            for (Character aa : modification.getPattern().getAminoAcidsAtTarget()) {
                sb.append(aa);
            }
            aminoAcidsAtTarget = sb.toString();
        } else {
            aminoAcidsAtTarget = ".";
        }
        writer.write(getCurrentTabSpace());
        writer.write("<SearchModification residues=\"");
        writer.write(aminoAcidsAtTarget);
        writer.write("\" massDelta=\"");
        writer.write(Double.toString(modification.getRoundedMass()));
        writer.write("\" fixedMod= \"");
        writer.write(Boolean.toString(searchParameters.getModificationParameters().getFixedModifications().contains(modName)));
        writer.write("\" >");
        writer.newLine();
        tabCounter++;
        // add modification specificity
        if (modificationType != ModificationType.modaa) {
            writer.write(getCurrentTabSpace());
            writer.write("<SpecificityRules>");
            writer.newLine();
            tabCounter++;
            switch(modificationType) {
                case modn_protein:
                case modnaa_protein:
                    writeCvTerm(new CvTerm("PSI-MS", "MS:1002057", "modification specificity protein N-term", null));
                    break;
                case modn_peptide:
                case modnaa_peptide:
                    writeCvTerm(new CvTerm("PSI-MS", "MS:1001189", "modification specificity peptide N-term", null));
                    break;
                case modc_protein:
                case modcaa_protein:
                    writeCvTerm(new CvTerm("PSI-MS", "MS:1002058", "modification specificity protein C-term", null));
                    break;
                case modc_peptide:
                case modcaa_peptide:
                    writeCvTerm(new CvTerm("PSI-MS", "MS:1001190", "modification specificity peptide C-term", null));
                    break;
                default:
                    break;
            }
            tabCounter--;
            writer.write(getCurrentTabSpace());
            writer.write("</SpecificityRules>");
            writer.newLine();
        }
        // add the modification cv term
        CvTerm ptmCvTerm = modification.getUnimodCvTerm();
        if (ptmCvTerm != null) {
            writeCvTerm(ptmCvTerm);
        } else {
            // try PSI-MOD instead
            ptmCvTerm = modification.getPsiModCvTerm();
            if (ptmCvTerm != null) {
                writeCvTerm(ptmCvTerm);
            } else {
                writeCvTerm(new CvTerm("PSI-MS", "MS:1001460", "unknown modification", null));
            }
        }
        // add modification type/index
        switch(mzIdentMLVersion) {
            case v1_1:
                break;
            case v1_2:
                Integer modIndex = modIndexMap.get(modMass);
                if (modIndex == null) {
                    throw new IllegalArgumentException("No index found for PTM " + modification.getName() + " of mass " + modMass + ".");
                }
                writeCvTerm(new CvTerm("PSI-MS", "MS:1002504", "modification index", modIndex.toString()));
                break;
            default:
                throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
        }
        tabCounter--;
        writer.write(getCurrentTabSpace());
        writer.write("</SearchModification>");
        writer.newLine();
    }
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</ModificationParams>");
    writer.newLine();
    // Digestion
    DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
    if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.unSpecific) {
        writer.write(getCurrentTabSpace());
        writer.write("<Enzymes independent=\"false\">");
        writer.newLine();
        tabCounter++;
        writer.write(getCurrentTabSpace());
        writer.write("<Enzyme name=\"unspecific cleavage\">");
        writer.newLine();
        tabCounter++;
        writer.write(getCurrentTabSpace());
        writer.write("<EnzymeName>");
        writer.newLine();
        tabCounter++;
        CvTerm enzymeCvTerm = new CvTerm("PSI-MS", "MS:1001091", "unspecific cleavage", null);
        writeCvTerm(enzymeCvTerm);
        tabCounter--;
        writer.write(getCurrentTabSpace());
        writer.write("</EnzymeName>");
        writer.newLine();
        tabCounter--;
        writer.write(getCurrentTabSpace());
        writer.write("</Enzyme>");
        writer.newLine();
    } else if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.wholeProtein) {
        writer.write(getCurrentTabSpace());
        writer.write("<Enzymes independent=\"false\">");
        writer.newLine();
        tabCounter++;
        writer.write(getCurrentTabSpace());
        writer.write("<Enzyme name=\"NoEnzyme\">");
        writer.newLine();
        tabCounter++;
        writer.write(getCurrentTabSpace());
        writer.write("<EnzymeName>");
        writer.newLine();
        tabCounter++;
        CvTerm enzymeCvTerm = new CvTerm("PSI-MS", "MS:1001955", "NoEnzyme", null);
        writeCvTerm(enzymeCvTerm);
        tabCounter--;
        writer.write(getCurrentTabSpace());
        writer.write("</EnzymeName>");
        writer.newLine();
        tabCounter--;
        writer.write(getCurrentTabSpace());
        writer.write("</Enzyme>");
        writer.newLine();
    } else {
        ArrayList<Enzyme> enzymes = digestionPreferences.getEnzymes();
        writer.write(getCurrentTabSpace());
        writer.write("<Enzymes independent=\"");
        writer.write(Boolean.toString(enzymes.size() > 1));
        writer.write("\">");
        writer.newLine();
        tabCounter++;
        for (Enzyme enzyme : enzymes) {
            String enzymeName = enzyme.getName();
            writer.write(getCurrentTabSpace());
            writer.write("<Enzyme missedCleavages=\"");
            writer.write(Integer.toString(digestionPreferences.getnMissedCleavages(enzymeName)));
            writer.write("\" semiSpecific=\"");
            writer.write(Boolean.toString(digestionPreferences.getSpecificity(enzymeName) == DigestionParameters.Specificity.semiSpecific));
            writer.write("\" ");
            // + "cTermGain=\"OH\" " // Element formula gained at CTerm
            // + "nTermGain=\"H\" " // Element formula gained at NTerm
            // @TODO: add <SiteRegexp><![CDATA[(?<=[KR])(?!P)]]></SiteRegexp>?
            writer.write("id=\"Enz1\" name=\"");
            writer.write(enzyme.getName());
            writer.write("\">");
            writer.newLine();
            tabCounter++;
            writer.write(getCurrentTabSpace());
            writer.write("<EnzymeName>");
            writer.newLine();
            tabCounter++;
            CvTerm enzymeCvTerm = enzyme.getCvTerm();
            if (enzymeCvTerm != null) {
                writeCvTerm(enzymeCvTerm);
            } else {
                writeUserParam(enzyme.getName());
            }
            tabCounter--;
            writer.write(getCurrentTabSpace());
            writer.write("</EnzymeName>");
            writer.newLine();
            tabCounter--;
            writer.write(getCurrentTabSpace());
            writer.write("</Enzyme>");
            writer.newLine();
            tabCounter--;
        }
    }
    writer.write(getCurrentTabSpace());
    writer.write("</Enzymes>");
    writer.newLine();
    // fragment tolerance
    writer.write(getCurrentTabSpace());
    writer.write("<FragmentTolerance>");
    writer.newLine();
    tabCounter++;
    String fragmentIonToleranceUnit;
    String unitAccession;
    switch(searchParameters.getFragmentAccuracyType()) {
        case DA:
            fragmentIonToleranceUnit = "dalton";
            unitAccession = "UO:0000221";
            break;
        case PPM:
            fragmentIonToleranceUnit = "parts per million";
            unitAccession = "UO:0000169";
            break;
        default:
            throw new UnsupportedOperationException("CV term not implemented for fragment accuracy in " + searchParameters.getFragmentAccuracyType() + ".");
    }
    writer.write(getCurrentTabSpace());
    writer.write("<cvParam accession=\"MS:1001412\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
    writer.write(fragmentIonToleranceUnit);
    writer.write("\" unitAccession=\"");
    writer.write(unitAccession);
    writer.write("\" value=\"");
    writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
    writer.write("\" ");
    writer.write("name=\"search tolerance plus value\" />");
    writer.newLine();
    writer.write(getCurrentTabSpace());
    writer.write("<cvParam accession=\"MS:1001413\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
    writer.write(fragmentIonToleranceUnit);
    writer.write("\" unitAccession=\"");
    writer.write(unitAccession);
    writer.write("\" value=\"");
    writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
    writer.write("\" name=\"search tolerance minus value\" />");
    writer.newLine();
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</FragmentTolerance>");
    writer.newLine();
    // precursor tolerance
    writer.write(getCurrentTabSpace());
    writer.write("<ParentTolerance>");
    writer.newLine();
    tabCounter++;
    String precursorIonToleranceUnit;
    switch(searchParameters.getPrecursorAccuracyType()) {
        case DA:
            precursorIonToleranceUnit = "dalton";
            break;
        case PPM:
            precursorIonToleranceUnit = "parts per million";
            break;
        default:
            throw new UnsupportedOperationException("CV term not implemented for precursor accuracy in " + searchParameters.getFragmentAccuracyType() + ".");
    }
    writer.write(getCurrentTabSpace());
    writer.write("<cvParam accession=\"MS:1001412\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
    writer.write(precursorIonToleranceUnit);
    writer.write("\" unitAccession=\"UO:0000169\" value=\"");
    writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
    writer.write("\" name=\"search tolerance plus value\" />");
    writer.newLine();
    writer.write(getCurrentTabSpace());
    writer.write("<cvParam accession=\"MS:1001413\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
    writer.write(precursorIonToleranceUnit);
    writer.write("\" unitAccession=\"UO:0000169\" value=\"");
    writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
    writer.write("\" name=\"search tolerance minus value\" />");
    tabCounter--;
    writer.newLine();
    writer.write(getCurrentTabSpace());
    writer.write("</ParentTolerance>");
    writer.newLine();
    // thresholds
    writer.write(getCurrentTabSpace());
    writer.write("<Threshold>");
    writer.newLine();
    tabCounter++;
    boolean targetDecoy = identificationParameters.getFastaParameters().isTargetDecoy();
    if (!targetDecoy) {
        writeCvTerm(new CvTerm("PSI-MS", "MS:1001494", "no threshold", null));
    } else {
        // Initial global thresholds
        IdMatchValidationParameters idMatchValidationPreferences = identificationParameters.getIdValidationParameters();
        writeCvTerm(new CvTerm("PSI-MS", "MS:1001364", "peptide sequence-level global FDR", Double.toString(Util.roundDouble(idMatchValidationPreferences.getDefaultPeptideFDR(), CONFIDENCE_DECIMALS))));
        writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(idMatchValidationPreferences.getDefaultPsmFDR(), CONFIDENCE_DECIMALS))));
        ModificationLocalizationParameters ptmScoringPreferences = identificationParameters.getModificationLocalizationParameters();
        if (ptmScoringPreferences.isProbabilisticScoreCalculation()) {
            if (ptmScoringPreferences.getSelectedProbabilisticScore() == ModificationLocalizationScore.PhosphoRS) {
                writeCvTerm(new CvTerm("PSI-MS", "MS:1002567", "phosphoRS score threshold", Double.toString(ptmScoringPreferences.getProbabilisticScoreThreshold())));
            }
        }
        writeCvTerm(new CvTerm("PSI-MS", "MS:1002557", "D-Score threshold", Double.toString(identificationParameters.getModificationLocalizationParameters().getDScoreThreshold())));
    // @TODO: add peptide and psm level annotation
    // // peptideshaker maps
    // PSMaps psMaps = new PSMaps();
    // psMaps = (PSMaps) identification.getUrParam(psMaps);
    // 
    // // peptide level threshold
    // PeptideSpecificMap peptideSpecificMap = psMaps.getPeptideSpecificMap();
    // ArrayList<String> peptideGroupsKeys = peptideSpecificMap.getKeys();
    // 
    // for (String key : peptideGroupsKeys) { // @TODO: find a way of annotating all thresholds..?
    // TargetDecoyMap targetDecoyMap = peptideSpecificMap.getTargetDecoyMap(key);
    // TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
    // double threshold = targetDecoyResults.getUserInput() / 100;
    // int thresholdType = targetDecoyResults.getInputType();
    // if (peptideGroupsKeys.size() > 1) {
    // String peptideClass = PeptideSpecificMap.getKeyName(searchParameters.getModificationProfile(), key);
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002544", "PeptideShaker peptide confidence type", peptideClass)); // peptide confidence type
    // }
    // if (thresholdType == 0) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002463", "distinct peptide-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
    // } else if (targetDecoyResults.getInputType() == 1) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1001364", "peptide sequence-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
    // } else if (targetDecoyResults.getInputType() == 2) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002462", "distinct peptide-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
    // }
    // }
    // 
    // // psm level threshold
    // ArrayList<Integer> chargesWithFileSpecificity = new ArrayList<Integer>();
    // PsmSpecificMap psmSpecificMap = psMaps.getPsmSpecificMap();
    // 
    // for (Integer charge : psmSpecificMap.getPossibleCharges()) {
    // for (String file : psmSpecificMap.getFilesAtCharge(charge)) {
    // if (!psmSpecificMap.isFileGrouped(charge, file)) { // @TODO: find a way of annotating all thresholds..?
    // chargesWithFileSpecificity.add(charge);
    // TargetDecoyMap targetDecoyMap = psMaps.getPsmSpecificMap().getTargetDecoyMap(charge, file);
    // TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
    // double threshold = targetDecoyResults.getUserInput() / 100;
    // int thresholdType = targetDecoyResults.getInputType();
    // String psmClass = "Charge " + charge + " of file " + file; // @TODO: annotate class?
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002543", "PeptideShaker PSM confidence type", "???")); // psm confidence type
    // if (thresholdType == 0) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002465", "PSM-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
    // } else if (targetDecoyResults.getInputType() == 1) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
    // } else if (targetDecoyResults.getInputType() == 2) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002464", "PSM-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
    // }
    // }
    // }
    // }
    // 
    // //@TODO: set the PSM group label
    // for (int charge : psmSpecificMap.getChargesFromGroupedFiles()) {
    // int correctedCharge = psmSpecificMap.getCorrectedCharge(charge);
    // if (correctedCharge == charge) {
    // TargetDecoyMap targetDecoyMap = psMaps.getPsmSpecificMap().getTargetDecoyMap(charge, null);
    // TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
    // double threshold = targetDecoyResults.getUserInput() / 100;
    // int thresholdType = targetDecoyResults.getInputType();
    // // @TODO: check the cv terms used!!!
    // if (thresholdType == 0) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002465", "PSM-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
    // } else if (targetDecoyResults.getInputType() == 1) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
    // } else if (targetDecoyResults.getInputType() == 2) {
    // writeCvTerm(new CvTerm("PSI-MS", "MS:1002464", "PSM-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
    // }
    // }
    // }
    // 
    // // @TODO: re-add psm ptm thresholds
    // PsmPTMMap psmPTMMap = psMaps.getPsmPTMMap();
    // if (psmPTMMap != null) { // backward compatibility: information only present in versions 0.28.2 and later
    // for (Double ptmMass : psmPTMMap.getModificationsScored()) {
    // for (int mapKey : psmPTMMap.getKeys(ptmMass).keySet()) {
    // TargetDecoyMap targetDecoyMap = psmPTMMap.getTargetDecoyMap(ptmMass, mapKey);
    // TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
    // double threshold = targetDecoyResults.getUserInput() / 100;
    // int thresholdType = targetDecoyResults.getInputType(); // For now only FDR is implemented but others will follow after my next transatlantic flight :)
    // String ptmClass = "Modification of mass " + ptmMass;
    // //@TODO: find cv terms
    // }
    // }
    // }
    // @TODO: one for ptm scores, one per ptm per charge state per file
    // match quality thresholds
    // @TODO: match quality thresholds?? some are per file...
    }
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</Threshold>");
    writer.newLine();
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</SpectrumIdentificationProtocol>");
    writer.newLine();
    // add ProteinDetectionProtocol
    writer.write(getCurrentTabSpace());
    writer.write("<ProteinDetectionProtocol analysisSoftware_ref=\"ID_software\" id=\"PeptideShaker_1\">");
    writer.newLine();
    tabCounter++;
    // br.write(getCurrentTabSpace() + "<AnalysisParams>" + lineBreak);
    // tabCounter++;
    // @TODO: add cv terms? (children of MS:1001302)
    // tabCounter--;
    // br.write(getCurrentTabSpace() + "</AnalysisParams>" + lineBreak);
    // protein level threshold
    writer.write(getCurrentTabSpace());
    writer.write("<Threshold>");
    writer.newLine();
    tabCounter++;
    if (!targetDecoy) {
        writeCvTerm(new CvTerm("PSI-MS", "MS:1001494", "no threshold", null));
    } else {
        PSMaps psMaps = new PSMaps();
        psMaps = (PSMaps) identification.getUrParam(psMaps);
        TargetDecoyMap proteinMap = psMaps.getProteinMap();
        TargetDecoyResults proteinTargetDecoyResults = proteinMap.getTargetDecoyResults();
        double threshold = proteinTargetDecoyResults.getUserInput() / 100;
        int thresholdType = proteinTargetDecoyResults.getInputType();
        if (thresholdType == 0) {
            // confidence
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002461", "protein group-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
        } else if (proteinTargetDecoyResults.getInputType() == 1) {
            // FDR
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002369", "protein group-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
        } else if (proteinTargetDecoyResults.getInputType() == 2) {
            // FNR
            writeCvTerm(new CvTerm("PSI-MS", "MS:1002460", "protein group-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
        }
    }
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</Threshold>");
    writer.newLine();
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</ProteinDetectionProtocol>");
    writer.newLine();
    tabCounter--;
    writer.write(getCurrentTabSpace());
    writer.write("</AnalysisProtocolCollection>");
    writer.newLine();
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) CvTerm(com.compomics.util.pride.CvTerm) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) Enzyme(com.compomics.util.experiment.biology.enzymes.Enzyme) ArrayList(java.util.ArrayList) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults)

Example 3 with IdMatchValidationParameters

use of com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters 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();
        }
    }
}
Also used : MatchesValidator(eu.isas.peptideshaker.validation.MatchesValidator) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) ModificationLocalizationScorer(eu.isas.peptideshaker.ptm.ModificationLocalizationScorer) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) ConnectException(java.net.ConnectException) UnknownHostException(java.net.UnknownHostException) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) FileFilter(javax.swing.filechooser.FileFilter) Filter(com.compomics.util.experiment.filtering.Filter) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) ProteinProcessor(eu.isas.peptideshaker.processing.ProteinProcessor) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) ValidationQCParametersDialog(com.compomics.util.gui.parameters.identification.advanced.ValidationQCParametersDialog)

Example 4 with IdMatchValidationParameters

use of com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters in project peptide-shaker by compomics.

the class MatchesValidator method validateIdentifications.

/**
 * This method validates the identification matches of an identification
 * object. Target Decoy thresholds must be set.
 *
 * @param identification The identification class containing the matches to
 * validate.
 * @param metrics If provided, metrics on fractions will be saved while
 * iterating the matches.
 * @param geneMaps The gene maps.
 * @param inputMap The target decoy map of all search engine scores.
 * @param waitingHandler The waiting handler displaying progress to the user
 * and allowing canceling the process.
 * @param exceptionHandler The handler for exceptions.
 * @param identificationFeaturesGenerator The identification features
 * generator computing information about the identification matches.
 * @param sequenceProvider The protein sequence provider.
 * @param proteinDetailsProvider The protein details provider.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param projectType The project type.
 * @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 validateIdentifications(Identification identification, Metrics metrics, InputMap inputMap, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, GeneMaps geneMaps, IdentificationParameters identificationParameters, ProjectType projectType, ProcessingParameters processingParameters) throws InterruptedException, TimeoutException {
    IdMatchValidationParameters validationParameters = identificationParameters.getIdValidationParameters();
    waitingHandler.setWaitingText("Finding FDR Thresholds. Please Wait...");
    for (int algorithm : inputMap.getInputAlgorithms()) {
        TargetDecoyMap targetDecoyMap = inputMap.getTargetDecoyMap(algorithm);
        TargetDecoyResults currentResults = targetDecoyMap.getTargetDecoyResults();
        currentResults.setInputType(1);
        currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
        currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
        targetDecoyMap.getTargetDecoySeries().getFDRResults(currentResults);
    }
    TargetDecoyResults currentResults = psmMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
    psmMap.getTargetDecoySeries().getFDRResults(currentResults);
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    currentResults = peptideMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultPeptideFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultPeptideFDR());
    peptideMap.getTargetDecoySeries().getFDRResults(currentResults);
    currentResults = proteinMap.getTargetDecoyResults();
    currentResults.setInputType(1);
    currentResults.setUserInput(validationParameters.getDefaultProteinFDR());
    currentResults.setFdrLimit(validationParameters.getDefaultProteinFDR());
    proteinMap.getTargetDecoySeries().getFDRResults(currentResults);
    ValidationQcParameters validationQCParameters = validationParameters.getValidationQCParameters();
    waitingHandler.setWaitingText("Match Validation and Quality Control. Please Wait...");
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.resetSecondaryProgressCounter();
    waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size() + identification.getPeptideIdentification().size() + 2 * identification.getSpectrumIdentificationSize());
    // validate the spectrum matches
    if (inputMap != null) {
        inputMap.resetAdvocateContributions();
    }
    AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
    double intensityLimit = annotationParameters.getAnnotationIntensityLimit();
    annotationParameters.setIntensityLimit(0);
    ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    ArrayList<PsmValidatorRunnable> psmRunnables = new ArrayList<>(processingParameters.getnThreads());
    for (int i = 1; i <= processingParameters.getnThreads(); i++) {
        PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, false, true);
        pool.submit(runnable);
        psmRunnables.add(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
    }
    // combine the precursor mz deviations from the different threads into one map
    HashMap<String, ArrayList<Double>> precursorMzDeviations = new HashMap<>(identification.getSpectrumIdentification().size());
    for (PsmValidatorRunnable runnable : psmRunnables) {
        for (String spectrumFileName : runnable.getThreadPrecursorMzDeviations().keySet()) {
            ArrayList<Double> threadPrecursorMzDeviations = runnable.getThreadPrecursorMzDeviations().get(spectrumFileName);
            ArrayList<Double> filePrecursorMzDeviations = precursorMzDeviations.get(spectrumFileName);
            if (filePrecursorMzDeviations != null) {
                filePrecursorMzDeviations.addAll(threadPrecursorMzDeviations);
            } else {
                precursorMzDeviations.put(spectrumFileName, threadPrecursorMzDeviations);
            }
        }
    }
    for (String spectrumFileName : precursorMzDeviations.keySet()) {
        double[] precursorMzDeviationsFile = precursorMzDeviations.get(spectrumFileName).stream().mapToDouble(a -> a).toArray();
        if (precursorMzDeviationsFile.length >= 100) {
            Arrays.sort(precursorMzDeviationsFile);
            identificationFeaturesGenerator.setMassErrorDistribution(spectrumFileName, precursorMzDeviationsFile);
        } else {
            // There are not enough precursors, disable probabilistic precursor filter
            if (validationQCParameters.getPsmFilters() != null) {
                for (Filter filter : validationQCParameters.getPsmFilters()) {
                    PsmFilter psmFilter = (PsmFilter) filter;
                    if (psmFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
                        psmFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
                        SearchParameters searchParameters = identificationParameters.getSearchParameters();
                        if (searchParameters.isPrecursorAccuracyTypePpm()) {
                            psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        } else {
                            psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        }
                    }
                    AssumptionFilter assumptionFilter = psmFilter.getAssumptionFilter();
                    if (assumptionFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
                        assumptionFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
                        SearchParameters searchParameters = identificationParameters.getSearchParameters();
                        if (searchParameters.isPrecursorAccuracyTypePpm()) {
                            assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        } else {
                            assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
                        }
                    }
                }
            }
        }
    }
    pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    for (int i = 1; i <= processingParameters.getnThreads(); i++) {
        PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, true, false);
        pool.submit(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
    }
    annotationParameters.setIntensityLimit(intensityLimit);
    if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
        // validate the peptides
        pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
        ArrayList<PeptideValidatorRunnable> peptideRunnables = new ArrayList<>(processingParameters.getnThreads());
        PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(waitingHandler);
        for (int i = 1; i <= processingParameters.getnThreads(); i++) {
            PeptideValidatorRunnable runnable = new PeptideValidatorRunnable(peptideMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, metrics);
            pool.submit(runnable);
            peptideRunnables.add(runnable);
        }
        if (waitingHandler.isRunCanceled()) {
            pool.shutdownNow();
            return;
        }
        pool.shutdown();
        if (!pool.awaitTermination(identification.getPeptideIdentification().size(), TimeUnit.MINUTES)) {
            throw new InterruptedException("Peptide matches validation timed out. Please contact the developers.");
        }
        HashMap<String, Integer> validatedTotalPeptidesPerFraction = new HashMap<>();
        ArrayList<Double> validatedPeptideLengths = new ArrayList<>();
        for (PeptideValidatorRunnable runnable : peptideRunnables) {
            HashMap<String, Integer> threadValidatedTotalPeptidesPerFraction = runnable.getValidatedTotalPeptidesPerFraction();
            for (String fraction : threadValidatedTotalPeptidesPerFraction.keySet()) {
                Integer nValidated = validatedTotalPeptidesPerFraction.get(fraction);
                if (nValidated == null) {
                    nValidated = 0;
                }
                nValidated += threadValidatedTotalPeptidesPerFraction.get(fraction);
                validatedTotalPeptidesPerFraction.put(fraction, nValidated);
            }
            validatedPeptideLengths.addAll(runnable.getValidatedPeptideLengths());
        }
        if (validatedPeptideLengths.size() >= 100) {
            NonSymmetricalNormalDistribution lengthDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(validatedPeptideLengths);
            metrics.setPeptideLengthDistribution(lengthDistribution);
        }
        metrics.setTotalPeptidesPerFraction(validatedTotalPeptidesPerFraction);
        if (projectType == ProjectType.protein) {
            // validate the proteins
            pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
            ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(waitingHandler);
            ArrayList<ProteinValidatorRunnable> proteinRunnables = new ArrayList<>(processingParameters.getnThreads());
            for (int i = 1; i <= processingParameters.getnThreads(); i++) {
                ProteinValidatorRunnable runnable = new ProteinValidatorRunnable(proteinMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, metrics, identificationParameters, waitingHandler, exceptionHandler);
                pool.submit(runnable);
                proteinRunnables.add(runnable);
            }
            if (waitingHandler.isRunCanceled()) {
                pool.shutdownNow();
                return;
            }
            pool.shutdown();
            if (!pool.awaitTermination(identification.getProteinIdentification().size(), TimeUnit.MINUTES)) {
                throw new InterruptedException("Protein matches validation timed out. Please contact the developers.");
            }
            long[] validatedTargetProteinKeys = proteinRunnables.stream().flatMap(runnable -> runnable.getValidatedProteinMatches().stream()).mapToLong(a -> a).toArray();
            metrics.setValidatedTargetProteinKeys(validatedTargetProteinKeys);
        }
    }
}
Also used : Arrays(java.util.Arrays) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) FractionParameters(com.compomics.util.parameters.identification.advanced.FractionParameters) TimeoutException(java.util.concurrent.TimeoutException) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinFilterItem(com.compomics.util.experiment.identification.filtering.items.ProteinFilterItem) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) Set(java.util.Set) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) Collectors(java.util.stream.Collectors) ProteinFilter(com.compomics.util.experiment.identification.filtering.ProteinFilter) Executors(java.util.concurrent.Executors) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) ExceptionHandler(com.compomics.util.exceptions.ExceptionHandler) Metrics(com.compomics.util.experiment.identification.peptide_shaker.Metrics) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) PeptideFilter(com.compomics.util.experiment.identification.filtering.PeptideFilter) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) NonSymmetricalNormalDistribution(com.compomics.util.math.statistics.distributions.NonSymmetricalNormalDistribution) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) InputMap(eu.isas.peptideshaker.scoring.maps.InputMap) ProjectType(com.compomics.util.parameters.peptide_shaker.ProjectType) ProcessingParameters(com.compomics.util.parameters.tools.ProcessingParameters) FilterItemComparator(com.compomics.util.experiment.filtering.FilterItemComparator) PeptideFilterItem(com.compomics.util.experiment.identification.filtering.items.PeptideFilterItem) ExecutorService(java.util.concurrent.ExecutorService) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) AssumptionFilterItem(com.compomics.util.experiment.identification.filtering.items.AssumptionFilterItem) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) TimeUnit(java.util.concurrent.TimeUnit) TreeMap(java.util.TreeMap) FastaParameters(com.compomics.util.experiment.io.biology.protein.FastaParameters) ProteinUtils(com.compomics.util.experiment.identification.utils.ProteinUtils) Filter(com.compomics.util.experiment.filtering.Filter) GeneMaps(com.compomics.util.experiment.biology.genes.GeneMaps) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) HashMap(java.util.HashMap) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) TimeoutException(java.util.concurrent.TimeoutException) NonSymmetricalNormalDistribution(com.compomics.util.math.statistics.distributions.NonSymmetricalNormalDistribution) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter) ProteinFilter(com.compomics.util.experiment.identification.filtering.ProteinFilter) PeptideFilter(com.compomics.util.experiment.identification.filtering.PeptideFilter) AssumptionFilter(com.compomics.util.experiment.identification.filtering.AssumptionFilter) Filter(com.compomics.util.experiment.filtering.Filter) ExecutorService(java.util.concurrent.ExecutorService) PsmFilter(com.compomics.util.experiment.identification.filtering.PsmFilter)

Aggregations

IdMatchValidationParameters (com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters)4 PSMaps (eu.isas.peptideshaker.scoring.PSMaps)3 TargetDecoyMap (eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap)3 Filter (com.compomics.util.experiment.filtering.Filter)2 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)2 AssumptionFilter (com.compomics.util.experiment.identification.filtering.AssumptionFilter)2 PsmFilter (com.compomics.util.experiment.identification.filtering.PsmFilter)2 FastaParameters (com.compomics.util.experiment.io.biology.protein.FastaParameters)2 ValidationQcParameters (com.compomics.util.parameters.identification.advanced.ValidationQcParameters)2 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)2 TargetDecoyResults (eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults)2 ArrayList (java.util.ArrayList)2 ExceptionHandler (com.compomics.util.exceptions.ExceptionHandler)1 Enzyme (com.compomics.util.experiment.biology.enzymes.Enzyme)1 GeneMaps (com.compomics.util.experiment.biology.genes.GeneMaps)1 Modification (com.compomics.util.experiment.biology.modifications.Modification)1 ModificationType (com.compomics.util.experiment.biology.modifications.ModificationType)1 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)1 FilterItemComparator (com.compomics.util.experiment.filtering.FilterItemComparator)1 Identification (com.compomics.util.experiment.identification.Identification)1