public void MsDataFileUriEncodingTest() { var fname = "test.mzML"; var pathSample = SampleHelp.EncodePath(fname, null, -1, null, true, false); var lockmassParametersA = new LockMassParameters(1.23, 3.45, 4.56); var lockmassParametersB = new LockMassParameters(1.23, null, 4.56); Assert.IsTrue(lockmassParametersA.CompareTo(LockMassParameters.EMPTY) > 0); Assert.IsTrue(lockmassParametersA.CompareTo(null) < 0); Assert.IsTrue(lockmassParametersB.CompareTo(lockmassParametersA) < 0); Assert.IsTrue(lockmassParametersA.CompareTo(new LockMassParameters(1.23, 3.45, 4.56)) == 0); var c = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) }); Assert.AreEqual(fname, c.MSDataFilePaths.First().GetFilePath()); Assert.IsTrue(c.MSDataFilePaths.First().GetCentroidMs1()); Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs2()); pathSample = SampleHelp.EncodePath(fname, null, -1, lockmassParametersA, false, true); c = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) }); Assert.AreEqual(lockmassParametersA, c.MSDataFilePaths.First().GetLockMassParameters()); Assert.IsTrue(c.MSDataFilePaths.First().GetCentroidMs2()); Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs1()); pathSample = SampleHelp.EncodePath(fname, "test_0", 1, lockmassParametersB, false, false); c = new ChromatogramSet("test", new[] { MsDataFileUri.Parse(pathSample) }); Assert.AreEqual(lockmassParametersB, c.MSDataFilePaths.First().GetLockMassParameters()); Assert.AreEqual("test_0", c.MSDataFilePaths.First().GetSampleName()); Assert.AreEqual(1, c.MSDataFilePaths.First().GetSampleIndex()); Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs1()); Assert.IsFalse(c.MSDataFilePaths.First().GetCentroidMs2()); }
private void VerifyFileInfoSerialization(string[] lines, string filePath, bool combinedIms) { var encodePath = SampleHelp.EncodePath(filePath, null, -1, null); var lineFilePath = lines.FirstOrDefault(l => l.Contains(encodePath + '"')); Assert.IsNotNull(lineFilePath); // Nothing gets serialized to the XML about whether the MsData had combined spectra - can only be found in the SKYD file }
public static MsDataFilePath[] GetWiffSubPaths(string filePath, string[] dataIds, Func <string, string[], IEnumerable <int> > sampleChooser) { if (dataIds == null) { return(null); } // WIFF without at least 2 samples just use its file name. if (dataIds.Length < 2) { return new[] { new MsDataFilePath(filePath, null, -1), } } ; // Escape all the sample ID names, so that they may be used in file names. for (int i = 0; i < dataIds.Length; i++) { dataIds[i] = SampleHelp.EscapeSampleId(dataIds[i]); } IEnumerable <int> sampleIndices; if (sampleChooser != null) { // Allow the user to choose from the list sampleIndices = sampleChooser(filePath, dataIds); if (sampleIndices == null) { return(null); } } else { int[] indexes = new int[dataIds.Length]; for (int i = 0; i < dataIds.Length; i++) { indexes[i] = i; } sampleIndices = indexes; } // Encode sub-paths var listPaths = new List <MsDataFilePath>(); foreach (int sampleIndex in sampleIndices) { listPaths.Add(new MsDataFilePath(filePath, dataIds[sampleIndex], sampleIndex)); } if (listPaths.Count == 0) { return(null); } return(listPaths.ToArray()); } }
private void VerifySerialization(string testPath, bool expect_mz5) { var text = File.ReadAllText(testPath); var filePath = TestFilesDir.GetTestPath(BSA_50fmol_TIMS_InfusionESI_10precd); var encodePath = SampleHelp.EncodePath(filePath, null, -1, null, false, false, !MsDataFileImpl.ForceUncombinedIonMobility); Assert.IsTrue(text.Contains(encodePath + '"')); if (expect_mz5) { filePath = TestFilesDir.GetTestPath(bsaFmolTimsInfusionesiPrecMz5Mz5); encodePath = SampleHelp.EncodePath(filePath, null, -1, null, false, false, false); Assert.IsTrue(text.Contains(encodePath + '"')); } }
private static void WriteRow(TextWriter writer, PeakTransitionGroupFeatures features, PeakGroupFeatures peakGroupFeatures, CultureInfo cultureInfo, double mProphetScore, double pValue, double qValue) { char separator = TextUtil.GetCsvSeparator(cultureInfo); string fileName = SampleHelp.GetFileName(features.Id.FilePath); var fieldsArray = new List <string> { Convert.ToString(features.Id, cultureInfo), Convert.ToString(features.Id.Run, cultureInfo), fileName, Convert.ToString(peakGroupFeatures.RetentionTime, cultureInfo), Convert.ToString(peakGroupFeatures.StartTime, cultureInfo), Convert.ToString(peakGroupFeatures.EndTime, cultureInfo), features.Id.NodePep.RawUnmodifiedTextId, // Unmodified sequence, or custom ion name features.Id.NodePep.RawTextId, // Modified sequence, or custom ion name features.Id.NodePepGroup.Name, Convert.ToString(features.Id.NodePep.IsDecoy ? 1 : 0, cultureInfo), ToFieldString((float)mProphetScore, cultureInfo), ToFieldString((float)pValue, cultureInfo), ToFieldString((float)qValue, cultureInfo) }; if (IsFilterTestData) { fieldsArray.Add(peakGroupFeatures.GetFilterPairsText(cultureInfo)); } foreach (var name in fieldsArray) { writer.WriteDsvField(name, separator); writer.Write(separator); } bool first = true; foreach (float featureColumn in peakGroupFeatures.Features) { if (!first) { writer.Write(separator); } writer.WriteDsvField(ToFieldString(featureColumn, cultureInfo), separator); first = false; } writer.WriteLine(); }
private static void WriteRow(TextWriter writer, PeakTransitionGroupFeatures features, PeakGroupFeatures peakGroupFeatures, CultureInfo cultureInfo, double mProphetScore, double pValue, double qValue) { char separator = TextUtil.GetCsvSeparator(cultureInfo); string fileName = SampleHelp.GetFileName(features.Id.FilePath); var fieldsArray = new List <string> { Convert.ToString(features.Id, cultureInfo), Convert.ToString(features.Id.Run, cultureInfo), fileName, // CONSIDER: This impacts memory consumption for large-scale DIA, and it is not clear anyone uses these Convert.ToString(peakGroupFeatures.RetentionTime, cultureInfo), Convert.ToString(peakGroupFeatures.StartTime, cultureInfo), Convert.ToString(peakGroupFeatures.EndTime, cultureInfo), features.Id.RawUnmodifiedTextId, // Unmodified sequence, or custom ion name features.Id.RawTextId, // Modified sequence, or custom ion name features.Id.NodePepGroup.Name, Convert.ToString(features.IsDecoy ? 1 : 0, cultureInfo), ToFieldString((float)mProphetScore, cultureInfo), ToFieldString((float)pValue, cultureInfo), ToFieldString((float)qValue, cultureInfo) }; foreach (var name in fieldsArray) { writer.WriteDsvField(name, separator); writer.Write(separator); } bool first = true; foreach (float featureColumn in peakGroupFeatures.Features) { if (!first) { writer.Write(separator); } writer.WriteDsvField(ToFieldString(featureColumn, cultureInfo), separator); first = false; } writer.WriteLine(); }
/// <summary> /// If the predicted retention time is auto calculated, add a "Show {Prediction} score" menu item. /// If there are retention time alignments available for the specified chromFileInfoId, then adds /// a "Align Times To {Specified File}" menu item to a context menu. /// </summary> private int InsertAlignmentMenuItems(ToolStripItemCollection items, ChromFileInfoId chromFileInfoId, int iInsert) { var predictRT = Document.Settings.PeptideSettings.Prediction.RetentionTime; if (predictRT != null && predictRT.IsAutoCalculated) { var menuItem = new ToolStripMenuItem(string.Format(Resources.SkylineWindow_ShowCalculatorScoreFormat, predictRT.Calculator.Name), null, (sender, eventArgs) => SkylineWindow.AlignToRtPrediction = !SkylineWindow.AlignToRtPrediction) { Checked = SkylineWindow.AlignToRtPrediction, }; items.Insert(iInsert++, menuItem); } if (null != chromFileInfoId && DocumentUI.Settings.HasResults && !DocumentUI.Settings.DocumentRetentionTimes.FileAlignments.IsEmpty) { foreach (var chromatogramSet in DocumentUI.Settings.MeasuredResults.Chromatograms) { var chromFileInfo = chromatogramSet.GetFileInfo(chromFileInfoId); if (null == chromFileInfo) { continue; } string fileItemName = Path.GetFileNameWithoutExtension(SampleHelp.GetFileName(chromFileInfo.FilePath)); var menuItemText = string.Format(Resources.SkylineWindow_AlignTimesToFileFormat, fileItemName); var alignToFileItem = new ToolStripMenuItem(menuItemText); if (ReferenceEquals(chromFileInfoId, SkylineWindow.AlignToFile)) { alignToFileItem.Click += (sender, eventArgs) => SkylineWindow.AlignToFile = null; alignToFileItem.Checked = true; } else { alignToFileItem.Click += (sender, eventArgs) => SkylineWindow.AlignToFile = chromFileInfoId; alignToFileItem.Checked = false; } items.Insert(iInsert++, alignToFileItem); } } return(iInsert); }
public void WiffResultsTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); SrmDocument doc = InitWiffDocument(testFilesDir); using (var docContainer = new ResultsTestDocumentContainer(doc, testFilesDir.GetTestPath("SimpleWiffTest.sky"))) { FileEx.SafeDelete(ChromatogramCache.FinalPathForName(docContainer.DocumentFilePath, null)); var listChromatograms = new List <ChromatogramSet>(); if (ExtensionTestContext.CanImportAbWiff) { string pathWiff = testFilesDir.GetTestPath("051309_digestion.wiff"); string[] dataIds = MsDataFileImpl.ReadIds(pathWiff); for (int i = 0; i < dataIds.Length; i++) { string nameSample = dataIds[i]; if (!Equals(nameSample, "test") && listChromatograms.Count == 0) { continue; } string pathSample = SampleHelp.EncodePath(pathWiff, nameSample, i, LockMassParameters.EMPTY, false, false); listChromatograms.Add(new ChromatogramSet(nameSample, new[] { MsDataFileUri.Parse(pathSample) })); } } else { listChromatograms.Add(new ChromatogramSet("test", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-test.mzML")) })); listChromatograms.Add(new ChromatogramSet("rfp9,before,h,1", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-rfp9,before,h,1.mzML")) })); } // Should have added test and one after Assert.AreEqual(2, listChromatograms.Count); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertEx.IsDocumentState(docResults, 6, 9, 9, 18, 54); Assert.IsTrue(docResults.Settings.MeasuredResults.IsLoaded); foreach (var nodeTran in docResults.PeptideTransitions) { Assert.IsTrue(nodeTran.HasResults); Assert.AreEqual(2, nodeTran.Results.Count); } // Remove the last chromatogram listChromatograms.RemoveAt(1); var docResultsSingle = docResults.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); AssertResult.IsDocumentResultsState(docResultsSingle, "test", 9, 2, 9, 8, 27); // Add mzXML version of test sample listChromatograms.Add(new ChromatogramSet("test-mzXML", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-s3.mzXML")) })); var docMzxml = docResults.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docMzxml, docResults, true)); docContainer.AssertComplete(); docMzxml = docContainer.Document; // Verify mzXML and native contained same results // Unfortunately mzWiff produces chromatograms with now zeros, which // need to be interpolated into place. This means a .wiff file and // its mzWiff mzXML file will never be the same. AssertResult.MatchChromatograms(docMzxml, 0, 1, -1, 0); } // TODO: Switch to a using clause when PWiz is fixed, and this assertion fails // AssertEx.ThrowsException<IOException>(() => testFilesDir.Dispose()); }