private void RemovePartialCacheFiles(string[] files) { WaitForChromatogramManagerQuiet(); foreach (var file in files) { string cacheFile = ChromatogramCache.PartPathForName(SkylineWindow.DocumentFilePath, new MsDataFilePath(file)); FileEx.SafeDelete(cacheFile, 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); } } }
public void WatersCacheTest() { // First test transition from per-replicate caching strategy to // single cache per document strategy. var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); // Open the replicate document, and let it reload the data from mzML // showing the document can find data files by name in its own directory, // since the document paths will not match those on disk. string docPath; var doc = InitWatersDocument(testFilesDir, out docPath); var docReload = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_rep.sky", out docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { var streamManager = docContainer.ChromatogramManager.StreamManager; Assert.IsTrue(docContainer.SetDocument(docReload, doc, true)); docContainer.AssertComplete(); docReload = docContainer.Document; // Release file handles to cache files created during load Assert.IsTrue(docContainer.SetDocument(doc, docReload)); // Delete the cache string cachePath = Path.ChangeExtension(docPath, ".skyd"); FileEx.SafeDelete(cachePath); // Then try using cached replicate files // Move per-replicate cache files into place var replicateCacheNames = new[] { "160109_Mix1_calcurve_rep_calcurve_070.skyd", "160109_Mix1_calcurve_rep_calcurve_073.skyd" }; GetCacheFiles(testFilesDir, replicateCacheNames); // Delete the files these cache DeleteFiles(testFilesDir, new[] { "160109_Mix1_calcurve_070.mzML", "160109_Mix1_calcurve_073.mzML", }); var docCached = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_rep.sky", out docPath); Assert.IsTrue(docContainer.SetDocument(docCached, doc, true)); docContainer.AssertComplete(); docCached = docContainer.Document; // The document with data from the .mzML files should be the same as // the one loaded from the .skyd files. // Unfortunately, this is to hard to maintain when cache changes are made. // AssertEx.Cloned(docCached, docReload); // The one cache should be present Assert.IsTrue(File.Exists(cachePath)); // And the replicate cache files should have been removed foreach (var cacheName in replicateCacheNames) { var path = testFilesDir.GetTestPath(cacheName); Assert.IsFalse(File.Exists(path)); } // Save the cache file time stamp // ReSharper disable once AssignNullToNotNullAttribute var cacheInfo = new FileInfo(cachePath); long cacheSize = cacheInfo.Length; // Adding files already in the document should have no impact on the cache. string extRaw = ExtensionTestContext.ExtWatersRaw; var listChromatograms = new List <ChromatogramSet>(docCached.Settings.MeasuredResults.Chromatograms) { new ChromatogramSet("extra1", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw)) }), new ChromatogramSet("extra2", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML")) }) }; // Adding a new file should cause the cache to grow. var settings = docCached.Settings.MeasuredResults.ChangeChromatograms(listChromatograms); var docGrow = docCached.ChangeMeasuredResults(settings); Assert.IsTrue(docContainer.SetDocument(docGrow, docCached, true)); docContainer.AssertComplete(); docGrow = docContainer.Document; cacheInfo = new FileInfo(cachePath); Assert.IsTrue(cacheSize < cacheInfo.Length); cacheSize = cacheInfo.Length; var writeTime = cacheInfo.LastWriteTime; listChromatograms.Add( new ChromatogramSet("double", new[] { testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw), testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML") })); settings = docGrow.Settings.MeasuredResults.ChangeChromatograms(listChromatograms); var docNoCacheChange1 = docGrow.ChangeMeasuredResults(settings); Assert.IsTrue(docContainer.SetDocument(docNoCacheChange1, docGrow, true)); docContainer.AssertComplete(); docNoCacheChange1 = docContainer.Document; Assert.AreEqual(writeTime, File.GetLastWriteTime(cachePath)); // Removing files should have no impact, until optimized listChromatograms.RemoveRange(listChromatograms.Count - 2, 2); listChromatograms.RemoveAt(1); settings = docNoCacheChange1.Settings.MeasuredResults.ChangeChromatograms(listChromatograms); var docNoCacheChange2 = docNoCacheChange1.ChangeMeasuredResults(settings); Assert.IsTrue(docContainer.SetDocument(docNoCacheChange2, docNoCacheChange1, true)); docContainer.AssertComplete(); docNoCacheChange2 = docContainer.Document; Assert.AreEqual(writeTime, File.GetLastWriteTime(cachePath)); // Optimizing should shrink the cache var results = docNoCacheChange2.Settings.MeasuredResults.OptimizeCache(docPath, streamManager); var docOptimized = docNoCacheChange2.ChangeSettings(docNoCacheChange2.Settings.ChangeMeasuredResults(results)); // This should not cause a reload Assert.IsTrue(docContainer.SetDocument(docOptimized, docNoCacheChange2, false)); cacheInfo = new FileInfo(cachePath); Assert.IsTrue(cacheSize > cacheInfo.Length); // Test file caches // First reload the files from .mzML docReload = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_file.sky", out docPath); // Change the path to use the right .skyd file docContainer.DocumentFilePath = docPath; Assert.IsTrue(docContainer.SetDocument(docReload, docOptimized, true)); docContainer.AssertComplete(); docReload = docContainer.Document; // Release file handles to cache files created during load Assert.IsTrue(docContainer.SetDocument(doc, docReload)); // Delete the cache cachePath = Path.ChangeExtension(docPath, ".skyd"); FileEx.SafeDelete(cachePath); // Then try using cached files // Move per-file cache files into place var fileCacheNames = new[] { "160109_Mix1_calcurve_075.mzML.skyd", "160109_Mix1_calcurve_078.mzML.skyd" }; GetCacheFiles(testFilesDir, fileCacheNames); // Swap the mzML files, so the test will fail, if not reading from the cache // CONSIDER: Should this really work, since they have different time stamps? string file075 = testFilesDir.GetTestPath("160109_Mix1_calcurve_075.mzML"); string file078 = testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML"); string fileTemp = file075 + ".tmp"; File.Move(file075, fileTemp); File.Move(file078, file075); File.Move(fileTemp, file078); docCached = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_file.sky", out docPath); // Make sure cache files exactly match the names the loader will look for var listResultsFiles = new List <MsDataFileUri>(); foreach (var chromatogram in docCached.Settings.MeasuredResults.Chromatograms) { listResultsFiles.AddRange(chromatogram.MSDataFilePaths); } for (int i = 0; i < fileCacheNames.Length; i++) { string partPath = ChromatogramCache.PartPathForName(docPath, listResultsFiles[i]); File.Move(testFilesDir.GetTestPath(fileCacheNames[i]), partPath); } Assert.IsTrue(docContainer.SetDocument(docCached, doc, true)); docContainer.AssertComplete(); // docCached = docContainer.Document; // The document with data from the .mzML files should be the same as // the one loaded from the .skyd files. // Unfortunately, this is to hard to maintain when cache changes are made. // AssertEx.Cloned(docCached, docReload); // The one cache should be present Assert.IsTrue(File.Exists(Path.ChangeExtension(docPath, ".skyd"))); // And the replicate cache files should have been removed foreach (var cacheName in fileCacheNames) { Assert.IsFalse(File.Exists(testFilesDir.GetTestPath(cacheName))); } } testFilesDir.Dispose(); }