use of com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator 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();
}
}
}
use of com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator in project peptide-shaker by compomics.
the class QCPanel method getPeptideModificationEnrichmentSpecificityDataset.
/**
* Returns the dataset for the peptide modification rate QC plot.
*
* @return the dataset for the peptide modification rate QC plot
*/
private DefaultCategoryDataset getPeptideModificationEnrichmentSpecificityDataset() {
ModificationFactory modificationFactory = ModificationFactory.getInstance();
Identification identification = peptideShakerGUI.getIdentification();
SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
ArrayList<String> modNames = modificationParameters.getAllNotFixedModifications();
HashMap<String, Integer> modifiedPeptidesMap = new HashMap<>(modNames.size());
HashMap<String, Integer> possiblyModifiedPeptidesMap = new HashMap<>(modNames.size());
progressDialog.setPrimaryProgressCounterIndeterminate(false);
progressDialog.setMaxPrimaryProgressCounter(identification.getPeptideIdentification().size());
progressDialog.setValue(0);
PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(progressDialog);
PeptideMatch peptideMatch;
while ((peptideMatch = peptideMatchesIterator.next()) != null) {
PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
if (psParameter.getMatchValidationLevel().isValidated()) {
Peptide peptide = peptideMatch.getPeptide();
for (String modName : modificationParameters.getAllNotFixedModifications()) {
Modification modification = modificationFactory.getModification(modName);
int[] possibleSites = ModificationUtils.getPossibleModificationSites(peptide, modification, sequenceProvider, modificationSequenceMatchingParameters);
if (possibleSites.length != 0) {
Integer nPossiblePeptides = possiblyModifiedPeptidesMap.get(modName);
if (nPossiblePeptides == null) {
possiblyModifiedPeptidesMap.put(modName, 1);
} else {
possiblyModifiedPeptidesMap.put(modName, nPossiblePeptides + 1);
}
boolean modified = false;
for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
if (modificationMatch.getModification().equals(modName)) {
modified = true;
break;
}
}
if (modified) {
Integer nModifiedPeptides = modifiedPeptidesMap.get(modName);
if (nModifiedPeptides == null) {
modifiedPeptidesMap.put(modName, 1);
} else {
modifiedPeptidesMap.put(modName, nModifiedPeptides + 1);
}
}
}
}
}
if (progressDialog.isRunCanceled()) {
break;
}
progressDialog.increaseSecondaryProgressCounter();
}
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (String modName : modificationParameters.getAllNotFixedModifications()) {
Integer nFound = modifiedPeptidesMap.get(modName);
if (nFound == null) {
nFound = 0;
}
Integer nPossible = possiblyModifiedPeptidesMap.get(modName);
Double rate = 0.0;
if (nPossible != null) {
rate = (100.0 * nFound) / nPossible;
}
dataset.addValue(rate, "Modified", modName);
double rest = 0.0;
if (nPossible != null) {
rest = 100 - rate;
}
dataset.addValue(rest, "Not Modified", modName);
}
return dataset;
}
use of com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator in project peptide-shaker by compomics.
the class QCPanel method getPeptideModificationEfficiencyDataset.
/**
* Returns the dataset for the peptide modification efficiency QC plot.
*
* @return the dataset for the peptide modification efficiency QC plot
*/
private DefaultCategoryDataset getPeptideModificationEfficiencyDataset() {
ModificationFactory modificationFactory = ModificationFactory.getInstance();
Identification identification = peptideShakerGUI.getIdentification();
SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingPreferences = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
ArrayList<String> modNames = modificationParameters.getAllNotFixedModifications();
HashMap<String, Integer> modifiedSitesMap = new HashMap<>(modNames.size());
HashMap<String, Integer> possibleSitesMap = new HashMap<>(modNames.size());
PSParameter psParameter = new PSParameter();
progressDialog.setPrimaryProgressCounterIndeterminate(false);
progressDialog.setMaxPrimaryProgressCounter(identification.getPeptideIdentification().size());
progressDialog.setValue(0);
PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(progressDialog);
PeptideMatch peptideMatch;
while ((peptideMatch = peptideMatchesIterator.next()) != null) {
psParameter = (PSParameter) peptideMatch.getUrParam(psParameter);
if (psParameter.getMatchValidationLevel().isValidated()) {
Peptide peptide = peptideMatch.getPeptide();
HashMap<String, Integer> peptideModificationsMap = new HashMap<>(peptide.getVariableModifications().length);
for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
String modName = modificationMatch.getModification();
Integer occurrence = peptideModificationsMap.get(modName);
if (occurrence == null) {
peptideModificationsMap.put(modName, 1);
} else {
peptideModificationsMap.put(modName, occurrence + 1);
}
}
for (String modName : modificationParameters.getAllNotFixedModifications()) {
Modification modification = modificationFactory.getModification(modName);
int[] possibleSites = ModificationUtils.getPossibleModificationSites(peptide, modification, sequenceProvider, modificationSequenceMatchingPreferences);
if (possibleSites.length != 0) {
Integer occurrencePeptide = peptideModificationsMap.get(modName);
if (occurrencePeptide != null) {
Integer occurrenceDataset = modifiedSitesMap.get(modName);
if (occurrenceDataset == null) {
modifiedSitesMap.put(modName, occurrencePeptide);
} else {
modifiedSitesMap.put(modName, occurrenceDataset + occurrencePeptide);
}
}
Integer possibleSitesDataset = possibleSitesMap.get(modName);
if (possibleSitesDataset == null) {
possibleSitesMap.put(modName, possibleSites.length);
} else {
possibleSitesMap.put(modName, possibleSitesDataset + possibleSites.length);
}
}
}
}
if (progressDialog.isRunCanceled()) {
break;
}
progressDialog.increaseSecondaryProgressCounter();
}
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (String modName : modificationParameters.getAllNotFixedModifications()) {
Integer nFound = modifiedSitesMap.get(modName);
if (nFound == null) {
nFound = 0;
}
Integer nPossible = possibleSitesMap.get(modName);
Double rate = 0.0;
if (nPossible != null) {
rate = (100.0 * nFound) / nPossible;
}
dataset.addValue(rate, "Modified", modName);
double rest = 100 - rate;
dataset.addValue(rest, "Not Modified", modName);
}
return dataset;
}
use of com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator in project peptide-shaker by compomics.
the class MatchesValidator method attachPeptideProbabilities.
/**
* Attaches the peptide posterior error probabilities to the peptide
* matches.
*
* @param identification the identification class containing the matches to
* validate
* @param fastaParameters the FASTA file parameters
* @param waitingHandler the handler displaying feedback to the user
*/
public void attachPeptideProbabilities(Identification identification, FastaParameters fastaParameters, WaitingHandler waitingHandler) {
waitingHandler.setWaitingText("Attaching Peptide Probabilities. Please Wait...");
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
waitingHandler.setMaxSecondaryProgressCounter(identification.getPeptideIdentification().size());
PSParameter psParameter = new PSParameter();
PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(waitingHandler);
PeptideMatch peptideMatch;
while ((peptideMatch = peptideMatchesIterator.next()) != null) {
long peptideKey = peptideMatch.getKey();
psParameter = (PSParameter) peptideMatch.getUrParam(psParameter);
if (fastaParameters.isTargetDecoy()) {
double probability = peptideMap.getProbability(psParameter.getScore());
psParameter.setProbability(probability);
} else {
psParameter.setProbability(1.0);
}
Set<String> fractions = psParameter.getFractions();
if (fractions == null) {
throw new IllegalArgumentException("Fractions not found for peptide " + peptideKey + ".");
}
for (String fraction : fractions) {
if (fastaParameters.isTargetDecoy()) {
double probability = peptideMap.getProbability(psParameter.getFractionScore(fraction));
psParameter.setFractionPEP(fraction, probability);
} else {
psParameter.setFractionPEP(fraction, 1.0);
}
}
identification.updateObject(peptideKey, peptideMatch);
waitingHandler.increaseSecondaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
use of com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator 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++;
}
}
}
}
Aggregations