예제 #1
0
        /**
         * Filters spectrum by number of highest abundance ions and by base peak percentage
         * @param s spectrum
         * @param topIons number of top ions to retain
         * @param basePeakPercentage percentage of base peak above which to retain
         * @return filtered spectrum
         */
        protected ISpectrum filterSpectrum(ISpectrum s, int topIons, double basePeakPercentage)
        {
            List <Ion> ions = s.GetIons();

            // Find base peak intensity
            double basePeakIntensity = 0.0;

            foreach (Ion ion in ions)
            {
                if (ion.Intensity > basePeakIntensity)
                {
                    basePeakIntensity = ion.Intensity;
                }
            }

            // Filter by base peak percentage if needed
            if (basePeakPercentage >= 0)
            {
                List <Ion> filteredIons = new List <Ion>();

                foreach (Ion ion in ions)
                {
                    if (ion.Intensity + EPSILON >= basePeakPercentage * basePeakIntensity)
                    {
                        filteredIons.Add(new Ion(ion.MZ, ion.Intensity));
                    }
                }

                ions = filteredIons;
            }

            // Filter by top ions if necessary
            if (topIons > 0 && ions.Count > topIons)
            {
                ions = ions.OrderByDescending(i => i.Intensity).ThenBy(m => m.MZ).ToList();

                ions = ions.GetRange(0, topIons);
            }

            return(new MSSpectrum(ions));
        }
예제 #2
0
        /**
         * Filters spectrum by number of highest abundance ions and by base peak percentage
         * @param s spectrum
         * @param topIons number of top ions to retain
         * @param basePeakPercentage percentage of base peak above which to retain
         * @return filtered spectrum
         */
        protected ISpectrum filterSpectrum(ISpectrum s, int topIons, double basePeakPercentage)
        {
            List<Ion> ions = s.GetIons();

            // Find base peak intensity
            double basePeakIntensity = 0.0;

            foreach (Ion ion in ions)
            {
                if (ion.Intensity > basePeakIntensity)
                    basePeakIntensity = ion.Intensity;
            }

            // Filter by base peak percentage if needed
            if (basePeakPercentage >= 0)
            {
                List<Ion> filteredIons = new List<Ion>();

                foreach (Ion ion in ions)
                {
                    if (ion.Intensity + EPSILON >= basePeakPercentage * basePeakIntensity)
                        filteredIons.Add(new Ion(ion.MZ, ion.Intensity));
                }

                ions = filteredIons;
            }

            // Filter by top ions if necessary
            if (topIons > 0 && ions.Count > topIons)
            {
                ions = ions.OrderByDescending(i => i.Intensity).ThenBy(m => m.MZ).ToList();

                ions = ions.GetRange(0, topIons);
            }

            return new MSSpectrum(ions);
        }