Package com.compomics.util.experiment.massspectrometry

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


        if (assumptionFilter.getPrecursorMzError() != null
                || assumptionFilter.getMinPrecursorMzError() != null
                || assumptionFilter.getMaxPrecursorMzError() != null) {

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

            if (assumptionFilter.getPrecursorMzError() != null) {
                double error = Math.abs(peptideAssumption.getDeltaMass(precursor.getMz(), searchParameters.isPrecursorAccuracyTypePpm()));
                if (assumptionFilter.getPrecursorMzErrorComparison() == RowFilter.ComparisonType.AFTER) {
                    if (error <= assumptionFilter.getPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMzErrorComparison() == RowFilter.ComparisonType.BEFORE) {
                    if (error >= assumptionFilter.getPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMzErrorComparison() == RowFilter.ComparisonType.EQUAL) {
                    if (error != assumptionFilter.getPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMzErrorComparison() == RowFilter.ComparisonType.NOT_EQUAL) {
                    if (error == assumptionFilter.getPrecursorMzError()) {
                        return false;
                    }
                }
            }

            if (assumptionFilter.getMinPrecursorMzError() != null) {
                double error = peptideAssumption.getDeltaMass(precursor.getMz(), searchParameters.isPrecursorAccuracyTypePpm());
                if (assumptionFilter.getPrecursorMinMzErrorComparison() == RowFilter.ComparisonType.AFTER) {
                    if (error <= assumptionFilter.getMinPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMinMzErrorComparison() == RowFilter.ComparisonType.BEFORE) {
                    if (error >= assumptionFilter.getMinPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMinMzErrorComparison() == RowFilter.ComparisonType.EQUAL) {
                    if (error != assumptionFilter.getMinPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMinMzErrorComparison() == RowFilter.ComparisonType.NOT_EQUAL) {
                    if (error == assumptionFilter.getMinPrecursorMzError()) {
                        return false;
                    }
                }
            }

            if (assumptionFilter.getMaxPrecursorMzError() != null) {
                double error = peptideAssumption.getDeltaMass(precursor.getMz(), searchParameters.isPrecursorAccuracyTypePpm());
                if (assumptionFilter.getPrecursorMaxMzErrorComparison() == RowFilter.ComparisonType.AFTER) {
                    if (error <= assumptionFilter.getMaxPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMaxMzErrorComparison() == RowFilter.ComparisonType.BEFORE) {
                    if (error >= assumptionFilter.getMaxPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMaxMzErrorComparison() == RowFilter.ComparisonType.EQUAL) {
                    if (error != assumptionFilter.getMaxPrecursorMzError()) {
                        return false;
                    }
                } else if (assumptionFilter.getPrecursorMaxMzErrorComparison() == RowFilter.ComparisonType.NOT_EQUAL) {
                    if (error == assumptionFilter.getMaxPrecursorMzError()) {
                        return false;
                    }
                }
            }
        }
        if (assumptionFilter.getCharges() != null) {
            int charge = peptideAssumption.getIdentificationCharge().value;
            if (!assumptionFilter.getCharges().contains(charge)) {
                return false;
            }
        }

        if (assumptionFilter.getSequenceCoverage() != null) {

            SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
            MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
            Peptide peptide = peptideAssumption.getPeptide();
            if (peptideSpectrumAnnotator == null) {
                peptideSpectrumAnnotator = new PeptideSpectrumAnnotator();
            }
            HashMap<Integer, ArrayList<IonMatch>> ionMatches = peptideSpectrumAnnotator.getCoveredAminoAcids(annotationPreferences.getIonTypes(),
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("sequence" + SEPARATOR);
                writer.write("modif" + SEPARATOR);
                writer.write("score" + SEPARATOR);
                writer.write("main AC" + SEPARATOR);
                writer.write("description" + SEPARATOR);
                writer.write("compound" + SEPARATOR);
                writer.write("jobid" + SEPARATOR);
                writer.write("pmkey" + 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

     */
    public static void writeRecalibratedSpectra(boolean recalibratePrecursors, boolean recalibrateFragmentIons, File folder,
            Identification identification, AnnotationPreferences annotationPreferences, WaitingHandler waitingHandler)
            throws IOException, MzMLUnmarshallerException, SQLException, ClassNotFoundException, InterruptedException {

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

        int progress = 1;

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

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

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

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

            // Debug part
            if (debug) {

                RunMzDeviation runMzDeviation = spectrumRecalibrator.getRunMzDeviations(fileName);

                File debugFile = new File(folder, "debug" + getRecalibratedFileName(fileName) + "_precursors.txt");
                BufferedWriter debugWriter = new BufferedWriter(new FileWriter(debugFile));
                debugWriter.write("rt\tgrade\toffset");
                debugWriter.newLine();

                for (double key : runMzDeviation.getPrecursorRTList()) {

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

                    debugWriter.write(key + "\t");
                    debugWriter.write(runMzDeviation.getSlope(key) + "\t");
                    debugWriter.write(runMzDeviation.getOffset(key) + "\t");
                    debugWriter.newLine();
                }

                debugWriter.flush();
                debugWriter.close();

                debugFile = new File(folder, getRecalibratedFileName(fileName) + "_fragments.txt");
                debugWriter = new BufferedWriter(new FileWriter(debugFile));

                for (double rtKey : runMzDeviation.getPrecursorRTList()) {

                    debugWriter.write(rtKey + "\nm/z");

                    for (double mzKey : runMzDeviation.getFragmentMZList(rtKey)) {

                        debugWriter.write("\t" + mzKey);

                    }
                    debugWriter.newLine();
                    debugWriter.write("Error");

                    for (double mzKey : runMzDeviation.getFragmentMZList(rtKey)) {

                        debugWriter.write("\t" + runMzDeviation.getFragmentMzError(rtKey, mzKey));

                    }

                    debugWriter.newLine();
                }
                debugWriter.flush();
                debugWriter.close();
                // End of debug part
            }

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

            File file = new File(folder, getRecalibratedFileName(fileName));
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            if (waitingHandler != null) {
                waitingHandler.setWaitingText("Recalibrating Spectra. Writing Spectra. Please Wait... (" + progress + "/" + spectrumFactory.getMgfFileNames().size() + ")");
                waitingHandler.resetSecondaryProgressCounter();
                waitingHandler.setMaxSecondaryProgressCounter(spectrumFactory.getNSpectra(fileName));
            }

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

                if (debug) {
                    //System.out.println(new Date() + " recalibrating " + spectrumTitle + "\n");
                }

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.