Package com.compomics.util.experiment.massspectrometry

Examples of com.compomics.util.experiment.massspectrometry.SpectrumFactory


        if (selectedFolder != null) {

            peptideShakerGUI.setLastSelectedFolder(selectedFolder.getAbsolutePath());

            SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
            for (String fileName : spectrumFactory.getMgfFileNames()) {
                String newName = RecalibrationExporter.getRecalibratedFileName(fileName);
                File testFile = new File(selectedFolder, newName);
                if (testFile.exists()) {
                    int outcome = JOptionPane.showConfirmDialog(this,
                            "File(s) already exist, shall it be overwritten?", "Selected File(s) Already Exists",
View Full Code Here


     *
     * @return a boolean indicating whether the loading was successful
     */
    public boolean loadSpectrumFiles(File folder, WaitingHandler waitingHandler) throws FileNotFoundException, IOException {

        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();

        for (String spectrumFileName : identification.getSpectrumFiles()) {
            File providedSpectrumLocation = projectDetails.getSpectrumFile(spectrumFileName);
            File projectFolder = cpsFile.getParentFile();
            File dataFolder = new File(projectFolder, "data");
            // try to locate the spectrum file
            if (providedSpectrumLocation == null || !providedSpectrumLocation.exists()) {
                File fileInProjectFolder = new File(projectFolder, spectrumFileName);
                File fileInDataFolder = new File(dataFolder, spectrumFileName);
                File fileInGivenFolder = new File(folder, spectrumFileName);
                if (fileInProjectFolder.exists()) {
                    projectDetails.addSpectrumFile(fileInProjectFolder);
                } else if (fileInDataFolder.exists()) {
                    projectDetails.addSpectrumFile(fileInDataFolder);
                } else if (fileInGivenFolder.exists()) {
                    projectDetails.addSpectrumFile(fileInDataFolder);
                } else {
                    return false;
                }
            }
            File mgfFile = projectDetails.getSpectrumFile(spectrumFileName);
            spectrumFactory.addSpectra(mgfFile, waitingHandler);
        }

        return true;
    }
View Full Code Here

     *
     * @return a boolean indicating whether the loading was successful
     */
    public boolean loadSpectrumFile(String spectrumFileName, WaitingHandler waitingHandler) throws FileNotFoundException, IOException {

        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();

        File providedSpectrumLocation = projectDetails.getSpectrumFile(spectrumFileName);
        File projectFolder = cpsFile.getParentFile();
        File dataFolder = new File(projectFolder, "data");

        // try to locate the spectrum file
        if (providedSpectrumLocation == null || !providedSpectrumLocation.exists()) {
            File fileInProjectFolder = new File(projectFolder, spectrumFileName);
            File fileInDataFolder = new File(dataFolder, spectrumFileName);

            if (fileInProjectFolder.exists()) {
                projectDetails.addSpectrumFile(fileInProjectFolder);
            } else if (fileInDataFolder.exists()) {
                projectDetails.addSpectrumFile(fileInDataFolder);
            } else {
                return false;
            }
        }

        File mgfFile = projectDetails.getSpectrumFile(spectrumFileName);
        spectrumFactory.addSpectra(mgfFile, waitingHandler);

        return true;
    }
View Full Code Here

     */
    private void insertAreaCharts() {

        AnnotationPreferences annotationPreferences = peptideShakerGUI.getAnnotationPreferences();
        PtmtableContent tempContent, tableContent = new PtmtableContent();
        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();

        for (String spectrumKey : spectrumKeys) {
            try {
                MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
                SpectrumMatch spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumKey);
                tempContent = PtmtableContent.getPTMTableContent(peptide, ptm, nPTM, spectrum, annotationPreferences.getIonTypes(),
                        annotationPreferences.getNeutralLosses(), annotationPreferences.getValidatedCharges(),
                        spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value,
                        annotationPreferences.getFragmentIonAccuracy(), spectrum.getIntensityLimit(annotationPreferences.getAnnotationIntensityLimit()));
View Full Code Here

        AnnotationPreferences annotationPreferences = peptideShakerGUI.getAnnotationPreferences();
        PtmtableContent tempContent, tableContent = new PtmtableContent();
        MSnSpectrum spectrum;
        SpectrumMatch spectrumMatch;
        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
        PTMFactory ptmFactory = PTMFactory.getInstance();
        String ptmName = ptm.getName(), shortName = ptmFactory.getShortName(ptmName);

        for (String spectrumKey : spectrumKeys) {
            try {
                spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
                spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumKey);
                tempContent = PtmtableContent.getPTMTableContent(peptide, ptm, nPTM, spectrum, annotationPreferences.getIonTypes(),
                        annotationPreferences.getNeutralLosses(), annotationPreferences.getValidatedCharges(),
                        spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value,
                        annotationPreferences.getFragmentIonAccuracy(), spectrum.getIntensityLimit(annotationPreferences.getAnnotationIntensityLimit()));
View Full Code Here

        }

        if (psmFilter.getPrecursorMz() != null
                || psmFilter.getPrecursorRT() != null) {

            SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
            Precursor precursor = spectrumFactory.getPrecursor(spectrumKey);

            if (psmFilter.getPrecursorMz() != null) {
                if (psmFilter.getPrecursorMzComparison() == RowFilter.ComparisonType.AFTER) {
                    if (precursor.getMz() <= psmFilter.getPrecursorMz()) {
                        return false;
View Full Code Here

            if (targetedPTMs == null || targetedPTMs.isEmpty()) {
                throw new IllegalArgumentException("No modification provided for the Progenesis PTM export.");
            }
        }

        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
        PSParameter psParameter = new PSParameter();

        if (exportType == ExportType.validated_psms_peptides || exportType == ExportType.validated_psms_peptides_proteins || exportType == ExportType.confident_ptms) {
            if (waitingHandler != null) {
                waitingHandler.setWaitingText("Progenesis Export - Loading Peptides. Please Wait...");
            }
            identification.loadPeptideMatchParameters(psParameter, waitingHandler);
        }
        if (exportType == ExportType.validated_psms_peptides_proteins || exportType == ExportType.confident_ptms) {
            if (waitingHandler != null) {
                waitingHandler.setWaitingText("Progenesis Export - Loading Proteins. Please Wait...");
            }
            identification.loadProteinMatchParameters(psParameter, waitingHandler);
        }

        if (waitingHandler != null && waitingHandler.isRunCanceled()) {
            return;
        }

        FileWriter f = new FileWriter(destinationFile);
        try {
            BufferedWriter writer = new BufferedWriter(f);

            try {
                writer.write("Q1" + SEPARATOR);
                writer.write("Q3" + SEPARATOR);
                writer.write("RT_detected" + SEPARATOR);
                writer.write("isotype" + SEPARATOR);
                writer.write("uniprot_id" + SEPARATOR);
                writer.write("relative_intensity" + SEPARATOR);
                writer.write("stripped_sequence" + SEPARATOR);
                writer.write("modification_sequence" + SEPARATOR);
                writer.write("prec_z" + SEPARATOR);
                writer.write("protein_name" + SEPARATOR);
                writer.write("frg_type" + SEPARATOR);
                writer.write("frg_z" + SEPARATOR);
                writer.write("frg_nr" + SEPARATOR);
                writer.newLine();

                for (int i = 0; i < spectrumFactory.getMgfFileNames().size(); i++) {

                    String mgfFile = spectrumFactory.getMgfFileNames().get(i);

                    if (waitingHandler != null) {
                        waitingHandler.setWaitingText("Exporting Spectra - Loading PSMs. Please Wait... (" + (i + 1) + "/" + spectrumFactory.getMgfFileNames().size() + ")");
                    }
                    identification.loadSpectrumMatches(mgfFile, waitingHandler);
                    if (waitingHandler != null) {
                        waitingHandler.setWaitingText("Exporting Spectra - Loading PSM Parameters. Please Wait... (" + (i + 1) + "/" + spectrumFactory.getMgfFileNames().size() + ")");
                    }
                    identification.loadSpectrumMatchParameters(mgfFile, psParameter, waitingHandler);
                    if (waitingHandler != null) {
                        waitingHandler.setWaitingText("Exporting Spectra - Writing File. Please Wait...");
                        // reset the progress bar
                        waitingHandler.resetSecondaryProgressCounter();
                        waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
                    }

                    for (String spectrumTitle : spectrumFactory.getSpectrumTitles(mgfFile)) {

                        String spectrumKey = Spectrum.getSpectrumKey(mgfFile, spectrumTitle);

                        if (identification.matchExists(spectrumKey)) {
                            psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
View Full Code Here

        FileWriter f = new FileWriter(destinationFile);

        try {
            BufferedWriter b = new BufferedWriter(f);
            try {
                SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
                ArrayList<String> validatedProteins = identificationFeaturesGenerator.getValidatedProteins(waitingHandler, filterPreferences);
                PSParameter psParameter = new PSParameter();

                if (waitingHandler != null) {
                    waitingHandler.setWaitingText("Inclusion List - Loading Proteins. Please Wait...");
                }
                identification.loadProteinMatches(validatedProteins, waitingHandler);

                if (waitingHandler != null) {
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                    waitingHandler.setWaitingText("Inclusion List - Loading Protein Details. Please Wait...");
                }
                identification.loadProteinMatchParameters(validatedProteins, psParameter, waitingHandler);

                if (waitingHandler != null) {
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                    waitingHandler.setWaitingText("Inclusion List - Writing File. Please Wait...");
                    waitingHandler.resetSecondaryProgressCounter();
                    waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size());
                }

                for (String proteinMatchKey : identification.getProteinIdentification()) {

                    psParameter = (PSParameter) identification.getProteinMatchParameter(proteinMatchKey, psParameter);

                    if (!proteinFilters.contains(psParameter.getProteinInferenceClass())) {

                        ProteinMatch proteinMatch = identification.getProteinMatch(proteinMatchKey);
                        identification.loadPeptideMatchParameters(proteinMatch.getPeptideMatchesKeys(), psParameter, null);
                        ArrayList<String> peptideMatches = new ArrayList<String>();

                        for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
                            psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
                            if (psParameter.getMatchValidationLevel().isValidated()) {
                                boolean passesFilter = true;
                                for (PeptideFilterType filterType : peptideFilters) {
                                    String sequence = Peptide.getSequence(peptideKey);
                                    if (filterType == PeptideFilterType.degenerated) {
                                        if (psParameter.getProteinInferenceClass() != PSParameter.NOT_GROUP) {
                                            passesFilter = false;
                                            break;
                                        }
                                    } else if (filterType == PeptideFilterType.miscleaved) {
                                        if (searchParameters.getEnzyme().getNmissedCleavages(sequence) > 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()) {
                            identification.loadPeptideMatches(peptideMatches, null);
                            for (String peptideKey : peptideMatches) {
                                PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
                                ArrayList<String> validatedPsms = new ArrayList<String>();
                                identification.loadSpectrumMatchParameters(peptideMatch.getSpectrumMatches(), psParameter, null);
                                for (String spectrumKey : peptideMatch.getSpectrumMatches()) {
                                    psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                                    if (psParameter.getMatchValidationLevel().isValidated()) {
                                        validatedPsms.add(spectrumKey);
                                    }
                                }
                                if (!validatedPsms.isEmpty()) {
                                    identification.loadSpectrumMatches(validatedPsms, null);
                                    ArrayList<Double> retentionTimes = new ArrayList<Double>();
                                    for (String spectrumKey : validatedPsms) {
                                        retentionTimes.add(spectrumFactory.getPrecursor(spectrumKey).getRt());
                                    }
                                    for (String spectrumKey : validatedPsms) {
                                        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                                        if (spectrumMatch.getBestPeptideAssumption() != null) {
                                            String line = getInclusionListLine(spectrumMatch, retentionTimes, rtWindow, exportFormat, searchParameters);
View Full Code Here

    private static String getInclusionListLine(SpectrumMatch spectrumMatch, ArrayList<Double> retentionTimes, double rtWindow,
            ExportFormat exportFormat, SearchParameters searchParameters) throws IOException, MzMLUnmarshallerException {

        String spectrumKey = spectrumMatch.getKey();

        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
        Precursor precursor = spectrumFactory.getPrecursor(spectrumKey);

        switch (exportFormat) {
            case Thermo:
                int index = (int) (0.25 * retentionTimes.size());
                double rtMin = retentionTimes.get(index) / 60;
View Full Code Here

     * @throws InterruptedException
     */
    public static void exportPepnovoTrainingFiles(File destinationFolder, Identification identification, AnnotationPreferences annotationPreferences, Double fdr, Double fnr,
            boolean recalibrate, WaitingHandler waitingHandler) throws IOException, MzMLUnmarshallerException, SQLException, ClassNotFoundException, InterruptedException {

        SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
        SpectrumRecalibrator spectrumRecalibrator = new SpectrumRecalibrator();

        PSMaps psMaps = new PSMaps();
        psMaps = (PSMaps) identification.getUrParam(psMaps);
        PsmSpecificMap psmTargetDecoyMap = psMaps.getPsmSpecificMap();

        int progress = 1;

        for (String fileName : spectrumFactory.getMgfFileNames()) {

            if (recalibrate) {
                if (waitingHandler != null) {
                    if (waitingHandler.isRunCanceled()) {
                        break;
                    }

                    waitingHandler.setWaitingText("Recalibrating Spectra. Please Wait... (" + progress + "/" + spectrumFactory.getMgfFileNames().size() + ")");
                    waitingHandler.setSecondaryProgressCounter(0);
                    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
                    waitingHandler.setMaxSecondaryProgressCounter(2 * spectrumFactory.getNSpectra(fileName));
                }

                spectrumRecalibrator.estimateErrors(fileName, identification, annotationPreferences, waitingHandler);
            }

            PSParameter psParameter = new PSParameter();
            identification.loadSpectrumMatchParameters(fileName, psParameter, waitingHandler);

            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.setWaitingText("Selecting Good PSMs. Please Wait... (" + progress + "/" + spectrumFactory.getMgfFileNames().size() + ")");
                // reset the progress bar
                waitingHandler.resetSecondaryProgressCounter();
                waitingHandler.setMaxSecondaryProgressCounter(spectrumFactory.getSpectrumTitles(fileName).size());
            }

            ArrayList<String> keys = new ArrayList<String>();
            for (String spectrumTitle : spectrumFactory.getSpectrumTitles(fileName)) {

                String spectrumKey = Spectrum.getSpectrumKey(fileName, spectrumTitle);
                if (identification.matchExists(spectrumKey)) {
                    psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                    Integer charge = new Integer(psParameter.getSpecificMapKey());
                    String spectrumFile = Spectrum.getSpectrumFile(spectrumKey);
                    Double fdrThreshold = getFdrThreshold(psmTargetDecoyMap, charge, spectrumTitle, fdr);
                    double confidenceLevel = getHighConfidenceThreshold(psmTargetDecoyMap, charge, spectrumFile, fdrThreshold);
                    if (psParameter.getPsmConfidence() >= confidenceLevel) {
                        keys.add(spectrumKey);
                    }
                }
                if (waitingHandler != null) {
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                    waitingHandler.increaseSecondaryProgressCounter();
                }
            }
            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.setWaitingText("Loading PSMs. Please Wait... (" + progress + "/"
                        + spectrumFactory.getMgfFileNames().size() + ")");
            }
            identification.loadSpectrumMatches(keys, waitingHandler);

            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.setWaitingText("Exporting PepNovo Training Files. Please Wait... (" + progress + "/" + spectrumFactory.getMgfFileNames().size() + ").");
                // reset the progress bar
                waitingHandler.resetSecondaryProgressCounter();
                waitingHandler.setMaxSecondaryProgressCounter(spectrumFactory.getSpectrumTitles(fileName).size());
            }

            File file = new File(destinationFolder, getGoodSetFileName(fileName));
            BufferedWriter writerGood = new BufferedWriter(new FileWriter(file));
            file = new File(destinationFolder, getBadSetFileName(fileName));
            BufferedWriter writerBad = new BufferedWriter(new FileWriter(file));
            BufferedWriter writerRecalibration = null;
            if (recalibrate) {
                file = new File(destinationFolder, getRecalibratedFileName(fileName));
                writerRecalibration = new BufferedWriter(new FileWriter(file));
            }

            try {
                for (String spectrumTitle : spectrumFactory.getSpectrumTitles(fileName)) {

                    String spectrumKey = Spectrum.getSpectrumKey(fileName, spectrumTitle);

                    MSnSpectrum spectrum = null;
                    if (recalibrate) {
                        spectrum = spectrumRecalibrator.recalibrateSpectrum(fileName, spectrumTitle, true, true);
                        spectrum.writeMgf(writerRecalibration);
                    }
                    if (identification.matchExists(spectrumKey)) {
                        psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                        Integer charge = new Integer(psParameter.getSpecificMapKey());
                        String spectrumFile = Spectrum.getSpectrumFile(spectrumKey);
                        Double fdrThreshold = getFdrThreshold(psmTargetDecoyMap, charge, spectrumTitle, fdr);
                        double confidenceLevel = getHighConfidenceThreshold(psmTargetDecoyMap, charge, spectrumFile, fdrThreshold);
                        if (psParameter.getPsmConfidence() >= confidenceLevel) {
                            if (spectrum == null) {
                                spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
                            }
                            SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                            if (spectrumMatch.getBestPeptideAssumption() != null) {
                                String sequence = spectrumMatch.getBestPeptideAssumption().getPeptide().getSequence();
                                HashMap<String, String> tags = new HashMap<String, String>();
                                tags.put("SEQ", sequence);
                                spectrum.writeMgf(writerGood, tags);
                            }
                        }
                        confidenceLevel = getLowConfidenceThreshold(psmTargetDecoyMap, charge, spectrumFile, fnr, fdrThreshold);
                        if (psParameter.getPsmConfidence() <= confidenceLevel) {
                            if (spectrum == null) {
                                spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
                            }
                            spectrum.writeMgf(writerBad);
                        }
                    }

View Full Code Here

TOP

Related Classes of com.compomics.util.experiment.massspectrometry.SpectrumFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.