// This function looks for spectra in the specified range. The original
        // version of this function returned IEnumerable<TandemMassSpectrum>,
        // and this is still conceptually what we are trying to do. However,
        // the above appears to generate a lot of garbage, because this
        // function occurs inside an inner loop of DatabaseSearcher.DoSearch.
        //
        // Thus, instead, we require the caller to pass in a buffer of indices,
        // out_indices, which we clear and re-fill with an array of spectrum
        // indices.
        //
        // If precursorMonoisotopicPeakCorrection is false, then you should
        // pass
        //   minimumMonoisotopicPeakOffset = 0 and
        //   maximumMonoisotopicPeakOffset = 0.
        public void GetTandemMassSpectraInMassRange(double precursorMass, MassTolerance precursorMassTolerance, 
            int minimumMonoisotopicPeakOffset, int maximumMonoisotopicPeakOffset,
            List<int> out_indices)
        {
            out_indices.Clear();
            for(int i = minimumMonoisotopicPeakOffset; i <= maximumMonoisotopicPeakOffset; i++)
            {
                double precursor_mass = precursorMass + i * Constants.C12_C13_MASS_DIFFERENCE;

                double minimum_precursor_mass = precursor_mass - precursorMassTolerance;
                double maximum_precursor_mass = precursor_mass + precursorMassTolerance;

                int index = BinarySearch(NextHigherDouble(maximum_precursor_mass));
                if(index == Count)
                {
                    index--;
                }
                while(index >= 0 && this[index].PrecursorMass >= minimum_precursor_mass)
                {
                    if(this[index].PrecursorMass <= maximum_precursor_mass)
                    {
                        out_indices.Add(index);
                    }
                    index--;
                }
            }
        }
示例#2
0
 public void Load(string rawFilepath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
                  double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
                  bool assignChargeStates, bool deisotope, MassTolerance isotopicMZTolerance, int maximumThreads)
 {
     Load(rawFilepath, minimumAssumedPrecursorChargeState, maximumAssumedPrecursorChargeState,
          absoluteThreshold, relativeThresholdPercent, maximumNumberOfPeaks,
          assignChargeStates, maximumThreads);
 }
 public void Load(string rawFilepath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
     double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
     bool assignChargeStates, bool deisotope, MassTolerance isotopicMZTolerance, int maximumThreads)
 {
     Load(rawFilepath, minimumAssumedPrecursorChargeState, maximumAssumedPrecursorChargeState,
         absoluteThreshold, relativeThresholdPercent, maximumNumberOfPeaks,
         assignChargeStates, maximumThreads);
 }
示例#4
0
        public PeptideSpectrumMatch(TandemMassSpectrum spectrum, Peptide peptide, MassTolerance productMassTolerance)
        {
            Spectrum = spectrum;
            Peptide  = peptide;

            PrecursorMassErrorDa  = spectrum.PrecursorMass - (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass);
            PrecursorMassErrorPpm = PrecursorMassErrorDa / (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass) * 1e6;

            ScoreMatch(productMassTolerance);
        }
示例#5
0
        public PeptideSpectrumMatch(TandemMassSpectrum spectrum, Peptide peptide, MassTolerance productMassTolerance)
        {
            Spectrum = spectrum;
            Peptide = peptide;

            PrecursorMassErrorDa = spectrum.PrecursorMass - (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass);
            PrecursorMassErrorPpm = PrecursorMassErrorDa / (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass) * 1e6;

            ScoreMatch(productMassTolerance);
        }
示例#6
0
        private static List<MSPeak> Deisotope(IEnumerable<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>(peaks);

            int p = new_peaks.Count - 1;
            while(p >= 1)
            {
                int q = p - 1;
                bool removed = false;
                while(q >= 0)
                {
                    if(new_peaks[p].MZ > (new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    if(new_peaks[p].Intensity < new_peaks[q].Intensity)
                    {
                        if(polarity == 0)
                        {
                            if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                            {
                                new_peaks.RemoveAt(p);
                                removed = true;
                                break;
                            }
                        }
                        else
                        {
                            for(int c = polarity; polarity > 0 ? c <= maxAbsoluteCharge : c >= -maxAbsoluteCharge; c += polarity)
                            {
                                if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE / Math.Abs(c), isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                                {
                                    new_peaks.RemoveAt(p);
                                    removed = true;
                                    break;
                                }
                            }
                        }
                        if(removed)
                        {
                            break;
                        }
                    }

                    q--;
                }

                p--;
            }

            return new_peaks;
        }
示例#7
0
        private static List<MSPeak> AssignChargeStates(IList<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>();

            for(int i = 0; i < peaks.Count; i++)
            {
                int j = i + 1;
                List<int> charges = new List<int>();
                while(j < peaks.Count)
                {
                    if(peaks[j].MZ > (peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    for(int c = polarity * maxAbsoluteCharge; polarity > 0 ? c >= 1 : c <= -1; c -= polarity)
                    {
                        // remove harmonic charges, e.g. don't consider peak as a +2 (0.5 Th spacing) if it could be a +4 (0.25 Th spacing)
                        if(HARMONIC_CHARGE_DETECTION)
                        {
                            bool harmonic = false;
                            foreach(int c2 in charges)
                            {
                                if(c2 % c == 0)
                                {
                                    harmonic = true;
                                    break;
                                }
                            }
                            if(harmonic)
                            {
                                continue;
                            }
                        }

                        if(Math.Abs(MassTolerance.CalculateMassError(peaks[j].MZ, peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE / c, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                        {
                            new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, c, polarity));
                            charges.Add(c);
                        }
                    }

                    j++;
                }
                if(charges.Count == 0)
                {
                    new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, 0, polarity));
                }
            }

            return new_peaks;
        }
 public DatabaseSearcher(IList<string> dataFilepaths,
     int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
     double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
     bool assignChargeStates, bool deisotope,
     string proteinFastaDatabaseFilepath, bool onTheFlyDecoys,
     Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
     IEnumerable<Modification> fixedModifications, IEnumerable<Modification> variableModifications, int maximumVariableModificationIsoforms,
     MassTolerance precursorMassTolerance, MassType precursorMassType,
     bool precursorMonoisotopicPeakCorrection, int minimumPrecursorMonoisotopicPeakOffset, int maximumPrecursorMonoisotopicPeakOffset,
     MassTolerance productMassTolerance, MassType productMassType,
     double maximumFalseDiscoveryRate, bool considerModifiedFormsAsUniquePeptides,
     int maximumThreads, bool minimizeMemoryUsage,
     string outputFolder)
 {
     this.dataFilepaths = dataFilepaths;
     this.assignChargeStates = assignChargeStates;
     this.deisotope = deisotope;
     this.proteinFastaDatabaseFilepath = proteinFastaDatabaseFilepath;
     this.onTheFlyDecoys = onTheFlyDecoys;
     this.protease = protease;
     this.maximumMissedCleavages = maximumMissedCleavages;
     this.initiatorMethionineBehavior = initiatorMethionineBehavior;
     this.fixedModifications = fixedModifications;
     this.variableModifications = variableModifications;
     this.maximumVariableModificationIsoforms = maximumVariableModificationIsoforms;
     this.minimumAssumedPrecursorChargeState = minimumAssumedPrecursorChargeState;
     this.maximumAssumedPrecursorChargeState = maximumAssumedPrecursorChargeState;
     this.absoluteThreshold = absoluteThreshold;
     this.relativeThresholdPercent = relativeThresholdPercent;
     this.maximumNumberOfPeaks = maximumNumberOfPeaks;
     this.precursorMassTolerance = precursorMassTolerance;
     this.precursorMassType = precursorMassType;
     this.precursorMonoisotopicPeakCorrection = precursorMonoisotopicPeakCorrection;
     this.minimumPrecursorMonoisotopicPeakOffset = minimumPrecursorMonoisotopicPeakOffset;
     this.maximumPrecursorMonoisotopicPeakOffset = maximumPrecursorMonoisotopicPeakOffset;
     this.productMassTolerance = productMassTolerance;
     this.productMassType = productMassType;
     this.maximumFalseDiscoveryRate = maximumFalseDiscoveryRate;
     this.considerModifiedFormsAsUniquePeptides = considerModifiedFormsAsUniquePeptides;
     this.maximumThreads = maximumThreads;
     this.minimizeMemoryUsage = minimizeMemoryUsage;
     this.outputFolder = outputFolder;
 }
示例#9
0
        public IEnumerable <TandemMassSpectrum> GetTandemMassSpectraInMassRange(double precursorMass, MassTolerance precursorMassTolerance)
        {
            double minimum_precursor_mass = precursorMass - precursorMassTolerance;
            double maximum_precursor_mass = precursorMass + precursorMassTolerance;

            int index = BinarySearch(NextHigherDouble(maximum_precursor_mass));

            if (index == Count)
            {
                index--;
            }
            while (index >= 0 && this[index].PrecursorMass >= minimum_precursor_mass)
            {
                if (this[index].PrecursorMass <= maximum_precursor_mass)
                {
                    yield return(this[index]);
                }
                index--;
            }
        }
示例#10
0
 public IEnumerable <TandemMassSpectrum> GetTandemMassSpectraInMassRanges(double precursorMass, IEnumerable <double> acceptedPrecursorMassErrors, MassTolerance precursorMassTolerance)
 {
     foreach (double accepted_precursor_mass_error in acceptedPrecursorMassErrors)
     {
         foreach (TandemMassSpectrum spectrum in GetTandemMassSpectraInMassRange(precursorMass + accepted_precursor_mass_error, precursorMassTolerance))
         {
             yield return(spectrum);
         }
     }
 }
示例#11
0
        static void Main(string[] args)
        {
            if(args.Length > 0)
            {
                Arguments arguments = new Arguments(args);
                List<string> data = new List<string>(arguments["d"].Split(','));
                int min_assumed_precursor_charge_state = 2;
                if(arguments["minprecz"] != null)
                {
                    min_assumed_precursor_charge_state = int.Parse(arguments["minprecz"]);
                }
                int max_assumed_precursor_charge_state = 4;
                if(arguments["maxprecz"] != null)
                {
                    max_assumed_precursor_charge_state = int.Parse(arguments["maxprecz"]);
                }
                double abs_threshold = -1.0;
                if(arguments["at"] != null)
                {
                    abs_threshold = double.Parse(arguments["at"], CultureInfo.InvariantCulture);
                }
                double rel_threshold_percent = -1.0;
                if(arguments["rt"] != null)
                {
                    rel_threshold_percent = double.Parse(arguments["rt"], CultureInfo.InvariantCulture);
                }
                int max_peaks = 400;
                if(arguments["mp"] != null)
                {
                    max_peaks = int.Parse(arguments["mp"]);
                }
                bool assign_charge_states = true;
                if(arguments["acs"] != null)
                {
                    assign_charge_states = bool.Parse(arguments["acs"]);
                }
                bool deisotope = true;
                if(arguments["di"] != null)
                {
                    deisotope = bool.Parse(arguments["di"]);
                }
                string database = arguments["db"];
                bool append_decoys;
                if(arguments["ad"] != null)
                {
                    append_decoys = bool.Parse(arguments["ad"]);
                }
                else
                {
                    append_decoys = !ProteinFastaReader.HasDecoyProteins(database);
                }
                ProteaseDictionary proteases = ProteaseDictionary.Instance;
                Protease protease = proteases["trypsin (no proline rule)"];
                if(arguments["p"] != null)
                {
                    protease = proteases[arguments["p"]];
                }
                int max_missed_cleavages = 2;
                if(arguments["mmc"] != null)
                {
                    max_missed_cleavages = int.Parse(arguments["mmc"]);
                }
                InitiatorMethionineBehavior initiator_methionine_behavior = InitiatorMethionineBehavior.Variable;
                if(arguments["imb"] != null)
                {
                    initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), arguments["imb"], true);
                }
                ModificationDictionary mods = ModificationDictionary.Instance;
                List<Modification> fixed_mods = new List<Modification>();
                if(arguments["fm"] != null)
                {
                    foreach(string fixed_mod in arguments["fm"].Split(','))
                    {
                        fixed_mods.Add(mods[fixed_mod]);
                    }
                }
                List<Modification> variable_mods = new List<Modification>();
                if(arguments["vm"] != null)
                {
                    foreach(string variable_mod in arguments["vm"].Split(','))
                    {
                        variable_mods.Add(mods[variable_mod]);
                    }
                }
                int max_variable_mod_isoforms_per_peptide = 1024;
                if(arguments["mvmi"] != null)
                {
                    max_variable_mod_isoforms_per_peptide = int.Parse(arguments["mvmi"]);
                }
                double precursor_mass_tolerance_value = 2.1;
                if(arguments["precmtv"] != null)
                {
                    precursor_mass_tolerance_value = double.Parse(arguments["precmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits precursor_mass_tolerance_units = MassToleranceUnits.Da;
                if(arguments["precmtu"] != null)
                {
                    precursor_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["precmtu"], true);
                }
                MassTolerance precursor_mass_tolerance = new MassTolerance(precursor_mass_tolerance_value, precursor_mass_tolerance_units);
                MassType precursor_mass_type = MassType.Monoisotopic;
                if(arguments["precmt"] != null)
                {
                    precursor_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["precmt"], true);
                }
                bool prec_mono_correction = false;
                if(arguments["pmc"] != null)
                {
                    prec_mono_correction = bool.Parse(arguments["pmc"]);
                }
                int min_prec_mono_offset = -3;
                if(arguments["minpmo"] != null)
                {
                    min_prec_mono_offset = int.Parse(arguments["minpmo"]);
                }
                int max_prec_mono_offset = 1;
                if(arguments["maxpmo"] != null)
                {
                    max_prec_mono_offset = int.Parse(arguments["maxpmo"]);
                }
                double product_mass_tolerance_value = 0.025;
                if(arguments["prodmtv"] != null)
                {
                    product_mass_tolerance_value = double.Parse(arguments["prodmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits product_mass_tolerance_units = MassToleranceUnits.Da;
                if(arguments["prodmtu"] != null)
                {
                    product_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["prodmtu"], true);
                }
                MassTolerance product_mass_tolerance = new MassTolerance(product_mass_tolerance_value, product_mass_tolerance_units);
                MassType product_mass_type = MassType.Monoisotopic;
                if(arguments["prodmt"] != null)
                {
                    product_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["prodmt"], true);
                }
                double max_fdr = 0.01;
                if(arguments["fdr"] != null)
                {
                    max_fdr = double.Parse(arguments["fdr"], CultureInfo.InvariantCulture) / 100.0;
                }
                bool consider_mods_unique = false;
                if(arguments["cmu"] != null)
                {
                    consider_mods_unique = bool.Parse(arguments["cmu"]);
                }
                int max_threads = Environment.ProcessorCount;
                if(arguments["mt"] != null)
                {
                    max_threads = int.Parse(arguments["mt"]);
                }
                bool minimize_memory_usage = false;
                if(arguments["mmu"] != null)
                {
                    minimize_memory_usage = bool.Parse(arguments["mmu"]);
                }
                string output_folder = Environment.CurrentDirectory;
                if(arguments["o"] != null)
                {
                    output_folder = arguments["o"];
                }

                DatabaseSearcher database_searcher = new DatabaseSearcher(data,
                    min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                    abs_threshold, rel_threshold_percent, max_peaks,
                    assign_charge_states, deisotope,
                    database, append_decoys,
                    protease, max_missed_cleavages, initiator_methionine_behavior,
                    fixed_mods, variable_mods, max_variable_mod_isoforms_per_peptide,
                    precursor_mass_tolerance, precursor_mass_type,
                    prec_mono_correction, min_prec_mono_offset, max_prec_mono_offset,
                    product_mass_tolerance, product_mass_type,
                    max_fdr, consider_mods_unique,
                    max_threads, minimize_memory_usage,
                    output_folder);

                database_searcher.Starting += HandleStarting;
                database_searcher.StartingFile += HandleStartingFile;
                database_searcher.UpdateStatus += HandleUpdateStatus;
                database_searcher.UpdateProgress += HandleUpdateProgress;
                database_searcher.ThrowException += HandleThrowException;
                database_searcher.FinishedFile += HandleFinishedFile;
                database_searcher.Finished += HandleFinished;

                database_searcher.Search();
            }
            else
            {
                Console.WriteLine("USAGE");
            }
        }
示例#12
0
        private static List<MSPeak> Deisotope(IEnumerable<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>(peaks);

            int p = new_peaks.Count - 1;
            while(p >= 1)
            {
                int q = p - 1;
                bool removed = false;
                while(q >= 0)
                {
                    if(new_peaks[p].MZ > (new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    if(new_peaks[p].Intensity < new_peaks[q].Intensity)
                    {
                        if(polarity == 0)
                        {
                            if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                            {
                                new_peaks.RemoveAt(p);
                                removed = true;
                                break;
                            }
                        }
                        else
                        {
                            for(int c = polarity; polarity > 0 ? c <= maxAbsoluteCharge : c >= -maxAbsoluteCharge; c += polarity)
                            {
                                if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE / Math.Abs(c), isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                                {
                                    new_peaks.RemoveAt(p);
                                    removed = true;
                                    break;
                                }
                            }
                        }
                        if(removed)
                        {
                            break;
                        }
                    }

                    q--;
                }

                p--;
            }

            return new_peaks;
        }
        // Calculates the score for this match. Both product_masses_buf and
        // fast_q_sorter are modified by this method; see Init's documentation
        // for details.
        private void ScoreMatch(MassTolerance productMassTolerance, ref double[] product_masses_buf, FastQSorter fast_q_sorter)
        {
            // Calculate the theoretical product masses and store them in
            // product_masses_buf, which is aliased under the more informative
            // name theoretical_product_masses for the code below.
            TotalProducts = Peptide.CalculateProductMasses(PRODUCT_TYPES[Spectrum.FragmentationMethod],
                                                           ref product_masses_buf, fast_q_sorter);
            double[] theoretical_product_masses = product_masses_buf;

            // speed optimizations
            int num_theoretical_products = TotalProducts;
            double[] experimental_masses = Spectrum.Masses;
            double[] experimental_intensities = Spectrum.Intensities;
            int num_experimental_peaks = experimental_masses.Length;
            double product_mass_tolerance_value = productMassTolerance.Value;
            MassToleranceUnits product_mass_tolerance_units = productMassTolerance.Units;

            MatchingProducts = 0;
            int t = 0;
            int e = 0;
            while(t < num_theoretical_products && e < num_experimental_peaks)
            {
                double mass_difference = experimental_masses[e] - theoretical_product_masses[t];
                if(product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t] * 1e6;
                }
                if(Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingProducts++;
                    t++;
                }
                else if(mass_difference < 0)
                {
                    e++;
                }
                else if(mass_difference > 0)
                {
                    t++;
                }
            }
            MatchingProductsFraction = (double)MatchingProducts / TotalProducts;

            MatchingIntensity = 0.0;
            int e2 = 0;
            int t2 = 0;
            while(e2 < num_experimental_peaks && t2 < num_theoretical_products)
            {
                double mass_difference = experimental_masses[e2] - theoretical_product_masses[t2];
                if(product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t2] * 1e6;
                }
                if(Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingIntensity += experimental_intensities[e2];
                    e2++;
                }
                else if(mass_difference < 0)
                {
                    e2++;
                }
                else if(mass_difference > 0)
                {
                    t2++;
                }
            }
            MatchingIntensityFraction = MatchingIntensity / Spectrum.TotalIntensity;

            MorpheusScore = MatchingProducts + MatchingIntensityFraction;
        }
示例#14
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (lstData.Items.Count == 0)
            {
                MessageBox.Show("No data files selected");
                btnAdd.Focus();
                return;
            }
            List <string> data_filepaths = new List <string>(lstData.Items.Count);

            foreach (string data_filepath in lstData.Items)
            {
                data_filepaths.Add(data_filepath);
            }
            bool   assign_charge_states = chkAssignChargeStates.Checked;
            bool   deisotope            = chkDeisotope.Checked;
            string fasta_filepath       = txtFastaFile.Text;

            if (!File.Exists(fasta_filepath))
            {
                if (fasta_filepath.Length > 0)
                {
                    MessageBox.Show("Invalid protein database file: " + fasta_filepath);
                }
                else
                {
                    MessageBox.Show("Invalid protein database file");
                }
                txtFastaFile.Focus();
                return;
            }
            bool     on_the_fly_decoys    = chkOnTheFlyDecoys.Checked;
            Protease protease             = (Protease)cboProtease.SelectedItem;
            int      max_missed_cleavages = (int)numMaxMissedCleavages.Value;
            InitiatorMethionineBehavior initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), cboInitiatorMethionineBehavior.Text, true);
            List <Modification>         fixed_modifications           = new List <Modification>(clbFixedModifications.CheckedItems.Count);

            foreach (object fixed_modification in clbFixedModifications.CheckedItems)
            {
                fixed_modifications.Add((Modification)fixed_modification);
            }
            List <Modification> variable_modifications = new List <Modification>(clbVariableModifications.CheckedItems.Count);

            foreach (object variable_modification in clbVariableModifications.CheckedItems)
            {
                variable_modifications.Add((Modification)variable_modification);
            }
            int    max_variable_mod_isoforms          = (int)numMaxVariableModIsoforms.Value;
            int    min_assumed_precursor_charge_state = (int)numMinimumAssumedPrecursorChargeState.Value;
            int    max_assumed_precursor_charge_state = (int)numMaximumAssumedPrecursorChargeState.Value;
            double absolute_threshold = -1.0;

            if (chkAbsoluteThreshold.Checked)
            {
                if (!double.TryParse(txtAbsoluteThreshold.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out absolute_threshold))
                {
                    MessageBox.Show("Cannot parse absolute MS/MS peak threshold: " + txtAbsoluteThreshold.Text);
                    txtAbsoluteThreshold.Focus();
                    return;
                }
            }
            double relative_threshold_percent = -1.0;

            if (chkRelativeThreshold.Checked)
            {
                if (!double.TryParse(txtRelativeThresholdPercent.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out relative_threshold_percent))
                {
                    MessageBox.Show("Cannot parse relative MS/MS peak threshold: " + txtRelativeThresholdPercent.Text);
                    txtRelativeThresholdPercent.Focus();
                    return;
                }
            }
            int max_peaks = -1;

            if (chkMaxNumPeaks.Checked)
            {
                max_peaks = (int)numMaxPeaks.Value;
            }
            MassTolerance precursor_mass_tolerance       = new MassTolerance((double)numPrecursorMassTolerance.Value, (MassToleranceUnits)cboPrecursorMassToleranceUnits.SelectedIndex);
            MassType      precursor_mass_type            = (MassType)cboPrecursorMassType.SelectedIndex;
            List <double> accepted_precursor_mass_errors = new List <double>();

            if (txtAcceptedPrecursorMassErrors.Text.Length > 0)
            {
                foreach (string accepted_precursor_mass_error_text in txtAcceptedPrecursorMassErrors.Text.Split(';'))
                {
                    double accepted_precursor_mass_error;
                    if (!double.TryParse(accepted_precursor_mass_error_text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out accepted_precursor_mass_error))
                    {
                        MessageBox.Show("Cannot parse accepted precursor mass errors: " + txtRelativeThresholdPercent.Text);
                        txtAcceptedPrecursorMassErrors.Focus();
                        return;
                    }
                    accepted_precursor_mass_errors.Add(accepted_precursor_mass_error);
                }
            }
            else
            {
                accepted_precursor_mass_errors.Add(0.0);
            }
            MassTolerance product_mass_tolerance   = new MassTolerance((double)numProductMassTolerance.Value, (MassToleranceUnits)cboProductMassToleranceUnits.SelectedIndex);
            MassType      product_mass_type        = (MassType)cboProductMassType.SelectedIndex;
            double        max_false_discovery_rate = (double)numMaximumFalseDiscoveryRatePercent.Value / 100.0;
            bool          consider_modified_unique = chkConsiderModifiedUnique.Checked;
            int           max_threads           = (int)numMaxThreads.Value;
            bool          minimize_memory_usage = chkMinimizeMemoryUsage.Checked;
            string        output_folder         = txtOutputFolder.Text;

            if (!Directory.Exists(output_folder))
            {
                try
                {
                    Directory.CreateDirectory(output_folder);
                }
                catch
                {
                    if (output_folder.Length > 0)
                    {
                        MessageBox.Show("Invalid output folder: " + output_folder);
                    }
                    else
                    {
                        MessageBox.Show("Invalid output folder");
                    }
                    txtOutputFolder.Focus();
                    return;
                }
            }

            DatabaseSearcher database_searcher = new DatabaseSearcher(data_filepaths,
                                                                      min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                                                                      absolute_threshold, relative_threshold_percent, max_peaks,
                                                                      assign_charge_states, deisotope,
                                                                      fasta_filepath, on_the_fly_decoys,
                                                                      protease, max_missed_cleavages, initiator_methionine_behavior,
                                                                      fixed_modifications, variable_modifications, max_variable_mod_isoforms,
                                                                      precursor_mass_tolerance, precursor_mass_type,
                                                                      accepted_precursor_mass_errors,
                                                                      product_mass_tolerance, product_mass_type,
                                                                      max_false_discovery_rate, consider_modified_unique,
                                                                      max_threads, minimize_memory_usage,
                                                                      output_folder);

            database_searcher.Starting     += HandleStarting;
            database_searcher.StartingFile += HandleStartingFile;
            database_searcher.UpdateStatus += HandleUpdateStatus;
            database_searcher.ReportTaskWithoutProgress += HandleReportTaskWithoutProgress;
            database_searcher.ReportTaskWithProgress    += HandleReportTaskWithProgress;
            database_searcher.UpdateProgress            += HandleUpdateProgress;
            database_searcher.ThrowException            += HandleThrowException;
            database_searcher.FinishedFile += HandleFinishedFile;
            database_searcher.Finished     += HandleFinished;

            lstData.SelectedItem = null;
            tspbProgress.Value   = tspbProgress.Minimum;

            Thread thread = new Thread(new ThreadStart(database_searcher.Search));

            thread.IsBackground = true;
            thread.Start();
        }
示例#15
0
        static void Main(string[] args)
        {
            if(args.Length > 0)
            {
                Arguments arguments = new Arguments(args);
                List<string> data = new List<string>(arguments["d"].Split(','));
                int min_assumed_precursor_charge_state = 2;
                if(arguments["minprecz"] != null)
                {
                    min_assumed_precursor_charge_state = int.Parse(arguments["minprecz"]);
                }
                int max_assumed_precursor_charge_state = 4;
                if(arguments["maxprecz"] != null)
                {
                    max_assumed_precursor_charge_state = int.Parse(arguments["maxprecz"]);
                }
                double abs_threshold = -1.0;
                if(arguments["at"] != null)
                {
                    abs_threshold = double.Parse(arguments["at"], CultureInfo.InvariantCulture);
                }
                double rel_threshold_percent = -1.0;
                if(arguments["rt"] != null)
                {
                    rel_threshold_percent = double.Parse(arguments["rt"], CultureInfo.InvariantCulture);
                }
                int max_peaks = 400;
                if(arguments["mp"] != null)
                {
                    max_peaks = int.Parse(arguments["mp"]);
                }
                bool assign_charge_states = true;
                if(arguments["acs"] != null)
                {
                    assign_charge_states = bool.Parse(arguments["acs"]);
                }
                bool deisotope = true;
                if(arguments["di"] != null)
                {
                    deisotope = bool.Parse(arguments["di"]);
                }
                string database = arguments["db"];
                Dictionary<string, Modification> known_variable_modifications = null;
                HashSet<Modification> variable_mods = new HashSet<Modification>();
                if(Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
                {
                    bool no_uniprot_mods = false;
                    if(arguments["noup"] != null)
                    {
                        no_uniprot_mods = bool.Parse(arguments["noup"]);
                    }
                    if (!no_uniprot_mods)
                    {
                        known_variable_modifications = ProteomeDatabaseReader.ReadUniProtXmlModifications(database);
                        variable_mods.UnionWith(known_variable_modifications.Values);
                    }
                }
                bool append_decoys = false;
                if(arguments["ad"] != null)
                {
                    append_decoys = bool.Parse(arguments["ad"]);
                }
                else
                {
                    append_decoys = Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase) || !ProteomeDatabaseReader.HasDecoyProteins(database);
                }
                ProteaseDictionary proteases = ProteaseDictionary.Instance;
                Protease protease = proteases["trypsin (no proline rule)"];
                if(arguments["p"] != null)
                {
                    protease = proteases[arguments["p"]];
                }
                int max_missed_cleavages = 2;
                if(arguments["mmc"] != null)
                {
                    max_missed_cleavages = int.Parse(arguments["mmc"]);
                }
                InitiatorMethionineBehavior initiator_methionine_behavior = InitiatorMethionineBehavior.Variable;
                if(arguments["imb"] != null)
                {
                    initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), arguments["imb"], true);
                }
                ModificationDictionary mods = ModificationDictionary.Instance;
                List<Modification> fixed_mods = new List<Modification>();
                if(arguments["fm"] != null)
                {
                    foreach(string fixed_mod in arguments["fm"].Split(';'))
                    {
                        fixed_mods.Add(mods[fixed_mod]);
                    }
                }
                if(arguments["vm"] != null)
                {
                    foreach(string variable_mod in arguments["vm"].Split(';'))
                    {
                        Modification mod;
                        if(!mods.TryGetValue(variable_mod, out mod))
                        {
                            known_variable_modifications.TryGetValue(variable_mod, out mod);
                        }
                        variable_mods.Add(mod);
                    }
                }
                int max_variable_mod_isoforms_per_peptide = 1024;
                if(arguments["mvmi"] != null)
                {
                    max_variable_mod_isoforms_per_peptide = int.Parse(arguments["mvmi"]);
                }
                double precursor_mass_tolerance_value = 2.1;
                if(arguments["precmtv"] != null)
                {
                    precursor_mass_tolerance_value = double.Parse(arguments["precmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits precursor_mass_tolerance_units = MassToleranceUnits.Da;
                if(arguments["precmtu"] != null)
                {
                    precursor_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["precmtu"], true);
                }
                MassTolerance precursor_mass_tolerance = new MassTolerance(precursor_mass_tolerance_value, precursor_mass_tolerance_units);
                MassType precursor_mass_type = MassType.Monoisotopic;
                if(arguments["precmt"] != null)
                {
                    precursor_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["precmt"], true);
                }
                List<double> accepted_precursor_mass_errors = new List<double>();
                if(arguments["apme"] != null && arguments["apme"].Length > 0)
                {
                    foreach(string accepted_precursor_mass_error in arguments["apme"].Split(';'))
                    {
                        accepted_precursor_mass_errors.Add(double.Parse(accepted_precursor_mass_error, CultureInfo.InvariantCulture));
                    }
                }
                else
                {
                    accepted_precursor_mass_errors.Add(0.0);
                }
                double product_mass_tolerance_value = 0.015;
                if(arguments["prodmtv"] != null)
                {
                    product_mass_tolerance_value = double.Parse(arguments["prodmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits product_mass_tolerance_units = MassToleranceUnits.Da;
                if(arguments["prodmtu"] != null)
                {
                    product_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["prodmtu"], true);
                }
                MassTolerance product_mass_tolerance = new MassTolerance(product_mass_tolerance_value, product_mass_tolerance_units);
                MassType product_mass_type = MassType.Monoisotopic;
                if(arguments["prodmt"] != null)
                {
                    product_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["prodmt"], true);
                }
                double max_fdr = 0.01;
                if(arguments["fdr"] != null)
                {
                    max_fdr = double.Parse(arguments["fdr"], CultureInfo.InvariantCulture) / 100.0;
                }
                bool consider_mods_unique = false;
                if(arguments["cmu"] != null)
                {
                    consider_mods_unique = bool.Parse(arguments["cmu"]);
                }
                int max_threads = Environment.ProcessorCount;
                if(arguments["mt"] != null)
                {
                    max_threads = int.Parse(arguments["mt"]);
                }
                bool minimize_memory_usage = false;
                if(arguments["mmu"] != null)
                {
                    minimize_memory_usage = bool.Parse(arguments["mmu"]);
                }
                string output_folder = Environment.CurrentDirectory;
                if(arguments["o"] != null)
                {
                    output_folder = arguments["o"];
                }

                DatabaseSearcher database_searcher = new DatabaseSearcher(data,
                    min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                    abs_threshold, rel_threshold_percent, max_peaks,
                    assign_charge_states, deisotope,
                    database, append_decoys,
                    protease, max_missed_cleavages, initiator_methionine_behavior,
                    fixed_mods, variable_mods, max_variable_mod_isoforms_per_peptide,
                    precursor_mass_tolerance, precursor_mass_type,
                    accepted_precursor_mass_errors,
                    product_mass_tolerance, product_mass_type,
                    max_fdr, consider_mods_unique,
                    max_threads, minimize_memory_usage,
                    output_folder);

                database_searcher.Starting += HandleStarting;
                database_searcher.StartingFile += HandleStartingFile;
                database_searcher.UpdateStatus += HandleUpdateStatus;
                database_searcher.UpdateProgress += HandleUpdateProgress;
                database_searcher.ThrowException += HandleThrowException;
                database_searcher.FinishedFile += HandleFinishedFile;
                database_searcher.Finished += HandleFinished;

                database_searcher.Search();
            }
            else
            {
                Console.WriteLine(Program.GetProductNameAndVersion() + " USAGE");
            }
        }
示例#16
0
        public void Load(string mzmlFilepath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
            double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
            bool assignChargeStates, bool deisotope, MassTolerance isotopicMZTolerance, int maximumThreads)
        {
            OnReportTaskWithoutProgress(EventArgs.Empty);

            XmlDocument mzML_temp = new XmlDocument();
            mzML_temp.Load(mzmlFilepath);
            XPathNavigator mzML = mzML_temp.CreateNavigator();

            XmlNamespaceManager xnm = new XmlNamespaceManager(mzML.NameTable);
            xnm.AddNamespace("mzML", mzML_temp.DocumentElement.NamespaceURI);

            Dictionary<string, XPathNodeIterator> referenceable_param_groups = new Dictionary<string, XPathNodeIterator>();
            foreach(XPathNavigator referenceable_param_group in mzML.Select("//mzML:mzML/mzML:referenceableParamGroupList/mzML:referenceableParamGroup", xnm))
            {
                referenceable_param_groups.Add(referenceable_param_group.GetAttribute("id", string.Empty), referenceable_param_group.SelectChildren(XPathNodeType.All));
            }

            ParallelOptions parallel_options = new ParallelOptions();
            parallel_options.MaxDegreeOfParallelism = maximumThreads;

            Dictionary<string, SpectrumNavigator> ms1s = null;
            if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1)
            {
                ms1s = new Dictionary<string, SpectrumNavigator>();
#if NON_MULTITHREADED
                foreach(XPathNavigator spectrum_navigator in mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>())
#else
                Parallel.ForEach(mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>(), parallel_options, spectrum_navigator =>
#endif
                {
                    string scan_id = spectrum_navigator.GetAttribute("id", string.Empty);
                    int ms_level = -1;

                    foreach(XPathNavigator spectrum_child_navigator in spectrum_navigator.SelectChildren(XPathNodeType.All))
                    {
                        if(spectrum_child_navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                        {
                            if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                            {
                                ms_level = int.Parse(spectrum_child_navigator.GetAttribute("value", string.Empty));
                            }
                        }
                        else if(spectrum_child_navigator.Name.Equals("referenceableParamGroupRef", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach(XPathNavigator navigator in referenceable_param_groups[spectrum_child_navigator.GetAttribute("ref", string.Empty)])
                            {
                                if(navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                                {
                                    if(navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                                    {
                                        ms_level = int.Parse(navigator.GetAttribute("value", string.Empty));
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if(ms_level == 1)
                    {
                        lock(ms1s)
                        {
                            ms1s.Add(scan_id, new SpectrumNavigator(spectrum_navigator, xnm));
                        }
                    }
                }
#if !NON_MULTITHREADED
                );
#endif
            }

            int num_spectra = int.Parse(mzML.SelectSingleNode("//mzML:mzML/mzML:run/mzML:spectrumList", xnm).GetAttribute("count", string.Empty));

            OnReportTaskWithProgress(EventArgs.Empty);
            object progress_lock = new object();
            int spectra_processed = 0;
            int old_progress = 0;

#if NON_MULTITHREADED
            foreach(XPathNavigator spectrum_navigator in mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>())
#else
            Parallel.ForEach(mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>(), parallel_options, spectrum_navigator =>
#endif
            {
                int spectrum_index = int.Parse(spectrum_navigator.GetAttribute("index", string.Empty));
                int spectrum_number = spectrum_index + 1;
                string spectrum_id = spectrum_navigator.GetAttribute("id", string.Empty);
                string spectrum_title = null;
                int ms_level = -1;
                int polarity = 0;
                double retention_time_minutes = double.NaN;
                string precursor_scan_id = null;
                double precursor_mz = double.NaN;
                int charge = 0;
                double precursor_intensity = double.NaN;
                string fragmentation_method = "collision-induced dissociation";
                double[] mz = null;
                double[] intensity = null;

                foreach(XPathNavigator spectrum_child_navigator in spectrum_navigator.SelectChildren(XPathNodeType.All))
                {
                    if(spectrum_child_navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                    {
                        if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                        {
                            ms_level = int.Parse(spectrum_child_navigator.GetAttribute("value", string.Empty));
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("positive scan", StringComparison.OrdinalIgnoreCase))
                        {
                            polarity = 1;
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("negative scan", StringComparison.OrdinalIgnoreCase))
                        {
                            polarity = -1;
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("spectrum title", StringComparison.OrdinalIgnoreCase))
                        {
                            spectrum_title = spectrum_child_navigator.GetAttribute("value", string.Empty);
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("referenceableParamGroupRef", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach(XPathNavigator navigator in referenceable_param_groups[spectrum_child_navigator.GetAttribute("ref", string.Empty)])
                        {
                            if(navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                            {
                                if(navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                                {
                                    ms_level = int.Parse(navigator.GetAttribute("value", string.Empty));
                                }
                                else if(navigator.GetAttribute("name", string.Empty).Equals("positive scan", StringComparison.OrdinalIgnoreCase))
                                {
                                    polarity = 1;
                                }
                                else if(navigator.GetAttribute("name", string.Empty).Equals("negative scan", StringComparison.OrdinalIgnoreCase))
                                {
                                    polarity = -1;
                                }
                            }
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("scanList", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach(XPathNavigator navigator in spectrum_child_navigator.Select("mzML:scan/mzML:cvParam", xnm))
                        {
                            if(navigator.GetAttribute("name", string.Empty).Equals("scan start time", StringComparison.OrdinalIgnoreCase))
                            {
                                retention_time_minutes = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                                if(navigator.GetAttribute("unitName", string.Empty).StartsWith("s", StringComparison.OrdinalIgnoreCase))
                                {
                                    retention_time_minutes = TimeSpan.FromSeconds(retention_time_minutes).TotalMinutes;
                                }
                            }
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("precursorList", StringComparison.OrdinalIgnoreCase))
                    {
                        XPathNavigator precursor_node = spectrum_child_navigator.SelectSingleNode("mzML:precursor", xnm);
                        precursor_scan_id = precursor_node.GetAttribute("spectrumRef", string.Empty);
                        foreach(XPathNavigator navigator in precursor_node.Select("mzML:selectedIonList/mzML:selectedIon/mzML:cvParam", xnm))
                        {
                            if(navigator.GetAttribute("name", string.Empty).Equals("selected ion m/z", StringComparison.OrdinalIgnoreCase))
                            {
                                precursor_mz = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                            }
                            else if(navigator.GetAttribute("name", string.Empty).Equals("charge state", StringComparison.OrdinalIgnoreCase))
                            {
                                charge = int.Parse(navigator.GetAttribute("value", string.Empty));
                                if(polarity < 0)
                                {
                                    charge = -charge;
                                }
                            }
                            else if(navigator.GetAttribute("name", string.Empty).Equals("peak intensity", StringComparison.OrdinalIgnoreCase))
                            {
                                precursor_intensity = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                            }
                        }
                        XPathNavigator navigator2 = spectrum_child_navigator.SelectSingleNode("mzML:precursor/mzML:activation/mzML:cvParam", xnm);
                        if(navigator2 != null)
                        {
                            fragmentation_method = navigator2.GetAttribute("name", string.Empty);
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("binaryDataArrayList", StringComparison.OrdinalIgnoreCase))
                    {
                        ReadDataFromSpectrumNavigator(spectrum_child_navigator.Select("mzML:binaryDataArray/*", xnm), out mz, out intensity);
                    }
                    if(ms_level == 1)
                    {
                        break;
                    }
                }

                if(ms_level >= 2)
                {
                    if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1 && precursor_scan_id != null)
                    {
                        SpectrumNavigator ms1;
                        if(ms1s.TryGetValue(precursor_scan_id, out ms1))
                        {
                            double[] ms1_mz;
                            double[] ms1_intensity;
                            ms1.GetSpectrum(out ms1_mz, out ms1_intensity);
                            int index = -1;
                            for(int i = ms1_mz.GetLowerBound(0); i <= ms1_mz.GetUpperBound(0); i++)
                            {
                                if(index < 0 || Math.Abs(ms1_mz[i] - precursor_mz) < Math.Abs(ms1_mz[index] - precursor_mz))
                                {
                                    index = i;
                                }
                            }
                            precursor_mz = ms1_mz[index];
                            precursor_intensity = ms1_intensity[index];
                        }
                    }

                    if(mz != null && intensity != null && mz.Length > 0 && intensity.Length > 0)
                    {
                        List<MSPeak> peaks = new List<MSPeak>(mz.Length);
                        for(int i = 0; i < mz.Length; i++)
                        {
                            peaks.Add(new MSPeak(mz[i], intensity[i], 0, polarity));
                        }

                        peaks = FilterPeaks(peaks, absoluteThreshold, relativeThresholdPercent, maximumNumberOfPeaks);
                        if(peaks.Count > 0)
                        {
                            peaks.Sort(MSPeak.AscendingMZComparison);
                            for(int c = (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? minimumAssumedPrecursorChargeState : charge);
                                c <= (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? maximumAssumedPrecursorChargeState : charge); c++)
                            {
                                List<MSPeak> new_peaks = peaks;
                                if(assignChargeStates)
                                {
                                    new_peaks = AssignChargeStates(new_peaks, c, polarity, isotopicMZTolerance);
                                    if(deisotope)
                                    {
                                        new_peaks = Deisotope(new_peaks, c, polarity, isotopicMZTolerance);
                                    }
                                }

                                double precursor_mass = MSPeak.MassFromMZ(precursor_mz, c);

                                TandemMassSpectrum spectrum = new TandemMassSpectrum(mzmlFilepath, spectrum_number, spectrum_id, spectrum_title, retention_time_minutes, fragmentation_method, precursor_mz, precursor_intensity, c, precursor_mass, new_peaks);
                                lock(this)
                                {
                                    Add(spectrum);
                                }
                            }
                        }
                    }
                }

                lock(progress_lock)
                {
                    spectra_processed++;
                    int new_progress = (int)((double)spectra_processed / num_spectra * 100);
                    if(new_progress > old_progress)
                    {
                        OnUpdateProgress(new ProgressEventArgs(new_progress));
                        old_progress = new_progress;
                    }
                }
            }
#if !NON_MULTITHREADED
            );
#endif
        }
示例#17
0
        private void ScoreMatch(MassTolerance productMassTolerance)
        {
            double[] theoretical_product_masses = Peptide.CalculateProductMasses(PRODUCT_TYPES[Spectrum.FragmentationMethod]).ToArray();
            TotalProducts = theoretical_product_masses.Length;

            // speed optimizations
            int num_theoretical_products = theoretical_product_masses.Length;

            double[]           experimental_masses          = Spectrum.Masses;
            double[]           experimental_intensities     = Spectrum.Intensities;
            int                num_experimental_peaks       = experimental_masses.Length;
            double             product_mass_tolerance_value = productMassTolerance.Value;
            MassToleranceUnits product_mass_tolerance_units = productMassTolerance.Units;

            MatchingProducts = 0;
            int t = 0;
            int e = 0;

            while (t < num_theoretical_products && e < num_experimental_peaks)
            {
                double mass_difference = experimental_masses[e] - theoretical_product_masses[t];
                if (product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t] * 1e6;
                }
                if (Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingProducts++;
                    t++;
                }
                else if (mass_difference < 0)
                {
                    e++;
                }
                else if (mass_difference > 0)
                {
                    t++;
                }
            }
            MatchingProductsFraction = (double)MatchingProducts / TotalProducts;

            MatchingIntensity = 0.0;
            int e2 = 0;
            int t2 = 0;

            while (e2 < num_experimental_peaks && t2 < num_theoretical_products)
            {
                double mass_difference = experimental_masses[e2] - theoretical_product_masses[t2];
                if (product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t2] * 1e6;
                }
                if (Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingIntensity += experimental_intensities[e2];
                    e2++;
                }
                else if (mass_difference < 0)
                {
                    e2++;
                }
                else if (mass_difference > 0)
                {
                    t2++;
                }
            }
            MatchingIntensityFraction = MatchingIntensity / Spectrum.TotalIntensity;

            MorpheusScore = MatchingProducts + MatchingIntensityFraction;
        }
        // This Init method needs to be called before this object can be used.
        // For more info, see how we use these objects in DatabaseSearcher.
        //
        // We copy the peptide parameter deeply (because these sometimes come
        // from reusable buffers) but not the spectrum parameter (because these
        // are not reused).
        //
        // The array product_masses_buf is used for temporary internal storage
        // and may be resized. It needs to be local to the current thread; no
        // locking is performed. Its contents are not of interest to the
        // caller.
        //
        // The fast_q_sorter object also need to be local to the current
        // thread, as its internal state will be modified.
        public void Init(TandemMassSpectrum spectrum, Peptide peptide, MassTolerance productMassTolerance,
            ref double[] product_masses_buf, FastQSorter fast_q_sorter)
        {
            Spectrum = spectrum;
            if(Peptide == null)
                Peptide = new Peptide();
            Peptide.CopyFrom(peptide);

            PrecursorMassErrorDa = spectrum.PrecursorMass - (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass);
            PrecursorMassErrorPpm = PrecursorMassErrorDa / (precursorMassType == MassType.Average ? peptide.AverageMass : peptide.MonoisotopicMass) * 1e6;

            ScoreMatch(productMassTolerance, ref product_masses_buf, fast_q_sorter);
        }
示例#19
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if(lstData.Items.Count == 0)
            {
                MessageBox.Show("No data files selected");
                btnAdd.Focus();
                return;
            }
            List<string> data_filepaths = new List<string>(lstData.Items.Count);
            foreach(string data_filepath in lstData.Items)
            {
                data_filepaths.Add(data_filepath);
            }
            bool assign_charge_states = chkAssignChargeStates.Checked;
            bool deisotope = chkDeisotope.Checked;
            string fasta_filepath = txtFastaFile.Text;
            if(!File.Exists(fasta_filepath))
            {
                if(fasta_filepath.Length > 0)
                {
                    MessageBox.Show("Invalid protein database file: " + fasta_filepath);
                }
                else
                {
                    MessageBox.Show("Invalid protein database file");
                }
                txtFastaFile.Focus();
                return;
            }
            bool on_the_fly_decoys = chkOnTheFlyDecoys.Checked;
            Protease protease = (Protease)cboProtease.SelectedItem;
            int max_missed_cleavages = (int)numMaxMissedCleavages.Value;
            InitiatorMethionineBehavior initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), cboInitiatorMethionineBehavior.Text, true);
            List<Modification> fixed_modifications = new List<Modification>(clbFixedModifications.CheckedItems.Count);
            foreach(object fixed_modification in clbFixedModifications.CheckedItems)
            {
                fixed_modifications.Add((Modification)fixed_modification);
            }
            List<Modification> variable_modifications = new List<Modification>(clbVariableModifications.CheckedItems.Count);
            foreach(object variable_modification in clbVariableModifications.CheckedItems)
            {
                variable_modifications.Add((Modification)variable_modification);
            }
            int max_variable_mod_isoforms = (int)numMaxVariableModIsoforms.Value;
            int min_assumed_precursor_charge_state = (int)numMinimumAssumedPrecursorChargeState.Value;
            int max_assumed_precursor_charge_state = (int)numMaximumAssumedPrecursorChargeState.Value;
            double absolute_threshold = -1.0;
            if(chkAbsoluteThreshold.Checked)
            {
                if(!double.TryParse(txtAbsoluteThreshold.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out absolute_threshold))
                {
                    MessageBox.Show("Cannot parse absolute MS/MS peak threshold: " + txtAbsoluteThreshold.Text);
                    txtAbsoluteThreshold.Focus();
                    return;
                }
            }
            double relative_threshold_percent = -1.0;
            if(chkRelativeThreshold.Checked)
            {
                if(!double.TryParse(txtRelativeThresholdPercent.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out relative_threshold_percent))
                {
                    MessageBox.Show("Cannot parse relative MS/MS peak threshold: " + txtRelativeThresholdPercent.Text);
                    txtRelativeThresholdPercent.Focus();
                    return;
                }
            }
            int max_peaks = -1;
            if(chkMaxNumPeaks.Checked)
            {
                max_peaks = (int)numMaxPeaks.Value;
            }
            MassTolerance precursor_mass_tolerance = new MassTolerance((double)numPrecursorMassTolerance.Value, (MassToleranceUnits)cboPrecursorMassToleranceUnits.SelectedIndex);
            MassType precursor_mass_type = (MassType)cboPrecursorMassType.SelectedIndex;
            List<double> accepted_precursor_mass_errors = new List<double>();
            if(txtAcceptedPrecursorMassErrors.Text.Length > 0)
            {
                foreach(string accepted_precursor_mass_error_text in txtAcceptedPrecursorMassErrors.Text.Split(';'))
                {
                    double accepted_precursor_mass_error;
                    if(!double.TryParse(accepted_precursor_mass_error_text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out accepted_precursor_mass_error))
                    {
                        MessageBox.Show("Cannot parse accepted precursor mass errors: " + txtRelativeThresholdPercent.Text);
                        txtAcceptedPrecursorMassErrors.Focus();
                        return;
                    }
                    accepted_precursor_mass_errors.Add(accepted_precursor_mass_error);
                }
            }
            else
            {
                accepted_precursor_mass_errors.Add(0.0);
            }
            MassTolerance product_mass_tolerance = new MassTolerance((double)numProductMassTolerance.Value, (MassToleranceUnits)cboProductMassToleranceUnits.SelectedIndex);
            MassType product_mass_type = (MassType)cboProductMassType.SelectedIndex;
            double max_false_discovery_rate = (double)numMaximumFalseDiscoveryRatePercent.Value / 100.0;
            bool consider_modified_unique = chkConsiderModifiedUnique.Checked;
            int max_threads = (int)numMaxThreads.Value;
            bool minimize_memory_usage = chkMinimizeMemoryUsage.Checked;
            string output_folder = txtOutputFolder.Text;
            if(!Directory.Exists(output_folder))
            {
                try
                {
                    Directory.CreateDirectory(output_folder);
                }
                catch
                {
                    if(output_folder.Length > 0)
                    {
                        MessageBox.Show("Invalid output folder: " + output_folder);
                    }
                    else
                    {
                        MessageBox.Show("Invalid output folder");
                    }
                    txtOutputFolder.Focus();
                    return;
                }
            }

            DatabaseSearcher database_searcher = new DatabaseSearcher(data_filepaths,
                min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                absolute_threshold, relative_threshold_percent, max_peaks,
                assign_charge_states, deisotope,
                fasta_filepath, on_the_fly_decoys,
                protease, max_missed_cleavages, initiator_methionine_behavior,
                fixed_modifications, variable_modifications, max_variable_mod_isoforms,
                precursor_mass_tolerance, precursor_mass_type,
                accepted_precursor_mass_errors,
                product_mass_tolerance, product_mass_type,
                max_false_discovery_rate, consider_modified_unique,
                max_threads, minimize_memory_usage,
                output_folder);

            database_searcher.Starting += HandleStarting;
            database_searcher.StartingFile += HandleStartingFile;
            database_searcher.UpdateStatus += HandleUpdateStatus;
            database_searcher.ReportTaskWithoutProgress += HandleReportTaskWithoutProgress;
            database_searcher.ReportTaskWithProgress += HandleReportTaskWithProgress;
            database_searcher.UpdateProgress += HandleUpdateProgress;
            database_searcher.ThrowException += HandleThrowException;
            database_searcher.FinishedFile += HandleFinishedFile;
            database_searcher.Finished += HandleFinished;

            lstData.SelectedItem = null;
            tspbProgress.Value = tspbProgress.Minimum;

            Thread thread = new Thread(new ThreadStart(database_searcher.Search));
            thread.IsBackground = true;
            thread.Start();
        }
示例#20
0
        private static List<MSPeak> AssignChargeStates(IList<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>();

            for(int i = 0; i < peaks.Count; i++)
            {
                int j = i + 1;
                List<int> charges = new List<int>();
                while(j < peaks.Count)
                {
                    if(peaks[j].MZ > (peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    for(int c = polarity * maxAbsoluteCharge; polarity > 0 ? c >= 1 : c <= -1; c -= polarity)
                    {
                        // remove harmonic charges, e.g. don't consider peak as a +2 (0.5 Th spacing) if it could be a +4 (0.25 Th spacing)
                        if(HARMONIC_CHARGE_DETECTION)
                        {
                            bool harmonic = false;
                            foreach(int c2 in charges)
                            {
                                if(c2 % c == 0)
                                {
                                    harmonic = true;
                                    break;
                                }
                            }
                            if(harmonic)
                            {
                                continue;
                            }
                        }

                        if(Math.Abs(MassTolerance.CalculateMassError(peaks[j].MZ, peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE / c, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                        {
                            new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, c, polarity));
                            charges.Add(c);
                        }
                    }

                    j++;
                }
                if(charges.Count == 0)
                {
                    new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, 0, polarity));
                }
            }

            return new_peaks;
        }
示例#21
0
        private void ScoreMatch(MassTolerance productMassTolerance)
        {
            double[] theoretical_product_masses = Peptide.CalculateProductMasses(PRODUCT_TYPES[Spectrum.FragmentationMethod]).ToArray();
            TotalProducts = theoretical_product_masses.Length;

            // speed optimizations
            int num_theoretical_products = theoretical_product_masses.Length;
            double[] experimental_masses = Spectrum.Masses;
            double[] experimental_intensities = Spectrum.Intensities;
            int num_experimental_peaks = experimental_masses.Length;
            double product_mass_tolerance_value = productMassTolerance.Value;
            MassToleranceUnits product_mass_tolerance_units = productMassTolerance.Units;

            MatchingProducts = 0;
            int t = 0;
            int e = 0;
            while(t < num_theoretical_products && e < num_experimental_peaks)
            {
                double mass_difference = experimental_masses[e] - theoretical_product_masses[t];
                if(product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t] * 1e6;
                }
                if(Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingProducts++;
                    t++;
                }
                else if(mass_difference < 0)
                {
                    e++;
                }
                else if(mass_difference > 0)
                {
                    t++;
                }
            }
            MatchingProductsFraction = (double)MatchingProducts / TotalProducts;

            MatchingIntensity = 0.0;
            int e2 = 0;
            int t2 = 0;
            while(e2 < num_experimental_peaks && t2 < num_theoretical_products)
            {
                double mass_difference = experimental_masses[e2] - theoretical_product_masses[t2];
                if(product_mass_tolerance_units == MassToleranceUnits.ppm)
                {
                    mass_difference = mass_difference / theoretical_product_masses[t2] * 1e6;
                }
                if(Math.Abs(mass_difference) <= product_mass_tolerance_value)
                {
                    MatchingIntensity += experimental_intensities[e2];
                    e2++;
                }
                else if(mass_difference < 0)
                {
                    e2++;
                }
                else if(mass_difference > 0)
                {
                    t2++;
                }
            }
            MatchingIntensityFraction = MatchingIntensity / Spectrum.TotalIntensity;

            MorpheusScore = MatchingProducts + MatchingIntensityFraction;
        }
示例#22
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Arguments     arguments = new Arguments(args);
                List <string> data      = new List <string>(arguments["d"].Split(','));
                int           min_assumed_precursor_charge_state = 2;
                if (arguments["minprecz"] != null)
                {
                    min_assumed_precursor_charge_state = int.Parse(arguments["minprecz"]);
                }
                int max_assumed_precursor_charge_state = 4;
                if (arguments["maxprecz"] != null)
                {
                    max_assumed_precursor_charge_state = int.Parse(arguments["maxprecz"]);
                }
                double abs_threshold = -1.0;
                if (arguments["at"] != null)
                {
                    abs_threshold = double.Parse(arguments["at"], CultureInfo.InvariantCulture);
                }
                double rel_threshold_percent = -1.0;
                if (arguments["rt"] != null)
                {
                    rel_threshold_percent = double.Parse(arguments["rt"], CultureInfo.InvariantCulture);
                }
                int max_peaks = 400;
                if (arguments["mp"] != null)
                {
                    max_peaks = int.Parse(arguments["mp"]);
                }
                bool assign_charge_states = true;
                if (arguments["acs"] != null)
                {
                    assign_charge_states = bool.Parse(arguments["acs"]);
                }
                bool deisotope = true;
                if (arguments["di"] != null)
                {
                    deisotope = bool.Parse(arguments["di"]);
                }
                string database = arguments["db"];
                Dictionary <string, Modification> known_variable_modifications = null;
                HashSet <Modification>            variable_mods = new HashSet <Modification>();
                if (Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase))
                {
                    bool no_uniprot_mods = false;
                    if (arguments["noup"] != null)
                    {
                        no_uniprot_mods = bool.Parse(arguments["noup"]);
                    }
                    if (!no_uniprot_mods)
                    {
                        known_variable_modifications = ProteomeDatabaseReader.ReadUniProtXmlModifications(database);
                        variable_mods.UnionWith(known_variable_modifications.Values);
                    }
                }
                bool append_decoys = false;
                if (arguments["ad"] != null)
                {
                    append_decoys = bool.Parse(arguments["ad"]);
                }
                else
                {
                    append_decoys = Path.GetExtension(database).Equals(".xml", StringComparison.InvariantCultureIgnoreCase) || !ProteomeDatabaseReader.HasDecoyProteins(database);
                }
                ProteaseDictionary proteases = ProteaseDictionary.Instance;
                Protease           protease  = proteases["trypsin (no proline rule)"];
                if (arguments["p"] != null)
                {
                    protease = proteases[arguments["p"]];
                }
                int max_missed_cleavages = 2;
                if (arguments["mmc"] != null)
                {
                    max_missed_cleavages = int.Parse(arguments["mmc"]);
                }
                InitiatorMethionineBehavior initiator_methionine_behavior = InitiatorMethionineBehavior.Variable;
                if (arguments["imb"] != null)
                {
                    initiator_methionine_behavior = (InitiatorMethionineBehavior)Enum.Parse(typeof(InitiatorMethionineBehavior), arguments["imb"], true);
                }
                ModificationDictionary mods       = ModificationDictionary.Instance;
                List <Modification>    fixed_mods = new List <Modification>();
                if (arguments["fm"] != null)
                {
                    foreach (string fixed_mod in arguments["fm"].Split(';'))
                    {
                        fixed_mods.Add(mods[fixed_mod]);
                    }
                }
                if (arguments["vm"] != null)
                {
                    foreach (string variable_mod in arguments["vm"].Split(';'))
                    {
                        Modification mod;
                        if (!mods.TryGetValue(variable_mod, out mod))
                        {
                            known_variable_modifications.TryGetValue(variable_mod, out mod);
                        }
                        variable_mods.Add(mod);
                    }
                }
                int max_variable_mod_isoforms_per_peptide = 1024;
                if (arguments["mvmi"] != null)
                {
                    max_variable_mod_isoforms_per_peptide = int.Parse(arguments["mvmi"]);
                }
                double precursor_mass_tolerance_value = 2.1;
                if (arguments["precmtv"] != null)
                {
                    precursor_mass_tolerance_value = double.Parse(arguments["precmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits precursor_mass_tolerance_units = MassToleranceUnits.Da;
                if (arguments["precmtu"] != null)
                {
                    precursor_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["precmtu"], true);
                }
                MassTolerance precursor_mass_tolerance = new MassTolerance(precursor_mass_tolerance_value, precursor_mass_tolerance_units);
                MassType      precursor_mass_type      = MassType.Monoisotopic;
                if (arguments["precmt"] != null)
                {
                    precursor_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["precmt"], true);
                }
                List <double> accepted_precursor_mass_errors = new List <double>();
                if (arguments["apme"] != null && arguments["apme"].Length > 0)
                {
                    foreach (string accepted_precursor_mass_error in arguments["apme"].Split(';'))
                    {
                        accepted_precursor_mass_errors.Add(double.Parse(accepted_precursor_mass_error, CultureInfo.InvariantCulture));
                    }
                }
                else
                {
                    accepted_precursor_mass_errors.Add(0.0);
                }
                double product_mass_tolerance_value = 0.015;
                if (arguments["prodmtv"] != null)
                {
                    product_mass_tolerance_value = double.Parse(arguments["prodmtv"], CultureInfo.InvariantCulture);
                }
                MassToleranceUnits product_mass_tolerance_units = MassToleranceUnits.Da;
                if (arguments["prodmtu"] != null)
                {
                    product_mass_tolerance_units = (MassToleranceUnits)Enum.Parse(typeof(MassToleranceUnits), arguments["prodmtu"], true);
                }
                MassTolerance product_mass_tolerance = new MassTolerance(product_mass_tolerance_value, product_mass_tolerance_units);
                MassType      product_mass_type      = MassType.Monoisotopic;
                if (arguments["prodmt"] != null)
                {
                    product_mass_type = (MassType)Enum.Parse(typeof(MassType), arguments["prodmt"], true);
                }
                double max_fdr = 0.01;
                if (arguments["fdr"] != null)
                {
                    max_fdr = double.Parse(arguments["fdr"], CultureInfo.InvariantCulture) / 100.0;
                }
                bool consider_mods_unique = false;
                if (arguments["cmu"] != null)
                {
                    consider_mods_unique = bool.Parse(arguments["cmu"]);
                }
                int max_threads = Environment.ProcessorCount;
                if (arguments["mt"] != null)
                {
                    max_threads = int.Parse(arguments["mt"]);
                }
                bool minimize_memory_usage = false;
                if (arguments["mmu"] != null)
                {
                    minimize_memory_usage = bool.Parse(arguments["mmu"]);
                }
                string output_folder = Environment.CurrentDirectory;
                if (arguments["o"] != null)
                {
                    output_folder = arguments["o"];
                }

                DatabaseSearcher database_searcher = new DatabaseSearcher(data,
                                                                          min_assumed_precursor_charge_state, max_assumed_precursor_charge_state,
                                                                          abs_threshold, rel_threshold_percent, max_peaks,
                                                                          assign_charge_states, deisotope,
                                                                          database, append_decoys,
                                                                          protease, max_missed_cleavages, initiator_methionine_behavior,
                                                                          fixed_mods, variable_mods, max_variable_mod_isoforms_per_peptide,
                                                                          precursor_mass_tolerance, precursor_mass_type,
                                                                          accepted_precursor_mass_errors,
                                                                          product_mass_tolerance, product_mass_type,
                                                                          max_fdr, consider_mods_unique,
                                                                          max_threads, minimize_memory_usage,
                                                                          output_folder);

                database_searcher.Starting       += HandleStarting;
                database_searcher.StartingFile   += HandleStartingFile;
                database_searcher.UpdateStatus   += HandleUpdateStatus;
                database_searcher.UpdateProgress += HandleUpdateProgress;
                database_searcher.ThrowException += HandleThrowException;
                database_searcher.FinishedFile   += HandleFinishedFile;
                database_searcher.Finished       += HandleFinished;

                database_searcher.Search();
            }
            else
            {
                Console.WriteLine(Program.GetProductNameAndVersion() + " USAGE");
            }
        }
示例#23
0
        public void Load(string mzmlFilepath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState,
            double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks,
            bool assignChargeStates, bool deisotope, MassTolerance isotopicMZTolerance, int maximumThreads)
        {
            OnReportTaskWithoutProgress(EventArgs.Empty);

            XmlDocument mzML_temp = new XmlDocument();
            mzML_temp.Load(mzmlFilepath);
            XPathNavigator mzML = mzML_temp.CreateNavigator();

            XmlNamespaceManager xnm = new XmlNamespaceManager(mzML.NameTable);
            xnm.AddNamespace("mzML", mzML_temp.DocumentElement.NamespaceURI);

            Dictionary<string, XPathNodeIterator> referenceable_param_groups = new Dictionary<string, XPathNodeIterator>();
            foreach(XPathNavigator referenceable_param_group in mzML.Select("//mzML:mzML/mzML:referenceableParamGroupList/mzML:referenceableParamGroup", xnm))
            {
                referenceable_param_groups.Add(referenceable_param_group.GetAttribute("id", string.Empty), referenceable_param_group.SelectChildren(XPathNodeType.All));
            }

            ParallelOptions parallel_options = new ParallelOptions();
            parallel_options.MaxDegreeOfParallelism = maximumThreads;

            Dictionary<string, SpectrumNavigator> ms1s = null;
            if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1)
            {
                ms1s = new Dictionary<string, SpectrumNavigator>();
            #if NON_MULTITHREADED
                foreach(XPathNavigator spectrum_navigator in mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>())
            #else
                Parallel.ForEach(mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>(), parallel_options, spectrum_navigator =>
            #endif
                {
                    string scan_id = spectrum_navigator.GetAttribute("id", string.Empty);
                    int ms_level = -1;

                    foreach(XPathNavigator spectrum_child_navigator in spectrum_navigator.SelectChildren(XPathNodeType.All))
                    {
                        if(spectrum_child_navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                        {
                            if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                            {
                                ms_level = int.Parse(spectrum_child_navigator.GetAttribute("value", string.Empty));
                            }
                        }
                        else if(spectrum_child_navigator.Name.Equals("referenceableParamGroupRef", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach(XPathNavigator navigator in referenceable_param_groups[spectrum_child_navigator.GetAttribute("ref", string.Empty)])
                            {
                                if(navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                                {
                                    if(navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                                    {
                                        ms_level = int.Parse(navigator.GetAttribute("value", string.Empty));
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if(ms_level == 1)
                    {
                        lock(ms1s)
                        {
                            ms1s.Add(scan_id, new SpectrumNavigator(spectrum_navigator, xnm));
                        }
                    }
                }
            #if !NON_MULTITHREADED
                );
            #endif
            }

            int num_spectra = int.Parse(mzML.SelectSingleNode("//mzML:mzML/mzML:run/mzML:spectrumList", xnm).GetAttribute("count", string.Empty));

            OnReportTaskWithProgress(EventArgs.Empty);
            object progress_lock = new object();
            int spectra_processed = 0;
            int old_progress = 0;

            #if NON_MULTITHREADED
            foreach(XPathNavigator spectrum_navigator in mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>())
            #else
            Parallel.ForEach(mzML.Select("//mzML:mzML/mzML:run/mzML:spectrumList/mzML:spectrum", xnm).Cast<XPathNavigator>(), parallel_options, spectrum_navigator =>
            #endif
            {
                int spectrum_index = int.Parse(spectrum_navigator.GetAttribute("index", string.Empty));
                int spectrum_number = spectrum_index + 1;
                string spectrum_id = spectrum_navigator.GetAttribute("id", string.Empty);
                string spectrum_title = null;
                int ms_level = -1;
                int polarity = 0;
                double retention_time_minutes = double.NaN;
                string precursor_scan_id = null;
                double precursor_mz = double.NaN;
                int charge = 0;
                double precursor_intensity = double.NaN;
                string fragmentation_method = "collision-induced dissociation";
                double[] mz = null;
                double[] intensity = null;

                foreach(XPathNavigator spectrum_child_navigator in spectrum_navigator.SelectChildren(XPathNodeType.All))
                {
                    if(spectrum_child_navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                    {
                        if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                        {
                            ms_level = int.Parse(spectrum_child_navigator.GetAttribute("value", string.Empty));
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("positive scan", StringComparison.OrdinalIgnoreCase))
                        {
                            polarity = 1;
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("negative scan", StringComparison.OrdinalIgnoreCase))
                        {
                            polarity = -1;
                        }
                        else if(spectrum_child_navigator.GetAttribute("name", string.Empty).Equals("spectrum title", StringComparison.OrdinalIgnoreCase))
                        {
                            spectrum_title = spectrum_child_navigator.GetAttribute("value", string.Empty);
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("referenceableParamGroupRef", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach(XPathNavigator navigator in referenceable_param_groups[spectrum_child_navigator.GetAttribute("ref", string.Empty)])
                        {
                            if(navigator.Name.Equals("cvParam", StringComparison.OrdinalIgnoreCase))
                            {
                                if(navigator.GetAttribute("name", string.Empty).Equals("ms level", StringComparison.OrdinalIgnoreCase))
                                {
                                    ms_level = int.Parse(navigator.GetAttribute("value", string.Empty));
                                }
                                else if(navigator.GetAttribute("name", string.Empty).Equals("positive scan", StringComparison.OrdinalIgnoreCase))
                                {
                                    polarity = 1;
                                }
                                else if(navigator.GetAttribute("name", string.Empty).Equals("negative scan", StringComparison.OrdinalIgnoreCase))
                                {
                                    polarity = -1;
                                }
                            }
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("scanList", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach(XPathNavigator navigator in spectrum_child_navigator.Select("mzML:scan/mzML:cvParam", xnm))
                        {
                            if(navigator.GetAttribute("name", string.Empty).Equals("scan start time", StringComparison.OrdinalIgnoreCase))
                            {
                                retention_time_minutes = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                                if(navigator.GetAttribute("unitName", string.Empty).StartsWith("s", StringComparison.OrdinalIgnoreCase))
                                {
                                    retention_time_minutes = TimeSpan.FromSeconds(retention_time_minutes).TotalMinutes;
                                }
                            }
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("precursorList", StringComparison.OrdinalIgnoreCase))
                    {
                        XPathNavigator precursor_node = spectrum_child_navigator.SelectSingleNode("mzML:precursor", xnm);
                        precursor_scan_id = precursor_node.GetAttribute("spectrumRef", string.Empty);
                        foreach(XPathNavigator navigator in precursor_node.Select("mzML:selectedIonList/mzML:selectedIon/mzML:cvParam", xnm))
                        {
                            if(navigator.GetAttribute("name", string.Empty).Equals("selected ion m/z", StringComparison.OrdinalIgnoreCase))
                            {
                                precursor_mz = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                            }
                            else if(navigator.GetAttribute("name", string.Empty).Equals("charge state", StringComparison.OrdinalIgnoreCase))
                            {
                                charge = int.Parse(navigator.GetAttribute("value", string.Empty));
                                if(polarity < 0)
                                {
                                    charge = -charge;
                                }
                            }
                            else if(navigator.GetAttribute("name", string.Empty).Equals("peak intensity", StringComparison.OrdinalIgnoreCase))
                            {
                                precursor_intensity = double.Parse(navigator.GetAttribute("value", string.Empty), CultureInfo.InvariantCulture);
                            }
                        }
                        XPathNavigator navigator2 = spectrum_child_navigator.SelectSingleNode("mzML:precursor/mzML:activation/mzML:cvParam", xnm);
                        if(navigator2 != null)
                        {
                            fragmentation_method = navigator2.GetAttribute("name", string.Empty);
                        }
                    }
                    else if(spectrum_child_navigator.Name.Equals("binaryDataArrayList", StringComparison.OrdinalIgnoreCase))
                    {
                        ReadDataFromSpectrumNavigator(spectrum_child_navigator.Select("mzML:binaryDataArray/*", xnm), out mz, out intensity);
                    }
                    if(ms_level == 1)
                    {
                        break;
                    }
                }

                if(ms_level >= 2)
                {
                    if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1 && precursor_scan_id != null)
                    {
                        SpectrumNavigator ms1;
                        if(ms1s.TryGetValue(precursor_scan_id, out ms1))
                        {
                            double[] ms1_mz;
                            double[] ms1_intensity;
                            ms1.GetSpectrum(out ms1_mz, out ms1_intensity);
                            int index = -1;
                            for(int i = ms1_mz.GetLowerBound(0); i <= ms1_mz.GetUpperBound(0); i++)
                            {
                                if(index < 0 || Math.Abs(ms1_mz[i] - precursor_mz) < Math.Abs(ms1_mz[index] - precursor_mz))
                                {
                                    index = i;
                                }
                            }
                            precursor_mz = ms1_mz[index];
                            precursor_intensity = ms1_intensity[index];
                        }
                    }

                    if(mz != null && intensity != null && mz.Length > 0 && intensity.Length > 0)
                    {
                        List<MSPeak> peaks = new List<MSPeak>(mz.Length);
                        for(int i = 0; i < mz.Length; i++)
                        {
                            peaks.Add(new MSPeak(mz[i], intensity[i], 0, polarity));
                        }

                        peaks = FilterPeaks(peaks, absoluteThreshold, relativeThresholdPercent, maximumNumberOfPeaks);
                        if(peaks.Count > 0)
                        {
                            peaks.Sort(MSPeak.AscendingMZComparison);
                            for(int c = (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? minimumAssumedPrecursorChargeState : charge);
                                c <= (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? maximumAssumedPrecursorChargeState : charge); c++)
                            {
                                List<MSPeak> new_peaks = peaks;
                                if(assignChargeStates)
                                {
                                    new_peaks = AssignChargeStates(new_peaks, c, polarity, isotopicMZTolerance);
                                    if(deisotope)
                                    {
                                        new_peaks = Deisotope(new_peaks, c, polarity, isotopicMZTolerance);
                                    }
                                }

                                double precursor_mass = MSPeak.MassFromMZ(precursor_mz, c);

                                TandemMassSpectrum spectrum = new TandemMassSpectrum(mzmlFilepath, spectrum_number, spectrum_id, spectrum_title, retention_time_minutes, fragmentation_method, precursor_mz, precursor_intensity, c, precursor_mass, new_peaks);
                                lock(this)
                                {
                                    Add(spectrum);
                                }
                            }
                        }
                    }
                }

                lock(progress_lock)
                {
                    spectra_processed++;
                    int new_progress = (int)((double)spectra_processed / num_spectra * 100);
                    if(new_progress > old_progress)
                    {
                        OnUpdateProgress(new ProgressEventArgs(new_progress));
                        old_progress = new_progress;
                    }
                }
            }
            #if !NON_MULTITHREADED
            );
            #endif
        }