@Override public boolean isValidated( String itemName, FilterItemComparator filterItemComparator, Object value, String matchKey, Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, ShotgunProtocol shotgunProtocol, IdentificationParameters identificationParameters, PeptideSpectrumAnnotator peptideSpectrumAnnotator) throws IOException, InterruptedException, ClassNotFoundException, SQLException, MzMLUnmarshallerException, MathException { PeptideFilterItem filterItem = PeptideFilterItem.getItem(itemName); if (filterItem == null) { throw new IllegalArgumentException( "Filter item " + itemName + "not recognized as peptide filter item."); } String input = value.toString(); switch (filterItem) { case proteinAccession: PeptideMatch peptideMatch = identification.getPeptideMatch(matchKey); return filterItemComparator.passes( input, peptideMatch .getTheoreticPeptide() .getParentProteins(identificationParameters.getSequenceMatchingPreferences())); case proteinDescription: peptideMatch = identification.getPeptideMatch(matchKey); ArrayList<String> accessions = peptideMatch .getTheoreticPeptide() .getParentProteins(identificationParameters.getSequenceMatchingPreferences()); ArrayList<String> descriptions = new ArrayList<String>(); for (String accession : accessions) { Header proteinHeader = SequenceFactory.getInstance().getHeader(accession); descriptions.add(proteinHeader.getDescription()); } return filterItemComparator.passes(input, descriptions); case sequence: return filterItemComparator.passes(input, Peptide.getSequence(matchKey)); case ptm: peptideMatch = identification.getPeptideMatch(matchKey); ArrayList<String> ptms; PSPtmScores psPtmScores = new PSPtmScores(); psPtmScores = (PSPtmScores) peptideMatch.getUrParam(psPtmScores); if (psPtmScores != null) { ptms = psPtmScores.getScoredPTMs(); } else { ptms = new ArrayList<String>(0); } return filterItemComparator.passes(input, ptms); case nPSMs: peptideMatch = identification.getPeptideMatch(matchKey); Integer nPsms = peptideMatch.getSpectrumCount(); return filterItemComparator.passes(input, nPsms.toString()); case nValidatedPSMs: nPsms = identificationFeaturesGenerator.getNValidatedSpectraForPeptide(matchKey); return filterItemComparator.passes(input, nPsms.toString()); case nConfidentPSMs: nPsms = identificationFeaturesGenerator.getNConfidentSpectraForPeptide(matchKey); return filterItemComparator.passes(input, nPsms.toString()); case confidence: PSParameter psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(matchKey, psParameter); Double confidence = psParameter.getProteinConfidence(); return filterItemComparator.passes(input, confidence.toString()); case proteinInference: psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(matchKey, psParameter); Integer pi = psParameter.getProteinInferenceClass(); return filterItemComparator.passes(input, pi.toString()); case validationStatus: psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(matchKey, psParameter); Integer validation = psParameter.getMatchValidationLevel().getIndex(); return filterItemComparator.passes(input, validation.toString()); case stared: psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(matchKey, psParameter); String starred; if (psParameter.isStarred()) { starred = FilterItemComparator.trueFalse[0]; } else { starred = FilterItemComparator.trueFalse[1]; } return filterItemComparator.passes(input, starred); default: throw new IllegalArgumentException( "Protein filter not implemented for item " + filterItem.name + "."); } }
/** * Writes the desired section. * * @param identification the identification of the project * @param identificationFeaturesGenerator the identification features generator of the project * @param identificationParameters the identification parameters * @param keys the keys of the protein matches to output * @param nSurroundingAA the number of surrounding amino acids to export * @param linePrefix the line prefix to use. * @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 IOException exception thrown whenever an error occurred while interacting with a file * @throws SQLException thrown whenever an error occurred while interacting with the database * @throws ClassNotFoundException thrown whenever an error occurred while deserializing a match * from the database * @throws InterruptedException thrown whenever a threading error occurred while interacting with * the database * @throws MzMLUnmarshallerException thrown whenever an error occurred while reading an mzML file */ public void writeSection( Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, IdentificationParameters identificationParameters, ArrayList<String> keys, int nSurroundingAA, String linePrefix, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) throws IOException, SQLException, ClassNotFoundException, InterruptedException, MzMLUnmarshallerException { if (waitingHandler != null) { waitingHandler.setSecondaryProgressCounterIndeterminate(true); } if (header) { writeHeader(); } if (keys == null) { keys = new ArrayList<String>(identification.getPeptideIdentification()); } int line = 1; if (waitingHandler != null) { waitingHandler.setWaitingText("Exporting. Please Wait..."); waitingHandler.resetSecondaryProgressCounter(); waitingHandler.setMaxSecondaryProgressCounter(keys.size()); } PSParameter psParameter = new PSParameter(); ArrayList<UrParameter> parameters = new ArrayList<UrParameter>(1); parameters.add(psParameter); PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator( keys, parameters, psmSection != null, parameters, waitingHandler); while (peptideMatchesIterator.hasNext()) { if (waitingHandler != null) { if (waitingHandler.isRunCanceled()) { return; } waitingHandler.increaseSecondaryProgressCounter(); } PeptideMatch peptideMatch = peptideMatchesIterator.next(); String peptideKey = peptideMatch.getKey(); psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter); if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) { if (decoys || !peptideMatch .getTheoreticPeptide() .isDecoy(identificationParameters.getSequenceMatchingPreferences())) { boolean first = true; if (indexes) { if (linePrefix != null) { writer.write(linePrefix); } writer.write(line + ""); first = false; } for (ExportFeature exportFeature : peptideFeatures) { if (!first) { writer.addSeparator(); } else { first = false; } PsPeptideFeature peptideFeature = (PsPeptideFeature) exportFeature; writer.write( getfeature( identification, identificationFeaturesGenerator, identificationParameters, keys, nSurroundingAA, linePrefix, peptideMatch, psParameter, peptideFeature, validatedOnly, decoys, waitingHandler)); } writer.newLine(); if (psmSection != null) { String psmSectionPrefix = ""; if (linePrefix != null) { psmSectionPrefix += linePrefix; } psmSectionPrefix += line + "."; writer.increaseDepth(); if (waitingHandler != null) { waitingHandler.setDisplayProgress(false); } psmSection.writeSection( identification, identificationFeaturesGenerator, identificationParameters, peptideMatch.getSpectrumMatchesKeys(), psmSectionPrefix, nSurroundingAA, validatedOnly, decoys, waitingHandler); if (waitingHandler != null) { waitingHandler.setDisplayProgress(true); } writer.decreseDepth(); } line++; } } } }
/** * Indicates whether the match designated by the match key validates the given item using the * given comparator and value threshold. * * @param itemName the name of the item to filter on * @param filterItemComparator the comparator to use * @param value the value to use as a threshold * @param spectrumKey the key of the match of interest * @param peptideAssumption the assumption to validate * @param identification the identification objects where to get identification matches from * @param identificationFeaturesGenerator the identification feature generator where to get * identification features * @param identificationParameters the identification parameters used * @param peptideSpectrumAnnotator the annotator to use to annotate spectra when filtering on PSM * or assumptions * @return a boolean indicating whether the match designated by the protein key validates the * given item using the given comparator and value threshold. * @throws java.io.IOException exception thrown whenever an exception occurred while reading or * writing a file * @throws java.lang.InterruptedException exception thrown whenever a threading issue occurred * while validating that the match passes the filter * @throws java.lang.ClassNotFoundException exception thrown whenever an error occurred while * deserilalizing a match * @throws java.sql.SQLException exception thrown whenever an error occurred while interacting * with a database * @throws uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException exception thrown whenever an error * occurred while reading an mzML file * @throws org.apache.commons.math.MathException exception thrown whenever an error occurred while * doing statistics on a distribution */ public boolean isValidated( String itemName, FilterItemComparator filterItemComparator, Object value, String spectrumKey, PeptideAssumption peptideAssumption, Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, IdentificationParameters identificationParameters, PeptideSpectrumAnnotator peptideSpectrumAnnotator) throws IOException, InterruptedException, ClassNotFoundException, SQLException, MzMLUnmarshallerException, MathException { AssumptionFilterItem filterItem = AssumptionFilterItem.getItem(itemName); if (filterItem == null) { throw new IllegalArgumentException( "Filter item " + itemName + "not recognized as spectrum assumption filter item."); } String input = value.toString(); switch (filterItem) { case precrusorMz: Precursor precursor = SpectrumFactory.getInstance().getPrecursor(spectrumKey); Double mz = precursor.getMz(); return filterItemComparator.passes(input, mz.toString()); case precrusorRT: precursor = SpectrumFactory.getInstance().getPrecursor(spectrumKey); Double rt = precursor.getRt(); return filterItemComparator.passes(input, rt.toString()); case precrusorCharge: Integer charge = peptideAssumption.getIdentificationCharge().value; return filterItemComparator.passes(input, charge.toString()); case precrusorMzErrorDa: precursor = SpectrumFactory.getInstance().getPrecursor(spectrumKey); SearchParameters searchParameters = identificationParameters.getSearchParameters(); Double mzError = Math.abs( peptideAssumption.getDeltaMass( precursor.getMz(), false, searchParameters.getMinIsotopicCorrection(), searchParameters.getMaxIsotopicCorrection())); return filterItemComparator.passes(input, mzError.toString()); case precrusorMzErrorPpm: searchParameters = identificationParameters.getSearchParameters(); precursor = SpectrumFactory.getInstance().getPrecursor(spectrumKey); mzError = Math.abs( peptideAssumption.getDeltaMass( precursor.getMz(), true, searchParameters.getMinIsotopicCorrection(), searchParameters.getMaxIsotopicCorrection())); return filterItemComparator.passes(input, mzError.toString()); case precrusorMzErrorStat: searchParameters = identificationParameters.getSearchParameters(); precursor = SpectrumFactory.getInstance().getPrecursor(spectrumKey); mzError = peptideAssumption.getDeltaMass( precursor.getMz(), identificationParameters.getSearchParameters().isPrecursorAccuracyTypePpm(), searchParameters.getMinIsotopicCorrection(), searchParameters.getMaxIsotopicCorrection()); NonSymmetricalNormalDistribution precDeviationDistribution = identificationFeaturesGenerator.getMassErrorDistribution( Spectrum.getSpectrumFile(spectrumKey)); Double p; if (mzError > precDeviationDistribution.getMean()) { p = precDeviationDistribution.getDescendingCumulativeProbabilityAt(mzError); } else { p = precDeviationDistribution.getCumulativeProbabilityAt(mzError); } return filterItemComparator.passes(input, p.toString()); case sequenceCoverage: SpectrumFactory spectrumFactory = SpectrumFactory.getInstance(); MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey); Peptide peptide = peptideAssumption.getPeptide(); AnnotationSettings annotationPreferences = identificationParameters.getAnnotationPreferences(); SpecificAnnotationSettings specificAnnotationPreferences = annotationPreferences.getSpecificAnnotationPreferences( spectrum.getSpectrumKey(), peptideAssumption, identificationParameters.getSequenceMatchingPreferences(), identificationParameters .getPtmScoringPreferences() .getSequenceMatchingPreferences()); HashMap<Integer, ArrayList<IonMatch>> matches = peptideSpectrumAnnotator.getCoveredAminoAcids( annotationPreferences, specificAnnotationPreferences, (MSnSpectrum) spectrum, peptide); double nCovered = 0; int nAA = peptide.getSequence().length(); for (int i = 0; i <= nAA; i++) { ArrayList<IonMatch> matchesAtAa = matches.get(i); if (matchesAtAa != null && !matchesAtAa.isEmpty()) { nCovered++; } } Double coverage = 100.0 * nCovered / nAA; return filterItemComparator.passes(input, coverage.toString()); case algorithmScore: Double score = peptideAssumption.getRawScore(); if (score == null) { score = peptideAssumption.getScore(); } return filterItemComparator.passes(input, score.toString()); case fileNames: return filterItemComparator.passes(input, Spectrum.getSpectrumFile(spectrumKey)); case confidence: PSParameter psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(spectrumKey, psParameter); Double confidence = psParameter.getProteinConfidence(); return filterItemComparator.passes(input, confidence.toString()); case validationStatus: psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(spectrumKey, psParameter); Integer validation = psParameter.getMatchValidationLevel().getIndex(); return filterItemComparator.passes(input, validation.toString()); case stared: psParameter = new PSParameter(); psParameter = (PSParameter) identification.getPeptideMatchParameter(spectrumKey, psParameter); String starred; if (psParameter.isStarred()) { starred = FilterItemComparator.trueFalse[0]; } else { starred = FilterItemComparator.trueFalse[1]; } return filterItemComparator.passes(input, starred); default: throw new IllegalArgumentException( "Protein filter not implemented for item " + filterItem.name + "."); } }