Search in sources :

Example 1 with MatchValidationLevel

use of com.compomics.util.experiment.identification.validation.MatchValidationLevel in project peptide-shaker by compomics.

the class GOEAPanel method updateProteinTable.

/**
 * Update the protein table.
 */
private void updateProteinTable() {
    // @TODO: order the proteins in some way?
    if (goMappingsTable.getSelectedRow() != -1) {
        progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
        progressDialog.setPrimaryProgressCounterIndeterminate(true);
        progressDialog.setTitle("Loading Protein Data. Please Wait...");
        new Thread(new Runnable() {

            public void run() {
                try {
                    progressDialog.setVisible(true);
                } catch (IndexOutOfBoundsException e) {
                // ignore
                }
            }
        }, "ProgressDialog").start();
        new Thread("DisplayThread") {

            @Override
            public void run() {
                try {
                    // clear the old data
                    DefaultTableModel dm = (DefaultTableModel) proteinTable.getModel();
                    dm.getDataVector().removeAllElements();
                    dm.fireTableDataChanged();
                    // get the selected go accession number
                    String selectedGoAccession = (String) goMappingsTable.getValueAt(goMappingsTable.getSelectedRow(), goMappingsTable.getColumn("GO Accession").getModelIndex());
                    // remove the html tags
                    selectedGoAccession = selectedGoAccession.substring(selectedGoAccession.lastIndexOf("GTerm?id=") + "GTerm?id=".length(), selectedGoAccession.lastIndexOf("\"><font"));
                    // get the list of matching proteins
                    GeneMaps geneMaps = peptideShakerGUI.getGeneMaps();
                    HashSet<String> goProteins = geneMaps.getProteinsForGoTerm(selectedGoAccession);
                    Identification identification = peptideShakerGUI.getIdentification();
                    ArrayList<Long> proteinKeys = new ArrayList<>(goProteins.size());
                    HashMap<String, HashSet<Long>> proteinMap = identification.getProteinMap();
                    for (String goProtein : goProteins) {
                        HashSet<Long> tempKeys = proteinMap.get(goProtein);
                        if (tempKeys != null) {
                            proteinKeys.addAll(tempKeys);
                        }
                    }
                    // update the table
                    if (proteinTable.getModel() instanceof ProteinGoTableModel) {
                        ((ProteinGoTableModel) proteinTable.getModel()).updateDataModel(proteinKeys);
                    } else {
                        ProteinGoTableModel proteinTableModel = new ProteinGoTableModel(peptideShakerGUI.getIdentification(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getDisplayFeaturesGenerator(), proteinKeys, peptideShakerGUI.getDisplayParameters().showScores());
                        proteinTable.setModel(proteinTableModel);
                    }
                    setProteinGoTableProperties();
                    ((DefaultTableModel) proteinTable.getModel()).fireTableDataChanged();
                    if (proteinTable.getRowCount() > 0) {
                        // get the number of confident and doubtful matches
                        int nConfident = 0;
                        int nDoubtful = 0;
                        for (long proteinKey : proteinKeys) {
                            PSParameter psParameter = (PSParameter) (identification.getProteinMatch(proteinKey)).getUrParam(PSParameter.dummy);
                            MatchValidationLevel level = psParameter.getMatchValidationLevel();
                            if (level == MatchValidationLevel.confident) {
                                nConfident++;
                            } else if (level == MatchValidationLevel.doubtful) {
                                nDoubtful++;
                            }
                        }
                        String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Gene Ontology Enrichment Analysis - " + goMappingsTable.getValueAt(goMappingsTable.getSelectedRow(), goMappingsTable.getColumn("GO Term").getModelIndex()) + " (";
                        try {
                            if (nConfident > 0) {
                                title += (nConfident + nDoubtful) + "/" + proteinKeys.size() + " - " + nConfident + " confident, " + nDoubtful + " doubtful";
                            } else {
                                title += proteinKeys.size();
                            }
                        } catch (Exception eNValidated) {
                            peptideShakerGUI.catchException(eNValidated);
                        }
                        title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
                        ((TitledBorder) plotPanel.getBorder()).setTitle(title);
                        plotPanel.repaint();
                        proteinTable.setRowSelectionInterval(0, 0);
                        proteinTable.scrollRectToVisible(proteinTable.getCellRect(0, 0, false));
                        // update the protein selection
                        ProteinGoTableModel proteinGoTableModel = (ProteinGoTableModel) proteinTable.getModel();
                        int selectedGroupIndex = proteinTable.convertRowIndexToModel(proteinTable.getSelectedRow());
                        long proteinGroupKey = proteinGoTableModel.getProteins().get(selectedGroupIndex);
                        peptideShakerGUI.setSelectedItems(proteinGroupKey, NO_KEY, null, null);
                        proteinTableKeyReleased(null);
                    }
                    progressDialog.setRunFinished();
                } catch (Exception e) {
                    progressDialog.setRunFinished();
                    peptideShakerGUI.catchException(e);
                }
            }
        }.start();
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) Identification(com.compomics.util.experiment.identification.Identification) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ProteinGoTableModel(eu.isas.peptideshaker.gui.tablemodels.ProteinGoTableModel) GeneMaps(com.compomics.util.experiment.biology.genes.GeneMaps) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 2 with MatchValidationLevel

use of com.compomics.util.experiment.identification.validation.MatchValidationLevel 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 3 with MatchValidationLevel

use of com.compomics.util.experiment.identification.validation.MatchValidationLevel 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 4 with MatchValidationLevel

use of com.compomics.util.experiment.identification.validation.MatchValidationLevel in project peptide-shaker by compomics.

the class MatchValidationDialog method populateGUI.

/**
 * Populates the GUI with information on a protein match.
 *
 * @param identificationFeaturesGenerator
 * @param proteinMap
 */
private void populateGUI(TargetDecoyMap targetDecoyMap) {
    ValidationQcParameters validationQCPreferences = identificationParameters.getIdValidationParameters().getValidationQCParameters();
    // Validation level
    validationLevelJComboBox.setSelectedItem(psParameter.getMatchValidationLevel().getName());
    // Database info
    FastaParameters fastaParameters = identificationParameters.getFastaParameters();
    boolean targetDecoy = fastaParameters.isTargetDecoy();
    if (!targetDecoy) {
        targetDecoyLbl.setText("Target only");
        targetDecoyLbl.setForeground(Color.red);
    } else {
        targetDecoyLbl.setForeground(GREEN);
    }
    try {
        FastaSummary fastaSummary = FastaSummary.getSummary(fastaFile, fastaParameters, null);
        int nTarget = fastaSummary.nTarget;
        nTargetLbl.setText(nTarget + " target sequences");
        if (nTarget < 10000) {
            nTargetLbl.setForeground(Color.red);
        } else if (nTarget > 1000000) {
            nTargetLbl.setForeground(ORANGE);
        } else {
            nTargetLbl.setForeground(GREEN);
        }
    } catch (IOException iOException) {
        nTargetLbl.setText("Database size not available");
        nTargetLbl.setForeground(Color.red);
    }
    // Target/Decoy group
    ((TitledBorder) targetDecoyGroupPanel.getBorder()).setTitle("Target/Decoy Distributions");
    targetDecoyGroupPanel.repaint();
    if (targetDecoy) {
        int nTargetOnly = targetDecoyMap.getnTargetOnly();
        matchesBeforeFirstDecoyLbl.setText(nTargetOnly + " matches before the first decoy hit");
        TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
        double desiredThreshold = targetDecoyResults.getUserInput();
        double nTargetLimit = 100.0 / desiredThreshold;
        if (nTargetOnly < nTargetLimit) {
            matchesBeforeFirstDecoyLbl.setForeground(Color.red);
        } else {
            matchesBeforeFirstDecoyLbl.setForeground(GREEN);
        }
        recommendedNumberOfTargetHitsLbl.setText("Recommended: " + Util.roundDouble(nTargetLimit, 0) + " matches before the first decoy hit");
        double resolution = targetDecoyMap.getResolution();
        confidenceResolutionLbl.setText("PEP/Confidence resolution of " + Util.roundDouble(resolution, 2) + "%");
        double minResolution = desiredThreshold;
        if (resolution > 10 * minResolution) {
            confidenceResolutionLbl.setForeground(Color.red);
        } else if (resolution > minResolution) {
            confidenceResolutionLbl.setForeground(ORANGE);
        } else {
            confidenceResolutionLbl.setForeground(GREEN);
        }
        recommendedResolutionLbl.setText("Recommended: resolution < " + Util.roundDouble(minResolution, 2) + "%");
    } else {
        matchesBeforeFirstDecoyLbl.setText("No decoy");
        matchesBeforeFirstDecoyLbl.setForeground(Color.gray);
        confidenceResolutionLbl.setText("Impossible to estimate confidence resolution");
        confidenceResolutionLbl.setForeground(Color.gray);
    }
    // Target/decoy results
    if (targetDecoy) {
        double confidence = psParameter.getConfidence();
        MatchValidationLevel matchValidationLevel = psParameter.getMatchValidationLevel();
        validationStatusLbl.setText("Validation Status: " + matchValidationLevel.getName());
        switch(matchValidationLevel) {
            case confident:
                validationStatusLbl.setForeground(GREEN);
                break;
            case doubtful:
                validationStatusLbl.setForeground(ORANGE);
                break;
            case not_validated:
                validationStatusLbl.setForeground(Color.red);
                break;
            case none:
                validationStatusLbl.setForeground(Color.gray);
        }
        TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
        String validationThresholdTxt = "";
        double threshold = targetDecoyResults.getUserInput();
        int thresholdType = targetDecoyResults.getInputType();
        if (thresholdType == 0) {
            validationThresholdTxt += "Validation Threshold: " + Util.roundDouble(threshold, 2) + "%";
        } else if (targetDecoyResults.getInputType() == 1) {
            validationThresholdTxt += "FDR Threshold: " + Util.roundDouble(threshold, 2) + "%";
        } else if (targetDecoyResults.getInputType() == 2) {
            validationThresholdTxt += "FNR Threshold: " + Util.roundDouble(threshold, 2) + "%";
        }
        validationThresholdLbl.setText(validationThresholdTxt);
        confidenceLbl.setText("Confidence: " + Util.roundDouble(confidence, 2) + "%");
        double validationThreshold = targetDecoyResults.getConfidenceLimit();
        confidenceThresholdLbl.setText("Expected Confidence: " + Util.roundDouble(validationThreshold, 2) + "%");
        double margin = validationQCPreferences.getConfidenceMargin() * targetDecoyMap.getResolution();
        double confidenceThreshold = validationThreshold + margin;
        if (confidenceThreshold > 100) {
            confidenceThreshold = 100;
        }
        confidenceThresholdLbl.setText("Confident confidence: " + Util.roundDouble(confidenceThreshold, 2) + "%");
        if (confidence < validationThreshold) {
            confidenceLbl.setForeground(Color.red);
        } else if (confidence < confidenceThreshold) {
            confidenceLbl.setForeground(ORANGE);
        } else {
            confidenceLbl.setForeground(GREEN);
        }
    } else {
        validationStatusLbl.setText("Validation Status: " + psParameter.getMatchValidationLevel().getName());
        validationThresholdLbl.setText("Impossible to estimate validation threshold");
        confidenceLbl.setText("Impossible to estimate confidence");
        confidenceThresholdLbl.setText("Impossible to estimate confidence threshold");
        validationStatusLbl.setForeground(Color.gray);
        confidenceLbl.setForeground(Color.gray);
    }
    // Quality filters
    final DefaultTableModel tableModel = new FiltersTableModel();
    qualityFiltersTable.setModel(tableModel);
    qualityFiltersTable.getColumn("").setMaxWidth(50);
    qualityFiltersTable.getColumn(" ").setMaxWidth(50);
    qualityFiltersTable.getColumn(" ").setCellRenderer(new TrueFalseIconRenderer(new ImageIcon(this.getClass().getResource("/icons/accept-new.png")), new ImageIcon(this.getClass().getResource("/icons/error-new.png")), "Yes", "No"));
    int valid = 0;
    for (String qcCheck : psParameter.getQcCriteria()) {
        if (psParameter.isQcPassed(qcCheck)) {
            valid++;
        }
    }
    ((TitledBorder) qualityFiltersPanel.getBorder()).setTitle("Quality Filters (" + valid + "/" + psParameter.getQcCriteria().size() + ")");
}
Also used : ImageIcon(javax.swing.ImageIcon) DefaultTableModel(javax.swing.table.DefaultTableModel) IOException(java.io.IOException) TitledBorder(javax.swing.border.TitledBorder) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) TrueFalseIconRenderer(no.uib.jsparklines.extra.TrueFalseIconRenderer) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) FastaParameters(com.compomics.util.experiment.io.biology.protein.FastaParameters) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel)

Aggregations

MatchValidationLevel (com.compomics.util.experiment.identification.validation.MatchValidationLevel)4 Identification (com.compomics.util.experiment.identification.Identification)3 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)3 IOException (java.io.IOException)3 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)2 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)2 ModificationScoring (com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring)2 PSModificationScores (com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores)2 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)2 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)2 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)2 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)2 ExportFeature (com.compomics.util.io.export.ExportFeature)2 ExportWriter (com.compomics.util.io.export.ExportWriter)2 PsFragmentFeature (com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature)2 PsIdentificationAlgorithmMatchesFeature (com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature)2 PsPsmFeature (com.compomics.util.io.export.features.peptideshaker.PsPsmFeature)2 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)2 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)2 WaitingHandler (com.compomics.util.waiting.WaitingHandler)2