public void GetMainSubgroup(FeatureGroup group) { FeatureGroup mainSubGroup = new FeatureGroup(); double startTime = group.ApexTime - .005; double stopTime = group.ApexTime + .005; startTime = group.ApexTime; stopTime = group.ApexTime; Tuple <double, double> apexWindow = GetApexTimeWindow(group.allFeatures.First(), GetRTPeakIndex(group.allFeatures.First(), group.allFeatures.First().MaxPeak)); startTime = apexWindow.Item1; stopTime = apexWindow.Item2; foreach (Feature feature in group.allFeatures) { if (ApexCheck(feature, startTime, stopTime)) { mainSubGroup.AddFeature(feature); } } mainSubGroup.ApexTime = group.ApexTime; mainSubGroup.DoApexCalculations(); group.mainSubGroup = mainSubGroup; group.SubGroups.Add(mainSubGroup); }
private IEnumerable <FeatureGroup> GroupFeatures(IEnumerable <Feature> features, double time, int minNumberFragments = 5) { List <Feature> totalFeatures = features.OrderByDescending(f => f.MaxIntensity).ToList(); while (totalFeatures.Count > 0) { Feature maxfeature = totalFeatures[0]; totalFeatures.RemoveAt(0); double maxFeatureApex = maxfeature.ApexTime; FeatureGroup group = new FeatureGroup(maxfeature); group.ApexTime = maxFeatureApex; double minTime = maxFeatureApex - time / 2; double maxTime = maxFeatureApex + time / 2; int i = 0; while (i < totalFeatures.Count) { var feature = totalFeatures[i]; if (minTime <= feature.ApexTime && feature.ApexTime <= maxTime) { group.AddFeature(feature); totalFeatures.RemoveAt(i); } else { i++; } } if (group.Count >= minNumberFragments) { yield return(group); } } }
public void GetFeatureSubGroups(FeatureGroup group, int nextSubGroupPointer, int numFeaturesInSubGroups) { bool nextSubGroupPointerFound = false; if (numFeaturesInSubGroups != group.allFeatures.Count) { Feature maxFeature = group.allFeatures[nextSubGroupPointer]; // if (maxFeature.MaxPeak.Intensity < group.maxFeature.MaxPeak.Intensity * .06 || maxFeature.MaxPeak.Intensity < 100000 ) if (maxFeature.MaxPeak.Intensity < group.maxFeature.MaxPeak.Intensity * .06) { return; } //Binary search to the appropriate index (you'll need to store the actual RTPeak instead of just the intensity and time) int startIndex = GetRTPeakIndex(maxFeature, maxFeature.MaxPeak); //Get the apex time window for 93.5% intensity threshold Tuple <double, double> ApexTimeWindow = GetApexTimeWindow(maxFeature, startIndex); //Create a new subgroup, add the feature to the subgroup. FeatureGroup newSubGroup = new FeatureGroup(maxFeature); newSubGroup.ApexTime = maxFeature.ApexTime; //Check whether this has been included in a sub group. If not set that flag to true and increment numFeaturesInSubGroups. if (!maxFeature.includedInSubGroup) { maxFeature.includedInSubGroup = true; numFeaturesInSubGroups++; } maxFeature.numSubGroups++; //Iterate over all features in the group and see if their apexes align for (int i = 0; i < group.allFeatures.Count; i++) { //Check whether there is an apex for the feature if (ApexCheck(feature, 93.5 start, 93.5 stop))... Add to subgroup, if Feature hasn't been in a subgroup yet if (i != nextSubGroupPointer) { Feature currFeature = group.allFeatures[i]; if (ApexCheck(currFeature, ApexTimeWindow.Item1, ApexTimeWindow.Item2)) { newSubGroup.AddFeature(currFeature); if (!currFeature.includedInSubGroup) { currFeature.includedInSubGroup = true; numFeaturesInSubGroups++; } currFeature.numSubGroups++; } else { if (i > nextSubGroupPointer && !nextSubGroupPointerFound && !currFeature.includedInSubGroup) { nextSubGroupPointer = i; nextSubGroupPointerFound = true; } } } } newSubGroup.DoApexCalculations(); if (newSubGroup.allFeatures.Count > 1) { group.SubGroups.Add(newSubGroup); } GetFeatureSubGroups(group, nextSubGroupPointer, numFeaturesInSubGroups); } }