use of com.compomics.util.experiment.biology.enzymes.Enzyme 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.biology.enzymes.Enzyme 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();
}
}
}
}
use of com.compomics.util.experiment.biology.enzymes.Enzyme in project peptide-shaker by compomics.
the class PepXmlExport method writeMsmsRunSummary.
/**
* Writes the MS2 run summary section.
*
* @param sw the XML file writer
* @param identification the identification object containing the
* identification results
* @param spectrumProvider the spectrum provider
* @param identificationParameters the identification parameters
* @param waitingHandler a waiting handler to display progress and allow
* interrupting the process
*
* @throws IOException exception thrown whenever an error is encountered
* while reading or writing a file
*/
private void writeMsmsRunSummary(SimpleXmlWriter sw, Identification identification, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, WaitingHandler waitingHandler) throws IOException {
if (waitingHandler != null) {
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
// reset the progress bar
waitingHandler.resetSecondaryProgressCounter();
waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
}
TreeSet<String> msFiles = new TreeSet<>(identification.getSpectrumIdentification().keySet());
for (String spectrumFileName : msFiles) {
StringBuilder runStart = new StringBuilder();
runStart.append("<msms_run_summary");
String filePath = spectrumProvider.getFilePaths().get(spectrumFileName);
if (filePath != null) {
String baseName = IoUtil.removeExtension(filePath);
String extension = IoUtil.getExtension(new File(filePath));
runStart.append(" base_name=\"").append(baseName).append("\" ");
runStart.append("raw_data_type=\"").append(extension).append("\" ");
runStart.append("raw_data=\"").append(extension).append("\"");
}
runStart.append(">");
sw.writeLine(runStart.toString());
DigestionParameters digestionPreferences = identificationParameters.getSearchParameters().getDigestionParameters();
if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
for (Enzyme enzyme : digestionPreferences.getEnzymes()) {
DigestionParameters.Specificity specificity = digestionPreferences.getSpecificity(enzyme.getName());
writeEnzyme(sw, enzyme, specificity);
}
}
writeSearchSummary(sw, identificationParameters);
writeSpectrumQueries(sw, identification, spectrumProvider, identificationParameters, spectrumFileName, waitingHandler);
sw.writeLineDecreasedIndent("</msms_run_summary>");
if (waitingHandler != null && waitingHandler.isRunCanceled()) {
break;
}
}
}
use of com.compomics.util.experiment.biology.enzymes.Enzyme in project peptide-shaker by compomics.
the class PeptideShakerMethods method getIdentificationSettings.
/**
* Returns the identification settings details.
*
* @param searchParameters the search parameters
*
* @return the identification settings details
*/
public static String getIdentificationSettings(SearchParameters searchParameters) {
StringBuilder text = new StringBuilder("The identification settings were as follows: ");
DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
switch(digestionPreferences.getCleavageParameter()) {
case unSpecific:
text.append("No cleavage specificity; ");
break;
case wholeProtein:
text.append("No digestion; ");
break;
case enzyme:
for (int i = 0; i < digestionPreferences.getEnzymes().size(); i++) {
Enzyme enzyme = digestionPreferences.getEnzymes().get(i);
String enzymeName = enzyme.getName();
if (i > 0) {
if (digestionPreferences.getEnzymes().size() == 2) {
text.append(" and ");
} else {
text.append(", ");
if (i == digestionPreferences.getEnzymes().size() - 1) {
text.append("and ");
}
}
}
text.append(enzymeName).append(", ").append(digestionPreferences.getSpecificity(enzymeName)).append(", with a maximum of ").append(digestionPreferences.getnMissedCleavages(enzymeName)).append(" missed cleavages");
}
break;
default:
throw new UnsupportedOperationException("Cleavage of type " + digestionPreferences.getCleavageParameter() + " not supported.");
}
text.append(searchParameters.getPrecursorAccuracy()).append(" ").append(searchParameters.getPrecursorAccuracyType()).append(" as MS1 and ").append(searchParameters.getFragmentIonAccuracy()).append(" ").append(searchParameters.getFragmentAccuracyType()).append(" as MS2 tolerances; ");
ModificationFactory ptmFactory = ModificationFactory.getInstance();
ArrayList<String> fixedPtmsNames = searchParameters.getModificationParameters().getFixedModifications();
if (!fixedPtmsNames.isEmpty()) {
text.append("fixed modifications: ");
for (int i = 0; i < fixedPtmsNames.size(); i++) {
if (i > 0) {
if (fixedPtmsNames.size() == 2) {
text.append(" and ");
} else {
text.append(", ");
if (i == fixedPtmsNames.size() - 1) {
text.append("and ");
}
}
}
String ptmName = fixedPtmsNames.get(i);
Modification ptm = ptmFactory.getModification(ptmName);
char sign = ptm.getRoundedMass() < 0 ? '-' : '+';
text.append(ptmName).append(" (").append(sign).append(ptm.getRoundedMass()).append(" Da)");
}
text.append(", ");
}
ArrayList<String> variablePtmsNames = searchParameters.getModificationParameters().getVariableModifications();
if (!variablePtmsNames.isEmpty()) {
text.append(" variable modifications: ");
for (int i = 0; i < variablePtmsNames.size(); i++) {
if (i > 0) {
if (fixedPtmsNames.size() == 2) {
text.append(" and ");
} else {
text.append(", ");
if (i == fixedPtmsNames.size() - 1) {
text.append("and ");
}
}
}
String ptmName = variablePtmsNames.get(i);
Modification ptm = ptmFactory.getModification(ptmName);
char sign = ptm.getRoundedMass() < 0 ? '-' : '+';
text.append(ptmName).append(" (").append(sign).append(ptm.getRoundedMass()).append(" Da)");
}
text.append(", ");
}
ArrayList<String> refinementFixedPtmsNames = searchParameters.getModificationParameters().getRefinementFixedModifications();
if (!refinementFixedPtmsNames.isEmpty()) {
text.append("fixed modifications during refinement procedure: ");
for (int i = 0; i < refinementFixedPtmsNames.size(); i++) {
if (i > 0) {
if (fixedPtmsNames.size() == 2) {
text.append(" and ");
} else {
text.append(", ");
if (i == fixedPtmsNames.size() - 1) {
text.append("and ");
}
}
}
String ptmName = refinementFixedPtmsNames.get(i);
Modification ptm = ptmFactory.getModification(ptmName);
char sign = ptm.getRoundedMass() < 0 ? '-' : '+';
text.append(ptmName).append(" (").append(sign).append(ptm.getRoundedMass()).append(" Da)");
}
text.append(", ");
}
ArrayList<String> refinementVariablePtmsNames = searchParameters.getModificationParameters().getRefinementVariableModifications();
if (!refinementVariablePtmsNames.isEmpty()) {
text.append("variable modifications during refinement procedure: ");
for (int i = 0; i < refinementVariablePtmsNames.size(); i++) {
if (i > 0) {
if (fixedPtmsNames.size() == 2) {
text.append(" and ");
} else {
text.append(", ");
if (i == fixedPtmsNames.size() - 1) {
text.append("and ");
}
}
}
String ptmName = refinementVariablePtmsNames.get(i);
Modification ptm = ptmFactory.getModification(ptmName);
char sign = ptm.getRoundedMass() < 0 ? '-' : '+';
text.append(ptmName).append(" (").append(sign).append(ptm.getRoundedMass()).append(" Da)");
}
}
text.append(". All algorithms specific settings are listed in the Certificate of Analysis available in the supplementary information.");
return text.toString();
}
use of com.compomics.util.experiment.biology.enzymes.Enzyme in project peptide-shaker by compomics.
the class MzIdentMLExport method writeAnalysisProtocol.
/**
* Write the analysis protocol.
*/
private void writeAnalysisProtocol() {
writer.write(getCurrentTabSpace());
writer.write("<AnalysisProtocolCollection>");
writer.newLine();
tabCounter++;
// add spectrum identification protocol
writer.write(getCurrentTabSpace());
writer.write("<SpectrumIdentificationProtocol analysisSoftware_ref=\"ID_software\" id=\"SearchProtocol_1\">");
writer.newLine();
tabCounter++;
// the search type
writer.write(getCurrentTabSpace());
writer.write("<SearchType>");
writer.newLine();
tabCounter++;
writeCvTerm(new CvTerm("PSI-MS", "MS:1001083", "ms-ms search", null));
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</SearchType>");
writer.newLine();
// the search parameters
SearchParameters searchParameters = identificationParameters.getSearchParameters();
writer.write(getCurrentTabSpace());
writer.write("<AdditionalSearchParams>");
writer.newLine();
tabCounter++;
writeCvTerm(new CvTerm("PSI-MS", "MS:1001211", "parent mass type mono", null));
writeCvTerm(new CvTerm("PSI-MS", "MS:1001256", "fragment mass type mono", null));
switch(mzIdentMLVersion) {
case v1_1:
break;
case v1_2:
writeCvTerm(new CvTerm("PSI-MS", "MS:1002492", "consensus scoring", null));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002490", "peptide-level scoring", null));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002497", "group PSMs by sequence with modifications", null));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002491", "modification localization scoring", null));
break;
default:
throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
}
// @TODO: list all search parameters from the search engines used?
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</AdditionalSearchParams>");
writer.newLine();
// the modifications
writer.write(getCurrentTabSpace());
writer.write("<ModificationParams>");
writer.newLine();
tabCounter++;
// create the ptm index map
switch(mzIdentMLVersion) {
case v1_1:
break;
case v1_2:
for (String modName : searchParameters.getModificationParameters().getAllModifications()) {
Modification modification = modificationProvider.getModification(modName);
Double modMass = modification.getMass();
Integer index = modIndexMap.get(modMass);
if (index == null) {
modIndexMap.put(modMass, modIndexMap.size());
}
}
break;
default:
throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
}
// iterate and add the modifications
for (String modName : searchParameters.getModificationParameters().getAllModifications()) {
Modification modification = modificationProvider.getModification(modName);
ModificationType modificationType = modification.getModificationType();
double modMass = modification.getMass();
String aminoAcidsAtTarget;
if (modificationType == ModificationType.modaa || modificationType == ModificationType.modcaa_peptide || modificationType == ModificationType.modcaa_protein || modificationType == ModificationType.modnaa_peptide || modificationType == ModificationType.modnaa_protein) {
StringBuilder sb = new StringBuilder();
for (Character aa : modification.getPattern().getAminoAcidsAtTarget()) {
sb.append(aa);
}
aminoAcidsAtTarget = sb.toString();
} else {
aminoAcidsAtTarget = ".";
}
writer.write(getCurrentTabSpace());
writer.write("<SearchModification residues=\"");
writer.write(aminoAcidsAtTarget);
writer.write("\" massDelta=\"");
writer.write(Double.toString(modification.getRoundedMass()));
writer.write("\" fixedMod= \"");
writer.write(Boolean.toString(searchParameters.getModificationParameters().getFixedModifications().contains(modName)));
writer.write("\" >");
writer.newLine();
tabCounter++;
// add modification specificity
if (modificationType != ModificationType.modaa) {
writer.write(getCurrentTabSpace());
writer.write("<SpecificityRules>");
writer.newLine();
tabCounter++;
switch(modificationType) {
case modn_protein:
case modnaa_protein:
writeCvTerm(new CvTerm("PSI-MS", "MS:1002057", "modification specificity protein N-term", null));
break;
case modn_peptide:
case modnaa_peptide:
writeCvTerm(new CvTerm("PSI-MS", "MS:1001189", "modification specificity peptide N-term", null));
break;
case modc_protein:
case modcaa_protein:
writeCvTerm(new CvTerm("PSI-MS", "MS:1002058", "modification specificity protein C-term", null));
break;
case modc_peptide:
case modcaa_peptide:
writeCvTerm(new CvTerm("PSI-MS", "MS:1001190", "modification specificity peptide C-term", null));
break;
default:
break;
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</SpecificityRules>");
writer.newLine();
}
// add the modification cv term
CvTerm ptmCvTerm = modification.getUnimodCvTerm();
if (ptmCvTerm != null) {
writeCvTerm(ptmCvTerm);
} else {
// try PSI-MOD instead
ptmCvTerm = modification.getPsiModCvTerm();
if (ptmCvTerm != null) {
writeCvTerm(ptmCvTerm);
} else {
writeCvTerm(new CvTerm("PSI-MS", "MS:1001460", "unknown modification", null));
}
}
// add modification type/index
switch(mzIdentMLVersion) {
case v1_1:
break;
case v1_2:
Integer modIndex = modIndexMap.get(modMass);
if (modIndex == null) {
throw new IllegalArgumentException("No index found for PTM " + modification.getName() + " of mass " + modMass + ".");
}
writeCvTerm(new CvTerm("PSI-MS", "MS:1002504", "modification index", modIndex.toString()));
break;
default:
throw new UnsupportedOperationException("mzIdentML version " + mzIdentMLVersion.name + " not supported.");
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</SearchModification>");
writer.newLine();
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</ModificationParams>");
writer.newLine();
// Digestion
DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.unSpecific) {
writer.write(getCurrentTabSpace());
writer.write("<Enzymes independent=\"false\">");
writer.newLine();
tabCounter++;
writer.write(getCurrentTabSpace());
writer.write("<Enzyme name=\"unspecific cleavage\">");
writer.newLine();
tabCounter++;
writer.write(getCurrentTabSpace());
writer.write("<EnzymeName>");
writer.newLine();
tabCounter++;
CvTerm enzymeCvTerm = new CvTerm("PSI-MS", "MS:1001091", "unspecific cleavage", null);
writeCvTerm(enzymeCvTerm);
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</EnzymeName>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</Enzyme>");
writer.newLine();
} else if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.wholeProtein) {
writer.write(getCurrentTabSpace());
writer.write("<Enzymes independent=\"false\">");
writer.newLine();
tabCounter++;
writer.write(getCurrentTabSpace());
writer.write("<Enzyme name=\"NoEnzyme\">");
writer.newLine();
tabCounter++;
writer.write(getCurrentTabSpace());
writer.write("<EnzymeName>");
writer.newLine();
tabCounter++;
CvTerm enzymeCvTerm = new CvTerm("PSI-MS", "MS:1001955", "NoEnzyme", null);
writeCvTerm(enzymeCvTerm);
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</EnzymeName>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</Enzyme>");
writer.newLine();
} else {
ArrayList<Enzyme> enzymes = digestionPreferences.getEnzymes();
writer.write(getCurrentTabSpace());
writer.write("<Enzymes independent=\"");
writer.write(Boolean.toString(enzymes.size() > 1));
writer.write("\">");
writer.newLine();
tabCounter++;
for (Enzyme enzyme : enzymes) {
String enzymeName = enzyme.getName();
writer.write(getCurrentTabSpace());
writer.write("<Enzyme missedCleavages=\"");
writer.write(Integer.toString(digestionPreferences.getnMissedCleavages(enzymeName)));
writer.write("\" semiSpecific=\"");
writer.write(Boolean.toString(digestionPreferences.getSpecificity(enzymeName) == DigestionParameters.Specificity.semiSpecific));
writer.write("\" ");
// + "cTermGain=\"OH\" " // Element formula gained at CTerm
// + "nTermGain=\"H\" " // Element formula gained at NTerm
// @TODO: add <SiteRegexp><![CDATA[(?<=[KR])(?!P)]]></SiteRegexp>?
writer.write("id=\"Enz1\" name=\"");
writer.write(enzyme.getName());
writer.write("\">");
writer.newLine();
tabCounter++;
writer.write(getCurrentTabSpace());
writer.write("<EnzymeName>");
writer.newLine();
tabCounter++;
CvTerm enzymeCvTerm = enzyme.getCvTerm();
if (enzymeCvTerm != null) {
writeCvTerm(enzymeCvTerm);
} else {
writeUserParam(enzyme.getName());
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</EnzymeName>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</Enzyme>");
writer.newLine();
tabCounter--;
}
}
writer.write(getCurrentTabSpace());
writer.write("</Enzymes>");
writer.newLine();
// fragment tolerance
writer.write(getCurrentTabSpace());
writer.write("<FragmentTolerance>");
writer.newLine();
tabCounter++;
String fragmentIonToleranceUnit;
String unitAccession;
switch(searchParameters.getFragmentAccuracyType()) {
case DA:
fragmentIonToleranceUnit = "dalton";
unitAccession = "UO:0000221";
break;
case PPM:
fragmentIonToleranceUnit = "parts per million";
unitAccession = "UO:0000169";
break;
default:
throw new UnsupportedOperationException("CV term not implemented for fragment accuracy in " + searchParameters.getFragmentAccuracyType() + ".");
}
writer.write(getCurrentTabSpace());
writer.write("<cvParam accession=\"MS:1001412\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
writer.write(fragmentIonToleranceUnit);
writer.write("\" unitAccession=\"");
writer.write(unitAccession);
writer.write("\" value=\"");
writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
writer.write("\" ");
writer.write("name=\"search tolerance plus value\" />");
writer.newLine();
writer.write(getCurrentTabSpace());
writer.write("<cvParam accession=\"MS:1001413\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
writer.write(fragmentIonToleranceUnit);
writer.write("\" unitAccession=\"");
writer.write(unitAccession);
writer.write("\" value=\"");
writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
writer.write("\" name=\"search tolerance minus value\" />");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</FragmentTolerance>");
writer.newLine();
// precursor tolerance
writer.write(getCurrentTabSpace());
writer.write("<ParentTolerance>");
writer.newLine();
tabCounter++;
String precursorIonToleranceUnit;
switch(searchParameters.getPrecursorAccuracyType()) {
case DA:
precursorIonToleranceUnit = "dalton";
break;
case PPM:
precursorIonToleranceUnit = "parts per million";
break;
default:
throw new UnsupportedOperationException("CV term not implemented for precursor accuracy in " + searchParameters.getFragmentAccuracyType() + ".");
}
writer.write(getCurrentTabSpace());
writer.write("<cvParam accession=\"MS:1001412\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
writer.write(precursorIonToleranceUnit);
writer.write("\" unitAccession=\"UO:0000169\" value=\"");
writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
writer.write("\" name=\"search tolerance plus value\" />");
writer.newLine();
writer.write(getCurrentTabSpace());
writer.write("<cvParam accession=\"MS:1001413\" cvRef=\"PSI-MS\" unitCvRef=\"UO\" unitName=\"");
writer.write(precursorIonToleranceUnit);
writer.write("\" unitAccession=\"UO:0000169\" value=\"");
writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
writer.write("\" name=\"search tolerance minus value\" />");
tabCounter--;
writer.newLine();
writer.write(getCurrentTabSpace());
writer.write("</ParentTolerance>");
writer.newLine();
// thresholds
writer.write(getCurrentTabSpace());
writer.write("<Threshold>");
writer.newLine();
tabCounter++;
boolean targetDecoy = identificationParameters.getFastaParameters().isTargetDecoy();
if (!targetDecoy) {
writeCvTerm(new CvTerm("PSI-MS", "MS:1001494", "no threshold", null));
} else {
// Initial global thresholds
IdMatchValidationParameters idMatchValidationPreferences = identificationParameters.getIdValidationParameters();
writeCvTerm(new CvTerm("PSI-MS", "MS:1001364", "peptide sequence-level global FDR", Double.toString(Util.roundDouble(idMatchValidationPreferences.getDefaultPeptideFDR(), CONFIDENCE_DECIMALS))));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(idMatchValidationPreferences.getDefaultPsmFDR(), CONFIDENCE_DECIMALS))));
ModificationLocalizationParameters ptmScoringPreferences = identificationParameters.getModificationLocalizationParameters();
if (ptmScoringPreferences.isProbabilisticScoreCalculation()) {
if (ptmScoringPreferences.getSelectedProbabilisticScore() == ModificationLocalizationScore.PhosphoRS) {
writeCvTerm(new CvTerm("PSI-MS", "MS:1002567", "phosphoRS score threshold", Double.toString(ptmScoringPreferences.getProbabilisticScoreThreshold())));
}
}
writeCvTerm(new CvTerm("PSI-MS", "MS:1002557", "D-Score threshold", Double.toString(identificationParameters.getModificationLocalizationParameters().getDScoreThreshold())));
// @TODO: add peptide and psm level annotation
// // peptideshaker maps
// PSMaps psMaps = new PSMaps();
// psMaps = (PSMaps) identification.getUrParam(psMaps);
//
// // peptide level threshold
// PeptideSpecificMap peptideSpecificMap = psMaps.getPeptideSpecificMap();
// ArrayList<String> peptideGroupsKeys = peptideSpecificMap.getKeys();
//
// for (String key : peptideGroupsKeys) { // @TODO: find a way of annotating all thresholds..?
// TargetDecoyMap targetDecoyMap = peptideSpecificMap.getTargetDecoyMap(key);
// TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
// double threshold = targetDecoyResults.getUserInput() / 100;
// int thresholdType = targetDecoyResults.getInputType();
// if (peptideGroupsKeys.size() > 1) {
// String peptideClass = PeptideSpecificMap.getKeyName(searchParameters.getModificationProfile(), key);
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002544", "PeptideShaker peptide confidence type", peptideClass)); // peptide confidence type
// }
// if (thresholdType == 0) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002463", "distinct peptide-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
// } else if (targetDecoyResults.getInputType() == 1) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1001364", "peptide sequence-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
// } else if (targetDecoyResults.getInputType() == 2) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002462", "distinct peptide-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
// }
// }
//
// // psm level threshold
// ArrayList<Integer> chargesWithFileSpecificity = new ArrayList<Integer>();
// PsmSpecificMap psmSpecificMap = psMaps.getPsmSpecificMap();
//
// for (Integer charge : psmSpecificMap.getPossibleCharges()) {
// for (String file : psmSpecificMap.getFilesAtCharge(charge)) {
// if (!psmSpecificMap.isFileGrouped(charge, file)) { // @TODO: find a way of annotating all thresholds..?
// chargesWithFileSpecificity.add(charge);
// TargetDecoyMap targetDecoyMap = psMaps.getPsmSpecificMap().getTargetDecoyMap(charge, file);
// TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
// double threshold = targetDecoyResults.getUserInput() / 100;
// int thresholdType = targetDecoyResults.getInputType();
// String psmClass = "Charge " + charge + " of file " + file; // @TODO: annotate class?
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002543", "PeptideShaker PSM confidence type", "???")); // psm confidence type
// if (thresholdType == 0) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002465", "PSM-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
// } else if (targetDecoyResults.getInputType() == 1) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
// } else if (targetDecoyResults.getInputType() == 2) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002464", "PSM-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
// }
// }
// }
// }
//
// //@TODO: set the PSM group label
// for (int charge : psmSpecificMap.getChargesFromGroupedFiles()) {
// int correctedCharge = psmSpecificMap.getCorrectedCharge(charge);
// if (correctedCharge == charge) {
// TargetDecoyMap targetDecoyMap = psMaps.getPsmSpecificMap().getTargetDecoyMap(charge, null);
// TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
// double threshold = targetDecoyResults.getUserInput() / 100;
// int thresholdType = targetDecoyResults.getInputType();
// // @TODO: check the cv terms used!!!
// if (thresholdType == 0) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002465", "PSM-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // confidence
// } else if (targetDecoyResults.getInputType() == 1) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002350", "PSM-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FDR
// } else if (targetDecoyResults.getInputType() == 2) {
// writeCvTerm(new CvTerm("PSI-MS", "MS:1002464", "PSM-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS)))); // FNR
// }
// }
// }
//
// // @TODO: re-add psm ptm thresholds
// PsmPTMMap psmPTMMap = psMaps.getPsmPTMMap();
// if (psmPTMMap != null) { // backward compatibility: information only present in versions 0.28.2 and later
// for (Double ptmMass : psmPTMMap.getModificationsScored()) {
// for (int mapKey : psmPTMMap.getKeys(ptmMass).keySet()) {
// TargetDecoyMap targetDecoyMap = psmPTMMap.getTargetDecoyMap(ptmMass, mapKey);
// TargetDecoyResults targetDecoyResults = targetDecoyMap.getTargetDecoyResults();
// double threshold = targetDecoyResults.getUserInput() / 100;
// int thresholdType = targetDecoyResults.getInputType(); // For now only FDR is implemented but others will follow after my next transatlantic flight :)
// String ptmClass = "Modification of mass " + ptmMass;
// //@TODO: find cv terms
// }
// }
// }
// @TODO: one for ptm scores, one per ptm per charge state per file
// match quality thresholds
// @TODO: match quality thresholds?? some are per file...
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</Threshold>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</SpectrumIdentificationProtocol>");
writer.newLine();
// add ProteinDetectionProtocol
writer.write(getCurrentTabSpace());
writer.write("<ProteinDetectionProtocol analysisSoftware_ref=\"ID_software\" id=\"PeptideShaker_1\">");
writer.newLine();
tabCounter++;
// br.write(getCurrentTabSpace() + "<AnalysisParams>" + lineBreak);
// tabCounter++;
// @TODO: add cv terms? (children of MS:1001302)
// tabCounter--;
// br.write(getCurrentTabSpace() + "</AnalysisParams>" + lineBreak);
// protein level threshold
writer.write(getCurrentTabSpace());
writer.write("<Threshold>");
writer.newLine();
tabCounter++;
if (!targetDecoy) {
writeCvTerm(new CvTerm("PSI-MS", "MS:1001494", "no threshold", null));
} else {
PSMaps psMaps = new PSMaps();
psMaps = (PSMaps) identification.getUrParam(psMaps);
TargetDecoyMap proteinMap = psMaps.getProteinMap();
TargetDecoyResults proteinTargetDecoyResults = proteinMap.getTargetDecoyResults();
double threshold = proteinTargetDecoyResults.getUserInput() / 100;
int thresholdType = proteinTargetDecoyResults.getInputType();
if (thresholdType == 0) {
// confidence
writeCvTerm(new CvTerm("PSI-MS", "MS:1002461", "protein group-level global confidence", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
} else if (proteinTargetDecoyResults.getInputType() == 1) {
// FDR
writeCvTerm(new CvTerm("PSI-MS", "MS:1002369", "protein group-level global FDR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
} else if (proteinTargetDecoyResults.getInputType() == 2) {
// FNR
writeCvTerm(new CvTerm("PSI-MS", "MS:1002460", "protein group-level global FNR", Double.toString(Util.roundDouble(threshold, CONFIDENCE_DECIMALS))));
}
}
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</Threshold>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</ProteinDetectionProtocol>");
writer.newLine();
tabCounter--;
writer.write(getCurrentTabSpace());
writer.write("</AnalysisProtocolCollection>");
writer.newLine();
}
Aggregations