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 static bool HasUnmatchedLibraryRuns(SrmDocument doc) { var libraries = doc.Settings.PeptideSettings.Libraries; if (!libraries.HasLibraries || !libraries.HasDocumentLibrary) { return(false); } for (int i = 0; i < libraries.LibrarySpecs.Count; i++) { if (libraries.LibrarySpecs[i].IsDocumentLibrary) { var documentLibrary = libraries.Libraries[i]; // CONSIDER: Load the library? if (documentLibrary == null) { return(false); } foreach (var dataFile in documentLibrary.LibraryFiles.FilePaths) { if (!doc.Settings.HasResults || doc.Settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(dataFile)) == null) { return(true); } } } } return(false); }
public override IEnumerable <double> GetRetentionTimesWithSequences(string filePath, IEnumerable <Target> peptideSequences, ref int?iFile) { if (!iFile.HasValue) { iFile = FindFileInList(MsDataFileUri.Parse(filePath), _sourceFiles); } if (iFile.Value < 0) { return(new double[0]); } var times = new List <double>(); foreach (var entry in LibraryEntriesWithSequences(peptideSequences)) { FileData fileData; if (entry.FileDatas.TryGetValue(iFile.Value, out fileData)) { if (fileData.ApexTime.HasValue) { times.Add(fileData.ApexTime.Value); } } } return(times); }
protected override void DoTest() { TestFilesZip = GetPerfTestDataURL(@"PerfNegativeIonDIA.zip"); TestFilesPersistent = new[] { "neg.mzML", "pos.mzML" }; // list of files that we'd like to unzip alongside parent zipFile, and (re)use in place var testFilesDir = new TestFilesDir(TestContext, TestFilesZip, null, TestFilesPersistent); RunUI(() => SkylineWindow.OpenFile(testFilesDir.GetTestPath("Test positive-negative.sky"))); WaitForDocumentLoaded(); ImportResultsFiles(TestFilesPersistent.Select(file => MsDataFileUri.Parse(testFilesDir.GetTestPath(file)))); // Verify that pos ion has a chromatogram for pos replicate, and neg ion has one for neg replicate var doc = WaitForDocumentLoaded(400000); var results = doc.Settings.MeasuredResults; var negIndex = results.Chromatograms[0].Name.Equals("neg") ? 0 : 1; var posIndex = (negIndex == 1) ? 0 : 1; var tolerance = .005f; foreach (var pair in doc.MoleculePrecursorPairs) { var index = pair.NodeGroup.PrecursorCharge < 0 ? negIndex : posIndex; var message = "expected a chromatogram for precursor and for product in replicate \"" + results.Chromatograms[index].Name + "\""; ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(index, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo), message); foreach (var chromGroup in chromGroupInfo) { Assert.AreEqual(2, chromGroup.TransitionPointSets.Count(), message); } } }
public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions) { System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); TestSmallMolecules = false; // We have an explicit test for that here string docPath; SrmDocument document = InitAgilentMseDocument(testFilesDir, out docPath); if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { var refine = new RefinementSettings(); document = refine.ConvertToSmallMolecules(document, asSmallMolecules); } using (var docContainer = new ResultsTestDocumentContainer(document, docPath)) { var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AgilentMse\BSA-AI-0-10-25-41_first_100_scans.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting just one peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(0.2462, (double)nodePep.GetMeasuredRetentionTime(0), .0001, "averaged retention time differs in node " + nodePep.RawTextId); Assert.AreEqual(0.3333, (double)nodePep.GetPeakCountRatio(0), 0.0001); nPeptides++; } } Assert.AreEqual(1, nPeptides); } testFilesDir.Dispose(); }
private void RunMultiplePeptidesSameMz(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { TestDirectoryName = asSmallMolecules.ToString(); } TestSmallMolecules = false; // Don't need the magic test node, we have an explicit test var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument document = InitMultiplePeptidesSameMzDocument(testFilesDir, out docPath); document = (new RefinementSettings()).ConvertToSmallMolecules(document, asSmallMolecules); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AMultiplePeptidesSameMz\ljz_20131201k_Newvariant_standards_braf.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); // without the fix, only the first pair will have a chromatogram } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting three peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(34.2441024780273, (double)nodePep.GetMeasuredRetentionTime(0), .0001); nPeptides++; } } Assert.AreEqual(3, nPeptides); // without the fix this will give just one result // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
private static IDictionary <Target, double> GetFirstRetentionTimes( SrmSettings settings, RetentionTimeSource retentionTimeSource) { var libraryRetentionTimes = settings.GetRetentionTimes(MsDataFileUri.Parse(retentionTimeSource.Name)); if (null == libraryRetentionTimes) { return(new Dictionary <Target, double>()); } return(libraryRetentionTimes.GetFirstRetentionTimes()); }
private static void doTest(TestFilesDir testFilesDir, string skyFile, double expectedRT, string[] filenames, double?expectedRatio) { string docPath; var document = InitExplicitRTDocument(testFilesDir, skyFile, out docPath); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); foreach (var filename in filenames) { var path = MsDataFileUri.Parse(filename + ExtensionTestContext.ExtWatersRaw); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); } var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(1, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); } var nResults = 0; foreach (var nodePep in document.Molecules) { foreach (var results in nodePep.Results) { foreach (var result in results) { Assert.AreEqual(expectedRT, result.RetentionTime ?? 0, .1); // We should pick peaks based on explicit RT if (expectedRatio.HasValue) // If we didn't, ratios won't be right { Assert.IsNotNull(result.LabelRatios[0].Ratio); Assert.AreEqual(expectedRatio.Value, result.LabelRatios[0].Ratio.Ratio, .1); } nResults++; } } } Assert.AreEqual(filenames.Length * document.MoleculeGroupCount, nResults); // Release file handles docContainer.Release(); }
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); } } } }
protected void ImportFile(string fileName) { var importResultsDlg = ShowDialog <ImportResultsDlg>(SkylineWindow.ImportResults); RunUI(() => { importResultsDlg.RadioAddNewChecked = true; var path = new KeyValuePair <string, MsDataFileUri[]> [1]; path[0] = new KeyValuePair <string, MsDataFileUri[]>(Path.GetFileNameWithoutExtension(fileName), new[] { MsDataFileUri.Parse(fileName) }); importResultsDlg.NamedPathSets = path; }); OkDialog(importResultsDlg, importResultsDlg.OkDialog); WaitForCondition(2 * 60 * 1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 2 minutes }
public bool VerifyRetentionTimes(IEnumerable <string> resultsFiles) { foreach (var resultsFile in resultsFiles) { LibraryRetentionTimes retentionTimes; if (DocLib.TryGetRetentionTimes(MsDataFileUri.Parse(resultsFile), out retentionTimes)) { if (retentionTimes.PeptideRetentionTimes.Any(t => t.RetentionTime <= 0)) { return(false); } } } return(true); }
public void ThermoMixedPeptidesTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument docMixed = InitMixedDocument(testFilesDir, out docPath); FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); SrmDocument docUnmixed = InitUnmixedDocument(testFilesDir, out docPath); FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); string extRaw = ExtensionTestContext.ExtThermoRaw; var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet("rep03", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_03" + extRaw)) }), new ChromatogramSet("rep05", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_05" + extRaw)) }) }; var docResults = docMixed.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainerMixed = new ResultsTestDocumentContainer(docMixed, docPath); Assert.IsTrue(docContainerMixed.SetDocument(docResults, docMixed, true)); docContainerMixed.AssertComplete(); docMixed = docContainerMixed.Document; SrmDocument docMixedUnmixed = (SrmDocument)docMixed.ChangeChildren(new DocNode[0]); IdentityPath tempPath; docMixedUnmixed = docMixedUnmixed.AddPeptideGroups(docUnmixed.PeptideGroups, true, IdentityPath.ROOT, out tempPath, out tempPath); docResults = docUnmixed.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainerUnmixed = new ResultsTestDocumentContainer(docUnmixed, docPath); Assert.IsTrue(docContainerUnmixed.SetDocument(docResults, docUnmixed, true)); docContainerUnmixed.AssertComplete(); docUnmixed = docContainerUnmixed.Document; AssertEx.DocumentCloned(docMixedUnmixed, docUnmixed); docContainerMixed.Release(); docContainerUnmixed.Release(); }
public void ThermoNonMatchingRTTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); string extRaw = ExtensionTestContext.ExtThermoRaw; var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet("rep03", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_03" + extRaw)) }), }; ValidateRelativeRT(RelativeRT.Preceding, doc, docPath, listChromatograms); ValidateRelativeRT(RelativeRT.Overlapping, doc, docPath, listChromatograms); ValidateRelativeRT(RelativeRT.Unknown, doc, docPath, listChromatograms); }
public static ResultNameMap <IDictionary <Target, double> > ReadAllRetentionTimes(SrmDocument document, ResultNameMap <RetentionTimeSource> sources) { var allRetentionTimes = new Dictionary <string, IDictionary <Target, double> >(); foreach (var source in sources) { var library = document.Settings.PeptideSettings.Libraries.GetLibrary(source.Value.Library); if (null == library) { continue; } LibraryRetentionTimes libraryRetentionTimes; if (!library.TryGetRetentionTimes(MsDataFileUri.Parse(source.Value.Name), out libraryRetentionTimes)) { continue; } allRetentionTimes.Add(source.Key, libraryRetentionTimes.GetFirstRetentionTimes()); } return(ResultNameMap.FromDictionary(allRetentionTimes)); }
protected override void DoTest() { var resultsPath = TestFilesDir.GetTestPath("PeakSortingIssue.raw"); var docPath = TestFilesDir.GetTestPath("PeakSortingIssue.sky"); var doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 3, 6, 90); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { var replicateName = Path.GetFileNameWithoutExtension(resultsPath); var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet(replicateName, new[] { MsDataFileUri.Parse(resultsPath) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertResult.IsDocumentResultsState(docResults, replicateName, 0, 0, 0, 0, 3); } }
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(); }
public static void MatchChromatograms(ResultsTestDocumentContainer docContainer, string path1, string path2, int delta, int missing, LockMassParameters lockMassParameters = null) { MatchChromatograms(docContainer, MsDataFileUri.Parse(path1), MsDataFileUri.Parse(path2), delta, missing, lockMassParameters); }
public void Open() { List <MsDataFileUri> dataSourceList = new List <MsDataFileUri>(); foreach (ListViewItem item in listView.SelectedItems) { if (!DataSourceUtil.IsFolderType(item.SubItems[1].Text)) { dataSourceList.Add(((SourceInfo)item.Tag).MsDataFileUri); } } if (dataSourceList.Count > 0) { DataSources = dataSourceList.ToArray(); _abortPopulateList = true; DialogResult = DialogResult.OK; return; } // No files selected: see if there is a folder selected that we // should navigate to foreach (ListViewItem item in listView.SelectedItems) { if (DataSourceUtil.IsFolderType(item.SubItems[1].Text)) { OpenFolderItem(item); return; } } try { // perhaps the user has typed an entire filename into the text box - or just garbage var fileOrDirName = sourcePathTextBox.Text; bool exists; bool triedAddingDirectory = false; while (!(exists = ((File.Exists(fileOrDirName) || Directory.Exists(fileOrDirName))))) { if (triedAddingDirectory) { break; } MsDataFilePath currentDirectoryPath = CurrentDirectory as MsDataFilePath; if (null == currentDirectoryPath) { break; } fileOrDirName = Path.Combine(currentDirectoryPath.FilePath, fileOrDirName); triedAddingDirectory = true; } if (exists) { if (DataSourceUtil.IsDataSource(fileOrDirName)) { DataSources = new[] { MsDataFileUri.Parse(fileOrDirName) }; DialogResult = DialogResult.OK; return; } else if (Directory.Exists(fileOrDirName)) { OpenFolder(new MsDataFilePath(fileOrDirName)); return; } } } // ReSharper disable once EmptyGeneralCatchClause catch {} // guard against user typed-in-garbage // No files or folders selected: Show an error message. MessageDlg.Show(this, Resources.OpenDataSourceDialog_Open_Please_select_one_or_more_data_sources); }
private IList <SpectrumDisplayInfo> GetSpectra(TransitionGroupDocNode nodeGroup, Target lookupSequence, ExplicitMods lookupMods) { var settings = DocumentUI.Settings; var charge = nodeGroup.PrecursorAdduct; var spectra = settings.GetBestSpectra(lookupSequence, charge, lookupMods).Select(s => new SpectrumDisplayInfo(s)).ToList(); // Showing redundant spectra is only supported for full-scan filtering when // the document has results files imported. if ((!settings.TransitionSettings.FullScan.IsEnabled && !settings.PeptideSettings.Libraries.HasMidasLibrary) || !settings.HasResults) { return(spectra); } try { var spectraRedundant = new List <SpectrumDisplayInfo>(); var dictReplicateNameFiles = new Dictionary <string, HashSet <string> >(); foreach (var spectrumInfo in settings.GetRedundantSpectra(nodeGroup.Peptide, lookupSequence, charge, nodeGroup.TransitionGroup.LabelType, lookupMods)) { var matchingFile = settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(spectrumInfo.FilePath)); if (matchingFile == null) { continue; } string replicateName = matchingFile.Chromatograms.Name; spectraRedundant.Add(new SpectrumDisplayInfo(spectrumInfo, replicateName, matchingFile.FilePath, matchingFile.FileOrder, spectrumInfo.RetentionTime, false)); // Include the best spectrum twice, once displayed in the normal // way and once displayed with its replicate and retetion time. if (spectrumInfo.IsBest) { string libName = spectrumInfo.LibName; var labelType = spectrumInfo.LabelType; int iBest = spectra.IndexOf(s => Equals(s.LibName, libName) && Equals(s.LabelType, labelType)); if (iBest != -1) { spectra[iBest] = new SpectrumDisplayInfo(spectra[iBest].SpectrumInfo, replicateName, matchingFile.FilePath, 0, spectrumInfo.RetentionTime, true); } } HashSet <string> setFiles; if (!dictReplicateNameFiles.TryGetValue(replicateName, out setFiles)) { setFiles = new HashSet <string>(); dictReplicateNameFiles.Add(replicateName, setFiles); } setFiles.Add(spectrumInfo.FilePath); } // Determine if replicate name is sufficient to uniquely identify the file foreach (var spectrumInfo in spectraRedundant) { string replicateName = spectrumInfo.ReplicateName; if (replicateName != null && dictReplicateNameFiles[replicateName].Count < 2) { spectrumInfo.IsReplicateUnique = true; } } spectraRedundant.Sort(); spectra.AddRange(spectraRedundant); return(spectra); } catch (Exception) { return(spectra); } }
public SpectrumIdentifier(string sourceFile, double retentionTime) : this(MsDataFileUri.Parse(sourceFile), retentionTime) { }
public SrmDocument Import(TextReader reader, IProgressMonitor progressMonitor, long lineCount, bool isMinutes, bool removeMissing = false, bool changePeaks = true) { IProgressStatus status = new ProgressStatus(Resources.PeakBoundaryImporter_Import_Importing_Peak_Boundaries); double timeConversionFactor = isMinutes ? 1.0 : 60.0; int linesRead = 0; int progressPercent = 0; var docNew = (SrmDocument)Document.ChangeIgnoreChangingChildren(true); var docReference = docNew; var sequenceToNode = MakeSequenceDictionary(Document); var fileNameToFileMatch = new Dictionary <string, ChromSetFileMatch>(); var trackAdjustedResults = new HashSet <ResultsKey>(); var modMatcher = new ModificationMatcher(); var canonicalSequenceDict = new Dictionary <string, string>(); // Add annotations as possible columns var allFieldNames = new List <string[]>(FIELD_NAMES); allFieldNames.AddRange(from def in Document.Settings.DataSettings.AnnotationDefs where def.AnnotationTargets.Contains(AnnotationDef.AnnotationTarget.precursor_result) select new[] { def.Name }); string line = reader.ReadLine(); linesRead++; int[] fieldIndices; int fieldsTotal; // If we aren't changing peaks, allow start and end time to be missing var requiredFields = changePeaks ? REQUIRED_FIELDS : REQUIRED_NO_CHROM; char correctSeparator = ReadFirstLine(line, allFieldNames, requiredFields, out fieldIndices, out fieldsTotal); while ((line = reader.ReadLine()) != null) { linesRead++; if (progressMonitor != null) { if (progressMonitor.IsCanceled) { return(Document); } int progressNew = (int)(linesRead * 100 / lineCount); if (progressPercent != progressNew) { progressMonitor.UpdateProgress(status = status.ChangePercentComplete(progressNew)); progressPercent = progressNew; } } var dataFields = new DataFields(fieldIndices, line.ParseDsvFields(correctSeparator), allFieldNames); if (dataFields.Length != fieldsTotal) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Line__0__field_count__1__differs_from_the_first_line__which_has__2_, linesRead, dataFields.Length, fieldsTotal)); } string modifiedPeptideString = dataFields.GetField(Field.modified_peptide); string fileName = dataFields.GetField(Field.filename); bool isDecoy = dataFields.IsDecoy(linesRead); IList <IdentityPath> pepPaths; if (!sequenceToNode.TryGetValue(Tuple.Create(modifiedPeptideString, isDecoy), out pepPaths)) { string canonicalSequence; if (!canonicalSequenceDict.TryGetValue(modifiedPeptideString, out canonicalSequence)) { if (modifiedPeptideString.Any(c => c < 'A' || c > 'Z')) { modMatcher.CreateMatches(Document.Settings, new List <string> { modifiedPeptideString }, Settings.Default.StaticModList, Settings.Default.HeavyModList); var nodeForModPep = modMatcher.GetModifiedNode(modifiedPeptideString); if (nodeForModPep == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Peptide_has_unrecognized_modifications__0__at_line__1_, modifiedPeptideString, linesRead)); } nodeForModPep = nodeForModPep.ChangeSettings(Document.Settings, SrmSettingsDiff.ALL); // Convert the modified peptide string into a standardized form that // converts unimod, names, etc, into masses, eg [+57.0] canonicalSequence = nodeForModPep.ModifiedTarget.Sequence; canonicalSequenceDict.Add(modifiedPeptideString, canonicalSequence); } } if (null != canonicalSequence) { sequenceToNode.TryGetValue(Tuple.Create(canonicalSequence, isDecoy), out pepPaths); } } if (null == pepPaths) { UnrecognizedPeptides.Add(modifiedPeptideString); continue; } Adduct charge; bool chargeSpecified = dataFields.TryGetCharge(linesRead, out charge); string sampleName = dataFields.GetField(Field.sample_name); double?apexTime = dataFields.GetTime(Field.apex_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_time_, linesRead); double?startTime = dataFields.GetTime(Field.start_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_, linesRead); double?endTime = dataFields.GetTime(Field.end_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_end_time_, linesRead); // Error if only one of startTime and endTime is null if (startTime == null && endTime != null) { if (changePeaks) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_start_time_on_line__0_, linesRead)); } endTime = null; } if (startTime != null && endTime == null) { if (changePeaks) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_end_time_on_line__0_, linesRead)); } startTime = null; } // Add filename to second dictionary if not yet encountered ChromSetFileMatch fileMatch; if (!fileNameToFileMatch.TryGetValue(fileName, out fileMatch)) { fileMatch = Document.Settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(fileName)); fileNameToFileMatch.Add(fileName, fileMatch); } if (fileMatch == null) { UnrecognizedFiles.Add(fileName); continue; } var chromSet = fileMatch.Chromatograms; string nameSet = chromSet.Name; ChromFileInfoId[] fileIds; if (sampleName == null) { fileIds = chromSet.MSDataFileInfos.Select(x => x.FileId).ToArray(); } else { var sampleFile = chromSet.MSDataFileInfos.FirstOrDefault(info => Equals(sampleName, info.FilePath.GetSampleName())); if (sampleFile == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Sample__0__on_line__1__does_not_match_the_file__2__, sampleName, linesRead, fileName)); } fileIds = new[] { sampleFile.FileId }; } // Define the annotations to be added var annotations = dataFields.GetAnnotations(); if (!changePeaks) { if (apexTime.HasValue) { annotations.Add(ComparePeakBoundaries.APEX_ANNOTATION, dataFields.GetField(Field.apex_time)); } if (startTime.HasValue && endTime.HasValue) { annotations.Add(ComparePeakBoundaries.START_TIME_ANNOTATION, dataFields.GetField(Field.start_time)); annotations.Add(ComparePeakBoundaries.END_TIME_ANNOTATION, dataFields.GetField(Field.end_time)); } } AnnotationsAdded = annotations.Keys.ToList(); // Loop over all the transition groups in that peptide to find matching charge, // or use all transition groups if charge not specified bool foundSample = false; foreach (var pepPath in pepPaths) { var nodePep = (PeptideDocNode)docNew.FindNode(pepPath); foreach (TransitionGroupDocNode groupNode in nodePep.Children) { if (chargeSpecified && charge != groupNode.TransitionGroup.PrecursorAdduct) { continue; } // Loop over the files in this groupNode to find the correct sample // Change peak boundaries for the transition group foreach (var fileId in GetApplicableFiles(fileIds, groupNode)) { var groupPath = new IdentityPath(pepPath, groupNode.Id); // Attach annotations if (annotations.Any()) { docNew = docNew.AddPrecursorResultsAnnotations(groupPath, fileId, annotations); } // Change peak var filePath = chromSet.GetFileInfo(fileId).FilePath; if (changePeaks) { docNew = docNew.ChangePeak(groupPath, nameSet, filePath, null, startTime, endTime, UserSet.IMPORTED, null, false); } // For removing peaks that are not in the file, if removeMissing = true trackAdjustedResults.Add(new ResultsKey(fileId.GlobalIndex, groupNode.Id)); foundSample = true; } } } if (!foundSample) { UnrecognizedChargeStates.Add(new UnrecognizedChargeState(charge, fileName, modifiedPeptideString)); } } // Remove peaks from the document that weren't in the file. if (removeMissing) { docNew = RemoveMissing(docNew, trackAdjustedResults, changePeaks); } // If nothing has changed, return the old Document before ChangeIgnoreChangingChildren was turned off if (!ReferenceEquals(docNew, docReference)) { Document = (SrmDocument)Document.ChangeIgnoreChangingChildren(false).ChangeChildrenChecked(docNew.Children); } return(Document); }
public void InitializeSpectrumSourceFiles(SrmDocument document) { if (!IsDDASearch) { if (DocLib == null) { return; } var measuredResults = document.Settings.MeasuredResults; foreach (var dataFile in DocLib.LibraryFiles.FilePaths) { var msDataFilePath = new MsDataFilePath(dataFile); SpectrumSourceFiles[dataFile] = new FoundResultsFilePossibilities(msDataFilePath.GetFileNameWithoutExtension()); // If a matching file is already in the document, then don't include // this library spectrum source in the set of files to find. if (measuredResults != null && measuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(dataFile)) != null) { continue; } if (File.Exists(dataFile) && DataSourceUtil.IsDataSource(dataFile)) { // We've found the dataFile in the exact location // specified in the document library, so just add it // to the "FOUND" list. SpectrumSourceFiles[dataFile].ExactMatch = msDataFilePath.ToString(); } } DocLib.ReadStream.CloseStream(); } }
public void ThermoCancelImportTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); var docContainer = new ResultsTestDocumentContainer(doc, docPath); string resultsPath = testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + ExtensionTestContext.ExtThermoRaw); string dirPath = Path.GetDirectoryName(resultsPath) ?? ""; // Remove any existing temp and cache files foreach (var path in Directory.GetFiles(dirPath)) { if (IsCacheOrTempFile(path)) { FileEx.SafeDelete(path); } } string name = Path.GetFileNameWithoutExtension(resultsPath); var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet(name, new[] { MsDataFileUri.Parse(resultsPath) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); // Start cache load, but don't wait for completion Assert.IsTrue(docContainer.SetDocument(docResults, doc)); // Wait up to 1 second for the cache to start being written for (int i = 0; i < 100; i++) { if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) != -1) { break; } Thread.Sleep(10); } Assert.IsTrue(Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) != -1, "Failed to create cache file"); // Cancel by reverting to the original document Assert.IsTrue(docContainer.SetDocument(doc, docResults)); // Wait up to 5 seconds for cancel to occur for (int i = 0; i < 50; i++) { if (docContainer.LastProgress.IsCanceled) { break; } Thread.Sleep(100); } if (!docContainer.LastProgress.IsCanceled) { Assert.Fail("Attempt to cancel results load failed. {0}", docContainer.LastProgress.ErrorException != null ? docContainer.LastProgress.ErrorException.Message : string.Empty); } // Wait up to 20 seconds for the cache to be removed for (int i = 0; i < 200; i++) { if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) == -1) { break; } Thread.Sleep(100); } // Cache file has been removed Assert.IsTrue(Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) == -1, "Failed to remove cache file"); testFilesDir.Dispose(); }
protected override void DoTest() { // Lest we get "To export a scheduled method, you must first choose a retention time predictor in Peptide Settings / Prediction, or import results for all peptides in the document." TestSmallMolecules = false; // Skyline Collision Energy Optimization RunUI(() => SkylineWindow.OpenFile(GetTestPath("CE_Vantage_15mTorr.sky"))); // Not L10N if (AsSmallMolecules) { var doc = WaitForDocumentLoaded(); var refine = new RefinementSettings(); SkylineWindow.SetDocument(refine.ConvertToSmallMolecules(doc), doc); } // Deriving a New Linear Equation, p. 2 var transitionSettingsUI = ShowDialog <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI); var editList = ShowDialog <EditListDlg <SettingsListBase <CollisionEnergyRegression>, CollisionEnergyRegression> > (transitionSettingsUI.EditCEList); RunUI(() => editList.SelectItem("Thermo")); // Not L10N EditCEDlg editItem = ShowDialog <EditCEDlg>(editList.EditItem); PauseForScreenShot <EditCEDlg>("Edit Collision Energy Equation form", 3); ChargeRegressionLine regressionLine2 = new ChargeRegressionLine(2, 0.034, 3.314); ChargeRegressionLine regressionLine3 = new ChargeRegressionLine(3, 0.044, 3.314); CheckRegressionLines(new[] { regressionLine2, regressionLine3 }, editItem.Regression.Conversions); RunUI(() => { editItem.DialogResult = DialogResult.OK; editList.DialogResult = DialogResult.Cancel; transitionSettingsUI.DialogResult = DialogResult.Cancel; }); WaitForClosedForm(transitionSettingsUI); // Measuring Retention Times for Method Scheduling, p. 3 { var exportMethodDlg = ShowDialog <ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List)); RunUI(() => { exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO; exportMethodDlg.ExportStrategy = ExportStrategy.Single; exportMethodDlg.OptimizeType = ExportOptimize.NONE; exportMethodDlg.MethodType = ExportMethodType.Standard; }); PauseForScreenShot <ExportMethodDlg.TransitionListView>("Export Transition List form", 4); RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"))); // Not L10N WaitForClosedForm(exportMethodDlg); } string filePathTemplate = GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"); // Not L10N CheckTransitionList(filePathTemplate, 1, 6); const string unscheduledName = "Unscheduled"; // Not L10N RunDlg <ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg => { importResultsDlg.RadioAddNewChecked = true; var path = new[] { new KeyValuePair <string, MsDataFileUri[]>(unscheduledName, // This is not actually a valid file path (missing OptimizeCE) // but Skyline should correctly find the file in the same folder // as the document. new[] { MsDataFileUri.Parse(GetTestPath("CE_Vantage_15mTorr_unscheduled" + ExtThermoRaw)) }) }; // Not L10N importResultsDlg.NamedPathSets = path; importResultsDlg.OkDialog(); }); WaitForCondition(5 * 60 * 1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 5 minutes AssertEx.IsDocumentState(SkylineWindow.Document, null, 7, 27, 30, 120); var docUnsched = SkylineWindow.Document; AssertResult.IsDocumentResultsState(SkylineWindow.Document, unscheduledName, docUnsched.MoleculeCount, docUnsched.MoleculeTransitionGroupCount, 0, docUnsched.MoleculeTransitionCount - 1, 0); RunUI(() => { SkylineWindow.ExpandProteins(); SkylineWindow.ExpandPeptides(); }); PauseForScreenShot("Main Skyline window", 5); // Creating Optimization Methods, p. 5 { var exportMethodDlg = ShowDialog <ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List)); RunUI(() => { exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO; exportMethodDlg.ExportStrategy = ExportStrategy.Buckets; exportMethodDlg.MaxTransitions = 110; exportMethodDlg.IgnoreProteins = true; exportMethodDlg.OptimizeType = ExportOptimize.CE; exportMethodDlg.MethodType = ExportMethodType.Scheduled; }); PauseForScreenShot <ExportMethodDlg.TransitionListView>("Export Transition List form", 6); RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr.csv"))); // Not L10N WaitForClosedForm(exportMethodDlg); } string filePathTemplate1 = GetTestPath("CE_Vantage_15mTorr_000{0}.csv"); // Not L10N CheckTransitionList(filePathTemplate1, 5, 9); var filePath = GetTestPath("CE_Vantage_15mTorr_0001.csv"); // Not L10N CheckCEValues(filePath, 11); // Analyze Optimization Data, p. 7 RunDlg <ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg => { importResultsDlg.RadioAddNewChecked = true; importResultsDlg.OptimizationName = ExportOptimize.CE; importResultsDlg.NamedPathSets = DataSourceUtil.GetDataSourcesInSubdirs(TestFilesDirs[0].FullPath).ToArray(); importResultsDlg.NamedPathSets[0] = new KeyValuePair <string, MsDataFileUri[]>("Optimize CE", importResultsDlg.NamedPathSets[0].Value.Take(5).ToArray()); // Not L10N importResultsDlg.OkDialog(); }); RunUI(() => { SkylineWindow.ShowSingleTransition(); SkylineWindow.AutoZoomBestPeak(); SkylineWindow.ShowPeakAreaReplicateComparison(); }); WaitForDocumentLoaded(15 * 60 * 1000); // 10 minutes if (AsSmallMolecules) { return; // Too peptide-centric from here to end of test } FindNode("IHGFDLAAINLQR"); RestoreViewOnScreen(8); PauseForScreenShot("Main Skyline window", 8); // p. 8 // Not L10N RemovePeptide("EGIHAQQK"); FindNode("IDALNENK"); RunUI(() => SkylineWindow.NormalizeAreaGraphTo(AreaNormalizeToView.area_percent_view)); PauseForScreenShot("Main Skyline window", 9); RunUI(SkylineWindow.EditDelete); RemovePeptide("LICDNTHITK"); // Creating a New Equation for CE, p. 9 var transitionSettingsUI1 = ShowDialog <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI); var editCEDlg1 = ShowDialog <EditListDlg <SettingsListBase <CollisionEnergyRegression>, CollisionEnergyRegression> >(transitionSettingsUI1.EditCEList); var addItem = ShowDialog <EditCEDlg>(editCEDlg1.AddItem); RunUI(() => { addItem.RegressionName = "Thermo Vantage Tutorial"; // Not L10N addItem.UseCurrentData(); }); var graphRegression = ShowDialog <GraphRegression>(addItem.ShowGraph); PauseForScreenShot <GraphRegression>("Collision Energy Regression graphs", 10); var graphDatas = graphRegression.RegressionGraphDatas.ToArray(); Assert.AreEqual(2, graphDatas.Length); ChargeRegressionLine regressionLine21 = new ChargeRegressionLine(2, 0.0305, 2.5061); ChargeRegressionLine regressionLine31 = new ChargeRegressionLine(3, 0.0397, 1.4217); var expectedRegressions = new[] { regressionLine21, regressionLine31 }; CheckRegressionLines(expectedRegressions, new[] { new ChargeRegressionLine(2, Math.Round(graphDatas[0].RegressionLine.Slope, 4), Math.Round(graphDatas[0].RegressionLine.Intercept, 4)), new ChargeRegressionLine(3, Math.Round(graphDatas[1].RegressionLine.Slope, 4), Math.Round(graphDatas[1].RegressionLine.Intercept, 4)), }); RunUI(graphRegression.CloseDialog); WaitForClosedForm(graphRegression); RunUI(addItem.OkDialog); WaitForClosedForm(addItem); RunUI(editCEDlg1.OkDialog); WaitForClosedForm(editCEDlg1); RunUI(transitionSettingsUI1.OkDialog); WaitForClosedForm(transitionSettingsUI1); // Optimizing Each Transition, p. 10 RunDlg <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, transitionSettingsUI2 => { transitionSettingsUI2.UseOptimized = true; transitionSettingsUI2.OptimizeType = OptimizedMethodType.Transition.GetLocalizedString(); transitionSettingsUI2.OkDialog(); }); RunDlg <ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List), exportMethodDlg => { exportMethodDlg.ExportStrategy = ExportStrategy.Single; exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_optimized.csv")); // Not L10N }); var filePathTemplate2 = GetTestPath("CE_Vantage_15mTorr_optimized.csv"); // Not L10N CheckTransitionList(filePathTemplate2, 1, 9); RunUI(() => SkylineWindow.SaveDocument()); WaitForConditionUI(() => !SkylineWindow.Dirty); }
public void DoThermoRatioTest(RefinementSettings.ConvertToSmallMoleculesMode smallMoleculesTestMode) { TestSmallMolecules = false; // We do this explicitly var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); SrmSettings settings = doc.Settings.ChangePeptideModifications(mods => mods.ChangeInternalStandardTypes(new[] { IsotopeLabelType.light })); doc = doc.ChangeSettings(settings); if (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none) { var docOrig = doc; var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, smallMoleculesTestMode); // This is our first example of a converted label doc - check roundtripping AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(docOrig, doc); AssertEx.Serializable(doc); } var docContainer = new ResultsTestDocumentContainer(doc, docPath); string extRaw = ExtensionTestContext.ExtThermoRaw; var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet("rep03", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_03" + extRaw)) }), new ChromatogramSet("rep05", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_05" + extRaw)) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; // Make sure all groups have at least 5 transitions (of 6) with ratios int ratioGroupMissingCount = 0; foreach (var nodeGroup in docResults.MoleculeTransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) { foreach (var result in nodeGroup.Results) { Assert.IsFalse(result[0].Ratio.HasValue, "Light group found with a ratio"); } foreach (TransitionDocNode nodeTran in nodeGroup.Children) { foreach (var resultTran in nodeTran.Results) { Assert.IsFalse(resultTran[0].Ratio.HasValue, "Light transition found with a ratio"); } } } else { bool missingRatio = false; foreach (ChromInfoList <TransitionGroupChromInfo> chromInfoList in nodeGroup.Results) { var ratioHeavy = chromInfoList[0].Ratio; if (!ratioHeavy.HasValue) { missingRatio = true; } } int ratioCount1 = 0; int ratioCount2 = 0; foreach (TransitionDocNode nodeTranHeavy in nodeGroup.Children) { float?ratioHeavy = nodeTranHeavy.Results[0][0].Ratio; if (ratioHeavy.HasValue) { Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value)); ratioCount1++; } ratioHeavy = nodeTranHeavy.Results[1][0].Ratio; if (ratioHeavy.HasValue) { Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value)); ratioCount2++; } } Assert.AreEqual(3, ratioCount1); if (ratioCount2 < 2) { ratioGroupMissingCount++; } else { Assert.IsFalse(missingRatio, "Precursor missing ratio when transitions have ratios"); } } } // 3 groups with less than 2 transition ratios Assert.AreEqual(3, ratioGroupMissingCount); // Remove the first light transition, checking that this removes the ratio // from the corresponding heavy transition, but not the entire group, until // after all light transitions have been removed. IdentityPath pathFirstPep = docResults.GetPathTo((int)SrmDocument.Level.Molecules, 0); var nodePep = (PeptideDocNode)docResults.FindNode(pathFirstPep); Assert.AreEqual(2, nodePep.Children.Count); var nodeGroupLight = (TransitionGroupDocNode)nodePep.Children[0]; IdentityPath pathGroupLight = new IdentityPath(pathFirstPep, nodeGroupLight.TransitionGroup); Assert.IsNull(nodeGroupLight.Results[0][0].Ratio, "Light group has ratio"); var nodeGroupHeavy = (TransitionGroupDocNode)nodePep.Children[1]; IdentityPath pathGroupHeavy = new IdentityPath(pathFirstPep, nodeGroupHeavy.TransitionGroup); float? ratioStart = nodeGroupHeavy.Results[0][0].Ratio; Assert.IsTrue(ratioStart.HasValue, "No starting heavy group ratio"); var expectedValues = new[] { 1.403414, 1.38697791, 1.34598482 }; for (int i = 0; i < 3; i++) { var pathLight = docResults.GetPathTo((int)SrmDocument.Level.Transitions, 0); var pathHeavy = docResults.GetPathTo((int)SrmDocument.Level.Transitions, 3); TransitionDocNode nodeTran = (TransitionDocNode)docResults.FindNode(pathHeavy); float? ratioTran = nodeTran.Results[0][0].Ratio; Assert.IsTrue(ratioTran.HasValue, "Expected transition ratio not found"); Assert.AreEqual(ratioTran.Value, expectedValues[i], 1.0e-5); docResults = (SrmDocument)docResults.RemoveChild(pathLight.Parent, docResults.FindNode(pathLight)); nodeTran = (TransitionDocNode)docResults.FindNode(pathHeavy); Assert.IsFalse(nodeTran.Results[0][0].Ratio.HasValue, "Unexpected transiton ratio found"); Assert.AreEqual(pathGroupHeavy, pathHeavy.Parent, "Transition found outside expected group"); // nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep); nodeGroupHeavy = (TransitionGroupDocNode)docResults.FindNode(pathGroupHeavy); // Assert.AreEqual(nodePep.Results[0][0].RatioToStandard, nodeGroupHeavy.Results[0][0].Ratio, // "Peptide and group ratios not equal"); if (i < 2) { float?ratioGroup = nodeGroupHeavy.Results[0][0].Ratio; Assert.IsTrue(ratioGroup.HasValue, "Group ratio removed with transition ratios"); Assert.AreEqual(ratioStart.Value, ratioGroup.Value, 0.1, "Unexpected group ratio change by more than 0.1"); } else { Assert.IsFalse(nodeGroupHeavy.Results[0][0].Ratio.HasValue, "Group ratio still present with no transition ratios"); } } bool asSmallMolecules = (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none); if (!asSmallMolecules) // GetTransitions() doesn't work the same way for small molecules - it only lists existing ones { bool firstAdd = true; var nodeGroupLightOrig = (TransitionGroupDocNode)doc.FindNode(pathGroupLight); DocNode[] lightChildrenOrig = nodeGroupLightOrig.Children.ToArray(); foreach (var nodeTran in nodeGroupLightOrig.GetTransitions(docResults.Settings, null, nodeGroupLightOrig.PrecursorMz, null, null, null, false)) { var transition = nodeTran.Transition; if (!firstAdd && lightChildrenOrig.IndexOf(node => Equals(node.Id, transition)) == -1) { continue; } // Add the first transition, and then the original transitions docResults = (SrmDocument)docResults.Add(pathGroupLight, nodeTran); nodeGroupHeavy = (TransitionGroupDocNode)docResults.FindNode(pathGroupHeavy); if (firstAdd) { Assert.IsNull(nodeGroupHeavy.Results[0][0].Ratio, "Unexpected heavy ratio found"); } else { Assert.IsNotNull(nodeGroupHeavy.Results[0][0].Ratio, "Heavy ratio null after adding light children"); } firstAdd = false; } Assert.AreEqual(ratioStart, nodeGroupHeavy.Results[0][0].Ratio); } // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
public void ThermoCancelImportTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string resultsPath = testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + ExtensionTestContext.ExtThermoRaw); string dirPath = Path.GetDirectoryName(resultsPath) ?? ""; string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); // Give this two chances to succeed. It can succeed tens of thousands of times // in a row, but it still occasionally fails on nightly tests. Hopefully two // tries will make this extremely unlikely. for (int tries = 0; tries < 2; tries++) { using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Remove any existing temp and cache files foreach (var path in Directory.GetFiles(dirPath)) { if (IsCacheOrTempFile(path)) { FileEx.SafeDelete(path); } } string name = Path.GetFileNameWithoutExtension(resultsPath); var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet(name, new[] { MsDataFileUri.Parse(resultsPath) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); // Start cache load, but don't wait for completion Assert.IsTrue(docContainer.SetDocument(docResults, doc)); // Wait up to 10 second for the cache to start being written bool cacheFound = false; for (int i = 0; i < 1000; i++) { if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) != -1) { cacheFound = true; break; } Thread.Sleep(10); } if (!cacheFound) { Assert.Fail(TextUtil.LineSeparate("Failed to create cache file. Found files:", TextUtil.LineSeparate(Directory.GetFiles(dirPath)))); } // Cancel by reverting to the original document Assert.IsTrue(docContainer.SetDocument(doc, docResults)); // Wait up to 10 seconds for cancel to occur bool cancelOccurred = false; for (int i = 0; i < 1000; i++) { if (docContainer.LastProgress != null && docContainer.LastProgress.IsCanceled) { cancelOccurred = true; break; } Thread.Sleep(10); } // Wait up to 20 seconds for the cache to be removed bool cacheRemoved = false; for (int i = 0; i < 200; i++) { if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) == -1) { cacheRemoved = true; break; } Thread.Sleep(100); } if (!cacheRemoved) { if (tries == 0 && File.Exists(Path.ChangeExtension(docPath, ChromatogramCache.EXT))) { // Allow a single failure where we end up with the final cache instead of a cancelation FileEx.SafeDelete(docPath); continue; // Try again } if (!cancelOccurred) { Assert.Fail("Attempt to cancel results load failed on try {0}. {1}", tries + 1, docContainer.LastProgress != null && docContainer.LastProgress.ErrorException != null ? docContainer.LastProgress.ErrorException.Message : string.Empty); } Assert.Fail(TextUtil.LineSeparate("Failed to remove cache file. Found files:", TextUtil.LineSeparate(Directory.GetFiles(dirPath)))); } break; // If we make it here then, successful } } // Cache file has been removed testFilesDir.Dispose(); }
private void RemoveCorrespondingReplicatesForLibraryRuns() { if (listResults.Items.Count != 0) { var newChromRemList = new List <ChromatogramSet>(ChromatogramsRemovedList); foreach (var dataFile in LibraryRunsRemovedList) { var matchingFile = DocumentUIContainer.Document.Settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(dataFile)); if (null != matchingFile) { int foundIndex = listResults.FindString(matchingFile.Chromatograms.Name); if (ListBox.NoMatches != foundIndex) { newChromRemList.Add(matchingFile.Chromatograms); listResults.Items.RemoveAt(foundIndex); if (listResults.Items.Count == 0) { break; } } } } ChromatogramsRemovedList = newChromRemList; } }
public void TestCollectStatistics() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" + ExtensionTestContext.ExtThermoRaw); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { MsDataFileUri.Parse(rawPath) }) }); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21); ChromCacheMinimizer chromCacheMinimizer = docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults); ChromCacheMinimizer.Settings settings = new ChromCacheMinimizer.Settings().ChangeDiscardUnmatchedChromatograms(true); ChromCacheMinimizer.MinStatistics minStatistics = null; chromCacheMinimizer.Minimize(settings, s => minStatistics = s, null); Assert.AreEqual(100, minStatistics.PercentComplete); Assert.AreEqual(1.0, minStatistics.MinimizedRatio); var docMissingFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().RemoveChild(docResults.PeptideGroups.First().Children[0])); var docWithOnlyFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().ChangeChildren(new[] { docResults.PeptideGroups.First().Children[0] })); ChromCacheMinimizer.MinStatistics statsMissingFirstProtein = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProtein = null; settings = settings.ChangeDiscardUnmatchedChromatograms(true); ChromCacheMinimizer minimizerMissingFirstProtein = docMissingFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docMissingFirstPeptide); ChromCacheMinimizer minimizerWithOnlyFirstProtein = docWithOnlyFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docWithOnlyFirstPeptide); minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProtein = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProtein = s, null); Assert.AreEqual(100, statsMissingFirstProtein.PercentComplete); Assert.AreEqual(100, statsWithOnlyFirstProtein.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProtein.MinimizedRatio + statsWithOnlyFirstProtein.MinimizedRatio, .00001); settings = settings.ChangeDiscardUnmatchedChromatograms(false); ChromCacheMinimizer.MinStatistics statsMissingFirstProteinKeepAll = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProteinKeepAll = null; minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProteinKeepAll = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProteinKeepAll = s, null); Assert.AreEqual(100, statsMissingFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProteinKeepAll.MinimizedRatio); Assert.AreEqual(100, statsWithOnlyFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsWithOnlyFirstProteinKeepAll.MinimizedRatio); } }
private void DoSubTest(TestFilesDir testFilesDir, string skyFile, double[] expectedRTs, string[] filenames, double?expectedRatio) { string docPath; var doc = InitExplicitRTDocument(testFilesDir, skyFile, out docPath); var listChromatograms = new List <ChromatogramSet>(); foreach (var filename in filenames) { var path = MsDataFileUri.Parse(filename + ExtensionTestContext.ExtWatersRaw); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); } var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(SkylineWindow.SetDocument(docResults, doc)); var document = WaitForDocumentLoaded(); float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var infos = new List <ChromatogramGroupInfo[]>(); foreach (var pair in document.MoleculePrecursorPairs) { for (var f = 0; f < filenames.Length; f++) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(f, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); infos.Add(chromGroupInfo); } } for (int i = 0; i < infos.Count; i++) { if (infos[i].Length == 0) { Assert.AreEqual(0, expectedRTs[i], "expected to find a peak at " + expectedRTs[i]); continue; } var chromatogramInfo = infos[i][0].GetTransitionInfo(0); var chromPeaks = chromatogramInfo.Peaks.ToList(); if (expectedRTs[i] == 0) // Not expecting to find a good peak { var errmsg = chromatogramInfo.BestPeakIndex >= 0 ? string.Format("Did not expect to find a peak at RT {0} in {1} ", chromPeaks[chromatogramInfo.BestPeakIndex].RetentionTime, skyFile) : string.Empty; Assert.AreEqual(-1, chromatogramInfo.BestPeakIndex, errmsg); } else if (chromatogramInfo.BestPeakIndex == -1) { Assert.Fail("expected to find a peak at {0} in {1}", expectedRTs[i], skyFile); } else { var peakRT = chromPeaks[chromatogramInfo.BestPeakIndex].RetentionTime; Assert.AreEqual(expectedRTs[i], peakRT, 0.1, string.Format("Expected to find a peak at RT {0} in {1}", expectedRTs[i], skyFile)); } } if (expectedRatio.HasValue) { var nResults = 0; foreach (var nodePep in document.Molecules) { foreach (var results in nodePep.Results) { foreach (var result in results) { Assert.IsNotNull(result.LabelRatios[0].Ratio); Assert.AreEqual(expectedRatio.Value, result.LabelRatios[0].Ratio.Ratio, .1); nResults++; } } } Assert.AreEqual(filenames.Length * document.MoleculeCount, nResults); } WaitForClosedAllChromatogramsGraph(); }
protected override void DoTest() { Settings.Default.PeakScoringModelList.Clear(); // Open the file RunUI(() => SkylineWindow.OpenFile(GetTestPath("SRMCourse_DosR-hDP__20130501-tutorial-empty.sky"))); // Not L10N WaitForDocumentLoaded(); // Add decoys var generateDecoysDlg = ShowDialog <GenerateDecoysDlg>(() => SkylineWindow.ShowGenerateDecoysDlg()); RunUI(() => { generateDecoysDlg.DecoysMethod = DecoyGeneration.REVERSE_SEQUENCE; generateDecoysDlg.NumDecoys = 29; }); PauseForScreenShot <GenerateDecoysDlg>("Add Decoy Peptides form", 2); RunUI(generateDecoysDlg.OkDialog); WaitForClosedForm(generateDecoysDlg); RestoreViewOnScreen(3); RunUI(() => SkylineWindow.SequenceTree.TopNode = SkylineWindow.SequenceTree.Nodes[11]); PauseForScreenShot("Targets view clipped from main window", 3); // Open the file with decoys RunUI(() => SkylineWindow.OpenFile(GetTestPath("SRMCourse_DosR-hDP__20130501-tutorial-empty-decoys.sky"))); // Not L10N WaitForDocumentLoaded(); // Import the raw data var importResultsDlg = ShowDialog <ImportResultsDlg>(SkylineWindow.ImportResults); RunUI(() => { importResultsDlg.RadioAddNewChecked = true; var path = new KeyValuePair <string, MsDataFileUri[]> [5]; for (int i = 0; i < 5; ++i) { path[i] = new KeyValuePair <string, MsDataFileUri[]>(_importFiles[i], new[] { MsDataFileUri.Parse(GetTestPath(_importFiles[i] + ExtAbWiff)) }); } importResultsDlg.NamedPathSets = path; }); var importResultsNameDlg = ShowDialog <ImportResultsNameDlg>(importResultsDlg.OkDialog); PauseForScreenShot <ImportResultsNameDlg>("Import Results common prefix form", 4); RunUI(() => { string prefix = importResultsNameDlg.Prefix; importResultsNameDlg.Prefix = prefix.Substring(0, prefix.Length - 1); importResultsNameDlg.YesDialog(); }); WaitForClosedForm(importResultsNameDlg); WaitForClosedForm(importResultsDlg); WaitForConditionUI(5 * 60 * 1000, () => SkylineWindow.DocumentUI.Settings.HasResults && SkylineWindow.DocumentUI.Settings.MeasuredResults.IsLoaded); // 5 minutes RestoreViewOnScreen(5); const string peptideSeqHighlight = "LPDGNGIELCR"; RunUI(() => { var nodeGroup = SkylineWindow.DocumentUI.PeptideTransitionGroups.ToArray()[71]; Assert.AreEqual(nodeGroup.TransitionGroup.Peptide.Sequence, peptideSeqHighlight); var chromGroupInfo = nodeGroup.ChromInfos.ToList()[0]; Assert.IsNotNull(chromGroupInfo.RetentionTime); // TODO: Fix the tutorial. This was supposed to be an incorrectly picked peak, but our default scoring is now good enough to pick it correctly Assert.AreEqual(chromGroupInfo.RetentionTime.Value, 18.0, 0.1); SkylineWindow.ChangeTextSize(TreeViewMS.LRG_TEXT_FACTOR); }); RunDlg <ChromChartPropertyDlg>(SkylineWindow.ShowChromatogramProperties, dlg => { dlg.FontSize = GraphFontSize.LARGE; dlg.OkDialog(); }); PauseForScreenShot("Main window", 5); // Test different point types on RTLinearRegressionGraph RunUI(() => { SkylineWindow.ShowRTRegressionGraphScoreToRun(); SkylineWindow.ShowPlotType(PlotTypeRT.correlation); SkylineWindow.ChooseCalculator("iRT_SRMAtlas_20121202_noLGG"); }); const int numDecoys = 30; CheckPointsTypeRT(PointsTypeRT.targets, SkylineWindow.Document.PeptideCount - numDecoys); CheckPointsTypeRT(PointsTypeRT.standards, SkylineWindow.Document.GetRetentionTimeStandards().Count); CheckPointsTypeRT(PointsTypeRT.decoys, numDecoys); RunUI(() => SkylineWindow.ShowGraphRetentionTime(false)); WaitForDocumentLoaded(); // Train the peak scoring model var reintegrateDlg = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog); PauseForScreenShot <ReintegrateDlg>("Reintegrate form", 6); var editDlg = ShowDialog <EditPeakScoringModelDlg>(reintegrateDlg.AddPeakScoringModel); RunUI(() => editDlg.TrainModel()); PauseForScreenShot <EditPeakScoringModelDlg.ModelTab>("Edit Peak Scoring Model form trained model", 6); RunUI(() => Assert.AreEqual(0.5926, editDlg.PeakCalculatorsGrid.Items[3].PercentContribution ?? 0, 0.005)); RunUI(() => editDlg.SelectedGraphTab = 2); PauseForScreenShot <EditPeakScoringModelDlg.PvalueTab>("Edit Peak Scoring Model form p value graph metafile", 7); RunUI(() => editDlg.SelectedGraphTab = 3); PauseForScreenShot <EditPeakScoringModelDlg.QvalueTab>("Edit Peak Scoring Model form q value graph metafile", 8); RunUI(() => editDlg.SelectedGraphTab = 1); RunUI(() => editDlg.PeakCalculatorsGrid.SelectRow(3)); PauseForScreenShot <EditPeakScoringModelDlg.FeaturesTab>("Edit Peak Scoring Model form feature score", 10); RunUI(() => { Assert.AreEqual(18, editDlg.PeakCalculatorsGrid.RowCount); // The rows which the tutorial says are missing scores are in fact missing scores foreach (int i in new[] { 2, 7, 8, 9, 10, 11, 13, 15 }) // MS1 scores are now missing, 19, 20, 21, 22 { Assert.IsFalse(editDlg.IsActiveCell(i, 0)); } editDlg.IsFindButtonVisible = true; editDlg.FindMissingValues(2); // Retention time editDlg.PeakScoringModelName = "test1"; }); PauseForScreenShot <EditPeakScoringModelDlg.FeaturesTab>("Edit Peak Scoring Model form find missing scores", 11); OkDialog(editDlg, editDlg.OkDialog); OkDialog(reintegrateDlg, reintegrateDlg.CancelDialog); PauseForScreenShot <FindResultsForm>("Find Results view clipped from main window", 12); // Remove the peptide with no library dot product, and train again FindResultsForm findResultsForm = null; var missingPeptides = new List <string> { "LGGNEQVTR", "IPVDSIYSPVLK", "YFNDGDIVEGTIVK", "DFDSLGTLR", "GGYAGMLVGSVGETVAQLAR", "GGYAGMLVGSVGETVAQLAR" }; var isDecoys = new List <bool> { false, false, false, false, false, true }; RunUI(() => { findResultsForm = FormUtil.OpenForms.OfType <FindResultsForm>().FirstOrDefault(); Assert.IsNotNull(findResultsForm); // ReSharper disable once PossibleNullReferenceException Assert.AreEqual(findResultsForm.ItemCount, 6); for (int i = 0; i < 6; ++i) { findResultsForm.ActivateItem(i); Assert.AreEqual(SkylineWindow.SelectedPeptideSequence, missingPeptides[i]); if (0 < i && i < 5) { SkylineWindow.SetStandardType(PeptideDocNode.STANDARD_TYPE_QC); } } }); RunUI(() => findResultsForm.Close()); for (int i = 0; i < 6; ++i) { if (!(0 < i && i < 5)) { RemovePeptide(missingPeptides[i], isDecoys[i]); } } if (IsCoverShotMode) { RestoreCoverViewOnScreen(); var reintegrateDlgCover = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog); var editModelCover = ShowDialog <EditPeakScoringModelDlg>(reintegrateDlgCover.AddPeakScoringModel); RunUI(() => { editModelCover.Top = SkylineWindow.Top + 8; editModelCover.Left = SkylineWindow.Right - editModelCover.Width - 8; editModelCover.PeakScoringModelName = "SRMCourse"; editModelCover.TrainModelClick(); }); TakeCoverShot(); OkDialog(editModelCover, editModelCover.CancelDialog); OkDialog(reintegrateDlgCover, reintegrateDlgCover.CancelDialog); return; } var reintegrateDlgNew = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog); var editListLibrary = ShowDialog <EditListDlg <SettingsListBase <PeakScoringModelSpec>, PeakScoringModelSpec> >( reintegrateDlgNew.EditPeakScoringModel); RunUI(() => editListLibrary.SelectItem("test1")); var editDlgLibrary = ShowDialog <EditPeakScoringModelDlg>(editListLibrary.EditItem); RunUI(() => { foreach (int i in new[] { 2, 8, 9, 10, 11 }) { Assert.IsTrue(editDlgLibrary.IsActiveCell(i, 0)); Assert.IsFalse(editDlgLibrary.PeakCalculatorsGrid.Items[i].IsEnabled); editDlgLibrary.PeakCalculatorsGrid.Items[i].IsEnabled = true; } editDlgLibrary.TrainModel(true); }); PauseForScreenShot <EditPeakScoringModelDlg.ModelTab>("Edit Peak Scoring Model form with library score", 13); RunUI(() => editDlgLibrary.SelectedGraphTab = 3); PauseForScreenShot <EditPeakScoringModelDlg.QvalueTab>("Edit Peak Scoring Model form q value graph with library score metafile", 14); OkDialog(editDlgLibrary, editDlgLibrary.OkDialog); // Open up the model again for editing, re-train with second best peaks and removing some scores RunUI(() => editListLibrary.SelectItem("test1")); // Not L10N var editDlgNew = ShowDialog <EditPeakScoringModelDlg>(editListLibrary.EditItem); RunUI(() => { Assert.IsFalse(editDlgNew.UsesSecondBest); Assert.IsTrue(editDlgNew.UsesDecoys); Assert.IsTrue(editDlgNew.PeakCalculatorsGrid.Items[4].IsEnabled); Assert.IsTrue(editDlgNew.PeakCalculatorsGrid.Items[4].PercentContribution < 0); Assert.IsTrue(editDlgNew.PeakCalculatorsGrid.Items[2].IsEnabled); Assert.IsTrue(editDlgNew.PeakCalculatorsGrid.Items[2].PercentContribution > 0); editDlgNew.UsesSecondBest = true; editDlgNew.PeakCalculatorsGrid.Items[4].IsEnabled = false; editDlgNew.PeakCalculatorsGrid.Items[2].IsEnabled = false; editDlgNew.TrainModel(true); // Check that these cells are still active even though they've been unchecked Assert.IsTrue(editDlgNew.IsActiveCell(6, 0)); }); PauseForScreenShot <EditPeakScoringModelDlg.ModelTab>("Edit Peak Scoring Model form with second best", 15); OkDialog(editDlgNew, editDlgNew.CancelDialog); OkDialog(editListLibrary, editListLibrary.OkDialog); // Apply the model to reintegrate peaks RunUI(() => { reintegrateDlgNew.ComboPeakScoringModelSelected = "test1"; reintegrateDlgNew.ReintegrateAll = true; reintegrateDlgNew.OverwriteManual = true; }); PauseForScreenShot <ReintegrateDlg>("Reintegrate form", 16); OkDialog(reintegrateDlgNew, reintegrateDlgNew.OkDialog); RunUI(() => { var nodeGroup = SkylineWindow.DocumentUI.PeptideTransitionGroups.ToArray()[70]; Assert.AreEqual(nodeGroup.TransitionGroup.Peptide.Sequence, peptideSeqHighlight); var chromGroupInfo = nodeGroup.ChromInfos.ToList()[0]; Assert.IsNotNull(chromGroupInfo.RetentionTime); Assert.AreEqual(18.0, chromGroupInfo.RetentionTime.Value, 0.1); }); FindNode(peptideSeqHighlight); PauseForScreenShot <GraphChromatogram>("Chromatogram graph metafile corrected peak at 18.0", 17); // Reintegrate slightly differently, with a q value cutoff var reintegrateDlgQ = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog); RunUI(() => { reintegrateDlgQ.ReintegrateAll = false; reintegrateDlgQ.Cutoff = 0.001; reintegrateDlgQ.OverwriteManual = true; }); OkDialog(reintegrateDlgQ, reintegrateDlgQ.OkDialog); PauseForScreenShot("Targets view with some null peaks clipped from main window", 17); PauseForScreenShot <GraphChromatogram>("Chromatogram graph metafile with no picked peak", 18); RestoreViewOnScreen(14); FindNode((622.3086).ToString(CultureInfo.CurrentCulture) + "++"); PauseForScreenShot("Main window with interference on transition", 19); // Export the mProphet features var mProphetExportDlg = ShowDialog <MProphetFeaturesDlg>(SkylineWindow.ShowMProphetFeaturesDialog); RunUI(() => mProphetExportDlg.BestScoresOnly = true); PauseForScreenShot <MProphetFeaturesDlg>("Export mProphet Features form", 20); // TODO: actually write the features here using WriteFeatures OkDialog(mProphetExportDlg, mProphetExportDlg.CancelDialog); // Export a report string pathReport = GetTestPath("qValues_Exported_report.csv"); const string qvalueHeader = "annotation_QValue"; string reportName = Resources.ReportSpecList_GetDefaults_Peptide_RT_Results; var reportExportDlg = ShowDialog <ExportLiveReportDlg>(SkylineWindow.ShowExportReportDialog); var manageViewsForm = ShowDialog <ManageViewsForm>(reportExportDlg.EditList); RunUI(() => manageViewsForm.SelectView(reportName)); PauseForScreenShot <ManageViewsForm>("Edit Reports form", 21); var customizeViewDlg = ShowDialog <ViewEditor>(manageViewsForm.EditView); PauseForScreenShot <ViewEditor.ChooseColumnsView>("Edit Report form", 22); RunUI(() => customizeViewDlg.ChooseColumnsTab.AddColumn(PropertyPath.Parse("Proteins!*.Peptides!*.Precursors!*.Results!*.Value") .Property(AnnotationDef.ANNOTATION_PREFIX + qvalueHeader))); PauseForScreenShot <ViewEditor.ChooseColumnsView>("Edit Report form with selected columns", 23); OkDialog(customizeViewDlg, customizeViewDlg.OkDialog); OkDialog(manageViewsForm, manageViewsForm.Close); RunUI(() => reportExportDlg.ReportName = reportName); OkDialog(reportExportDlg, () => reportExportDlg.OkDialog(pathReport, TextUtil.CsvSeparator)); Assert.IsTrue(File.Exists(pathReport)); using (var reader = new StreamReader(pathReport)) { string line = reader.ReadLine(); Assert.IsNotNull(line); var fieldHeaders = line.Split(TextUtil.CsvSeparator); const int qvalueColumnIndex = 6; Assert.AreEqual(qvalueColumnIndex + 1, fieldHeaders.Length); Assert.AreEqual(qvalueHeader, fieldHeaders[qvalueColumnIndex]); int qvalueCount = 0; while ((line = reader.ReadLine()) != null) { var fields = line.Split(TextUtil.CsvSeparator); double qvalue; if (double.TryParse(fields[qvalueColumnIndex], out qvalue)) { qvalueCount++; } } Assert.AreEqual(290, qvalueCount); // PrecursorResults field means 29 peptides * 5 replicates * 2 label types } // Open OpenSWATH gold standard dataset RunUI(() => SkylineWindow.OpenFile(GetTestPath("AQUA4_Human_picked_napedro2-mod2.sky"))); // Not L10N WaitForDocumentLoaded(); // Perform re-score of DIA data var manageResults = ShowDialog <ManageResultsDlg>(SkylineWindow.ManageResults); PauseForScreenShot <ManageResultsDlg>("Manage Results form", 25); var rescoreResultsDlg = ShowDialog <RescoreResultsDlg>(manageResults.Rescore); PauseForScreenShot <RescoreResultsDlg>("Re-score Results form", 25); RunUI(() => rescoreResultsDlg.Rescore(false)); WaitForCondition(10 * 60 * 1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 10 minutes (usually needs less, but code coverage analysis can be slow) WaitForClosedForm(rescoreResultsDlg); WaitForClosedForm(manageResults); WaitForConditionUI(() => FindOpenForm <AllChromatogramsGraph>() == null); WaitForDocumentLoaded(); // Train the peak scoring model for the DIA dataset var reintegrateDlgDia = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog); // Open the previous scoring model for use with the DIA dataset var editListDia = ShowDialog <EditListDlg <SettingsListBase <PeakScoringModelSpec>, PeakScoringModelSpec> >( reintegrateDlgDia.EditPeakScoringModel); RunUI(() => editListDia.SelectItem("test1")); var editDlgFromSrm = ShowDialog <EditPeakScoringModelDlg>(editListDia.EditItem); PauseForScreenShot <EditPeakScoringModelDlg.ModelTab>("Edit Peak Scoring Model form SRM model applied to DIA data", 26); RunUI(() => { ValidateCoefficients(editDlgFromSrm, 0); for (int j = 0; j < editDlgFromSrm.PeakCalculatorsGrid.Items.Count; ++j) { Assert.AreEqual(editDlgFromSrm.PeakCalculatorsGrid.Items[j].PercentContribution, null); } int i = 0; Assert.IsTrue(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); // Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsTrue(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsTrue(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsTrue(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsTrue(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i++, 0)); Assert.IsFalse(editDlgFromSrm.IsActiveCell(i, 0)); }); OkDialog(editDlgFromSrm, editDlgFromSrm.CancelDialog); OkDialog(editListDia, editListDia.CancelDialog); // Train a new model for the DIA dataset var editDlgDia = ShowDialog <EditPeakScoringModelDlg>(reintegrateDlgDia.AddPeakScoringModel); RunUI(() => { editDlgDia.UsesDecoys = false; editDlgDia.UsesSecondBest = true; editDlgDia.TrainModel(); }); RunUI(() => ValidateCoefficients(editDlgDia, 1)); PauseForScreenShot <EditPeakScoringModelDlg.ModelTab>("Edit Peak Scoring Model form DIA peak scoring dialog with second best", 27); RunUI(() => { editDlgDia.SelectedGraphTab = 1; editDlgDia.PeakCalculatorsGrid.SelectRow(2); editDlgDia.IsFindButtonVisible = true; editDlgDia.FindMissingValues(2); // Retention times editDlgDia.PeakScoringModelName = "testDIA"; }); OkDialog(editDlgDia, editDlgDia.OkDialog); RunUI(() => { reintegrateDlgDia.ReintegrateAll = true; reintegrateDlgDia.OverwriteManual = true; }); OkDialog(reintegrateDlgDia, reintegrateDlgDia.OkDialog); findResultsForm = FormUtil.OpenForms.OfType <FindResultsForm>().FirstOrDefault(); Assert.IsNotNull(findResultsForm); Assert.AreEqual(34, findResultsForm.ItemCount); }