public void TestBuildWaterShedMap() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var targetMz = 643.27094937; double ppmTolerance = 50; var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref intensityBlock); var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0).ToList(); Console.WriteLine(intensityBlock.Length); Assert.AreEqual(270000, intensityBlock.Length); Assert.AreEqual(12969, pointList.Count); Assert.AreEqual(pointList[1000].Intensity, 14.844082, 0.0001); Assert.AreEqual(pointList[5000].Intensity, 5.760, 0.0001); }
public void TestGetXic() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var targetMz = 582.32181703760114; double ppmTolerance = 25; var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, DataReader.FrameType.MS1, DataReader.ToleranceType.PPM); Console.WriteLine(intensityBlock.Length); }
public void Test3DSmooth() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var targetMz = 643.27094937; double ppmTolerance = 50; var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, DataReader.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref intensityBlock); Console.WriteLine(intensityBlock.Length); }
public void TestDoWaterShedAlgorithm() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var targetMz = 582.32181703760114; double ppmTolerance = 25; var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(11, 2); smoother.Smooth(ref intensityBlock); var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0); var featureList = FeatureDetection.DoWatershedAlgorithm(pointList); foreach (var featureBlob in featureList) { var mostIntensePoint = featureBlob.PointList.First(); Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity); } Console.WriteLine("******************************************************"); var intensityPointList = uimfUtil.GetXic(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var newPointList = WaterShedMapUtil.BuildWatershedMap(intensityPointList); smoother.Smooth(ref newPointList); var newFeatureList = FeatureDetection.DoWatershedAlgorithm(newPointList); foreach (var featureBlob in newFeatureList) { var mostIntensePoint = featureBlob.PointList.First(); Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity); } }
public void TestFragmentCorrelation() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var parentMz = 643.27094937; double ppmTolerance = 50; var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref parentIntensityBlock); // ReSharper disable RedundantArgumentDefaultValue var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0); // ReSharper restore RedundantArgumentDefaultValue var parentFeature = FeatureDetection.DoWatershedAlgorithm(parentPointList).First(); using (var fragmentReader = new StreamReader(@"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\testFiles\fragments.csv")) { while (!fragmentReader.EndOfStream) { var dataLine = fragmentReader.ReadLine(); if (string.IsNullOrWhiteSpace(dataLine)) { continue; } var mzString = dataLine.Trim(); var targetMz = double.Parse(mzString); TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv"); var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS2, DataReader.ToleranceType.PPM); var boundX = intensityBlock.GetUpperBound(0); var boundY = intensityBlock.GetUpperBound(1); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } unsmoothedWriter.WriteLine(row.ToString()); } unsmoothedWriter.Close(); smoother.Smooth(ref intensityBlock); TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv"); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } smoothedWriter.WriteLine(row.ToString()); } smoothedWriter.Close(); // ReSharper disable RedundantArgumentDefaultValue var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0); // ReSharper restore RedundantArgumentDefaultValue var featureList = FeatureDetection.DoWatershedAlgorithm(pointList); featureList = featureList.Where(x => x.PointList.Count > 50).OrderByDescending(x => x.PointList.Count); Console.WriteLine("******************************************************"); Console.WriteLine("targetMz = " + targetMz); foreach (var featureBlob in featureList) { // ReSharper disable once UnusedVariable var rSquared = FeatureCorrelator.CorrelateFeatures(parentFeature, featureBlob); //Point mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First(); //Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity + "\tRSquared = " + rSquared); } } } }
public void TestDoWaterShedAlgorithmPrecursorAndFragments() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var parentMz = 643.27094937; double ppmTolerance = 50; var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref parentIntensityBlock); // ReSharper disable RedundantArgumentDefaultValue var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0); // ReSharper restore RedundantArgumentDefaultValue var parentFeature = FeatureDetection.DoWatershedAlgorithm(parentPointList).First(); var statistics = parentFeature.Statistics; var scanLcMin = statistics.ScanLcMin; var scanLcMax = statistics.ScanLcMax; var scanImsMin = statistics.ScanImsMin; var scanImsMax = statistics.ScanImsMax; using (var fragmentReader = new StreamReader(@"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\testFiles\OneFragment.csv")) { while (!fragmentReader.EndOfStream) { var dataLine = fragmentReader.ReadLine(); if (string.IsNullOrWhiteSpace(dataLine)) { continue; } var mzString = dataLine.Trim(); var targetMz = double.Parse(mzString); TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv"); var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS2, scanLcMin, scanLcMax, scanImsMin, scanImsMax, DataReader.ToleranceType.PPM); var boundX = intensityBlock.GetUpperBound(0); var boundY = intensityBlock.GetUpperBound(1); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } unsmoothedWriter.WriteLine(row.ToString()); } unsmoothedWriter.Close(); smoother.Smooth(ref intensityBlock); TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv"); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } smoothedWriter.WriteLine(row.ToString()); } smoothedWriter.Close(); var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, scanLcMin, scanImsMin).ToList(); var featureList = FeatureDetection.DoWatershedAlgorithm(pointList).ToList(); Assert.AreEqual(430, pointList.Count); Assert.AreEqual(37, featureList.Count); Console.WriteLine("******************************************************"); Console.WriteLine("targetMz = " + targetMz); for (var i = 0; i < featureList.Count; i++) { var featureBlob = featureList[i]; var mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First(); Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity); if (i != 1) { continue; } // Num Points = 34 LC = 138 IMS = 122 Intensity = 79.5697959183673 Assert.AreEqual(34, featureBlob.PointList.Count); Assert.AreEqual(138, mostIntensePoint.ScanLc); Assert.AreEqual(122, mostIntensePoint.ScanIms); Assert.AreEqual(79.569796, mostIntensePoint.Intensity, 0.0001); } } } }
public void TestDoWaterShedAlgorithmOutput() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var targetMz = 643.27094937; double ppmTolerance = 50; TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw.csv"); var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, UIMFData.FrameType.MS1, DataReader.ToleranceType.PPM); var boundX = intensityBlock.GetUpperBound(0); var boundY = intensityBlock.GetUpperBound(1); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } unsmoothedWriter.WriteLine(row.ToString()); } unsmoothedWriter.Close(); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref intensityBlock); TextWriter smoothedWriter = new StreamWriter("smoothedRaw.csv"); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } smoothedWriter.WriteLine(row.ToString()); } smoothedWriter.Close(); var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, 0, 0); var featureList = FeatureDetection.DoWatershedAlgorithm(pointList).ToList(); Console.WriteLine(featureList.Count); var sortedFeatureList = featureList.OrderByDescending(x => x.PointList.Count); TextWriter intensityWriter = new StreamWriter("intensities.csv"); foreach (var featureBlob in sortedFeatureList) { var mostIntensePoint = featureBlob.PointList.First(); Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity); intensityWriter.WriteLine(mostIntensePoint.Intensity.ToString(CultureInfo.InvariantCulture)); } }
public void TestDoWaterShedAlgorithmPrecursorAndFragments() { var fileLocation = @"\\proto-2\UnitTest_Files\MultidimensionalFeatureFinding\BSA_10ugml_IMS6_TOF03_CID_27Aug12_Frodo_Collision_Energy_Collapsed.UIMF"; var uimfUtil = new UimfUtil(fileLocation); var parentMz = 643.27094937; double ppmTolerance = 50; var parentIntensityBlock = uimfUtil.GetXicAsArray(parentMz, ppmTolerance, DataReader.FrameType.MS1, DataReader.ToleranceType.PPM); var smoother = new SavitzkyGolaySmoother(5, 2); smoother.Smooth(ref parentIntensityBlock); var parentPointList = WaterShedMapUtil.BuildWatershedMap(parentIntensityBlock, 0, 0); var parentFeature = FeatureDetection.DoWatershedAlgorithm(parentPointList).First(); var statistics = parentFeature.Statistics; var scanLcMin = statistics.ScanLcMin; var scanLcMax = statistics.ScanLcMax; var scanImsMin = statistics.ScanImsMin; var scanImsMax = statistics.ScanImsMax; using (TextReader fragmentReader = new StreamReader(@"..\..\..\testFiles\OneFragment.csv")) { var line = ""; while ((line = fragmentReader.ReadLine()) != null) { var mzString = line.Trim(); var targetMz = double.Parse(mzString); TextWriter unsmoothedWriter = new StreamWriter("unsmoothedRaw" + targetMz + ".csv"); var intensityBlock = uimfUtil.GetXicAsArray(targetMz, ppmTolerance, DataReader.FrameType.MS2, scanLcMin, scanLcMax, scanImsMin, scanImsMax, DataReader.ToleranceType.PPM); var boundX = intensityBlock.GetUpperBound(0); var boundY = intensityBlock.GetUpperBound(1); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } unsmoothedWriter.WriteLine(row.ToString()); } unsmoothedWriter.Close(); smoother.Smooth(ref intensityBlock); TextWriter smoothedWriter = new StreamWriter("smoothedRaw" + targetMz + ".csv"); for (var i = 0; i < boundX; i++) { var row = new StringBuilder(); for (var j = 0; j < boundY; j++) { row.Append(intensityBlock[i, j] + ","); } smoothedWriter.WriteLine(row.ToString()); } smoothedWriter.Close(); var pointList = WaterShedMapUtil.BuildWatershedMap(intensityBlock, scanLcMin, scanImsMin); var featureList = FeatureDetection.DoWatershedAlgorithm(pointList); Console.WriteLine("******************************************************"); Console.WriteLine("targetMz = " + targetMz); foreach (var featureBlob in featureList) { var mostIntensePoint = featureBlob.PointList.OrderByDescending(x => x.Intensity).First(); Console.WriteLine("Num Points = " + featureBlob.PointList.Count + "\tLC = " + mostIntensePoint.ScanLc + "\tIMS = " + mostIntensePoint.ScanIms + "\tIntensity = " + mostIntensePoint.Intensity); } } } }