private void SendRequest() { while (true) { try { var chromatogramCache = ChorusSession.GenerateChromatograms(ChorusAccount, ChorusUrl, ChromatogramRequestDocument); if (null == chromatogramCache) { return; } var chromKeyIndiceses = chromatogramCache.GetChromKeys(ChorusUrl).ToList(); lock (this) { _chromatogramCache = chromatogramCache; _chromKeyIndiceses = chromKeyIndiceses; } return; } catch (Exception exception) { ChromTaskList.HandleException(exception); return; } } }
private string[] FindMissingFiles(IEnumerable <ChromatogramSet> chromatogramSets) { string documentPath = DocumentUIContainer.DocumentFilePath; string cachePath = ChromatogramCache.FinalPathForName(documentPath, null); // Collect all missing paths var listPathsMissing = new List <string>(); // Avoid checking paths multiple times for existence var setPaths = new HashSet <string>(); foreach (var filePath in chromatogramSets.SelectMany(set => set.MSDataFilePaths)) { MsDataFilePath msDataFilePath = filePath as MsDataFilePath; if (null == msDataFilePath) { continue; } string filePathPart = msDataFilePath.FilePath; if (setPaths.Contains(filePathPart)) { continue; } setPaths.Add(filePathPart); if (ChromatogramSet.GetExistingDataFilePath(cachePath, msDataFilePath) != null) { continue; } listPathsMissing.Add(filePathPart); } listPathsMissing.Sort(); return(listPathsMissing.ToArray()); }
private TemporaryDirectory ShareSkydFile(ZipFileShare zip, TemporaryDirectory tempDir) { string pathCache = ChromatogramCache.FinalPathForName(DocumentPath, null); if (!File.Exists(pathCache)) { return(tempDir); } if (ShareType.SkylineVersion != null && Document.Settings.HasResults) { var measuredResults = Document.Settings.MeasuredResults; if (measuredResults.CacheVersion.HasValue && !measuredResults.CacheVersion.Equals(ShareType.SkylineVersion.CacheFormatVersion)) { String cacheFileName = Path.GetFileName(pathCache); if (cacheFileName != null) { if (tempDir == null) { tempDir = new TemporaryDirectory(); } String newCachePath = Path.Combine(tempDir.DirPath, cacheFileName); MinimizeToFile(newCachePath, CacheFormat.FromVersion(ShareType.SkylineVersion.CacheFormatVersion)); zip.AddFile(newCachePath); return(tempDir); } } } zip.AddFile(pathCache); return(tempDir); }
private void DoTestImportSim(bool asSmallMolecules) { if (asSmallMolecules && !RunSmallMoleculeTestVersions) { System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var pepdoc = doc; if (asSmallMolecules) { var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(pepdoc, TestContext.ResultsDirectory); } using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the mzML file and verify Mz range Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512); Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557); } }
public void MinimizeToFile(string targetFile, CacheFormat cacheFormat) { var targetSkydFile = ChromatogramCache.FinalPathForName(targetFile, null); using (var skydSaver = new FileSaver(targetSkydFile, true)) using (var scansSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCANS_EXT, true)) using (var peaksSaver = new FileSaver(targetSkydFile + ChromatogramCache.PEAKS_EXT, true)) using (var scoreSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCORES_EXT, true)) { var minimizer = Document.Settings.MeasuredResults.GetChromCacheMinimizer(Document); var settings = new ChromCacheMinimizer.Settings().ChangeCacheFormat(cacheFormat); var lockObject = new object(); ProgressMonitor.UpdateProgress(_progressStatus = _progressStatus.ChangeMessage(Resources.SrmDocumentSharing_MinimizeToFile_Writing_chromatograms)); minimizer.Minimize(settings, stats => { if (ProgressMonitor.IsCanceled) { throw new OperationCanceledException(); } lock (lockObject) { ProgressMonitor.UpdateProgress(_progressStatus = _progressStatus.ChangePercentComplete(stats.PercentComplete)); } }, skydSaver.FileStream, scansSaver.FileStream, peaksSaver.FileStream, scoreSaver.FileStream); skydSaver.Commit(); } }
public ChromCacheMinimizer(SrmDocument document, ChromatogramCache chromatogramCache) { Document = document; ChromatogramCache = chromatogramCache; var chromGroupHeaderInfos = chromatogramCache.ChromGroupHeaderInfos.ToArray(); Array.Sort(chromGroupHeaderInfos, CompareLocation); ChromGroupHeaderInfos = Array.AsReadOnly(chromGroupHeaderInfos); _tolerance = (float) Document.Settings.TransitionSettings.Instrument.MzMatchTolerance; }
public Writer(ChromatogramCache chromatogramCache, Stream outputStream, FileStream outputStreamScans, FileStream outputStreamPeaks, FileStream outputStreamScores) { _originalCache = chromatogramCache; _outputStream = outputStream; _outputStreamScans = outputStreamScans; _outputStreamPeaks = outputStreamPeaks; _outputStreamScores = outputStreamScores; _scoreTypes = chromatogramCache.ScoreTypes.ToList(); }
private void RemovePartialCacheFiles(string[] files) { WaitForChromatogramManagerQuiet(); foreach (var file in files) { string cacheFile = ChromatogramCache.PartPathForName(SkylineWindow.DocumentFilePath, new MsDataFilePath(file)); FileEx.SafeDelete(cacheFile, true); } }
/// <summary> /// Add the given files to the queue of files to load. /// </summary> public void Load( IList <DataFileReplicates> loadList, SrmDocument document, string documentFilePath, ChromatogramCache cacheRecalc, MultiFileLoadMonitor loadMonitor, Action <IList <FileLoadCompletionAccumulator.Completion> > complete) { lock (this) { // Find non-duplicate paths to load. var uniqueLoadList = new List <DataFileReplicates>(); foreach (var loadItem in loadList) { // Ignore a file that is already being loaded (or is queued for loading). if (_loadingPaths.ContainsKey(loadItem.DataFile)) { continue; } int idIndex = document.Id.GlobalIndex; _loadingPaths.Add(loadItem.DataFile, idIndex); uniqueLoadList.Add(loadItem); } if (uniqueLoadList.Count == 0) { return; } int threadCount = GetOptimalThreadCount(_threadCountPreferred, uniqueLoadList.Count, _simultaneousFileOptions); _worker.RunAsync(threadCount, @"Load file"); var accumulator = new FileLoadCompletionAccumulator(complete, threadCount, uniqueLoadList.Count); // Add new paths to queue. foreach (var loadItem in uniqueLoadList) { var loadingStatus = new ChromatogramLoadingStatus(loadItem.DataFile, loadItem.ReplicateList); ChangeStatus(s => s.Add(loadingStatus)); // Queue work item to load the file. _worker.Add(new LoadInfo { Path = loadItem.DataFile, PartPath = loadItem.PartPath, Document = document, DocumentFilePath = documentFilePath, CacheRecalc = cacheRecalc, Status = loadingStatus, LoadMonitor = new SingleFileLoadMonitor(loadMonitor, loadItem.DataFile), Complete = accumulator.Complete }); } } }
public override void Dispose() { if (_cache != null) { _cache.ReadStream.CloseStream(); } _cache = null; _chromKeyIndices = null; _lastChromGroupInfo = null; }
public void CalcWriteArrays(ChromatogramCache chromatogramCache) { if (RetainedTransitionIndexes.Count == 0) { return; } CalcPeakInfo(chromatogramCache); CalcChromatogramBytes(); }
public ChromCacheMinimizer(SrmDocument document, ChromatogramCache chromatogramCache) { Document = document; ChromatogramCache = chromatogramCache; var chromGroupHeaderInfos = chromatogramCache.ChromGroupHeaderInfos.ToArray(); Array.Sort(chromGroupHeaderInfos, CompareLocation); ChromGroupHeaderInfos = Array.AsReadOnly(chromGroupHeaderInfos); _tolerance = (float)Document.Settings.TransitionSettings.Instrument.MzMatchTolerance; }
/// <summary> /// Add the given file to the queue of files to load. /// </summary> public void Load( IList <DataFileReplicates> loadList, SrmDocument document, string documentFilePath, ChromatogramCache cacheRecalc, MultiFileLoadMonitor loadMonitor, Action <ChromatogramCache, IProgressStatus> complete) { // This may be called on multiple background loader threads simultaneously, but QueueWorker can handle it. _worker.RunAsync(_threadCount, "Load file"); // Not L10N lock (this) { // Find non-duplicate paths to load. var uniqueLoadList = new List <DataFileReplicates>(); foreach (var loadItem in loadList) { // Ignore a file that is already being loaded (or is queued for loading). if (_loadingPaths.ContainsKey(loadItem.DataFile)) { continue; } int idIndex = document.Id.GlobalIndex; _loadingPaths.Add(loadItem.DataFile, idIndex); uniqueLoadList.Add(loadItem); } if (uniqueLoadList.Count == 0) { return; } // Add new paths to queue. foreach (var loadItem in uniqueLoadList) { var loadingStatus = new ChromatogramLoadingStatus(loadItem.DataFile, loadItem.ReplicateList); ChangeStatus(s => s.Add(loadingStatus)); // Queue work item to load the file. _worker.Add(new LoadInfo { Path = loadItem.DataFile, PartPath = loadItem.PartPath, Document = document, DocumentFilePath = documentFilePath, CacheRecalc = cacheRecalc, Status = loadingStatus, LoadMonitor = new SingleFileLoadMonitor(loadMonitor, loadItem.DataFile), Complete = complete }); } } }
private void DoTestAgilentCEOpt() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the .wiff file ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME)); } }
private void ShareDataAndView(ZipFile zip) { string pathCache = ChromatogramCache.FinalPathForName(DocumentPath, null); if (File.Exists(pathCache)) { zip.AddFile(pathCache, string.Empty); } string viewPath = SkylineWindow.GetViewFile(DocumentPath); if (File.Exists(viewPath)) { zip.AddFile(viewPath, string.Empty); } }
public void WriteEndOfFile() { _originalCache.WriteScanIds(_outputStreamScans); ChromatogramCache.WriteStructs(_outputStream, _outputStreamScans, _outputStreamPeaks, _outputStreamScores, _originalCache.CachedFiles, _chromGroupHeaderInfos, _transitions, _scoreTypes, _scoreCount, _peakCount, _originalCache); }
public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions) { Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } TestSmallMolecules = false; // We test small molecules explicitly in this test LocalizationHelper.InitThread(); // TODO: All unit tests should be correctly initialized var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("TROUBLED_File.sky"); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, testFilesDir.FullPath, asSmallMolecules); const int expectedMoleculeCount = 1; // At first small molecules did not support multiple label types AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 6); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("Rush_p3_96_21May16_Smeagol.mzML"); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) }); { // Import with symmetric isolation window var docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 3, 3); var nodeGroup = docResults.MoleculeTransitionGroups.First(); double ratio = nodeGroup.Results[0][0].Ratio ?? 0; // The expected ratio is 1.0, but the symmetric isolation window should produce poor results if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula { Assert.AreEqual(0.008, ratio, 0.001); } } } testFilesDir.Dispose(); }
public ChromatogramCache GenerateChromatograms(ChorusAccount chorusAccount, ChorusUrl chorusUrl, ChromatogramRequestDocument chromatogramRequestDocument) { var webRequest = (HttpWebRequest)WebRequest.Create(chorusUrl.GetChromExtractionUri()); AddAuthHeader(chorusAccount, webRequest); webRequest.Method = "POST"; // Not L10N var xmlSerializer = new XmlSerializer(typeof(ChromatogramRequestDocument)); xmlSerializer.Serialize(webRequest.GetRequestStream(), chromatogramRequestDocument); webRequest.GetRequestStream().Close(); return(SendRequest(webRequest, response => { MemoryStream memoryStream = new MemoryStream(); var responseStream = response.GetResponseStream(); if (responseStream != null) { byte[] buffer = new byte[65536]; int count; while ((count = responseStream.Read(buffer, 0, buffer.Length)) != 0) { memoryStream.Write(buffer, 0, count); } } if (0 == memoryStream.Length) { if (response.StatusCode != HttpStatusCode.OK) { throw new IOException(string.Format("Empty response: status = {0}", response.StatusCode)); // Not L10N } Debug.WriteLine("Zero byte response"); // Not L10N return null; } ChromatogramCache.RawData rawData; ChromatogramCache.LoadStructs(memoryStream, out rawData); var chromCacheFile = rawData.ChromCacheFiles[0]; rawData.ChromCacheFiles = new[] { new ChromCachedFile(chorusUrl, chromCacheFile.Flags, chromCacheFile.FileWriteTime, chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity, chromCacheFile.InstrumentInfoList), }; return new ChromatogramCache(string.Empty, rawData, new ChromatogramGeneratorTask.MemoryPooledStream(memoryStream)); })); }
private void DoTestAgilentCEOpt() { // The special mode for exercising non-proteomic molecules just doesn't make sense with this test TestSmallMolecules = false; var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the .wiff file ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME)); } }
private void LoadFile(LoadInfo loadInfo, int threadIndex) { ChromatogramCache.Build( loadInfo.Document, loadInfo.CacheRecalc, loadInfo.PartPath, loadInfo.Path, loadInfo.Status, loadInfo.LoadMonitor, loadInfo.Complete); var loadingStatus = loadInfo.Status as ChromatogramLoadingStatus; if (loadingStatus != null) { loadingStatus.Transitions.Flush(); } }
public ChorusResponseChromDataProvider(SrmDocument document, ChromFileInfo chromFileInfo, ProgressStatus progressStatus, int startPercent, int endPercent, ILoadMonitor loader) : base(chromFileInfo, progressStatus, startPercent, endPercent, loader) { ChromatogramCache.RawData rawData; MsDataFilePath msDataFilePath = (MsDataFilePath) chromFileInfo.FilePath; IPooledStream stream = loader.StreamManager.CreatePooledStream(msDataFilePath.FilePath, false); ChromatogramCache.LoadStructs(stream.Stream, out rawData); var chromCacheFile = rawData.ChromCacheFiles[0]; rawData.ChromCacheFiles = new[] { new ChromCachedFile(chromFileInfo.FilePath, chromCacheFile.Flags, chromCacheFile.FileWriteTime, chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity, chromCacheFile.InstrumentInfoList), }; var cache = new ChromatogramCache("cachePath", rawData, stream); // Not L10N _cachedChromatogramDataProvider = new CachedChromatogramDataProvider(cache, document, chromFileInfo.FilePath, chromFileInfo, null, progressStatus, startPercent, endPercent, loader); }
public void Complete(ChromatogramCache cache, IProgressStatus status) { var completedCount = Interlocked.Increment(ref _completedCount); var completion = new Completion(cache, status); if (_completionWorker == null) { _complete(new SingletonList <Completion>(completion)); } else { _completionWorker.Add(completion); if (completedCount == _loadingCount) { _completionWorker.DoneAdding(); } } }
public ChorusResponseChromDataProvider(SrmDocument document, ChromFileInfo chromFileInfo, IProgressStatus progressStatus, int startPercent, int endPercent, ILoadMonitor loader) : base(chromFileInfo, progressStatus, startPercent, endPercent, loader) { ChromatogramCache.RawData rawData; MsDataFilePath msDataFilePath = (MsDataFilePath)chromFileInfo.FilePath; IPooledStream stream = loader.StreamManager.CreatePooledStream(msDataFilePath.FilePath, false); ChromatogramCache.LoadStructs(stream.Stream, out rawData); var chromCacheFile = rawData.ChromCacheFiles[0]; rawData.ChromCacheFiles = new[] { new ChromCachedFile(chromFileInfo.FilePath, chromCacheFile.Flags, chromCacheFile.FileWriteTime, chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity, chromCacheFile.InstrumentInfoList), }; var cache = new ChromatogramCache("cachePath", rawData, stream); // Not L10N _cachedChromatogramDataProvider = new CachedChromatogramDataProvider(cache, document, chromFileInfo.FilePath, chromFileInfo, null, progressStatus, startPercent, endPercent, loader); }
public CachedChromatogramDataProvider(ChromatogramCache cache, SrmDocument document, MsDataFileUri dataFilePath, ChromFileInfo fileInfo, bool?singleMatchMz, ProgressStatus status, int startPercent, int endPercent, ILoadMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _cache = cache; _fileIndex = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath)); _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray(); _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity); _singleMatchMz = singleMatchMz.HasValue ? singleMatchMz.Value // Unfortunately, before the single matching status was // written into the cache file, we can only guess about its // status based on the overall document settings : document.Settings.TransitionSettings.FullScan.IsEnabled; }
public CachedChromatogramDataProvider(ChromatogramCache cache, SrmDocument document, MsDataFileUri dataFilePath, ChromFileInfo fileInfo, bool? singleMatchMz, ProgressStatus status, int startPercent, int endPercent, ILoadMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _cache = cache; _fileIndex = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath)); _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray(); _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity); _singleMatchMz = singleMatchMz.HasValue ? singleMatchMz.Value // Unfortunately, before the single matching status was // written into the cache file, we can only guess about its // status based on the overall document settings : document.Settings.TransitionSettings.FullScan.IsEnabled; }
public CachedChromatogramDataProvider(ChromatogramCache cache, SrmDocument document, MsDataFileUri dataFilePath, ChromFileInfo fileInfo, bool?singleMatchMz, IProgressStatus status, int startPercent, int endPercent, ILoadMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { // Deal with older cache formats where we did not record chromatogram polarity var assumeNegativeChargesInPreV11Caches = document.MoleculeTransitionGroups.All(p => p.PrecursorMz.IsNegative); // Need a newly loaded copy to allow for concurrent loading for multiple cached files _cache = ChromatogramCache.Load(cache.CachePath, new ProgressStatus(), loader, assumeNegativeChargesInPreV11Caches); _fileIndex = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath)); _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray(); foreach (var c in _chromKeyIndices.Where(i => i.Key.Precursor != 0)) { if (c.Key.Precursor.IsNegative) { _sourceHasNegativePolarityData = true; } else { _sourceHasPositivePolarityData = true; } } _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity); _singleMatchMz = singleMatchMz.HasValue ? singleMatchMz.Value // Unfortunately, before the single matching status was // written into the cache file, we can only guess about its // status based on the overall document settings : document.Settings.TransitionSettings.FullScan.IsEnabled; }
public void DoTestDemux(bool asSmallMolecules) { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPathMsx = testFilesDir.GetTestPath("MsxTest.sky"); string dataPathMsx = testFilesDir.GetTestPath("MsxTest.mzML"); string cachePathMsx = ChromatogramCache.FinalPathForName(docPathMsx, null); FileEx.SafeDelete(cachePathMsx); SrmDocument docMsx = ResultsUtil.DeserializeDocument(docPathMsx); if (asSmallMolecules) { var refine = new RefinementSettings(); docMsx = refine.ConvertToSmallMolecules(docMsx); } var fullScanInitialMsx = docMsx.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitialMsx.IsEnabledMsMs); TestMsx(docMsx, dataPathMsx); string docPathOverlap = testFilesDir.GetTestPath("OverlapTest.sky"); string dataPathOverlap = testFilesDir.GetTestPath("OverlapTest.mzML"); string cachePathOverlap = ChromatogramCache.FinalPathForName(docPathOverlap, null); FileEx.SafeDelete(cachePathOverlap); SrmDocument docOverlap = ResultsUtil.DeserializeDocument(docPathOverlap); if (asSmallMolecules) { var refine = new RefinementSettings(); docOverlap = refine.ConvertToSmallMolecules(docOverlap); } var fullScanInitialOverlap = docMsx.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitialOverlap.IsEnabledMsMs); TestOverlap(docOverlap, dataPathOverlap); }
private void DoTestImportSim(bool asSmallMolecules) { TestSmallMolecules = false; // Don't need that magic extra node var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var pepdoc = doc; if (asSmallMolecules) { var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(pepdoc); } var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the mzML file and verify Mz range Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512); Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557); }
public bool TryMinimizeToFile(string targetFile) { var targetSkydFile = ChromatogramCache.FinalPathForName(targetFile, null); using (var skydSaver = new FileSaver(targetSkydFile)) using (var scansSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCANS_EXT, true)) using (var peaksSaver = new FileSaver(targetSkydFile + ChromatogramCache.PEAKS_EXT, true)) using (var scoreSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCORES_EXT, true)) { skydSaver.Stream = File.OpenWrite(skydSaver.SafeName); using (var longWaitDlg = new LongWaitDlg(DocumentUIContainer)) { longWaitDlg.PerformWork(this, 1000, longWaitBroker => { longWaitBroker.Message = Resources.MinimizeResultsDlg_MinimizeToFile_Saving_new_cache_file; try { using (var backgroundWorker = new BackgroundWorker(this, longWaitBroker)) { backgroundWorker.RunBackground(skydSaver.Stream, scansSaver.FileStream, peaksSaver.FileStream, scoreSaver.FileStream); } } catch (ObjectDisposedException) { if (!longWaitBroker.IsCanceled) { throw; } } }); if (longWaitDlg.IsCanceled) { return(false); } } var skylineWindow = (SkylineWindow)DocumentUIContainer; if (!skylineWindow.SaveDocument(targetFile, false)) { return(false); } try { var measuredResults = DocumentUIContainer.Document.Settings.MeasuredResults.CommitCacheFile(skydSaver); SrmDocument docOrig, docNew; do { docOrig = DocumentUIContainer.Document; docNew = docOrig.ChangeMeasuredResults(measuredResults); } while (!DocumentUIContainer.SetDocument(docNew, docOrig)); } catch (Exception x) { var message = TextUtil.LineSeparate( string.Format( Resources .MinimizeResultsDlg_MinimizeToFile_An_unexpected_error_occurred_while_saving_the_data_cache_file__0__, targetFile), x.Message); MessageDlg.ShowWithException(this, message, x); return(false); } skylineWindow.InvalidateChromatogramGraphs(); } return(true); }
public void TestCommandLineNoJoin() { if (!ExtensionTestContext.CanImportWatersRaw) { return; } var testFilesDir = new TestFilesDir(TestContext, @"TestA\CommandLineNoJoinTest.zip"); string inDocPath = testFilesDir.GetTestPath("test.sky"); string rawFileRoot = testFilesDir.GetTestPath("RawFiles"); string[] rawFiles = { Path.Combine(rawFileRoot, "160109_Mix1_calcurve_071.raw"), Path.Combine(rawFileRoot, "160109_Mix1_calcurve_074.raw") }; Assert.IsTrue(Directory.Exists(rawFileRoot)); List <string> partialSkydFiles = new List <string>(); // First, create the partial .skyd files for each of the replicates. for (int iFile = 0; iFile < rawFiles.Length; iFile++) { string rawFile = rawFiles[iFile]; Assert.IsTrue(Directory.Exists(rawFile), rawFile); string outFile = testFilesDir.GetTestPath("partial" + iFile + ".sky"); RunCommand("--in=" + inDocPath, "--import-file=" + rawFile, "--out=" + outFile, "--import-no-join"); Assert.IsTrue(File.Exists(outFile), rawFile); string partialSkydFile = ChromatogramCache.PartPathForName(outFile, new MsDataFilePath(rawFile)); Assert.IsTrue(File.Exists(partialSkydFile), rawFile); partialSkydFiles.Add(partialSkydFile); File.Delete(outFile); } // Delete the raw files since we no longer need them, since we have the .skyd files Directory.Delete(rawFileRoot, true); Assert.IsFalse(Directory.Exists(rawFileRoot)); string completeFile = testFilesDir.GetTestPath("complete.sky"); Assert.IsNotNull(completeFile); string completeSkyd = Path.ChangeExtension(completeFile, "skyd"); Assert.IsFalse(File.Exists(completeFile)); Assert.IsFalse(File.Exists(completeSkyd)); List <string> args = new List <string> { "--in=" + inDocPath, "--out=" + completeFile }; args.AddRange(rawFiles.Select(file => "--import-file=" + file)); RunCommand(args.ToArray()); Assert.IsTrue(File.Exists(completeFile)); Assert.IsTrue(File.Exists(completeSkyd)); foreach (var partialSkydFile in partialSkydFiles) { Assert.IsFalse(File.Exists(partialSkydFile), partialSkydFile); } using (var stream = new FileStream(completeFile, FileMode.Open)) { var srmDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream); Assert.IsTrue(srmDocument.Settings.HasResults); Assert.AreEqual(rawFiles.Length, srmDocument.MeasuredResults.Chromatograms.Count); for (int iFile = 0; iFile < rawFiles.Length; iFile++) { var msDataFilePath = srmDocument.MeasuredResults.Chromatograms[iFile].MSDataFilePaths.First() as MsDataFilePath; Assert.IsNotNull(msDataFilePath); Assert.AreEqual(rawFiles[iFile], msDataFilePath.FilePath); } } }
protected void Complete(Exception x) { lock (this) { ChromatogramCache result = null; try { if (x == null && !_status.IsFinal) { long locationScanIds = 0, countBytesScanIds = 0; if (_fs.Stream != null) { locationScanIds = _fs.Stream.Position; countBytesScanIds = _fsScans.Stream.Position; ChromatogramCache.WriteStructs(_fs.Stream, _fsScans.Stream, _fsPeaks.Stream, _fsScores.Stream, _listCachedFiles, _listGroups, _listTransitions, _listTextIdBytes, _listScoreTypes, _scoreCount, _peakCount); _loader.StreamManager.Finish(_fs.Stream); _fs.Stream = null; _fs.Commit(_destinationStream); } // Create stream identifier, but do not open. The stream will be opened // the first time the document uses it. var readStream = _loader.StreamManager.CreatePooledStream(CachePath, false); _fsPeaks.Stream.Seek(0, SeekOrigin.Begin); _fsScores.Stream.Seek(0, SeekOrigin.Begin); var rawData = new ChromatogramCache.RawData { FormatVersion = ChromatogramCache.FORMAT_VERSION_CACHE, ChromCacheFiles = _listCachedFiles.ToArray(), ChromatogramEntries = _listGroups.ToArray(), ChromTransitions = _listTransitions.ToArray(), ChromatogramPeaks = new BlockedArray<ChromPeak>( count => ChromPeak.ReadArray(_fsPeaks.FileStream.SafeFileHandle, count), _peakCount, ChromPeak.SizeOf, ChromPeak.DEFAULT_BLOCK_SIZE), ScoreTypes = _listScoreTypes.ToArray(), Scores = new BlockedArray<float>( count => PrimitiveArrays.Read<float>(_fsScores.FileStream, count), _scoreCount, sizeof(float), ChromatogramCache.DEFAULT_SCORES_BLOCK_SIZE), TextIdBytes = _listTextIdBytes.ToArray(), LocationScanIds = locationScanIds, CountBytesScanIds = countBytesScanIds, }; result = new ChromatogramCache(CachePath, rawData, readStream); _loader.UpdateProgress(_status.Complete()); } } catch (Exception x2) { x = x2; } finally { Dispose(); } try { _completed(result, x); } catch (Exception x2) { _completed(null, x2); } } }
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()); }
public Completion(ChromatogramCache cache, IProgressStatus status) { Cache = cache; Status = status; }
public override void Dispose() { if (_cache != null) _cache.ReadStream.CloseStream(); _cache = null; _chromKeyIndices = null; _lastChromGroupInfo = null; }
private bool JoinNextPart() { // Check for cancellation on every part. if (_loader.IsCanceled) { _loader.UpdateProgress(_status = _status.Cancel()); Complete(null); return(false); } if (_currentPartIndex >= CacheFilePaths.Count) { Complete(null); return(false); } // If not cancelled, update progress. string cacheFilePath = CacheFilePaths[_currentPartIndex]; string message = string.Format(Resources.ChromCacheJoiner_JoinNextPart_Joining_file__0__, cacheFilePath); int percent = _currentPartIndex * 100 / CacheFilePaths.Count; _status = _status.ChangeMessage(message).ChangePercentComplete(percent); _loader.UpdateProgress(_status); try { using (var inStream = _loader.StreamManager.CreateStream(cacheFilePath, FileMode.Open, false)) { if (_fs.Stream == null) { _fs.Stream = _loader.StreamManager.CreateStream(_fs.SafeName, FileMode.Create, true); } ChromatogramCache.RawData rawData; long bytesData = ChromatogramCache.LoadStructs(inStream, out rawData); // If joining, then format version should have already been checked. Assume.IsTrue(ChromatogramCache.IsVersionCurrent(rawData.FormatVersion) || // WatersCacheTest uses older format partial caches rawData.FormatVersion == ChromatogramCache.FORMAT_VERSION_CACHE_2); int offsetFiles = _listCachedFiles.Count; int offsetTransitions = _listTransitions.Count; int offsetPeaks = _peakCount; int offsetScores = _scoreCount; long offsetPoints = _fs.Stream.Position; // Scan ids long offsetScanIds = _fsScans.Stream.Position; _listCachedFiles.AddRange(rawData.ChromCacheFiles.Select(f => f.RelocateScanIds(f.LocationScanIds + offsetScanIds))); if (rawData.CountBytesScanIds > 0) { inStream.Seek(rawData.LocationScanIds, SeekOrigin.Begin); inStream.TransferBytes(_fsScans.Stream, rawData.CountBytesScanIds); } _peakCount += rawData.ChromatogramPeaks.Length; rawData.ChromatogramPeaks.WriteArray(block => ChromPeak.WriteArray(_fsPeaks.FileStream.SafeFileHandle, block)); _listTransitions.AddRange(rawData.ChromTransitions); // Initialize the score types the first time through if (_scoreTypesCount == -1) { _listScoreTypes.AddRange(rawData.ScoreTypes); _scoreTypesCount = _listScoreTypes.Count; } else if (!ArrayUtil.EqualsDeep(_listScoreTypes, rawData.ScoreTypes)) { // If the existing score types in the caches are not the same, the caches cannot be joined if (_listScoreTypes.Intersect(rawData.ScoreTypes).Count() != _listScoreTypes.Count) { throw new InvalidDataException("Data cache files with different score types cannot be joined."); // Not L10N } } _scoreCount += rawData.Scores.Length; rawData.Scores.WriteArray(block => PrimitiveArrays.Write(_fsScores.Stream, block)); for (int i = 0; i < rawData.ChromatogramEntries.Length; i++) { rawData.RecalcEntry(i, offsetFiles, offsetTransitions, offsetPeaks, offsetScores, offsetPoints, _dictTextIdToByteIndex, _listTextIdBytes); } _listGroups.AddRange(rawData.ChromatogramEntries); inStream.Seek(0, SeekOrigin.Begin); long copyBytes = bytesData; while (copyBytes > 0) { int read = inStream.Read(_buffer, 0, (int)Math.Min(_buffer.Length, copyBytes)); _fs.Stream.Write(_buffer, 0, read); copyBytes -= read; } _currentPartIndex++; return(true); } } catch (InvalidDataException x) { Complete(x); } catch (IOException x) { Complete(x); } catch (Exception x) { Complete(new Exception(String.Format(Resources.ChromCacheJoiner_JoinNextPart_Failed_to_create_cache__0__, CachePath), x)); } return(false); }