/// <summary> /// Inserts a new feature tree into the mix... /// </summary> protected override void Insert(FeatureTree <T, U> node, T feature) { if (node == null) { node = new FeatureTree <T, U>(m_func); } node.Insert(feature); }
protected override void Add(T feature) { m_features.Add(feature); m_left = new FeatureTree <T, U>(m_func); m_right = new FeatureTree <T, U>(m_func); }
/// <summary> /// Clusters features based on some specified values. /// </summary> /// <param name="features"></param> /// <returns></returns> public List <TParentFeature> Cluster(List <TChildFeature> features, IProgress <ProgressData> progress = null) { var progressData = new ProgressData(progress); var clusters = new List <TParentFeature>(); var currentIndex = 0; int i = 0; //var n = features.Count(); // Sort the features based on m/z first //var msFeatures = new List<TChild>(); //msFeatures.AddRange(features); var msFeatures = features.ToList(); var n = msFeatures.Count; OnProgress("Sorting features for partitioning step"); msFeatures.Sort(sortFunction); OnProgress("Examining features within partitions"); // Iterate through all of the features while (currentIndex < n) { var hasGap = false; var lastFeature = msFeatures[currentIndex]; var lastIndex = currentIndex + 1; var gapFeatures = new List <TChildFeature> { lastFeature }; while (!hasGap && lastIndex < n) { i++; var currentFeature = msFeatures[lastIndex]; var massDiff = this.massDiffFunc(currentFeature, lastFeature); // Time to quit if (Math.Abs(massDiff) > massTolerance) { // Stop here... hasGap = true; } else { // Increment and save this feature lastIndex++; gapFeatures.Add(currentFeature); lastFeature = currentFeature; } } currentIndex = lastIndex; // Now that we have a gap...let's go a head and start building the features // first we build a scan dictionary // sorted by scans var featureMap = new Dictionary <int, List <TChildFeature> >(); foreach (var feature in gapFeatures) { var scan = feature.Scan; if (!featureMap.ContainsKey(scan)) { featureMap.Add(scan, new List <TChildFeature>()); } featureMap[scan].Add(feature); } // Now build the tree...where each node is a feature. var scans = featureMap.Keys.OrderBy(x => x); var tree = new FeatureTree <TChildFeature, TParentFeature>(comparison); foreach (var feature in scans.SelectMany(scan => featureMap[scan])) { tree.Insert(feature); } var newFeatures = tree.Build(); clusters.AddRange(newFeatures); progressData.Report(i, n); } return(clusters); }