示例#1
0
        /// <summary>
        /// Add a element to the cluster.
        /// </summary>
        /// <param name="e">The element to add.</param>
        public void Add(T e)
        {
            if (_centroid == null)
            {
                _centroid = ((ICentroidFactory <T>)e) as ICentroid <T>;
            }
            else
            {
                _centroid.Add(e);
            }

            _contents.Add(e);
        }
示例#2
0
        private void Orbitrap_MsScanArrived(object sender, MsScanEventArgs e)
        {
            // If examining code takes longer, in particular for some scans, it is wise
            // to use a processing queue in order to get the system as responsive as possible.

            using (IMsScan scan = (IMsScan)e.GetScan())                 // caution! You must dispose this, or you block shared memory!
            {
                Console.WriteLine("\n{0:HH:mm:ss,fff} scan with {1} centroids arrived", DateTime.Now, scan.CentroidCount);
#if ProfileAccessInsideEnumeration
                int max = 5;
                foreach (ICentroid c in scan.Centroids)
                {
                    if (max-- == 0)
                    {
                        break;
                    }
                    Console.Write("{0:F4},{1:0.0e0},z={2}  :  ", c.Mz, c.Intensity, c.Charge);

                    // Access to profile information is done INSIDE the enumeration of centroids: profile is available:
                    Console.WriteLine(string.Join("; ", c.Profile.Take(5).Select(n => string.Format("{0:F4},{1:0.0e0}", n.Mz, n.Intensity))));
                }
#elif ProfileAccessOutsideEnumeration
                ICentroid[] list = scan.Centroids.ToArray();
                for (int i = 0; i < Math.Min(5, list.Length); i++)
                {
                    ICentroid c = list[i];
                    Console.Write("{0:F4},{1:0.0e0},z={2}  :  ", c.Mz, c.Intensity, c.Charge);                          // works

                    // Access to profile information is done OUTSIDE the enumeration of centroids, which is done by ToArray(), no profile is available:
                    Console.WriteLine(string.Join("; ", c.Profile.Take(5).Select(n => string.Format("{0:F4},{1:0.0e0}", n.Mz, n.Intensity))));                     // crashes
                }
#else
                // Create an array where the profile is copied on enumeration if the above solution with ProfileAccessInsideEnumeration
                // does not fit. The way of processing shown here requies more memory and is slower.
                Tuple <ICentroid, IMassIntensity[]>[] list = scan.Centroids.Select(n => new Tuple <ICentroid, IMassIntensity[]>(n, (IMassIntensity[])n.Profile.Clone())).ToArray();
                for (int i = 0; i < Math.Min(5, list.Length); i++)
                {
                    Tuple <ICentroid, IMassIntensity[]> tuple = list[i];
                    Console.Write("{0:F4},{1:0.0e0},z={2}  :  ", tuple.Item1.Mz, tuple.Item1.Intensity, tuple.Item1.Charge);                      // works
                    Console.WriteLine(string.Join("; ", tuple.Item2.Take(5).Select(n => string.Format("{0:F4},{1:0.0e0}", n.Mz, n.Intensity))));  // works
                }
#endif
            }
        }
示例#3
0
 /// <summary>
 /// Create a cluster with one initial data point.
 /// </summary>
 /// <param name="d">The initial data point.</param>
 public Cluster(T d)
 {
     _contents.Add(d);
     _centroid = ((ICentroidFactory <T>)d).CreateCentroid();
 }
示例#4
0
 public Cluster(int id, IMean mean, ICentroid centroid)
 {
     Id       = id;
     Mean     = mean;
     Centroid = centroid;
 }