Esempio n. 1
0
        public static int CountMatches(double[] massesArray, MsmsPeakAnnotation[] descriptionsArray, double[] specMasses, float[] specIntensities,
                                       double tol, string tolUnit, out MsmsPeakAnnotation[] description,
                                       out float[] intensities, out float[] massDiffs, out int n)
        {
            if (specMasses == null)
            {
                n           = 0;
                description = new MsmsPeakAnnotation[0];
                intensities = new float[0];
                massDiffs   = new float[0];
                return(0);
            }
            int npeaks = specMasses.Length;

            if (npeaks == 0)
            {
                n           = 0;
                description = new MsmsPeakAnnotation[0];
                intensities = new float[0];
                massDiffs   = new float[0];
                return(0);
            }
            int k = 0;

            n = 0;
            List <MsmsPeakAnnotation> desc = null;
            List <float> intens            = null;
            List <float> dm = null;

            if (descriptionsArray != null)
            {
                desc   = new List <MsmsPeakAnnotation>();
                intens = new List <float>();
                dm     = new List <float>();
            }
            for (int i = 0; i < massesArray.Length; i++)
            {
                double m = massesArray[i];
                n++;
                int ind = ArrayUtil.ClosestIndex(specMasses, m);
                if (ind != -1 && Match(m, specMasses[ind], tol, tolUnit))
                {
                    k++;
                    if (descriptionsArray != null)
                    {
                        desc.Add(descriptionsArray[i]);
                        intens.Add(specIntensities[ind]);
                        dm.Add((float)(m - specMasses[ind]));
                    }
                }
            }
            description = null;
            intensities = null;
            massDiffs   = null;
            if (descriptionsArray != null)
            {
                description = desc.ToArray();
                intensities = intens.ToArray();
                massDiffs   = dm.ToArray();
            }
            return(k);
        }