Search in sources :

Example 6 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator 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 7 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class PsPeptideSection method getfeature.

/**
 * Returns the component of the section corresponding to the given feature.
 *
 * @param identification the identification of the project
 * @param identificationFeaturesGenerator the identification features
 * generator of the project
 * @param sequenceProvider a provider for the protein sequences
 * @param proteinDetailsProvider a provider for protein details
 * @param identificationParameters the identification parameters
 * @param nSurroundingAA the number of surrounding amino acids to export
 * @param linePrefix the line prefix to use.
 * @param peptideMatch the peptide match
 * @param peptideFeature the peptide feature to export
 * @param validatedOnly whether only validated matches should be exported
 * @param decoys whether decoy matches should be exported as well
 * @param waitingHandler the waiting handler
 *
 * @return the component of the section corresponding to the given feature
 */
public static String getfeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, IdentificationParameters identificationParameters, int nSurroundingAA, String linePrefix, PeptideMatch peptideMatch, PsPeptideFeature peptideFeature, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) {
    switch(peptideFeature) {
        case accessions:
            TreeMap<String, int[]> proteinMapping = peptideMatch.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
        case protein_description:
            proteinMapping = peptideMatch.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().map(accession -> proteinDetailsProvider.getDescription(accession)).collect(Collectors.joining(","));
        case protein_groups:
            TreeSet<Long> proteinGroups = identification.getProteinMatches(peptideMatch.getKey());
            return proteinGroups.stream().map(proteinGroupKey -> getProteinGroupText(proteinGroupKey, identification)).collect(Collectors.joining(";"));
        case best_protein_group_validation:
            MatchValidationLevel bestProteinValidationLevel = MatchValidationLevel.none;
            proteinGroups = identification.getProteinMatches(peptideMatch.getKey());
            for (long proteinGroup : proteinGroups) {
                if (identification.getProteinIdentification().contains(proteinGroup)) {
                    PSParameter psParameter = (PSParameter) (identification.getProteinMatch(proteinGroup)).getUrParam(PSParameter.dummy);
                    if (psParameter.getMatchValidationLevel().getIndex() > bestProteinValidationLevel.getIndex()) {
                        bestProteinValidationLevel = psParameter.getMatchValidationLevel();
                    }
                }
            }
            return bestProteinValidationLevel.getName();
        case confidence:
            PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return Double.toString(psParameter.getConfidence());
        case decoy:
            return PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider) ? "1" : "0";
        case hidden:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return psParameter.getHidden() ? "1" : "0";
        case localization_confidence:
            return getPeptideModificationLocationConfidence(peptideMatch, identificationParameters.getSearchParameters().getModificationParameters());
        case pi:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return psParameter.getProteinInferenceClassAsString();
        case position:
            proteinMapping = peptideMatch.getPeptide().getProteinMapping();
            return proteinMapping.entrySet().stream().map(entry -> getPeptideLocalizationText(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
        case psms:
            return Integer.toString(peptideMatch.getSpectrumCount());
        case variable_ptms:
            return PeptideUtils.getVariableModificationsAsString(peptideMatch.getPeptide());
        case fixed_ptms:
            ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            return PeptideUtils.getFixedModificationsAsString(peptideMatch.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
        case score:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return Double.toString(psParameter.getTransformedScore());
        case raw_score:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return Double.toString(psParameter.getScore());
        case sequence:
            return peptideMatch.getPeptide().getSequence();
        case missed_cleavages:
            int nMissedCleavages = peptideMatch.getPeptide().getNMissedCleavages(identificationParameters.getSearchParameters().getDigestionParameters());
            return Integer.toString(nMissedCleavages);
        case modified_sequence:
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            return peptideMatch.getPeptide().getTaggedModifiedSequence(modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false, false, true, null);
        case starred:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return psParameter.getStarred() ? "1" : "0";
        case aaBefore:
            TreeMap<String, String[]> aaMap = PeptideUtils.getAaBefore(peptideMatch.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> Arrays.stream(aas).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case aaAfter:
            aaMap = PeptideUtils.getAaAfter(peptideMatch.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> Arrays.stream(aas).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case nValidatedProteinGroups:
            return Integer.toString(identificationFeaturesGenerator.getNValidatedProteinGroups(peptideMatch.getKey(), waitingHandler));
        case unique_group:
            return identification.getProteinMatches(peptideMatch.getKey()).size() == 1 ? "1" : "0";
        case validated:
            psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            return psParameter.getMatchValidationLevel().toString();
        case validated_psms:
            return Integer.toString(identificationFeaturesGenerator.getNValidatedSpectraForPeptide(peptideMatch.getKey()));
        case probabilistic_score:
            PSModificationScores ptmScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
            if (ptmScores != null) {
                StringBuilder result = new StringBuilder();
                TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
                for (String mod : modList) {
                    ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
                    TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getProbabilisticSites());
                    if (!sites.isEmpty()) {
                        if (result.length() > 0) {
                            result.append(", ");
                        }
                        result.append(mod).append(" (");
                        boolean firstSite = true;
                        for (int site : sites) {
                            if (firstSite) {
                                firstSite = false;
                            } else {
                                result.append(", ");
                            }
                            result.append(site).append(": ").append(ptmScoring.getProbabilisticScore(site));
                        }
                        result.append(")");
                    }
                }
                return result.toString();
            }
            return "";
        case d_score:
            StringBuilder result = new StringBuilder();
            ptmScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
            if (ptmScores != null) {
                TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
                for (String mod : modList) {
                    ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
                    TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getDSites());
                    if (!sites.isEmpty()) {
                        if (result.length() > 0) {
                            result.append(", ");
                        }
                        result.append(mod).append(" (");
                        boolean firstSite = true;
                        for (int site : sites) {
                            if (firstSite) {
                                firstSite = false;
                            } else {
                                result.append(", ");
                            }
                            result.append(site).append(": ").append(ptmScoring.getDeltaScore(site));
                        }
                        result.append(")");
                    }
                }
                return result.toString();
            }
            return "";
        case confident_modification_sites:
            String sequence = peptideMatch.getPeptide().getSequence();
            return identificationFeaturesGenerator.getConfidentModificationSites(peptideMatch, sequence);
        case confident_modification_sites_number:
            return identificationFeaturesGenerator.getConfidentModificationSitesNumber(peptideMatch);
        case ambiguous_modification_sites:
            sequence = peptideMatch.getPeptide().getSequence();
            return identificationFeaturesGenerator.getAmbiguousModificationSites(peptideMatch, sequence);
        case ambiguous_modification_sites_number:
            return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(peptideMatch);
        case confident_phosphosites:
            ArrayList<String> modifications = new ArrayList<>(3);
            for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (ptm.contains("Phospho")) {
                    modifications.add(ptm);
                }
            }
            return identificationFeaturesGenerator.getConfidentModificationSites(peptideMatch, peptideMatch.getPeptide().getSequence(), modifications);
        case confident_phosphosites_number:
            modifications = new ArrayList<>(3);
            for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (ptm.contains("Phospho")) {
                    modifications.add(ptm);
                }
            }
            return identificationFeaturesGenerator.getConfidentModificationSitesNumber(peptideMatch, modifications);
        case ambiguous_phosphosites:
            modifications = new ArrayList<>(3);
            for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (ptm.contains("Phospho")) {
                    modifications.add(ptm);
                }
            }
            return identificationFeaturesGenerator.getAmbiguousModificationSites(peptideMatch, peptideMatch.getPeptide().getSequence(), modifications);
        case ambiguous_phosphosites_number:
            modifications = new ArrayList<>(3);
            for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (ptm.contains("Phospho")) {
                    modifications.add(ptm);
                }
            }
            return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(peptideMatch, modifications);
        default:
            return "Not implemented";
    }
}
Also used : PsPeptideFeature(com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature) PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature) Arrays(java.util.Arrays) ExportWriter(com.compomics.util.io.export.ExportWriter) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) PsIdentificationAlgorithmMatchesFeature(com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) PsPsmFeature(com.compomics.util.io.export.features.peptideshaker.PsPsmFeature) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) EnumSet(java.util.EnumSet) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) ExportFeature(com.compomics.util.io.export.ExportFeature) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) Collectors(java.util.stream.Collectors) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) ArrayList(java.util.ArrayList) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) TreeSet(java.util.TreeSet) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 8 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class PsPsmSection method getFeature.

/**
 * Writes the given feature of the current section.
 *
 * @param identification the identification of the project
 * @param identificationFeaturesGenerator the identification features
 * generator of the project
 * @param identificationParameters the identification parameters
 * @param linePrefix the line prefix
 * @param spectrumMatch the spectrum match inspected
 * @param psParameter the PeptideShaker parameter of the match
 * @param psmFeature the feature to export
 * @param validatedOnly indicates whether only validated hits should be
 * exported
 * @param decoys indicates whether decoys should be included in the export
 * @param waitingHandler the waiting handler
 *
 * @return the content corresponding to the given feature of the current
 * section
 */
public static String getFeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, IdentificationParameters identificationParameters, String linePrefix, SpectrumMatch spectrumMatch, PSParameter psParameter, PsPsmFeature psmFeature, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) {
    switch(psmFeature) {
        case protein_groups:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                TreeSet<Long> proteinGroups = identification.getProteinMatches(spectrumMatch.getBestPeptideAssumption().getPeptide().getKey());
                return proteinGroups.stream().map(key -> getProteinGroupText(key, identification)).collect(Collectors.joining(";"));
            }
            return "";
        case best_protein_group_validation:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                TreeSet<Long> proteinGroups = identification.getProteinMatches(spectrumMatch.getBestPeptideAssumption().getPeptide().getKey());
                int bestIndex = proteinGroups.stream().map(key -> ((PSParameter) identification.getProteinMatch(key).getUrParam(PSParameter.dummy)).getMatchValidationLevel()).mapToInt(MatchValidationLevel::getIndex).max().orElse(MatchValidationLevel.none.getIndex());
                return MatchValidationLevel.getMatchValidationLevel(bestIndex).getName();
            }
            return "";
        case probabilistic_score:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                PSModificationScores ptmScores = (PSModificationScores) spectrumMatch.getUrParam(PSModificationScores.dummy);
                if (ptmScores != null) {
                    StringBuilder result = new StringBuilder();
                    TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
                    for (String mod : modList) {
                        ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
                        TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getProbabilisticSites());
                        if (!sites.isEmpty()) {
                            if (result.length() > 0) {
                                result.append(", ");
                            }
                            result.append(mod).append(" (");
                            boolean firstSite = true;
                            for (int site : sites) {
                                if (firstSite) {
                                    firstSite = false;
                                } else {
                                    result.append(", ");
                                }
                                result.append(site).append(": ").append(ptmScoring.getProbabilisticScore(site));
                            }
                            result.append(")");
                        }
                    }
                    return result.toString();
                }
            }
            return "";
        case d_score:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                StringBuilder result = new StringBuilder();
                PSModificationScores ptmScores = (PSModificationScores) spectrumMatch.getUrParam(PSModificationScores.dummy);
                if (ptmScores != null) {
                    TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
                    for (String mod : modList) {
                        ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
                        TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getDSites());
                        if (!sites.isEmpty()) {
                            if (result.length() > 0) {
                                result.append(", ");
                            }
                            result.append(mod).append(" (");
                            boolean firstSite = true;
                            for (int site : sites) {
                                if (firstSite) {
                                    firstSite = false;
                                } else {
                                    result.append(", ");
                                }
                                result.append(site).append(": ").append(ptmScoring.getDeltaScore(site));
                            }
                            result.append(")");
                        }
                    }
                }
                return result.toString();
            }
            return "";
        case localization_confidence:
            return getPeptideModificationLocationConfidence(spectrumMatch, identificationParameters.getSearchParameters().getModificationParameters());
        case algorithm_score:
            PeptideAssumption bestPeptideAssumption = spectrumMatch.getBestPeptideAssumption();
            TagAssumption bestTagAssumption = spectrumMatch.getBestTagAssumption();
            if (bestPeptideAssumption != null) {
                return spectrumMatch.getAllPeptideAssumptions().filter(peptideAssumption -> peptideAssumption.getPeptide().isSameSequenceAndModificationStatus(bestPeptideAssumption.getPeptide(), identificationParameters.getSequenceMatchingParameters())).collect(Collectors.toMap(PeptideAssumption::getAdvocate, Function.identity(), (a, b) -> b.getScore() < a.getScore() ? b : a, TreeMap::new)).entrySet().stream().map(entry -> Util.keyValueToString(Advocate.getAdvocate(entry.getKey()).getName(), Double.toString(entry.getValue().getRawScore()))).collect(Collectors.joining(","));
            } else if (bestTagAssumption != null) {
                return spectrumMatch.getAllTagAssumptions().filter(tagAssumption -> tagAssumption.getTag().isSameSequenceAndModificationStatusAs(bestTagAssumption.getTag(), identificationParameters.getSequenceMatchingParameters())).collect(Collectors.toMap(TagAssumption::getAdvocate, Function.identity(), (a, b) -> b.getScore() < a.getScore() ? b : a, TreeMap::new)).entrySet().stream().map(entry -> Util.keyValueToString(Advocate.getAdvocate(entry.getKey()).getName(), Double.toString(entry.getValue().getRawScore()))).collect(Collectors.joining(","));
            }
            return "";
        case confidence:
            return Double.toString(psParameter.getConfidence());
        case score:
            return Double.toString(psParameter.getTransformedScore());
        case raw_score:
            return Double.toString(psParameter.getScore());
        case validated:
            return psParameter.getMatchValidationLevel().toString();
        case starred:
            return psParameter.getStarred() ? "1" : "0";
        case hidden:
            return psParameter.getHidden() ? "1" : "0";
        case confident_modification_sites:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                String sequence = spectrumMatch.getBestPeptideAssumption().getPeptide().getSequence();
                return identificationFeaturesGenerator.getConfidentModificationSites(spectrumMatch, sequence);
            }
            return "";
        case confident_modification_sites_number:
            return identificationFeaturesGenerator.getConfidentModificationSitesNumber(spectrumMatch);
        case ambiguous_modification_sites:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                String sequence = spectrumMatch.getBestPeptideAssumption().getPeptide().getSequence();
                return identificationFeaturesGenerator.getAmbiguousModificationSites(spectrumMatch, sequence);
            }
            return "";
        case ambiguous_modification_sites_number:
            return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(spectrumMatch);
        case confident_phosphosites:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                String sequence = spectrumMatch.getBestPeptideAssumption().getPeptide().getSequence();
                ArrayList<String> modifications = new ArrayList<>(3);
                for (String modName : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                    if (modName.toLowerCase().contains("phospho")) {
                        modifications.add(modName);
                    }
                }
                return identificationFeaturesGenerator.getConfidentModificationSites(spectrumMatch, sequence, modifications);
            }
            return "";
        case confident_phosphosites_number:
            ArrayList<String> modifications = new ArrayList<>(3);
            for (String modName : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (modName.toLowerCase().contains("phospho")) {
                    modifications.add(modName);
                }
            }
            return identificationFeaturesGenerator.getConfidentModificationSitesNumber(spectrumMatch, modifications);
        case ambiguous_phosphosites:
            if (spectrumMatch.getBestPeptideAssumption() != null) {
                String sequence = spectrumMatch.getBestPeptideAssumption().getPeptide().getSequence();
                modifications = new ArrayList<>(3);
                for (String modName : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                    if (modName.toLowerCase().contains("phospho")) {
                        modifications.add(modName);
                    }
                }
                return identificationFeaturesGenerator.getAmbiguousModificationSites(spectrumMatch, sequence, modifications);
            }
            return "";
        case ambiguous_phosphosites_number:
            modifications = new ArrayList<>(3);
            for (String modName : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
                if (modName.toLowerCase().contains("phospho")) {
                    modifications.add(modName);
                }
            }
            return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(spectrumMatch, modifications);
        default:
            return "Not implemented";
    }
}
Also used : PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature) Arrays(java.util.Arrays) ExportWriter(com.compomics.util.io.export.ExportWriter) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) PsIdentificationAlgorithmMatchesFeature(com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) Function(java.util.function.Function) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) PsPsmFeature(com.compomics.util.io.export.features.peptideshaker.PsPsmFeature) Advocate(com.compomics.util.experiment.identification.Advocate) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) EnumSet(java.util.EnumSet) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) ExportFeature(com.compomics.util.io.export.ExportFeature) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) Util(com.compomics.util.Util) Collectors(java.util.stream.Collectors) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) TreeSet(java.util.TreeSet) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 9 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class PsIdentificationAlgorithmMatchesSection method getPeptideAssumptionFeature.

/**
 * Writes the feature associated to the match of the given peptide
 * assumption.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param sequenceProvider The provider for the protein sequences.
 * @param proteinDetailsProvider The provider for protein details.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param linePrefix The line prefix.
 * @param nSurroundingAA The number of surrounding amino acids to export.
 * @param peptideAssumption The assumption for the match to inspect.
 * @param spectrumFile The name of the file of the spectrum.
 * @param spectrumTitle The title of the spectrum.
 * @param psParameter The PeptideShaker parameter of the match.
 * @param exportFeature The feature to export.
 * @param waitingHandler The waiting handler.
 *
 * @return The content corresponding to the given feature of the current
 * section.
 */
public static String getPeptideAssumptionFeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, String linePrefix, int nSurroundingAA, PeptideAssumption peptideAssumption, String spectrumFile, String spectrumTitle, PSParameter psParameter, PsIdentificationAlgorithmMatchesFeature exportFeature, WaitingHandler waitingHandler) {
    switch(exportFeature) {
        case rank:
            return Integer.toString(peptideAssumption.getRank());
        case variable_ptms:
            ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            TreeMap<String, TreeSet<Integer>> modMap = getModMap(peptideAssumption.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, true);
            return modMap.entrySet().stream().map(entry -> getModificationAsString(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
        case fixed_ptms:
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            modMap = getModMap(peptideAssumption.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false);
            return modMap.entrySet().stream().map(entry -> getModificationAsString(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
        case accessions:
            TreeMap<String, int[]> proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
        case protein_description:
            proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().map(accession -> proteinDetailsProvider.getDescription(accession)).collect(Collectors.joining(","));
        case algorithm_confidence:
            return Double.toString(psParameter.getConfidence());
        case algorithm_delta_confidence:
            Double delta = psParameter.getAlgorithmDeltaPEP();
            return delta == null ? "Not available" : Double.toString(100 * delta);
        case delta_confidence:
            delta = psParameter.getDeltaPEP();
            return Double.toString(100 * delta);
        case decoy:
            return PeptideUtils.isDecoy(peptideAssumption.getPeptide(), sequenceProvider) ? "1" : "0";
        case hidden:
            return psParameter.getHidden() ? "1" : "0";
        case identification_charge:
            return Integer.toString(peptideAssumption.getIdentificationCharge());
        case isotope:
            double precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Integer.toString(peptideAssumption.getIsotopeNumber(precursorMz, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case mz:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(precursorMz);
        case total_spectrum_intensity:
            Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getTotalIntensity());
        case max_intensity:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getMaxIntensity());
        case intensity_coverage:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            Peptide peptide = peptideAssumption.getPeptide();
            AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            IonMatch[] matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            double coveredIntensity = Arrays.stream(matches).mapToDouble(ionMatch -> ionMatch.peakIntensity).sum();
            double coverage = 100 * coveredIntensity / spectrum.getTotalIntensity();
            return Double.toString(coverage);
        case mz_error_ppm:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(peptideAssumption.getDeltaMz(precursorMz, true, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case mz_error_da:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(peptideAssumption.getDeltaMz(precursorMz, false, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case rt:
            double precursorRt = spectrumProvider.getPrecursorRt(spectrumFile, spectrumTitle);
            return Double.toString(precursorRt);
        case algorithm_raw_score:
            int id = peptideAssumption.getAdvocate();
            double score = peptideAssumption.getRawScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case algorithm_score:
            id = peptideAssumption.getAdvocate();
            score = peptideAssumption.getScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case sequence:
            return peptideAssumption.getPeptide().getSequence();
        case aaBefore:
            TreeMap<String, String[]> aaMap = PeptideUtils.getAaBefore(peptideAssumption.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> (Arrays.stream(aas)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case aaAfter:
            aaMap = PeptideUtils.getAaAfter(peptideAssumption.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> (Arrays.stream(aas)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case position:
            proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.values().stream().map(positions -> (Arrays.stream(positions)).mapToObj(pos -> Integer.toString(pos)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case missed_cleavages:
            peptide = peptideAssumption.getPeptide();
            int nMissedCleavages = peptide.getNMissedCleavages(identificationParameters.getSearchParameters().getDigestionParameters());
            return Integer.toString(nMissedCleavages);
        case modified_sequence:
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            return peptideAssumption.getPeptide().getTaggedModifiedSequence(modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false, false, true, null);
        case spectrum_charge:
            Precursor precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return precursor.getPossibleChargesAsString();
        case precursor_intensity:
            precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return Double.toString(precursor.intensity);
        case spectrum_file:
            return spectrumFile;
        case spectrum_array_list:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return spectrum.getPeakListAsString();
        case spectrum_title:
            return spectrumTitle;
        case spectrum_scan_number:
            // TODO: To get scan numbers from cms when source mgf files have that info
            return "";
        case starred:
            return psParameter.getStarred() ? "1" : "0";
        case theoretical_mass:
            return Double.toString(peptideAssumption.getPeptide().getMass());
        case validated:
            if (psParameter.getMatchValidationLevel() != null) {
                return psParameter.getMatchValidationLevel().toString();
            } else {
                return "";
            }
        case sequence_coverage:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            int sequenceLength = peptide.getSequence().length();
            int[] aaCoverage = new int[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).forEach(ionMatch -> aaCoverage[((PeptideFragmentIon) ionMatch.ion).getNumber() - 1] = 1);
            double nIons = Arrays.stream(aaCoverage).sum();
            coverage = 100 * nIons / sequenceLength;
            return Double.toString(coverage);
        case longest_amino_acid_sequence_annotated:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            String sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            boolean[] coverageForward = new boolean[sequenceLength];
            boolean[] coverageRewind = new boolean[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> {
                if (PeptideFragmentIon.isForward(peptideFragmentIon.getSubType())) {
                    coverageForward[peptideFragmentIon.getNumber() - 1] = true;
                } else {
                    coverageRewind[peptideFragmentIon.getNumber() - 1] = true;
                }
            });
            boolean[] aaCoverageB = new boolean[sequenceLength];
            boolean previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageForward[aaIndex];
                if (current && previous) {
                    aaCoverageB[aaIndex] = true;
                }
                previous = current;
            }
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageRewind[aaIndex];
                if (current && previous) {
                    aaCoverageB[sequenceLength - aaIndex - 1] = true;
                }
                previous = current;
            }
            StringBuilder currentTag = new StringBuilder();
            String longestTag = new String();
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                if (aaCoverageB[aaIndex]) {
                    currentTag.append(sequence.charAt(aaIndex));
                } else {
                    if (currentTag.length() > longestTag.length()) {
                        longestTag = currentTag.toString();
                    }
                    currentTag = new StringBuilder();
                }
            }
            if (currentTag.length() > longestTag.length()) {
                longestTag = currentTag.toString();
            }
            return longestTag;
        case longest_amino_acid_sequence_annotated_single_serie:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            HashMap<Integer, boolean[]> ionCoverage = new HashMap<>(6);
            ionCoverage.put(PeptideFragmentIon.A_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.B_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.C_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.X_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.Y_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.Z_ION, new boolean[sequenceLength]);
            Arrays.stream(matches).filter(ionMatch -> ionMatch.charge == 1 && ionMatch.ion instanceof PeptideFragmentIon && !ionMatch.ion.hasNeutralLosses()).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> ionCoverage.get(peptideFragmentIon.getSubType())[peptideFragmentIon.getNumber() - 1] = true);
            longestTag = new String();
            currentTag = new StringBuilder();
            previous = true;
            for (int ionType : PeptideFragmentIon.getPossibleSubtypes()) {
                for (int i = 0; i < sequenceLength; i++) {
                    int aaIndex = PeptideFragmentIon.isForward(ionType) ? i : sequence.length() - i - 1;
                    boolean current = ionCoverage.get(ionType)[i];
                    if (current && previous) {
                        currentTag.append(sequence.charAt(aaIndex));
                    } else {
                        if (currentTag.length() > longestTag.length()) {
                            if (PeptideFragmentIon.isForward(ionType)) {
                                currentTag.reverse();
                            }
                            longestTag = currentTag.toString();
                        }
                        currentTag = new StringBuilder();
                    }
                    previous = current;
                }
                if (currentTag.length() > longestTag.length()) {
                    if (PeptideFragmentIon.isForward(ionType)) {
                        currentTag.reverse();
                    }
                    longestTag = currentTag.toString();
                }
            }
            return longestTag;
        case amino_acids_annotated:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            coverageForward = new boolean[sequenceLength];
            coverageRewind = new boolean[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> {
                if (PeptideFragmentIon.isForward(peptideFragmentIon.getSubType())) {
                    coverageForward[peptideFragmentIon.getNumber() - 1] = true;
                } else {
                    coverageRewind[peptideFragmentIon.getNumber() - 1] = true;
                }
            });
            aaCoverageB = new boolean[sequenceLength];
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageForward[aaIndex];
                if (current && previous) {
                    aaCoverageB[aaIndex] = true;
                }
                previous = current;
            }
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageRewind[aaIndex];
                if (current && previous) {
                    aaCoverageB[sequenceLength - aaIndex - 1] = true;
                }
                previous = current;
            }
            StringBuilder tag = new StringBuilder();
            double gap = 0;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                if (aaCoverageB[aaIndex]) {
                    if (gap > 0) {
                        tag.append("<").append(gap).append(">");
                    }
                    tag.append(sequence.charAt(aaIndex));
                    gap = 0;
                } else {
                    gap += AminoAcid.getAminoAcid(sequence.charAt(aaIndex)).getMonoisotopicMass();
                }
            }
            if (gap > 0) {
                tag.append("<").append(gap).append(">");
            }
            return tag.toString();
        default:
            return "Not implemented";
    }
}
Also used : ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) IntStream(java.util.stream.IntStream) PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature) Arrays(java.util.Arrays) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) ExportWriter(com.compomics.util.io.export.ExportWriter) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) PsIdentificationAlgorithmMatchesFeature(com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) HashMap(java.util.HashMap) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WaitingHandler(com.compomics.util.waiting.WaitingHandler) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Advocate(com.compomics.util.experiment.identification.Advocate) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) AminoAcid(com.compomics.util.experiment.biology.aminoacids.AminoAcid) EnumSet(java.util.EnumSet) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) ExportFeature(com.compomics.util.io.export.ExportFeature) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) Tag(com.compomics.util.experiment.identification.amino_acid_tags.Tag) IOException(java.io.IOException) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) Collectors(java.util.stream.Collectors) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Collections(java.util.Collections) HashMap(java.util.HashMap) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) TreeSet(java.util.TreeSet) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)

Example 10 with IdentificationFeaturesGenerator

use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.

the class OverviewPanel method updatePeptidePanelTitle.

/**
 * Updates the peptide panel title with the number of validated/confident
 * proteins.
 */
public void updatePeptidePanelTitle() {
    SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) proteinTable.getModel();
    IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
    long proteinKey = proteinKeys[tableModel.getViewIndex(proteinTable.getSelectedRow())];
    ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
    int nValidatedPeptides = identificationFeaturesGenerator.getNValidatedPeptides(proteinKey);
    int nConfidentPeptides = identificationFeaturesGenerator.getNConfidentPeptides(proteinKey);
    int nPeptides = proteinMatch.getPeptideCount();
    String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Peptides (";
    if (nConfidentPeptides > 0) {
        title += nValidatedPeptides + "/" + nPeptides + " - " + nConfidentPeptides + " confident, " + (nValidatedPeptides - nConfidentPeptides) + " doubtful";
    } else {
        title += nValidatedPeptides + "/" + nPeptides;
    }
    title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
    ((TitledBorder) peptidesPanel.getBorder()).setTitle(title);
    peptidesPanel.repaint();
}
Also used : IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SelfUpdatingTableModel(com.compomics.util.gui.tablemodels.SelfUpdatingTableModel) TitledBorder(javax.swing.border.TitledBorder)

Aggregations

IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)14 Identification (com.compomics.util.experiment.identification.Identification)8 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)6 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)6 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)5 SelfUpdatingTableModel (com.compomics.util.gui.tablemodels.SelfUpdatingTableModel)5 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)5 Collectors (java.util.stream.Collectors)5 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)4 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)4 MatchValidationLevel (com.compomics.util.experiment.identification.validation.MatchValidationLevel)4 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)4 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)4 ProgressDialogX (com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX)4 ExportFeature (com.compomics.util.io.export.ExportFeature)4 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)4 WaitingHandler (com.compomics.util.waiting.WaitingHandler)4