public LcMsPeakMatrix(LcMsRun run, LcMsFeatureLikelihood scorer = null, int minScanCharge = 1, int maxScanCharge = 60, int maxThreadCount = 0) { Run = run; _maxThreadCount = maxThreadCount; _ms1PeakList = new List<Ms1Peak>(); Ms1Spectra = new List<Ms1Spectrum>(); var ms1ScanNums = run.GetMs1ScanVector(); NColumns = ms1ScanNums.Length; MinSearchCharge = minScanCharge; MaxSearchCharge = maxScanCharge; NRows = Math.Min(MaxSearchCharge - MinSearchCharge + 1, 35); for (var i = 0; i < Math.Min(ms1ScanNums.Length, ushort.MaxValue); i++) { var ms1Spec = run.GetMs1Spectrum(ms1ScanNums[i]); Ms1Spectra.Add(ms1Spec); foreach (var peak in ms1Spec.Peaks) _ms1PeakList.Add(peak as Ms1Peak); } _ms1PeakList.Sort(); _distProfileAcrossCharge = new double[NRows]; _corrProfileAcrossCharge = new double[NRows]; _intensityAcrossCharge = new double[NRows]; _summedEnvelopeColRange = new int[NRows, 2]; _featureMatrix = null; Comparer = new MzComparerWithBinning(27); // 16ppm _scorer = scorer; _seedEnvelopes = new List<KeyValuePair<double, ObservedIsotopeEnvelope>>(); _ms1Filter = null; }
public LcMsFeatureContainer(List <Ms1Spectrum> ms1Spectra, LcMsFeatureLikelihood scorer, INodeComparer <LcMsPeakCluster> mergeComparer) { _featureList = new List <LcMsPeakCluster>(); _spectra = ms1Spectra; _scorer = scorer; _mergeComparer = mergeComparer; }
/// <summary> /// Constructor /// </summary> /// <param name="parameters"></param> public LcMsFeatureFinderLauncher(LcMsFeatureFinderInputParameter parameters = null) { Parameters = parameters ?? new LcMsFeatureFinderInputParameter(); try { _likelihoodScorer = new LcMsFeatureLikelihood(Parameters.LikelihoodScoreThreshold); } catch (FileNotFoundException fe) { ShowErrorMessage(fe.Message); return; } }
public LcMsPeakMatrix(LcMsRun run, ISequenceFilter ms1Filter, LcMsFeatureLikelihood scorer = null, int minScanCharge = 1, int maxScanCharge = 60, int maxThreadCount = 0) : this(run, scorer, minScanCharge, maxScanCharge, maxThreadCount) { _ms1Filter = ms1Filter; }
public void TestLcMsFeatureXic() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); const string rawFile = @"\\proto-11\MSXML_Cache\PBF_Gen_1_193\2015_1\CPTAC_Intact_rep2_15Jan15_Bane_C2-14-08-02RZ.pbf"; //const string rawFile = @"D:\MassSpecFiles\training\raw\QC_Shew_Intact_26Sep14_Bane_C2Column3.pbf"; if (!File.Exists(rawFile)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, rawFile); } var run = PbfLcMsRun.GetLcMsRun(rawFile); var scorer = new LcMsFeatureLikelihood(); var featureFinder = new LcMsPeakMatrix(run, scorer); var feature = featureFinder.GetLcMsPeakCluster(2388.278, 4, 3774, 3907); //feature = featureFinder.GetLcMsPeakCluster(8151.3706, 7, 13, 4201, 4266); //feature = featureFinder.GetLcMsPeakCluster(8151.41789, 7, 13, 2861, 2941); var ms1ScanToIndex = run.GetMs1ScanNumToIndex(); var minCol = ms1ScanToIndex[feature.MinScanNum]; var maxCol = ms1ScanToIndex[feature.MaxScanNum]; //var minRow = feature.MinCharge - LcMsPeakMatrix.MinScanCharge; //var maxRow = feature.MaxCharge - LcMsPeakMatrix.MinScanCharge; Console.WriteLine("---------------------------------------------------------------"); for (var i = 0; i < feature.Envelopes.Length; i++) { for (var j = 0; j < feature.Envelopes[i].Length; j++) { Console.Write(feature.Envelopes[i][j] != null ? feature.Envelopes[i][j].PearsonCorrelation : 0); Console.Write("\t"); } Console.Write("\n"); } Console.WriteLine("---------------------------------------------------------------"); for (var i = 0; i < feature.Envelopes.Length; i++) { for (var j = 0; j < feature.Envelopes[i].Length; j++) { Console.Write(feature.Envelopes[i][j] != null ? feature.Envelopes[i][j].BhattacharyyaDistance : 0); Console.Write("\t"); } Console.Write("\n"); } Console.WriteLine("---------------------------------------------------------------"); for (var i = 0; i < feature.Envelopes.Length; i++) { for (var j = 0; j < feature.Envelopes[i].Length; j++) { Console.Write(feature.Envelopes[i][j] != null ? feature.Envelopes[i][j].Abundance : 0); Console.Write("\t"); } Console.Write("\n"); } }
public void TestLcMsFeatureFinder() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); const string rawFile = @"D:\MassSpecFiles\training\raw\QC_Shew_Intact_26Sep14_Bane_C2Column3.pbf"; //const string rawFile = @"D:\MassSpecFiles\CompRef\CPTAC_Intact_CR_Pool_2_25Jun15_Bane_15-02-02RZ.pbf"; //const string rawFile = @"D:\MassSpecFiles\IMER\Dey_IMERblast_01_08May14_Alder_14-01-33.pbf"; //const string rawFile = @"\\proto-11\MSXML_Cache\PBF_Gen_1_193\2015_3\MZ20150729FG_WT1.pbf"; if (!File.Exists(rawFile)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, rawFile); } // var outTsvFilePath = MassSpecDataReaderFactory.ChangeExtension(rawFile, "ms1ft"); //var scoreDataPath = @"D:\MassSpecFiles\training"; var scorer = new LcMsFeatureLikelihood(); var stopwatch = Stopwatch.StartNew(); Console.WriteLine(@"Start loading MS1 data from {0}", rawFile); var run = PbfLcMsRun.GetLcMsRun(rawFile); var featureFinder = new LcMsPeakMatrix(run, scorer); Console.WriteLine(@"Complete loading MS1 data. Elapsed Time = {0:0.000} sec", (stopwatch.ElapsedMilliseconds)/1000.0d); var container = new LcMsFeatureContainer(featureFinder.Ms1Spectra, scorer, new LcMsFeatureMergeComparer(new Tolerance(10))); var minSearchMassBin = featureFinder.Comparer.GetBinNumber(11180.33677); var maxSearchMassBin = featureFinder.Comparer.GetBinNumber(11180.33677); double totalMassBin = maxSearchMassBin - minSearchMassBin + 1; Console.WriteLine(@"Start MS1 feature extraction."); stopwatch.Restart(); for (var binNum = minSearchMassBin; binNum <= maxSearchMassBin; binNum++) { var clusters = featureFinder.FindFeatures(binNum); container.Add(clusters); if (binNum > minSearchMassBin && (binNum - minSearchMassBin)%1000 == 0) { var elapsed = (stopwatch.ElapsedMilliseconds)/1000.0d; var processedBins = binNum - minSearchMassBin; var processedPercentage = ((double) processedBins/totalMassBin)*100; Console.WriteLine( @"Processing {0:0.0}% of mass bins ({1:0.0} Da); elapsed time = {2:0.000} sec; # of features = {3}", processedPercentage, featureFinder.Comparer.GetMzEnd(binNum), elapsed, container.NumberOfFeatures); } } Console.WriteLine(@"Complete MS1 feature extraction."); Console.WriteLine(@" - Elapsed time = {0:0.000} sec", (stopwatch.ElapsedMilliseconds)/1000.0d); Console.WriteLine(@" - Number of extracted features = {0}", container.NumberOfFeatures); // write result files Console.WriteLine(@"Start selecting mutually independent features from feature network graph"); stopwatch.Stop(); // Start to quantify accurate abundance stopwatch.Restart(); //var quantAnalyzer = new TargetMs1FeatureMatrix(run); //var oriResult = new List<Ms1FeatureCluster>(); //var quantResult = new List<Ms1Feature>(); var featureId = 0; var ms1ScanNums = run.GetMs1ScanVector(); //tsvWriter.WriteLine(GetHeaderString() + "\tQMinScanNum\tQMaxScanNum\tQMinCharge\tQMaxCharge\tQAbundance"); var filteredFeatures = container.GetFilteredFeatures(featureFinder); foreach (var feature in filteredFeatures) { Console.Write(featureId); Console.Write("\t"); Console.Write(feature.Mass); Console.Write("\t"); Console.Write(feature.MinScanNum); Console.Write("\t"); Console.Write(feature.MaxScanNum); Console.Write("\t"); Console.Write(feature.MinCharge); Console.Write("\t"); Console.Write(feature.MaxCharge); Console.Write("\t"); Console.Write(feature.RepresentativeScanNum); Console.Write("\t"); Console.Write(feature.RepresentativeMz); Console.Write("\t"); Console.Write(feature.RepresentativeCharge); Console.Write("\t"); //Console.Write(feature.BestSummedEnvelopeDistance); Console.Write("\t"); //Console.Write(feature.BestEnvelopeDistance); Console.Write("\t"); Console.Write(feature.BestDistanceScoreAcrossCharge[0]); Console.Write("\t"); Console.Write(feature.BestDistanceScoreAcrossCharge[1]); Console.Write("\t"); Console.Write(feature.BestCorrelationScoreAcrossCharge[0]); Console.Write("\t"); Console.Write(feature.BestCorrelationScoreAcrossCharge[1]); Console.Write("\t"); Console.Write(feature.BestIntensityScoreAcrossCharge[0]); Console.Write("\t"); Console.Write(feature.BestIntensityScoreAcrossCharge[1]); Console.Write("\t"); Console.Write(feature.AbundanceDistributionAcrossCharge[0]); Console.Write("\t"); Console.Write(feature.AbundanceDistributionAcrossCharge[1]); Console.Write("\t"); Console.Write(feature.XicCorrelationBetweenBestCharges[0]); Console.Write("\t"); Console.Write(feature.XicCorrelationBetweenBestCharges[1]); Console.Write("\t"); Console.Write(feature.Score); Console.Write("\n"); featureId++; } }
public void TestFeatureExampleForFigure() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); const string rawFile = @"\\proto-11\MSXML_Cache\PBF_Gen_1_193\2015_1\CPTAC_Intact_rep6_15Jan15_Bane_C2-14-08-02RZ.pbf"; //const string rawFile = @"D:\MassSpecFiles\training\raw\QC_Shew_Intact_26Sep14_Bane_C2Column3.pbf"; if (!File.Exists(rawFile)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, rawFile); } var run = PbfLcMsRun.GetLcMsRun(rawFile); var scorer = new LcMsFeatureLikelihood(); var featureFinder = new LcMsPeakMatrix(run, scorer); var feature = featureFinder.GetLcMsPeakCluster(28061.6177, 20, 34, 7624, 7736); var writer = new StreamWriter(@"D:\MassSpecFiles\CPTAC_rep10\example\peaks.txt"); var envelope = feature.TheoreticalEnvelope; foreach (var e in envelope.Isotopes) Console.WriteLine(e.Ratio); foreach (var env in feature.EnumerateEnvelopes()) { var corr = env.PearsonCorrelation; for(var i = 0; i < envelope.Size; i++) { var peak = env.Peaks[i]; if (peak == null) continue; writer.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\n", env.ScanNum, run.GetElutionTime(env.ScanNum), env.Charge, i, peak.Mz, peak.Intensity, corr); } } writer.Close(); }