public void TestChargeStateSplit(string path) { var data = File.ReadAllLines(path); var map = new Dictionary <int, List <MSFeatureLight> >(); for (var i = 1; i < data.Length; i++) { var feature = new MSFeatureLight(); var msFeatureData = data[i].Split(','); feature.ChargeState = Convert.ToInt32(msFeatureData[0]); feature.MassMonoisotopic = Convert.ToDouble(msFeatureData[1]); feature.Scan = Convert.ToInt32(msFeatureData[2]); feature.Abundance = Convert.ToInt64(msFeatureData[3]); if (!map.ContainsKey(feature.ChargeState)) { map.Add(feature.ChargeState, new List <MSFeatureLight>()); } map[feature.ChargeState].Add(feature); } var features = new List <UMCLight>(); foreach (var charge in map.Keys) { var feature = new UMCLight(); foreach (var msFeature in map[charge]) { feature.AddChildFeature(msFeature); } feature.CalculateStatistics(ClusterCentroidRepresentation.Median); features.Add(feature); } var finder = new MsFeatureTreeClusterer <MSFeatureLight, UMCLight>(); var comparison = finder.CompareMonoisotopic(features[0], features[1]); Assert.AreNotEqual(comparison, 0); }
public void TestChargeStateSplit(string path) { var data = File.ReadAllLines(path); var map = new Dictionary<int, List<MSFeatureLight>>(); for (var i = 1; i < data.Length; i++) { var feature = new MSFeatureLight(); var msFeatureData = data[i].Split(','); feature.ChargeState = Convert.ToInt32(msFeatureData[0]); feature.MassMonoisotopic = Convert.ToDouble(msFeatureData[1]); feature.Scan = Convert.ToInt32(msFeatureData[2]); feature.Abundance = Convert.ToInt64(msFeatureData[3]); if (!map.ContainsKey(feature.ChargeState)) { map.Add(feature.ChargeState, new List<MSFeatureLight>()); } map[feature.ChargeState].Add(feature); } var features = new List<UMCLight>(); foreach (var charge in map.Keys) { var feature = new UMCLight(); foreach (var msFeature in map[charge]) { feature.AddChildFeature(msFeature); } feature.CalculateStatistics(ClusterCentroidRepresentation.Median); features.Add(feature); } var finder = new MsFeatureTreeClusterer<MSFeatureLight, UMCLight>(); var comparison = finder.CompareMonoisotopic(features[0], features[1]); Assert.AreNotEqual(comparison, 0); }
public void CreateFeaturesTest(string relativePath, string outputPath) { var path = GetPath(relativePath); var tolerances = new FeatureTolerances { Mass = 13, Net = .01, DriftTime = 30, FragmentationWindowSize = .5 }; var reader = new MsFeatureLightFileReader(); var rawFeatures = reader.ReadFile(path); var msFilterOptions = new MsFeatureFilteringOptions { ChargeRange = new FilterRange(1,6), MinimumIntensity = 200000, ShouldUseDeisotopingFilter = true, ShouldUseIntensityFilter = true }; rawFeatures = LcmsFeatureFilters.FilterMsFeatures(rawFeatures, msFilterOptions); var finder = new MsFeatureTreeClusterer<MSFeatureLight, UMCLight> {Tolerances = tolerances}; finder.Progress += (sender, args) => Console.WriteLine(args.Message); var features = finder.Cluster(rawFeatures.ToList()); var filterOptions = new LcmsFeatureFilteringOptions { FeatureLengthRange = new FilterRange { Maximum = 30, Minimum = 10 } }; features = LcmsFeatureFilters.FilterFeatures(features, filterOptions); Console.WriteLine(@"Found - {0} features", features.Count); using (var writer = File.CreateText(GetPath(outputPath))) { var index = 0; foreach (var feature in features) { feature.Id = index++; feature.CalculateStatistics(ClusterCentroidRepresentation.Mean); writer.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}", TextDelimiter, feature.Net, feature.ChargeState, feature.Mz, feature.Scan, feature.MassMonoisotopic, feature.MassMonoisotopicAligned, feature.Id, feature.ScanStart, feature.ScanEnd, feature.ScanAligned ); } } }
/// <summary> /// Finds features /// </summary> /// <returns></returns> public List<UMCLight> FindFeatures(List<MSFeatureLight> msFeatures, LcmsFeatureFindingOptions options, ISpectraProvider provider) { var clusterer = new MsFeatureTreeClusterer<MSFeatureLight, UMCLight> { Tolerances = new FeatureTolerances { Mass = options.InstrumentTolerances.Mass, Net = options.MaximumNetRange }, ScanTolerance = options.MaximumScanRange, SpectraProvider = provider //TODO: Make sure we have a mass range for XIC's too.... }; clusterer.SpectraProvider = provider; OnStatus("Starting cluster definition"); clusterer.Progress += (sender, args) => OnStatus(args.Message); var features = clusterer.Cluster(msFeatures); var minScan = int.MaxValue; var maxScan = int.MinValue; foreach (var feature in msFeatures) { minScan = Math.Min(feature.Scan, minScan); maxScan = Math.Max(feature.Scan, maxScan); } var id = 0; var newFeatures = new List<UMCLight>(); foreach (var feature in features) { if (feature.MsFeatures.Count < 1) continue; feature.Net = Convert.ToDouble(feature.Scan - minScan)/Convert.ToDouble(maxScan - minScan); feature.CalculateStatistics(ClusterCentroidRepresentation.Median); feature.Net = feature.Net; feature.Id = id++; newFeatures.Add(feature); //Sets the width of the feature to be the width of the peak, not the width of the tails var maxAbundance = double.MinValue; var maxAbundanceIndex = 0; for (var msFeatureIndex = 0; msFeatureIndex < feature.MsFeatures.Count - 1; msFeatureIndex++) { var msFeature = feature.MsFeatures[msFeatureIndex]; if (msFeature.Abundance > maxAbundance) { maxAbundance = msFeature.Abundance; maxAbundanceIndex = msFeatureIndex; } } for (var msFeatureIndex = maxAbundanceIndex; msFeatureIndex > 0; msFeatureIndex--) { if (feature.MsFeatures[msFeatureIndex].Abundance / maxAbundance <= 0.05) { feature.ScanStart = feature.MsFeatures[msFeatureIndex].Scan; break; } } for (var msFeatureIndex = maxAbundanceIndex; msFeatureIndex < feature.MsFeatures.Count - 1; msFeatureIndex++) { if (feature.MsFeatures[msFeatureIndex].Abundance / maxAbundance <= 0.05) { feature.ScanEnd = feature.MsFeatures[msFeatureIndex].Scan; break; } } } return features; }
public void CreateFeaturesTest(string relativePath, string outputPath) { var path = GetPath(relativePath); var tolerances = new FeatureTolerances { Mass = 13, Net = .01, DriftTime = 30, FragmentationWindowSize = .5 }; var reader = new MsFeatureLightFileReader(); var rawFeatures = reader.ReadFile(path); var msFilterOptions = new MsFeatureFilteringOptions { ChargeRange = new FilterRange(1, 6), MinimumIntensity = 200000, ShouldUseDeisotopingFilter = true, ShouldUseIntensityFilter = true }; rawFeatures = LcmsFeatureFilters.FilterMsFeatures(rawFeatures, msFilterOptions); var finder = new MsFeatureTreeClusterer <MSFeatureLight, UMCLight> { Tolerances = tolerances }; finder.Progress += (sender, args) => Console.WriteLine(args.Message); var features = finder.Cluster(rawFeatures.ToList()); var filterOptions = new LcmsFeatureFilteringOptions { FeatureLengthRangeScans = new FilterRange { Maximum = 30, Minimum = 10 } }; features = LcmsFeatureFilters.FilterFeatures(features, filterOptions); Console.WriteLine(@"Found - {0} features", features.Count); using (var writer = File.CreateText(GetPath(outputPath))) { var index = 0; foreach (var feature in features) { feature.Id = index++; feature.CalculateStatistics(ClusterCentroidRepresentation.Mean); writer.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}", TextDelimiter, feature.Net, feature.ChargeState, feature.Mz, feature.Scan, feature.MassMonoisotopic, feature.MassMonoisotopicAligned, feature.Id, feature.ScanStart, feature.ScanEnd, feature.ScanAligned ); } } }