use of com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature in project peptide-shaker by compomics.
the class PsPeptideSection method getfeature.
/**
* Returns the component of the section corresponding to the given feature.
*
* @param identification the identification of the project
* @param identificationFeaturesGenerator the identification features
* generator of the project
* @param sequenceProvider a provider for the protein sequences
* @param proteinDetailsProvider a provider for protein details
* @param identificationParameters the identification parameters
* @param nSurroundingAA the number of surrounding amino acids to export
* @param linePrefix the line prefix to use.
* @param peptideMatch the peptide match
* @param peptideFeature the peptide feature to export
* @param validatedOnly whether only validated matches should be exported
* @param decoys whether decoy matches should be exported as well
* @param waitingHandler the waiting handler
*
* @return the component of the section corresponding to the given feature
*/
public static String getfeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, IdentificationParameters identificationParameters, int nSurroundingAA, String linePrefix, PeptideMatch peptideMatch, PsPeptideFeature peptideFeature, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) {
switch(peptideFeature) {
case accessions:
TreeMap<String, int[]> proteinMapping = peptideMatch.getPeptide().getProteinMapping();
return proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
case protein_description:
proteinMapping = peptideMatch.getPeptide().getProteinMapping();
return proteinMapping.navigableKeySet().stream().map(accession -> proteinDetailsProvider.getDescription(accession)).collect(Collectors.joining(","));
case protein_groups:
TreeSet<Long> proteinGroups = identification.getProteinMatches(peptideMatch.getKey());
return proteinGroups.stream().map(proteinGroupKey -> getProteinGroupText(proteinGroupKey, identification)).collect(Collectors.joining(";"));
case best_protein_group_validation:
MatchValidationLevel bestProteinValidationLevel = MatchValidationLevel.none;
proteinGroups = identification.getProteinMatches(peptideMatch.getKey());
for (long proteinGroup : proteinGroups) {
if (identification.getProteinIdentification().contains(proteinGroup)) {
PSParameter psParameter = (PSParameter) (identification.getProteinMatch(proteinGroup)).getUrParam(PSParameter.dummy);
if (psParameter.getMatchValidationLevel().getIndex() > bestProteinValidationLevel.getIndex()) {
bestProteinValidationLevel = psParameter.getMatchValidationLevel();
}
}
}
return bestProteinValidationLevel.getName();
case confidence:
PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return Double.toString(psParameter.getConfidence());
case decoy:
return PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider) ? "1" : "0";
case hidden:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return psParameter.getHidden() ? "1" : "0";
case localization_confidence:
return getPeptideModificationLocationConfidence(peptideMatch, identificationParameters.getSearchParameters().getModificationParameters());
case pi:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return psParameter.getProteinInferenceClassAsString();
case position:
proteinMapping = peptideMatch.getPeptide().getProteinMapping();
return proteinMapping.entrySet().stream().map(entry -> getPeptideLocalizationText(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
case psms:
return Integer.toString(peptideMatch.getSpectrumCount());
case variable_ptms:
return PeptideUtils.getVariableModificationsAsString(peptideMatch.getPeptide());
case fixed_ptms:
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
return PeptideUtils.getFixedModificationsAsString(peptideMatch.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
case score:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return Double.toString(psParameter.getTransformedScore());
case raw_score:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return Double.toString(psParameter.getScore());
case sequence:
return peptideMatch.getPeptide().getSequence();
case missed_cleavages:
int nMissedCleavages = peptideMatch.getPeptide().getNMissedCleavages(identificationParameters.getSearchParameters().getDigestionParameters());
return Integer.toString(nMissedCleavages);
case modified_sequence:
modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
return peptideMatch.getPeptide().getTaggedModifiedSequence(modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false, false, true, null);
case starred:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return psParameter.getStarred() ? "1" : "0";
case aaBefore:
TreeMap<String, String[]> aaMap = PeptideUtils.getAaBefore(peptideMatch.getPeptide(), nSurroundingAA, sequenceProvider);
return aaMap.values().stream().map(aas -> Arrays.stream(aas).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
case aaAfter:
aaMap = PeptideUtils.getAaAfter(peptideMatch.getPeptide(), nSurroundingAA, sequenceProvider);
return aaMap.values().stream().map(aas -> Arrays.stream(aas).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
case nValidatedProteinGroups:
return Integer.toString(identificationFeaturesGenerator.getNValidatedProteinGroups(peptideMatch.getKey(), waitingHandler));
case unique_group:
return identification.getProteinMatches(peptideMatch.getKey()).size() == 1 ? "1" : "0";
case validated:
psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
return psParameter.getMatchValidationLevel().toString();
case validated_psms:
return Integer.toString(identificationFeaturesGenerator.getNValidatedSpectraForPeptide(peptideMatch.getKey()));
case probabilistic_score:
PSModificationScores ptmScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
if (ptmScores != null) {
StringBuilder result = new StringBuilder();
TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
for (String mod : modList) {
ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getProbabilisticSites());
if (!sites.isEmpty()) {
if (result.length() > 0) {
result.append(", ");
}
result.append(mod).append(" (");
boolean firstSite = true;
for (int site : sites) {
if (firstSite) {
firstSite = false;
} else {
result.append(", ");
}
result.append(site).append(": ").append(ptmScoring.getProbabilisticScore(site));
}
result.append(")");
}
}
return result.toString();
}
return "";
case d_score:
StringBuilder result = new StringBuilder();
ptmScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
if (ptmScores != null) {
TreeSet<String> modList = new TreeSet<>(ptmScores.getScoredModifications());
for (String mod : modList) {
ModificationScoring ptmScoring = ptmScores.getModificationScoring(mod);
TreeSet<Integer> sites = new TreeSet<>(ptmScoring.getDSites());
if (!sites.isEmpty()) {
if (result.length() > 0) {
result.append(", ");
}
result.append(mod).append(" (");
boolean firstSite = true;
for (int site : sites) {
if (firstSite) {
firstSite = false;
} else {
result.append(", ");
}
result.append(site).append(": ").append(ptmScoring.getDeltaScore(site));
}
result.append(")");
}
}
return result.toString();
}
return "";
case confident_modification_sites:
String sequence = peptideMatch.getPeptide().getSequence();
return identificationFeaturesGenerator.getConfidentModificationSites(peptideMatch, sequence);
case confident_modification_sites_number:
return identificationFeaturesGenerator.getConfidentModificationSitesNumber(peptideMatch);
case ambiguous_modification_sites:
sequence = peptideMatch.getPeptide().getSequence();
return identificationFeaturesGenerator.getAmbiguousModificationSites(peptideMatch, sequence);
case ambiguous_modification_sites_number:
return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(peptideMatch);
case confident_phosphosites:
ArrayList<String> modifications = new ArrayList<>(3);
for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
if (ptm.contains("Phospho")) {
modifications.add(ptm);
}
}
return identificationFeaturesGenerator.getConfidentModificationSites(peptideMatch, peptideMatch.getPeptide().getSequence(), modifications);
case confident_phosphosites_number:
modifications = new ArrayList<>(3);
for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
if (ptm.contains("Phospho")) {
modifications.add(ptm);
}
}
return identificationFeaturesGenerator.getConfidentModificationSitesNumber(peptideMatch, modifications);
case ambiguous_phosphosites:
modifications = new ArrayList<>(3);
for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
if (ptm.contains("Phospho")) {
modifications.add(ptm);
}
}
return identificationFeaturesGenerator.getAmbiguousModificationSites(peptideMatch, peptideMatch.getPeptide().getSequence(), modifications);
case ambiguous_phosphosites_number:
modifications = new ArrayList<>(3);
for (String ptm : identificationParameters.getSearchParameters().getModificationParameters().getAllNotFixedModifications()) {
if (ptm.contains("Phospho")) {
modifications.add(ptm);
}
}
return identificationFeaturesGenerator.getAmbiguousModificationSiteNumber(peptideMatch, modifications);
default:
return "Not implemented";
}
}
use of com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature in project peptide-shaker by compomics.
the class PsPeptideSection method writeSection.
/**
* Writes the desired section.
*
* @param identification The identification of the project.
* @param identificationFeaturesGenerator The identification features
* generator of the project.
* @param sequenceProvider The sequence provider.
* @param proteinDetailsProvider The protein details provider.
* @param spectrumProvider The spectrum provider.
* @param identificationParameters The identification parameters.
* @param keys The keys of the PSM matches to output.
* @param linePrefix The line prefix.
* @param nSurroundingAA The number of surrounding amino acids to export.
* @param validatedOnly Whether only validated matches should be exported.
* @param decoys Whether decoy matches should be exported as well.
* @param waitingHandler The waiting handler.
*
* @throws java.io.IOException exception thrown if an error occurred while
* reading or writing a file
*/
public void writeSection(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, long[] keys, int nSurroundingAA, String linePrefix, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) throws IOException {
if (waitingHandler != null) {
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
if (header) {
writeHeader();
}
int lineNumber = 1;
if (waitingHandler != null) {
waitingHandler.setWaitingText("Exporting. Please Wait...");
waitingHandler.resetSecondaryProgressCounter();
waitingHandler.setMaxSecondaryProgressCounter(keys == null ? identification.getPeptideIdentification().size() : keys.length);
}
PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(keys, waitingHandler);
PeptideMatch peptideMatch;
while ((peptideMatch = peptideMatchesIterator.next()) != null) {
if (waitingHandler != null) {
if (waitingHandler.isRunCanceled()) {
return;
}
waitingHandler.increaseSecondaryProgressCounter();
}
PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {
if (decoys || !PeptideUtils.isDecoy(peptideMatch.getPeptide(), sequenceProvider)) {
boolean first = true;
if (indexes) {
if (linePrefix != null) {
writer.write(linePrefix);
}
writer.write(Integer.toString(lineNumber));
first = false;
}
for (ExportFeature exportFeature : peptideFeatures) {
if (!first) {
writer.addSeparator();
} else {
first = false;
}
PsPeptideFeature peptideFeature = (PsPeptideFeature) exportFeature;
writer.write(getfeature(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, identificationParameters, nSurroundingAA, linePrefix, peptideMatch, peptideFeature, validatedOnly, decoys, waitingHandler));
}
writer.newLine();
if (psmSection != null) {
String psmSectionPrefix = "";
if (linePrefix != null) {
psmSectionPrefix += linePrefix;
}
psmSectionPrefix += lineNumber + ".";
writer.increaseDepth();
if (waitingHandler != null) {
waitingHandler.setDisplayProgress(false);
}
psmSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, peptideMatch.getSpectrumMatchesKeys(), psmSectionPrefix, nSurroundingAA, validatedOnly, decoys, waitingHandler);
if (waitingHandler != null) {
waitingHandler.setDisplayProgress(true);
}
writer.decreseDepth();
}
lineNumber++;
}
}
}
}
Aggregations