Search in sources :

Example 1 with DigestionParameters

use of com.compomics.util.parameters.identification.search.DigestionParameters in project peptide-shaker by compomics.

the class QCPanel method getPeptideDataset.

/**
 * Returns the dataset to use for the peptide QC plot.
 */
private void getPeptideDataset() {
    maxValue = Double.MIN_VALUE;
    SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
    if (peptideValidatedPsmsJRadioButton.isSelected()) {
        progressDialog.setPrimaryProgressCounterIndeterminate(false);
        progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getPeptideIdentification().size());
        progressDialog.setValue(0);
        // values for the number of validated PSMs
        validatedValues = new ArrayList<>();
        validatedDoubtfulValues = new ArrayList<>();
        nonValidatedValues = new ArrayList<>();
        validatedDecoyValues = new ArrayList<>();
        nonValidatedDecoyValues = new ArrayList<>();
        PeptideMatchesIterator peptideMatchesIterator = peptideShakerGUI.getIdentification().getPeptideMatchesIterator(progressDialog);
        PeptideMatch peptideMatch;
        while ((peptideMatch = peptideMatchesIterator.next()) != null) {
            if (progressDialog.isRunCanceled()) {
                break;
            }
            double value = 0;
            for (long spectrumMatchKey : peptideMatch.getSpectrumMatchesKeys()) {
                if (progressDialog.isRunCanceled()) {
                    break;
                }
                SpectrumMatch spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumMatchKey);
                PSParameter spectrumParameter = (PSParameter) spectrumMatch.getUrParam(PSParameter.dummy);
                if (spectrumParameter.getMatchValidationLevel().isValidated() && !spectrumParameter.getHidden()) {
                    value = value + 1;
                }
            }
            if (value > maxValue) {
                maxValue = value;
            }
            PSParameter peptideParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            if (!peptideParameter.getHidden()) {
                if (!PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider)) {
                    if (peptideParameter.getMatchValidationLevel().isValidated()) {
                        if (peptideParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
                            validatedValues.add(value);
                        } else {
                            validatedDoubtfulValues.add(value);
                        }
                    } else {
                        nonValidatedValues.add(value);
                    }
                } else if (peptideParameter.getMatchValidationLevel().isValidated()) {
                    validatedDecoyValues.add(value);
                } else {
                    nonValidatedDecoyValues.add(value);
                }
            }
            progressDialog.increasePrimaryProgressCounter();
        }
    } else if (peptideMissedCleavagesJRadioButton.isSelected()) {
        progressDialog.setPrimaryProgressCounterIndeterminate(false);
        progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getPeptideIdentification().size());
        progressDialog.setValue(0);
        // Values for the missed cleavages
        validatedValues = new ArrayList<>();
        validatedDoubtfulValues = new ArrayList<>();
        nonValidatedValues = new ArrayList<>();
        validatedDecoyValues = new ArrayList<>();
        nonValidatedDecoyValues = new ArrayList<>();
        PeptideMatchesIterator peptideMatchesIterator = peptideShakerGUI.getIdentification().getPeptideMatchesIterator(progressDialog);
        PeptideMatch peptideMatch;
        while ((peptideMatch = peptideMatchesIterator.next()) != null) {
            if (progressDialog.isRunCanceled()) {
                break;
            }
            PSParameter peptideParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            if (!peptideParameter.getHidden()) {
                Double value = null;
                DigestionParameters digestionParameters = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getDigestionParameters();
                if (digestionParameters.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                    for (Enzyme enzyme : digestionParameters.getEnzymes()) {
                        int enzymeMissedCelavages = enzyme.getNmissedCleavages(peptideMatch.getPeptide().getSequence());
                        if (value == null || enzymeMissedCelavages < value) {
                            value = Double.valueOf(enzymeMissedCelavages);
                        }
                    }
                }
                if (value == null) {
                    value = 0.0;
                }
                if (value > 0) {
                    if (value > maxValue) {
                        maxValue = value;
                    }
                }
                if (!PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider)) {
                    if (peptideParameter.getMatchValidationLevel().isValidated()) {
                        if (peptideParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
                            validatedValues.add(value);
                        } else {
                            validatedDoubtfulValues.add(value);
                        }
                    } else {
                        nonValidatedValues.add(value);
                    }
                } else if (peptideParameter.getMatchValidationLevel().isValidated()) {
                    validatedDecoyValues.add(value);
                } else {
                    nonValidatedDecoyValues.add(value);
                }
            }
            progressDialog.increasePrimaryProgressCounter();
        }
    } else if (peptideLengthJRadioButton.isSelected()) {
        progressDialog.setPrimaryProgressCounterIndeterminate(false);
        progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getPeptideIdentification().size());
        progressDialog.setValue(0);
        // values for the peptide length
        validatedValues = new ArrayList<>();
        validatedDoubtfulValues = new ArrayList<>();
        nonValidatedValues = new ArrayList<>();
        validatedDecoyValues = new ArrayList<>();
        nonValidatedDecoyValues = new ArrayList<>();
        PeptideMatchesIterator peptideMatchesIterator = peptideShakerGUI.getIdentification().getPeptideMatchesIterator(progressDialog);
        PeptideMatch peptideMatch;
        while ((peptideMatch = peptideMatchesIterator.next()) != null) {
            if (progressDialog.isRunCanceled()) {
                break;
            }
            PSParameter peptideParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
            if (!peptideParameter.getHidden()) {
                double length = peptideMatch.getPeptide().getSequence().length();
                if (length > 0) {
                    if (length > maxValue) {
                        maxValue = length;
                    }
                }
                if (!PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider)) {
                    if (peptideParameter.getMatchValidationLevel().isValidated()) {
                        if (peptideParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
                            validatedValues.add(length);
                        } else {
                            validatedDoubtfulValues.add(length);
                        }
                    } else {
                        nonValidatedValues.add(length);
                    }
                } else if (peptideParameter.getMatchValidationLevel().isValidated()) {
                    validatedDecoyValues.add(length);
                } else {
                    nonValidatedDecoyValues.add(length);
                }
            }
            progressDialog.increasePrimaryProgressCounter();
        }
    }
}
Also used : SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) Enzyme(com.compomics.util.experiment.biology.enzymes.Enzyme) ArrayList(java.util.ArrayList) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 2 with DigestionParameters

use of com.compomics.util.parameters.identification.search.DigestionParameters in project peptide-shaker by compomics.

the class ProteinInference method compareMainProtein.

/**
 * Checks whether a new main protein (newAccession) of the new protein match
 * (newProteinMatch) is better than another one main protein (oldAccession)
 * of another protein match (oldProteinMatch). First checks the protein
 * evidence level (if available), if not there then checks the protein
 * description and peptide enzymaticity.
 *
 * @param oldProteinMatch the protein match of oldAccession
 * @param oldAccession the accession of the old protein
 * @param newProteinMatch the protein match of newAccession
 * @param newAccession the accession of the new protein
 * @param sequenceProvider the sequence provider
 * @param identificationParameters the identification parameters
 *
 * @return the product of the comparison: 1: better enzymaticity, 2: better
 * evidence, 3: better characterization, 0: equal or not better
 */
private int compareMainProtein(ProteinMatch oldProteinMatch, String oldAccession, ProteinMatch newProteinMatch, String newAccession, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, IdentificationParameters identificationParameters, Identification identification) {
    DigestionParameters digestionPreferences = identificationParameters.getSearchParameters().getDigestionParameters();
    if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
        boolean newEnzymatic = Arrays.stream(newProteinMatch.getPeptideMatchesKeys()).mapToObj(key -> identification.getPeptideMatch(key)).anyMatch(peptideMatch -> PeptideUtils.isEnzymatic(peptideMatch.getPeptide(), newAccession, sequenceProvider.getSequence(newAccession), digestionPreferences.getEnzymes()));
        boolean oldEnzymatic = Arrays.stream(oldProteinMatch.getPeptideMatchesKeys()).mapToObj(key -> identification.getPeptideMatch(key)).anyMatch(peptideMatch -> PeptideUtils.isEnzymatic(peptideMatch.getPeptide(), oldAccession, sequenceProvider.getSequence(oldAccession), digestionPreferences.getEnzymes()));
        if (newEnzymatic && !oldEnzymatic) {
            return 1;
        } else if (!newEnzymatic && oldEnzymatic) {
            return 0;
        }
    }
    Integer evidenceLevelOld = proteinDetailsProvider.getProteinEvidence(oldAccession);
    Integer evidenceLevelNew = proteinDetailsProvider.getProteinEvidence(newAccession);
    // compare protein evidence levels
    if (evidenceLevelOld != null && evidenceLevelNew != null) {
        if (evidenceLevelNew < evidenceLevelOld) {
            return 2;
        } else if (evidenceLevelOld < evidenceLevelNew) {
            return 0;
        }
    }
    // Compare descriptions for keywords of uncharacterized proteins
    String oldDescription = proteinDetailsProvider.getSimpleDescription(oldAccession);
    if (oldDescription == null || oldDescription.trim().isEmpty()) {
        oldDescription = proteinDetailsProvider.getDescription(oldAccession);
    }
    String newDescription = proteinDetailsProvider.getSimpleDescription(newAccession);
    if (newDescription == null || newDescription.trim().isEmpty()) {
        newDescription = proteinDetailsProvider.getDescription(newAccession);
    }
    boolean oldUncharacterized = false, newUncharacterized = false;
    for (String keyWord : KEYWORDS_UNCHARACTERIZED) {
        if (newDescription != null && newDescription.contains(keyWord)) {
            newUncharacterized = true;
        }
        if (oldDescription != null && oldDescription.contains(keyWord)) {
            oldUncharacterized = true;
        }
    }
    if (oldUncharacterized && !newUncharacterized) {
        return 3;
    } else if (!oldUncharacterized && newUncharacterized) {
        return 0;
    }
    return 0;
}
Also used : Arrays(java.util.Arrays) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) HashSet(java.util.HashSet) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) Metrics(com.compomics.util.experiment.identification.peptide_shaker.Metrics) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters)

Example 3 with DigestionParameters

use of com.compomics.util.parameters.identification.search.DigestionParameters in project peptide-shaker by compomics.

the class ProteinInferencePeptideLevelDialog method addPeptide.

/**
 * Add a peptide and the corresponding proteins to the graph.
 *
 * @param peptideKey the peptide key
 * @param nodeToolTips the node tool tips
 * @param nodes the nodes
 * @param nodeProperties the node properties
 * @param selectedNodes the selected nodes
 * @param edges the edges
 * @param edgeProperties the edge properties
 */
private void addPeptide(long peptideKey, HashMap<String, String> nodeToolTips, ArrayList<String> nodes, HashMap<String, String> nodeProperties, ArrayList<String> selectedNodes, HashMap<String, ArrayList<String>> edges, HashMap<String, String> edgeProperties) {
    PeptideMatch peptideMatch = (PeptideMatch) peptideShakerGUI.getIdentification().retrieveObject(peptideKey);
    String peptideNodeName = "Peptide " + peptideKey;
    if (!nodes.contains(peptideNodeName)) {
        ProteinDetailsProvider proteinDetailsProvider = peptideShakerGUI.getProteinDetailsProvider();
        SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
        // add the node
        nodes.add(peptideNodeName);
        // get the match validation level
        PSParameter peptideMatchParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
        String matchValidationLevel = "Validation: " + peptideMatchParameter.getMatchValidationLevel();
        nodeProperties.put(peptideNodeName, "" + peptideMatchParameter.getMatchValidationLevel().getIndex());
        // get the peptide node tooltip
        String peptideTooltip = peptideShakerGUI.getDisplayFeaturesGenerator().getTaggedPeptideSequence(peptideMatch, true, false, true);
        peptideTooltip = "<html>" + peptideTooltip + "<br><br>" + matchValidationLevel + "</html>";
        nodeToolTips.put(peptideNodeName, peptideTooltip);
        for (String tempProteinAccession : peptideMatch.getPeptide().getProteinMapping().keySet()) {
            String proteinNodeKey = "Protein " + tempProteinAccession;
            if (!nodes.contains(proteinNodeKey)) {
                // add the node
                nodes.add(proteinNodeKey);
                // get the match validation level
                long tempKey = ExperimentObject.asLong(tempProteinAccession);
                ProteinMatch tempProteinMatch = identification.getProteinMatch(tempKey);
                String nodeProperty = "";
                if (tempProteinMatch != null) {
                    PSParameter psParameter = (PSParameter) tempProteinMatch.getUrParam(PSParameter.dummy);
                    nodeProperty += psParameter.getMatchValidationLevel().getIndex();
                    matchValidationLevel = "Validation: " + psParameter.getMatchValidationLevel();
                } else {
                    nodeProperty += -1;
                    matchValidationLevel = "Validation: (not available)";
                }
                // get the protein evidence level
                Integer level = proteinDetailsProvider.getProteinEvidence(tempProteinAccession);
                String proteinEvidenceLevel = "Evidence: (not available)";
                if (level != null) {
                    nodeProperty += "|" + level;
                    try {
                        proteinEvidenceLevel = "Evidence: " + Header.getProteinEvidencAsString(level);
                    } catch (NumberFormatException e) {
                    // ignore
                    }
                }
                // add the node property
                nodeProperties.put(proteinNodeKey, nodeProperty);
                // add the tooltip
                nodeToolTips.put(proteinNodeKey, "<html>" + tempProteinAccession + "<br>" + proteinDetailsProvider.getSimpleDescription(tempProteinAccession) + "<br><br>" + matchValidationLevel + "<br>" + proteinEvidenceLevel + "<html>");
                // add any new peptides for the proteins
                if (tempProteinMatch != null) {
                    for (long tempPeptideKey : tempProteinMatch.getPeptideMatchesKeys()) {
                        addPeptide(tempPeptideKey, nodeToolTips, nodes, nodeProperties, selectedNodes, edges, edgeProperties);
                    }
                } else {
                    if (identification.getProteinMap().containsKey(tempProteinAccession)) {
                        identification.getProteinMap().get(tempProteinAccession).stream().flatMap(key -> Arrays.stream(identification.getProteinMatch(key).getPeptideMatchesKeys()).boxed()).distinct().forEach(tempPeptideKey -> addPeptide(tempPeptideKey, nodeToolTips, nodes, nodeProperties, selectedNodes, edges, edgeProperties));
                    }
                }
            }
            ArrayList<String> tempEdges = edges.get(peptideNodeName);
            if (tempEdges == null) {
                tempEdges = new ArrayList<>();
            }
            if (!tempEdges.contains(proteinNodeKey)) {
                tempEdges.add(proteinNodeKey);
                Boolean enzymatic = false;
                DigestionParameters digestionPreferences = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getDigestionParameters();
                if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                    enzymatic = PeptideUtils.isEnzymatic(peptideMatch.getPeptide(), tempProteinAccession, sequenceProvider.getSequence(tempProteinAccession), digestionPreferences.getEnzymes());
                }
                edgeProperties.put(peptideNodeName + "|" + proteinNodeKey, enzymatic.toString());
            }
            edges.put(peptideNodeName, tempEdges);
        }
    }
}
Also used : PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 4 with DigestionParameters

use of com.compomics.util.parameters.identification.search.DigestionParameters in project peptide-shaker by compomics.

the class PsSearchParametersSection method writeSection.

/**
 * Writes the desired section.
 *
 * @param searchParameters the search parameters of this project
 * @param projectDetails the project details
 * @param waitingHandler the waiting handler
 * @throws IOException exception thrown whenever an error occurred while
 * writing the file
 */
public void writeSection(SearchParameters searchParameters, ProjectDetails projectDetails, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        if (indexes) {
            writer.writeHeaderText("");
            writer.addSeparator();
        }
        writer.writeHeaderText("Parameter");
        writer.addSeparator();
        writer.writeHeaderText("Value");
        writer.newLine();
    }
    int line = 1;
    for (PsSearchFeature exportFeature : searchFeatures) {
        if (indexes) {
            writer.write(Integer.toString(line));
            writer.addSeparator();
        }
        writer.write(exportFeature.getTitle());
        writer.addSeparator();
        switch(exportFeature) {
            case database:
                String fastaFileName = IoUtil.getFileName(projectDetails.getFastaFile());
                writer.write(fastaFileName);
                break;
            case cleavage:
                DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
                writer.write(digestionPreferences.getCleavageParameter().toString());
                break;
            case enzyme:
                digestionPreferences = searchParameters.getDigestionParameters();
                if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                    String enzymeString = digestionPreferences.getEnzymes().stream().map(enzyme -> enzyme.getName()).collect(Collectors.joining(", "));
                    writer.write(enzymeString);
                }
                break;
            case mc:
                digestionPreferences = searchParameters.getDigestionParameters();
                if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                    String nMissedCleavagesString = digestionPreferences.getEnzymes().stream().map(enzyme -> digestionPreferences.getnMissedCleavages(enzyme.getName()).toString()).collect(Collectors.joining(", "));
                    writer.write(nMissedCleavagesString);
                }
                break;
            case specificity:
                digestionPreferences = searchParameters.getDigestionParameters();
                if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                    String specificityString = digestionPreferences.getEnzymes().stream().map(enzyme -> digestionPreferences.getSpecificity(enzyme.getName()).name).collect(Collectors.joining(", "));
                    writer.write(specificityString);
                }
                break;
            case fixed_modifications:
                writer.write(searchParameters.getModificationParameters().getFixedModifications().stream().collect(Collectors.joining(", ")));
                break;
            case variable_modifications:
                writer.write(searchParameters.getModificationParameters().getVariableModifications().stream().collect(Collectors.joining(", ")));
                break;
            case refinement_variable_modifications:
                writer.write(searchParameters.getModificationParameters().getRefinementVariableModifications().stream().collect(Collectors.joining(", ")));
                break;
            case refinement_fixed_modifications:
                writer.write(searchParameters.getModificationParameters().getRefinementFixedModifications().stream().collect(Collectors.joining(", ")));
                break;
            case forward_ion:
                writer.write(searchParameters.getForwardIons().stream().map(ion -> ion.toString()).collect(Collectors.joining(", ")));
                break;
            case rewind_ion:
                writer.write(searchParameters.getRewindIons().stream().map(ion -> ion.toString()).collect(Collectors.joining(", ")));
                break;
            case fragment_tolerance:
                writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
                break;
            case precursor_tolerance_unit:
                writer.write(searchParameters.getPrecursorAccuracyType().toString());
                break;
            case fragment_tolerance_unit:
                writer.write(searchParameters.getFragmentAccuracyType().toString());
                break;
            case precursor_tolerance:
                writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
                break;
            default:
                writer.write("Not implemented");
        }
        writer.newLine();
        line++;
    }
}
Also used : WaitingHandler(com.compomics.util.waiting.WaitingHandler) ExportWriter(com.compomics.util.io.export.ExportWriter) PsSearchFeature(com.compomics.util.io.export.features.peptideshaker.PsSearchFeature) IoUtil(com.compomics.util.io.IoUtil) ExportFeature(com.compomics.util.io.export.ExportFeature) ProjectDetails(eu.isas.peptideshaker.preferences.ProjectDetails) IOException(java.io.IOException) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) Collectors(java.util.stream.Collectors) EnumSet(java.util.EnumSet) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) ArrayList(java.util.ArrayList) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) PsSearchFeature(com.compomics.util.io.export.features.peptideshaker.PsSearchFeature)

Example 5 with DigestionParameters

use of com.compomics.util.parameters.identification.search.DigestionParameters in project peptide-shaker by compomics.

the class InclusionListExport method exportInclusionList.

/**
 * Writes an inclusion list based on the validated PSMs of the validated
 * peptides of the validated proteins.
 *
 * @param destinationFile the file where to write the inclusion list
 * @param identification the identification object containing all matches
 * and match parameters
 * @param identificationFeaturesGenerator the identification features
 * generator calculating identification metrics on the fly
 * @param spectrumProvider the spectrum provider
 * @param proteinFilters the inclusion list protein filters
 * @param peptideFilters the inclusion list peptide filters
 * @param exportFormat the export format
 * @param searchParameters the identification parameters
 * @param rtWindow the window to use for retention time
 * @param waitingHandler waiting handler displaying progress to the user
 * (can be null)
 * @param filterPreferences the general filtering preferences of this
 * project
 *
 * @throws IOException thrown if an error occurred while writing the file
 */
public static void exportInclusionList(File destinationFile, Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SpectrumProvider spectrumProvider, ArrayList<Integer> proteinFilters, ArrayList<PeptideFilterType> peptideFilters, ExportFormat exportFormat, SearchParameters searchParameters, double rtWindow, WaitingHandler waitingHandler, FilterParameters filterPreferences) throws IOException {
    if (waitingHandler != null) {
        if (waitingHandler.isRunCanceled()) {
            return;
        }
        waitingHandler.setWaitingText("Inclusion List - Writing File. Please Wait...");
        waitingHandler.resetSecondaryProgressCounter();
        waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size());
    }
    try (SimpleFileWriter writer = new SimpleFileWriter(destinationFile, false)) {
        ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(waitingHandler);
        ProteinMatch proteinMatch;
        while ((proteinMatch = proteinMatchesIterator.next()) != null) {
            PSParameter proteinParameter = (PSParameter) proteinMatch.getUrParam(PSParameter.dummy);
            if (!proteinFilters.contains(proteinParameter.getProteinInferenceGroupClass())) {
                ArrayList<Long> peptideMatches = new ArrayList<>();
                for (long peptideKey : proteinMatch.getPeptideMatchesKeys()) {
                    PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
                    PSParameter peptideParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
                    if (peptideParameter.getMatchValidationLevel().isValidated()) {
                        boolean passesFilter = true;
                        for (PeptideFilterType filterType : peptideFilters) {
                            String sequence = peptideMatch.getPeptide().getSequence();
                            if (filterType == PeptideFilterType.degenerated) {
                                if (peptideParameter.getProteinInferenceGroupClass() != PSParameter.NOT_GROUP) {
                                    passesFilter = false;
                                    break;
                                }
                            } else if (filterType == PeptideFilterType.miscleaved) {
                                Integer peptideMinMissedCleavages = null;
                                DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
                                if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
                                    for (Enzyme enzyme : digestionPreferences.getEnzymes()) {
                                        int tempMissedCleavages = enzyme.getNmissedCleavages(sequence);
                                        if (peptideMinMissedCleavages == null || tempMissedCleavages < peptideMinMissedCleavages) {
                                            peptideMinMissedCleavages = tempMissedCleavages;
                                        }
                                    }
                                }
                                if (peptideMinMissedCleavages != null && peptideMinMissedCleavages > 0) {
                                    passesFilter = false;
                                    break;
                                }
                            } else if (filterType == PeptideFilterType.reactive) {
                                if (sequence.contains("M") || sequence.contains("C") || sequence.contains("W") || sequence.contains("NG") || sequence.contains("DG") || sequence.contains("QG") || sequence.startsWith("N") || sequence.startsWith("Q")) {
                                    passesFilter = false;
                                    break;
                                }
                            }
                        }
                        if (passesFilter) {
                            peptideMatches.add(peptideKey);
                        }
                    }
                }
                if (!peptideMatches.isEmpty()) {
                    for (long peptideKey : peptideMatches) {
                        PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
                        ArrayList<SpectrumMatch> validatedPsms = new ArrayList<>(peptideMatch.getSpectrumCount());
                        ArrayList<Double> retentionTimes = new ArrayList<>(peptideMatch.getSpectrumCount());
                        for (long spectrumKey : peptideMatch.getSpectrumMatchesKeys()) {
                            SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                            if (spectrumMatch.getBestPeptideAssumption() != null) {
                                PSParameter spectrumParameter = (PSParameter) spectrumMatch.getUrParam(PSParameter.dummy);
                                if (spectrumParameter.getMatchValidationLevel().isValidated()) {
                                    validatedPsms.add(spectrumMatch);
                                    retentionTimes.add(spectrumProvider.getPrecursorRt(spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle()));
                                }
                            }
                        }
                        if (!validatedPsms.isEmpty()) {
                            for (SpectrumMatch spectrumMatch : validatedPsms) {
                                double precursorMz = spectrumProvider.getPrecursorMz(spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle());
                                String line = getInclusionListLine(spectrumMatch, retentionTimes, rtWindow, precursorMz, exportFormat, searchParameters);
                                writer.writeLine(line);
                            }
                        }
                    }
                }
            }
            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.increaseSecondaryProgressCounter();
            }
        }
    }
}
Also used : PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) Enzyme(com.compomics.util.experiment.biology.enzymes.Enzyme) ArrayList(java.util.ArrayList) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Aggregations

DigestionParameters (com.compomics.util.parameters.identification.search.DigestionParameters)12 PeptideMatch (com.compomics.util.experiment.identification.matches.PeptideMatch)7 ArrayList (java.util.ArrayList)7 Enzyme (com.compomics.util.experiment.biology.enzymes.Enzyme)6 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)6 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)6 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)4 ProteinDetailsProvider (com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider)3 Modification (com.compomics.util.experiment.biology.modifications.Modification)2 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)2 Identification (com.compomics.util.experiment.identification.Identification)2 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)2 PeptideMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator)2 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)2 WaitingHandler (com.compomics.util.waiting.WaitingHandler)2 TargetDecoyMap (eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 AminoAcidPattern (com.compomics.util.experiment.biology.aminoacids.sequence.AminoAcidPattern)1 ModificationFactory (com.compomics.util.experiment.biology.modifications.ModificationFactory)1