Search in sources :

Example 1 with PsPeptideFeature

use of com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature 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 2 with PsPeptideFeature

use of com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature in project peptide-shaker by compomics.

the class PsPeptideSection method writeSection.

/**
 * Writes the desired section.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param sequenceProvider The sequence provider.
 * @param proteinDetailsProvider The protein details provider.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param keys The keys of the PSM matches to output.
 * @param linePrefix The line prefix.
 * @param nSurroundingAA The number of surrounding amino acids 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.
 *
 * @throws java.io.IOException exception thrown if an error occurred while
 * reading or writing a file
 */
public void writeSection(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, long[] keys, int nSurroundingAA, String linePrefix, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        writeHeader();
    }
    int lineNumber = 1;
    if (waitingHandler != null) {
        waitingHandler.setWaitingText("Exporting. Please Wait...");
        waitingHandler.resetSecondaryProgressCounter();
        waitingHandler.setMaxSecondaryProgressCounter(keys == null ? identification.getPeptideIdentification().size() : keys.length);
    }
    PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(keys, waitingHandler);
    PeptideMatch peptideMatch;
    while ((peptideMatch = peptideMatchesIterator.next()) != null) {
        if (waitingHandler != null) {
            if (waitingHandler.isRunCanceled()) {
                return;
            }
            waitingHandler.increaseSecondaryProgressCounter();
        }
        PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
        if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {
            if (decoys || !PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider)) {
                boolean first = true;
                if (indexes) {
                    if (linePrefix != null) {
                        writer.write(linePrefix);
                    }
                    writer.write(Integer.toString(lineNumber));
                    first = false;
                }
                for (ExportFeature exportFeature : peptideFeatures) {
                    if (!first) {
                        writer.addSeparator();
                    } else {
                        first = false;
                    }
                    PsPeptideFeature peptideFeature = (PsPeptideFeature) exportFeature;
                    writer.write(getfeature(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, identificationParameters, nSurroundingAA, linePrefix, peptideMatch, peptideFeature, validatedOnly, decoys, waitingHandler));
                }
                writer.newLine();
                if (psmSection != null) {
                    String psmSectionPrefix = "";
                    if (linePrefix != null) {
                        psmSectionPrefix += linePrefix;
                    }
                    psmSectionPrefix += lineNumber + ".";
                    writer.increaseDepth();
                    if (waitingHandler != null) {
                        waitingHandler.setDisplayProgress(false);
                    }
                    psmSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, peptideMatch.getSpectrumMatchesKeys(), psmSectionPrefix, nSurroundingAA, validatedOnly, decoys, waitingHandler);
                    if (waitingHandler != null) {
                        waitingHandler.setDisplayProgress(true);
                    }
                    writer.decreseDepth();
                }
                lineNumber++;
            }
        }
    }
}
Also used : PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) PsPeptideFeature(com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature) ExportFeature(com.compomics.util.io.export.ExportFeature) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Aggregations

PeptideMatch (com.compomics.util.experiment.identification.matches.PeptideMatch)2 PeptideMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator)2 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)2 ExportFeature (com.compomics.util.io.export.ExportFeature)2 PsPeptideFeature (com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature)2 Identification (com.compomics.util.experiment.identification.Identification)1 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)1 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)1 ModificationScoring (com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring)1 PSModificationScores (com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores)1 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)1 MatchValidationLevel (com.compomics.util.experiment.identification.validation.MatchValidationLevel)1 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)1 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)1 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)1 ExportWriter (com.compomics.util.io.export.ExportWriter)1 PsFragmentFeature (com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature)1 PsIdentificationAlgorithmMatchesFeature (com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature)1 PsPsmFeature (com.compomics.util.io.export.features.peptideshaker.PsPsmFeature)1 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)1