Search in sources :

Example 1 with ModificationType

use of com.compomics.util.experiment.biology.modifications.ModificationType in project peptide-shaker by compomics.

the class Ms2PipExport method writeConfigFile.

/**
 * Writes a config file for a given model.
 *
 * @param configFile The file where to write.
 * @param model The name of the model.
 * @param searchParameters The search parameters.
 */
public static void writeConfigFile(File configFile, String model, SearchParameters searchParameters) {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    try (SimpleFileWriter writer = new SimpleFileWriter(configFile, false)) {
        writer.writeLine("model=" + model);
        writer.writeLine("out=csv");
        writer.writeLine("frag_error=" + searchParameters.getFragmentIonAccuracyInDaltons());
        for (String modName : searchParameters.getModificationParameters().getAllModifications()) {
            Modification modification = modificationFactory.getModification(modName);
            CvTerm cvTerm = modification.getUnimodCvTerm();
            if (cvTerm == null) {
                throw new IllegalArgumentException("No Unimod id found for modification " + modName + ".");
            }
            String unimodName = cvTerm.getName();
            double mass = modification.getMass();
            ModificationType modificationType = modification.getModificationType();
            switch(modificationType) {
                case modaa:
                case modcaa_peptide:
                case modcaa_protein:
                case modnaa_peptide:
                case modnaa_protein:
                    for (Character targetAa : modification.getPattern().getAminoAcidsAtTarget()) {
                        writer.writeLine(String.join("", "ptm=", unimodName, "," + Double.toString(mass), ",opt,", targetAa.toString()));
                    }
                    break;
                case modn_peptide:
                case modn_protein:
                    writer.writeLine(String.join("", "ptm=", unimodName, "," + Double.toString(mass), ",opt,N-term"));
                    break;
                case modc_peptide:
                case modc_protein:
                    writer.writeLine(String.join("", "ptm=", unimodName, "," + Double.toString(mass), ",opt,C-term"));
                    break;
                default:
                    throw new UnsupportedOperationException("Modification type " + modificationType + " not supported.");
            }
        }
    }
}
Also used : ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) Modification(com.compomics.util.experiment.biology.modifications.Modification) CvTerm(com.compomics.util.pride.CvTerm) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter)

Example 2 with ModificationType

use of com.compomics.util.experiment.biology.modifications.ModificationType in project peptide-shaker by compomics.

the class PepXmlExport method getModLine.

/**
 * Gets the line for a modification.
 *
 * @param modification the modification
 * @param variable a boolean indicating whether the modification is variable
 *
 * @return the line for a modification
 */
private String getModLine(Modification modification, boolean variable) {
    StringBuilder modificationLine = new StringBuilder();
    ModificationType modificationType = modification.getModificationType();
    if (modificationType == ModificationType.modaa || modificationType == ModificationType.modnaa_peptide || modificationType == ModificationType.modnaa_protein || modificationType == ModificationType.modcaa_peptide || modificationType == ModificationType.modcaa_protein) {
        modificationLine.append("<aminoacid_modification ");
        AminoAcidPattern aminoAcidPattern = modification.getPattern();
        modificationLine.append("aminoacid=\"").append(aminoAcidPattern.toString()).append("\" ");
        modificationLine.append("massdiff=\"").append(modification.getMass()).append("\" ");
        if (aminoAcidPattern.getAminoAcidsAtTarget().size() == 1) {
            Character aa = aminoAcidPattern.getAminoAcidsAtTarget().get(0);
            AminoAcid aminoAcid = AminoAcid.getAminoAcid(aa);
            if (!aminoAcid.iscombination()) {
                Double mass = aminoAcid.getMonoisotopicMass() + modification.getMass();
                modificationLine.append("mass=\"").append(mass).append("\" ");
            }
        }
        if (modificationType.isCTerm()) {
            modificationLine.append("peptide_terminus=\"c\" ");
        }
        if (modificationType.isNTerm()) {
            modificationLine.append("peptide_terminus=\"n\" ");
        }
    } else {
        modificationLine.append("<terminal_modification ");
        if (modificationType.isCTerm()) {
            modificationLine.append("terminus=\"c\" ");
        }
        if (modificationType.isNTerm()) {
            modificationLine.append("terminus=\"n\" ");
        }
        modificationLine.append("massdiff=\"").append(modification.getMass()).append("\" ");
        if (modificationType == ModificationType.modc_protein) {
            modificationLine.append("protein_terminus=\"c\" ");
        }
        if (modificationType == ModificationType.modn_protein) {
            modificationLine.append("protein_terminus=\"n\" ");
        }
        if (modificationType.isNTerm()) {
            double mass = Atom.H.getMonoisotopicMass() + modification.getMass();
            modificationLine.append("mass=\"").append(mass).append("\" ");
        }
        if (modificationType.isCTerm()) {
            double mass = Atom.H.getMonoisotopicMass() + Atom.O.getMonoisotopicMass() + modification.getMass();
            modificationLine.append("mass=\"").append(mass).append("\" ");
        }
    }
    if (variable) {
        modificationLine.append("variable=\"Y\" ");
    } else {
        modificationLine.append("variable=\"N\" ");
    }
    modificationLine.append("symbol=\"").append(modification.getName()).append("\" ");
    CvTerm cvTerm = modification.getUnimodCvTerm();
    if (cvTerm != null) {
        modificationLine.append("description=\"").append(cvTerm.getAccession()).append("\"");
    } else {
        // try PSI-MOD instead
        cvTerm = modification.getPsiModCvTerm();
        if (cvTerm != null) {
            modificationLine.append("description=\"").append(cvTerm.getAccession()).append("\"");
        }
    }
    modificationLine.append("/>");
    return modificationLine.toString();
}
Also used : AminoAcidPattern(com.compomics.util.experiment.biology.aminoacids.sequence.AminoAcidPattern) CvTerm(com.compomics.util.pride.CvTerm) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) AminoAcid(com.compomics.util.experiment.biology.aminoacids.AminoAcid)

Example 3 with ModificationType

use of com.compomics.util.experiment.biology.modifications.ModificationType 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();
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) CvTerm(com.compomics.util.pride.CvTerm) IdMatchValidationParameters(com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters) Enzyme(com.compomics.util.experiment.biology.enzymes.Enzyme) ArrayList(java.util.ArrayList) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) DigestionParameters(com.compomics.util.parameters.identification.search.DigestionParameters) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) TargetDecoyResults(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults)

Example 4 with ModificationType

use of com.compomics.util.experiment.biology.modifications.ModificationType in project peptide-shaker by compomics.

the class PepXmlExport method writeSearchHit.

/**
 * Writes a search hit section.
 *
 * @param sw the XML file writer
 * @param identification the identification object containing the
 * identification results
 * @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 writeSearchHit(SimpleXmlWriter sw, IdentificationParameters identificationParameters, PeptideAssumption peptideAssumption, double precursorMz, PSParameter psParameter, boolean mainHit) throws IOException {
    Peptide peptide = peptideAssumption.getPeptide();
    StringBuilder searchHitStart = new StringBuilder();
    searchHitStart.append("<search_hit hit_rank=\"").append(peptideAssumption.getRank()).append("\" ").append("peptide=\"").append(peptide.getSequence()).append("\" ");
    TreeMap<String, int[]> proteinMapping = peptide.getProteinMapping();
    String proteins = proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
    searchHitStart.append("protein=\"").append(proteins).append("\" ").append("num_tot_proteins=\"").append(proteinMapping.size()).append("\" ").append("calc_neutral_pep_mass=\"").append(peptideAssumption.getTheoreticMass()).append("\" ").append("massdiff=\"").append(peptideAssumption.getDeltaMz(precursorMz, false, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection())).append("\">");
    sw.writeLine(searchHitStart.toString());
    sw.increaseIndent();
    if (proteinMapping.size() > 1) {
        for (String accession : proteinMapping.navigableKeySet()) {
            StringBuilder proteinLine = new StringBuilder();
            proteinLine.append("<alternative_protein protein=\"").append(accession).append("\"/>");
            sw.writeLine(proteinLine.toString());
        }
    }
    ModificationMatch[] modificationMatches = peptide.getVariableModifications();
    if (modificationMatches.length > 0) {
        HashMap<Integer, Double> modifiedAminoAcids = new HashMap<>(modificationMatches.length);
        Double nTermMass = null;
        Double cTermMass = null;
        for (ModificationMatch modificationMatch : modificationMatches) {
            Modification modification = modificationFactory.getModification(modificationMatch.getModification());
            ModificationType modificationType = modification.getModificationType();
            if (modificationType == ModificationType.modn_protein || modificationType == ModificationType.modn_peptide) {
                if (nTermMass == null) {
                    nTermMass = Atom.H.getMonoisotopicMass();
                }
                nTermMass += modification.getMass();
            } else if (modificationType == ModificationType.modc_protein || modificationType == ModificationType.modc_peptide) {
                if (cTermMass == null) {
                    cTermMass = Atom.H.getMonoisotopicMass() + Atom.O.getMonoisotopicMass();
                }
                cTermMass += modification.getMass();
            } else {
                int site = modificationMatch.getSite();
                Double modMass = modifiedAminoAcids.get(site);
                if (modMass == null) {
                    modMass = 0.0;
                }
                modMass += modification.getMass();
                modifiedAminoAcids.put(site, modMass);
            }
        }
        StringBuilder modificationStart = new StringBuilder();
        modificationStart.append("<modification_info");
        if (nTermMass != null) {
            modificationStart.append(" mod_nterm_mass=\"").append(nTermMass).append("\"");
        }
        if (cTermMass != null) {
            modificationStart.append(" mod_cterm_mass=\"").append(nTermMass).append("\"");
        }
        modificationStart.append(">");
        sw.writeLine(modificationStart.toString());
        if (!modifiedAminoAcids.isEmpty()) {
            sw.increaseIndent();
            for (Integer site : modifiedAminoAcids.keySet()) {
                double modifiedMass = modifiedAminoAcids.get(site);
                StringBuilder modificationSite = new StringBuilder();
                modificationSite.append("<mod_aminoacid_mass position=\"").append(site).append("\" mass=\"").append(modifiedMass).append("\"/>");
                sw.writeLine(modificationSite.toString());
            }
            sw.decreaseIndent();
        }
        sw.writeLine("</modification_info>");
    }
    if (mainHit) {
        StringBuilder searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"PSM raw score\" value=\"").append(psParameter.getTransformedScore()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"PSM score\" value=\"").append(psParameter.getTransformedScore()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"PSM PEP\" value=\"").append(psParameter.getProbability()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"PSM confidence\" value=\"").append(psParameter.getConfidence()).append("\"/>");
        sw.writeLine(searchScore.toString());
    } else {
        StringBuilder searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"Identification algorithm raw score\" value=\"").append(peptideAssumption.getRawScore()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"Identification algorithm score\" value=\"").append(peptideAssumption.getScore()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"Identification algorithm PEP\" value=\"").append(psParameter.getProbability()).append("\"/>");
        sw.writeLine(searchScore.toString());
        searchScore = new StringBuilder();
        searchScore.append("<search_score name=\"Identification algorithm confidence\" value=\"").append(psParameter.getConfidence()).append("\"/>");
        sw.writeLine(searchScore.toString());
    }
    sw.writeLine("<analysis_result>");
    int advocateId = peptideAssumption.getAdvocate();
    Advocate advocate = Advocate.getAdvocate(advocateId);
    StringBuilder parameterLine = new StringBuilder();
    parameterLine.append("<parameter name=\"algorithm\" value=\"").append(advocate.getName()).append("\"/>");
    sw.writeLineIncreasedIndent(parameterLine.toString());
    for (ModificationMatch modificationMatch : modificationMatches) {
        parameterLine = new StringBuilder();
        parameterLine.append("<parameter name=\"ptm\" value=\"").append(modificationMatch.getModification()).append(" (").append(modificationMatch.getSite()).append(")").append("\"/>");
        sw.writeLine(parameterLine.toString());
    }
    parameterLine = new StringBuilder();
    parameterLine.append("<parameter name=\"charge\" value=\"").append(Integer.toString(peptideAssumption.getIdentificationCharge())).append("\"/>");
    sw.writeLine(parameterLine.toString());
    parameterLine = new StringBuilder();
    parameterLine.append("<parameter name=\"isotope\" value=\"").append(peptideAssumption.getIsotopeNumber(precursorMz, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection())).append("\"/>");
    sw.writeLine(parameterLine.toString());
    sw.writeLineDecreasedIndent("</analysis_result>");
    sw.writeLineDecreasedIndent("</search_hit>");
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) HashMap(java.util.HashMap) Advocate(com.compomics.util.experiment.identification.Advocate) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) Peptide(com.compomics.util.experiment.biology.proteins.Peptide)

Example 5 with ModificationType

use of com.compomics.util.experiment.biology.modifications.ModificationType in project peptide-shaker by compomics.

the class PeptideChecker method checkPeptide.

/**
 * Corrects the protein mapping based on the confident or inferred variable
 * modifications when located at the protein termini or targeting amino acid
 * patterns.
 *
 * @param peptide the peptide to check
 * @param sequenceProvider a protein sequence provider
 * @param modificationMatchingParameters the modification sequence matching
 * parameters
 */
public static void checkPeptide(Peptide peptide, SequenceProvider sequenceProvider, SequenceMatchingParameters modificationMatchingParameters) {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    ModificationMatch[] variableModifications = peptide.getVariableModifications();
    TreeMap<String, int[]> proteinMapping = peptide.getProteinMapping();
    for (ModificationMatch modificationMatch : variableModifications) {
        if (modificationMatch.getConfident() || modificationMatch.getInferred()) {
            Modification modification = modificationFactory.getModification(modificationMatch.getModification());
            ModificationType modificationType = modification.getModificationType();
            if (modificationType == ModificationType.modn_protein || modificationType == ModificationType.modnaa_protein) {
                proteinMapping = getNTermMapping(proteinMapping);
            } else if (modificationType == ModificationType.modc_protein || modificationType == ModificationType.modcaa_protein) {
                proteinMapping = getCTermMapping(proteinMapping, peptide.getSequence().length(), sequenceProvider);
            }
            if (modification.getPattern().length() > 0) {
                proteinMapping = getPatternMapping(proteinMapping, modificationMatch, modification, peptide.getSequence().length(), sequenceProvider, modificationMatchingParameters);
            }
        }
    }
    peptide.setProteinMapping(proteinMapping);
}
Also used : ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType)

Aggregations

ModificationType (com.compomics.util.experiment.biology.modifications.ModificationType)5 Modification (com.compomics.util.experiment.biology.modifications.Modification)4 CvTerm (com.compomics.util.pride.CvTerm)3 ModificationFactory (com.compomics.util.experiment.biology.modifications.ModificationFactory)2 ModificationMatch (com.compomics.util.experiment.identification.matches.ModificationMatch)2 AminoAcid (com.compomics.util.experiment.biology.aminoacids.AminoAcid)1 AminoAcidPattern (com.compomics.util.experiment.biology.aminoacids.sequence.AminoAcidPattern)1 Enzyme (com.compomics.util.experiment.biology.enzymes.Enzyme)1 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)1 Advocate (com.compomics.util.experiment.identification.Advocate)1 SimpleFileWriter (com.compomics.util.io.flat.SimpleFileWriter)1 IdMatchValidationParameters (com.compomics.util.parameters.identification.advanced.IdMatchValidationParameters)1 ModificationLocalizationParameters (com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters)1 DigestionParameters (com.compomics.util.parameters.identification.search.DigestionParameters)1 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)1 PSMaps (eu.isas.peptideshaker.scoring.PSMaps)1 TargetDecoyMap (eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap)1 TargetDecoyResults (eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyResults)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1