private ChromatogramRequestDocument GetChromatogramRequestDocument(SpectrumFilter spectrumFilter) { ChromatogramRequestDocument chromatogramRequestDocument = spectrumFilter.ToChromatogramRequestDocument(); if (null == _retentionTimePredictor) { return(chromatogramRequestDocument); } var peptidesBySequence = new Dictionary <string, PeptideDocNode>(); foreach (var peptide in _srmDocument.Molecules) { peptidesBySequence[peptide.RawTextId] = peptide; } var chromatogramGroups = new List <ChromatogramRequestDocumentChromatogramGroup>(); foreach (var chromatogramGroup in chromatogramRequestDocument.ChromatogramGroup) { PeptideDocNode peptideDocNode = null; if (!string.IsNullOrEmpty(chromatogramGroup.ModifiedSequence)) { peptidesBySequence.TryGetValue(chromatogramGroup.ModifiedSequence, out peptideDocNode); } bool isFirstPassPeptide = peptideDocNode != null && _retentionTimePredictor.IsFirstPassPeptide(peptideDocNode); if (_firstPass == isFirstPassPeptide) { chromatogramGroups.Add(chromatogramGroup); } } chromatogramRequestDocument.ChromatogramGroup = chromatogramGroups.ToArray(); return(chromatogramRequestDocument); }
public ChromatogramRequestProvider(SrmDocument srmDocument, ChorusUrl chorusUrl, IRetentionTimePredictor retentionTimePredictor, bool firstPass) { _srmDocument = srmDocument; _chorusUrl = chorusUrl; _retentionTimePredictor = retentionTimePredictor; _firstPass = firstPass; // Create a SpectrumFilter without an IRetentionTimeProvider in order to get the list of ChromKeys that we will eventually provide. SpectrumFilter spectrumFilter = new SpectrumFilter(_srmDocument, _chorusUrl, null); _chromKeys = ImmutableList.ValueOf(ListChromKeys(GetChromatogramRequestDocument(spectrumFilter))); }
public void TestMsx(SrmDocument doc, string dataPath) { // Load the file and check MsDataFileImpl using (var file = new MsDataFileImpl(dataPath)) { var filter = new SpectrumFilter(doc, null, null); Assert.IsTrue(filter.EnabledMsMs); var demultiplexer = new MsxDemultiplexer(file, filter); demultiplexer.ForceInitializeFile(); // Check that the demultiplexer found the correct multiplexing parameters Assert.AreEqual(5, demultiplexer.IsoWindowsPerScan); Assert.AreEqual(100, demultiplexer.NumIsoWindows); Assert.AreEqual(20, demultiplexer.DutyCycleLength); var isoMapper = demultiplexer.IsoMapperTest; Assert.AreEqual(100, isoMapper.NumWindows); // Check the isolation window mapper responsible for mapping each unique isolation // window detected in the file to a unique index TestIsolationWindowMapper(isoMapper, file, 4.00182); var transBinner = new TransitionBinner(filter, isoMapper); // Test creation of a transition binner from a spectrum filter TestTransitionBinnerFromFilter(transBinner, isoMapper); var testSpectrum = file.GetSpectrum(TEST_SPECTRUM); // Generate a transition binner containing a lot of tough cases with // overlapping transitions and test double[] binnedExpected = { 0.0, 25160.11261, 18254.06375, 18254.06375, 18254.06375, 11090.00577, 19780.18628, 19780.18628 }; var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected); TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM); TestPeakIntensityCorrection(testSpectrum, isoMapper, demultiplexer); int[] intensityIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296 }; double[] intensityValues = { 0.0, 0.0, 0.0, 0.0, 142.95, 349.75, 542.87, 511.77, 248.4, 0.0, 49.28, 1033.65, 278.56, 0.0, 0.0, 0.0, 0.0, 0.0 }; // Test demultiplexing of a real spectrum TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM, testSpectrum, intensityIndices, intensityValues, 0); } }
protected override void DoTest() { string chorusRequestOutputDirectory; if (null != TestContext.TestResultsDirectory) { chorusRequestOutputDirectory = Path.Combine(TestContext.TestResultsDirectory, "chorusrequests"); Directory.CreateDirectory(chorusRequestOutputDirectory); } else { // When running unit tests under resharper, we have no TestResultsDirectory, so we only send // the output to Console.Out. chorusRequestOutputDirectory = null; } var xmlSerializer = new XmlSerializer(typeof(pwiz.Skyline.Model.Results.RemoteApi.GeneratedCode.ChromatogramRequestDocument)); foreach (var chorusDataSet in ChorusDataSets) { TestFilesDir testFilesDir = TestFilesDirForUrl(chorusDataSet.SkyZipUrl); string skyFileName = Path.GetFileName(testFilesDir.FullPath); Assert.IsNotNull(skyFileName, "skyFileName != null"); StringAssert.EndsWith(skyFileName, ".sky"); skyFileName = Uri.UnescapeDataString(skyFileName); string skyFilePath = Path.Combine(testFilesDir.FullPath, skyFileName); RunUI(() => SkylineWindow.OpenFile(skyFilePath)); WaitForDocumentLoaded(); SrmDocument document = null; RunUI(() => { document = SkylineWindow.DocumentUI; }); Assert.IsNotNull(document); SpectrumFilter spectrumFilterData = new SpectrumFilter(document, MsDataFileUri.Parse(""), null); var chorusRequestDocument = spectrumFilterData.ToChromatogramRequestDocument(); Console.Out.WriteLine("***BEGIN {0}.chorusrequest.xml***", chorusDataSet.Name); using (var xmlWriter = XmlWriter.Create(Console.Out, new XmlWriterSettings { Encoding = Encoding.UTF8 })) { xmlSerializer.Serialize(xmlWriter, chorusRequestDocument); } Console.Out.WriteLine("***END {0}.chorusrequest.xml***", chorusDataSet.Name); if (null != chorusRequestOutputDirectory) { string outputFile = Path.Combine(chorusRequestOutputDirectory, chorusDataSet.Name + ".chorusrequest.xml"); using (var stream = new FileStream(outputFile, FileMode.Create)) { xmlSerializer.Serialize(stream, chorusRequestDocument); } } } }
public void TestOverlap(SrmDocument doc, string dataPath) { // Load the file and check MsDataFileImpl using (var file = new MsDataFileImpl(dataPath)) { var filter = new SpectrumFilter(doc, null, null); Assert.IsTrue(filter.EnabledMsMs); var demultiplexer = new OverlapDemultiplexer(file, filter); demultiplexer.ForceInitializeFile(); // Check that the demultiplexer found the correct multiplexing parameters Assert.AreEqual(1, demultiplexer.IsoWindowsPerScan); Assert.AreEqual(40, demultiplexer.NumIsoWindows); Assert.AreEqual(41, demultiplexer.NumDeconvRegions); var isoMapper = demultiplexer.IsoMapperTest; // Basic checks of IsolationWindowMapper TestIsolationWindowMapper(isoMapper, file, 20.009); // Checks of overlap-specific functionality in IsolationWindowMapper TestOverlapIsolationWindowMapper(isoMapper, file); var transBinner = new TransitionBinner(filter, isoMapper); // Test creation of a transition binner from a spectrum filter TestTransitionBinnerFromFilter(transBinner, isoMapper); var testSpectrum = file.GetSpectrum(TEST_SPECTRUM_OVERLAP); // Generate a transition binner containing a lot of tough cases with // overlapping transitions and test double[] binnedExpected = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected); TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM_OVERLAP); int[] intensityIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296 }; double[] intensityValues = { 0.0, 0.0, 0.0, 0.0, 4545.85, 15660.49, 35050.01, 56321.66, 62715.75, 43598.31, 23179.42, 2745.94, 3870.54, 4060.16, 3148.17, 1656.38, 0.0, 0.0 }; // Test demultiplexing of a real spectrum TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM_OVERLAP, testSpectrum, intensityIndices, intensityValues, 0); } }
public double GetScore(Sequence sequence, int charge, int scan, LcMsRun lcmsRun) { var mass = sequence.Composition.Mass + Composition.H2O.Mass; var spectrum = lcmsRun.GetSpectrum(scan); var ionTypes = _rankScore.GetIonTypes(charge, mass); var filteredSpectrum = SpectrumFilter.FilterIonPeaks(sequence, spectrum, ionTypes, _tolerance); var match = new SpectrumMatch(sequence, filteredSpectrum, charge); var score = 0.0; var rankedPeaks = new RankedPeaks(filteredSpectrum); foreach (var ionType in ionTypes) { var ions = match.GetCleavageIons(ionType); foreach (var ion in ions) { var rank = rankedPeaks.RankIon(ion, _tolerance); score += _rankScore.GetScore(ionType, rank, charge, mass); } } return(score); }
private void btnExport_Click(object sender, EventArgs e) { string strReferenceFile = (string)comboBoxReferenceFile.SelectedItem; string strSaveFileName = string.Empty; if (!string.IsNullOrEmpty(_documentFilePath)) { strSaveFileName = Path.GetFileNameWithoutExtension(_documentFilePath); } if (!string.IsNullOrEmpty(strReferenceFile)) { strSaveFileName += Path.GetFileNameWithoutExtension(strReferenceFile); } strSaveFileName += ".ChorusRequest.xml"; // Not L10N strSaveFileName = strSaveFileName.Replace(' ', '_'); using (var saveFileDialog = new SaveFileDialog { FileName = strSaveFileName }) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(saveFileDialog.FileName)) { return; } SpectrumFilter spectrumFilterData = new SpectrumFilter(Document, MsDataFileUri.Parse(strReferenceFile), null); using (var saver = new FileSaver(saveFileDialog.FileName)) { if (!saver.CanSave(this)) { return; } using (var stream = new StreamWriter(saver.SafeName)) { var xmlSerializer = new XmlSerializer(typeof(Model.Results.RemoteApi.GeneratedCode.ChromatogramRequestDocument)); xmlSerializer.Serialize(stream, spectrumFilterData.ToChromatogramRequestDocument()); } saver.Commit(); } } Close(); }
private void ComputeMatch(SpectrumMatch match, int charge, int massIndex) { var isDecoy = match.Decoy; var massErrors = _massErrors[charge][massIndex]; var rankTable = (isDecoy ? _drankTables[charge][massIndex] : _rankTables[charge][massIndex]); var ionFrequencies = _ionProbabilities[charge][massIndex]; var acMatch = match; if (Config.AcquisitionMethod == AcquisitionMethod.Dia) { // filter out all peaks except ion peaks var ionPeakSpectrum = SpectrumFilter.FilterIonPeaks(match.Sequence, match.Spectrum, Config.IonTypes, Config.Tolerance); acMatch = new SpectrumMatch(acMatch.Sequence, ionPeakSpectrum, acMatch.ScanNum, acMatch.PrecursorCharge, acMatch.Decoy); } else { _precursorOffsets[charge][massIndex].AddMatch(match); // filter precursor peaks var precursorFilter = new PrecursorFilter(_precursorOffsets[charge][massIndex], Config.MassErrorTolerance); acMatch = precursorFilter.Filter(acMatch); } rankTable.AddMatch(acMatch); if (isDecoy) { return; } massErrors.AddMatch(match); var filteredSpectrum = SpectrumFilter.GetFilteredSpectrum(match.Spectrum, Config.WindowWidth, Config.RetentionCount); var filteredMatch = new SpectrumMatch(match.Sequence, filteredSpectrum, match.PrecursorCharge); ionFrequencies.AddMatch(filteredMatch); }
public ChromatogramRequestDocument GetChromatogramRequest() { SpectrumFilter spectrumFilter = new SpectrumFilter(_srmDocument, _chorusUrl, null, _firstPass ? null : _retentionTimePredictor); return GetChromatogramRequestDocument(spectrumFilter); }
private ChromatogramRequestDocument GetChromatogramRequestDocument(SpectrumFilter spectrumFilter) { ChromatogramRequestDocument chromatogramRequestDocument = spectrumFilter.ToChromatogramRequestDocument(); if (null == _retentionTimePredictor) { return chromatogramRequestDocument; } var peptidesBySequence = new Dictionary<string, PeptideDocNode>(); foreach (var peptide in _srmDocument.Molecules) { peptidesBySequence[peptide.RawTextId] = peptide; } var chromatogramGroups = new List<ChromatogramRequestDocumentChromatogramGroup>(); foreach (var chromatogramGroup in chromatogramRequestDocument.ChromatogramGroup) { PeptideDocNode peptideDocNode = null; if (!string.IsNullOrEmpty(chromatogramGroup.ModifiedSequence)) { peptidesBySequence.TryGetValue(chromatogramGroup.ModifiedSequence, out peptideDocNode); } bool isFirstPassPeptide = peptideDocNode == null || _retentionTimePredictor.IsFirstPassPeptide(peptideDocNode); if (_firstPass == isFirstPassPeptide) { chromatogramGroups.Add(chromatogramGroup); } } chromatogramRequestDocument.ChromatogramGroup = chromatogramGroups.ToArray(); return chromatogramRequestDocument; }
public ChromatogramRequestDocument GetChromatogramRequest() { SpectrumFilter spectrumFilter = new SpectrumFilter(_srmDocument, _chorusUrl, null, _firstPass ? null : _retentionTimePredictor); return(GetChromatogramRequestDocument(spectrumFilter)); }
static public float SpectrumField(SpectrumFilter spectrumFilter, float linearizedFrequency, float levelBeat) { float peakInverse; EditorGUILayout.Space(); Rect rect = GUILayoutUtility.GetRect(120, 1000, 64, 64); bool insideRect = rect.Contains(Event.current.mousePosition); if (rect.Contains(Event.current.mousePosition)) { mousePosition = Event.current.mousePosition - rect.min; GUI.changed = true; } #if UNITY_2017_2_OR_NEWER if (Event.current.type == EventType.MouseDown && insideRect) #else if (Event.current.type == EventType.mouseDown && insideRect) #endif { markerPos = Event.current.mousePosition - rect.min; linearizedFrequency = markerPos.x / rect.width; mouseDown = true; GUI.changed = true; } #if UNITY_2017_2_OR_NEWER else if (Event.current.type == EventType.MouseUp) #else else if (Event.current.type == EventType.mouseUp) #endif { mouseDown = false; } #if UNITY_2017_2_OR_NEWER if ((Event.current.type == EventType.MouseDrag && mouseDown)) #else if ((Event.current.type == EventType.mouseDrag && mouseDown)) #endif { markerPos = Event.current.mousePosition - rect.min; linearizedFrequency = markerPos.x / rect.width; GUI.changed = true; } linearizedFrequency = Mathf.Clamp01(linearizedFrequency); GUI.BeginGroup(rect); #if UNITY_2017_2_OR_NEWER if (Event.current.type == EventType.Repaint) #else if (Event.current.type == EventType.repaint) #endif { GL.Clear(true, false, Color.grey); if (mat == null) { var shader = Shader.Find("Hidden/LDG/UI"); mat = new Material(shader); } mat.SetPass(0); // background DrawGL.Rect(rect, true, new Color(0.33f, 0.33f, 0.33f)); if (spectrumFilter) { peakInverse = 1.0f - Mathf.Clamp01(levelBeat); // peak line DrawGL.Line(new Vector2(0, peakInverse * rect.height), new Vector2(rect.width, peakInverse * rect.height), new Color(0.15f, 0.15f, 0.15f)); // mouse x pos if (insideRect) { DrawGL.Line(new Vector2(mousePosition.x, 0), new Vector2(mousePosition.x, rect.height), new Color(0.15f, 0.15f, 0.15f)); } if (EditorApplication.isPlaying && Time.frameCount > 5) { //DrawGL.Curve(spectrumFilter.spectrumSource.normalizedPeaks, 1, rect.width, rect.height, new Color(0.2f, 0.2f, 0.2f)); DrawGL.Graph(spectrumFilter.fallingLevels, 1, rect.width, rect.height, new Color(0.0f, 0.5f, 1.0f), spectrumFilter.interpolationMode); // draw spectrum #if UNITY_5_6_OR_NEWER GL.Begin(GL.LINE_STRIP); for (int i = 0; i < rect.width; i++) { float iLevel = spectrumFilter.GetLevel((float)i / rect.width); GL.Color(new Color(0.0f, 0.75f, 0.0f)); GL.Vertex3(i, Mathf.Clamp01(1.0f - iLevel) * rect.height, 0); } #else GL.Begin(GL.LINES); Vector2 xy = Vector2.zero; Vector2 xyPrev = xy; for (int i = 0; i < rect.width; i++) { xy.Set(i, Mathf.Clamp01(1.0f - spectrumFilter.GetLevel((float)i / rect.width)) * rect.height); if (i > 0) { GL.Color(new Color(0.0f, 0.75f, 0.0f)); GL.Vertex3(xyPrev.x, xyPrev.y, 0); GL.Vertex3(xy.x, xy.y, 0); } xyPrev = xy; } #endif GL.End(); } } DrawGL.Line(new Vector2(linearizedFrequency * rect.width, 0), new Vector2(linearizedFrequency * rect.width, rect.height), new Color(0.95f, 0.2f, 0.2f)); // background outline DrawGL.Rect(rect, false, new Color(0.45f, 0.45f, 0.45f)); } GUI.EndGroup(); statsStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f); statsStyle.alignment = TextAnchor.UpperRight; float freq = Frequency.UnlinearizeFrequency(1.0f - Mathf.Clamp01(mousePosition.x / rect.width)); //GUI.Label(rect, "Freq: " + freq.ToString("n2") + ", Peak: " + levelBeat.ToString("n2") + " ", statsStyle); if (insideRect) { GUI.Label(rect, "Freq: " + freq.ToString("n2") + " ", statsStyle); } return(linearizedFrequency); }
public static List <double> RestoreSignalValues(ISignal signal, bool includeFi = true, SpectrumFilter filter = null) { List <double> result = new List <double>(); Dictionary <int, GarmonicSignal> garmonicSignals = new Dictionary <int, GarmonicSignal>(); double includeFiValue = Convert.ToDouble(includeFi); int N = 0; if (signal is GarmonicSignal) { garmonicSignals.Add(1, signal as GarmonicSignal); N = (signal as GarmonicSignal).N; } else { List <GarmonicSignal> filteredSignals = (signal as PoligarmonicSignal).Signals; if (filter != null) { filteredSignals = filter.Filter(filteredSignals); } for (int i = 1; i <= filteredSignals.Count; i++) { garmonicSignals.Add(filteredSignals[i - 1].GarmonicIndex, filteredSignals[i - 1]); N = filteredSignals[i - 1].N; } } for (int i = 1; i <= N; i++) { double accumulator = 0; foreach (var innerSignal in garmonicSignals) { var temp = innerSignal.Value.AFinder.AmplitudeValue * Math.Cos(((2 * Math.PI * i * innerSignal.Value.GarmonicIndex - 1) / N) - innerSignal.Value.AFinder.StartPhase); accumulator += temp; } result.Add(accumulator); } return(result); }