public static string GetNonExistentPath(string dir, string sharedSkyFile) { if (string.IsNullOrEmpty(sharedSkyFile)) { throw new ArgumentException(Resources .SkypFile_GetNonExistentPath_Name_of_shared_Skyline_archive_cannot_be_null_or_empty_); } var count = 1; var isSkyZip = PathEx.HasExtension(sharedSkyFile, SrmDocumentSharing.EXT_SKY_ZIP); var ext = isSkyZip ? SrmDocumentSharing.EXT_SKY_ZIP : SrmDocumentSharing.EXT; var fileNameNoExt = isSkyZip ? sharedSkyFile.Substring(0, sharedSkyFile.Length - SrmDocumentSharing.EXT_SKY_ZIP.Length) : Path.GetFileNameWithoutExtension(sharedSkyFile); var path = Path.Combine(dir, sharedSkyFile); while (File.Exists(path) || Directory.Exists(Path.Combine(dir, SrmDocumentSharing.ExtractDir(path)))) { // Add a suffix if a file with the given name already exists OR // a directory that would be created when opening this file exists. sharedSkyFile = fileNameNoExt + @"(" + count + @")" + ext; path = Path.Combine(dir, sharedSkyFile); count++; } return(Path.Combine(dir, sharedSkyFile)); }
private static bool ShareDocument(SrmDocument document, string documentPath, string fileDest, CommandStatusWriter statusWriter) { var waitBroker = new CommandProgressMonitor(statusWriter, new ProgressStatus(Resources.SkylineWindow_ShareDocument_Compressing_Files)); var sharing = new SrmDocumentSharing(document, documentPath, fileDest, false); try { sharing.Share(waitBroker); return true; } catch (Exception x) { statusWriter.WriteLine(Resources.SkylineWindow_ShareDocument_Failed_attempting_to_create_sharing_file__0__, fileDest); statusWriter.WriteLine(x.Message); } return false; }
public bool ShareDocument(string fileDest, bool completeSharing) { try { bool success = false; Helpers.TryTwice(() => { using (var longWaitDlg = new LongWaitDlg { Text = Resources.SkylineWindow_ShareDocument_Compressing_Files, }) { var sharing = new SrmDocumentSharing(DocumentUI, DocumentFilePath, fileDest, completeSharing); longWaitDlg.PerformWork(this, 1000, sharing.Share); success = !longWaitDlg.IsCanceled; } }); return success; } catch (Exception x) { var message = TextUtil.LineSeparate(string.Format(Resources.SkylineWindow_ShareDocument_Failed_attempting_to_create_sharing_file__0__, fileDest), x.Message); MessageDlg.ShowWithException(this, message, x); } return false; }
/* TODO bspratt drift time libs for small molecules [TestMethod] public void WatersImsMsePredictedDriftTimesChromatogramTestAsSmallMolecules() { WatersImsMseChromatogramTest(DriftFilterType.predictor, true); } [TestMethod] public void WatersImsMseLibraryDriftTimesChromatogramTestAsSmallMolecules() { WatersImsMseChromatogramTest(DriftFilterType.library, true); } */ private void WatersImsMseChromatogramTest(DriftFilterType mode, RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules = RefinementSettings.ConvertToSmallMoleculesMode.none) { string subdir = (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.none) ? null : asSmallMolecules.ToString(); var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE, subdir); TestSmallMolecules = false; // Don't need that extra magic node bool withDriftTimePredictor = (mode == DriftFilterType.predictor); // Load the doc that has a drift time predictor? bool withDriftTimeFilter = (mode != DriftFilterType.none); // Perform drift time filtering? (either with predictor, or with bare times in blib file) string docPath; SrmDocument document = InitWatersImsMseDocument(testFilesDir, withDriftTimePredictor ? "single_with_driftinfo.sky" : "single_no_driftinfo.sky", asSmallMolecules, out docPath); AssertEx.IsDocumentState(document, (withDriftTimePredictor || (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)) ? 1 : 0, 1, 1, 1, 8); // Drift time lib load bumps the doc version var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var docOriginal = doc; string testModeStr = withDriftTimePredictor ? "with drift time predictor" : "without drift time info"; if (withDriftTimeFilter && !withDriftTimePredictor) { // Use the bare drift times in the spectral library var librarySpec = new BiblioSpecLiteSpec("drift test", testFilesDir.GetTestPath("mse-mobility.filtered-scaled.blib")); doc = doc.ChangeSettings( doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })). ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesResolvingPower(100)). ChangePeptidePrediction(p => p.ChangeUseLibraryDriftTimes(true)) ); testModeStr = "with drift times from spectral library"; } var listChromatograms = new List<ChromatogramSet>(); // A small subset of the QC_HDMSE_02_UCA168_3495_082213 data set (RT 21.5-22.5) from Will Thompson const string path = @"waters-mobility.mz5"; listChromatograms.Add(AssertResult.FindChromatogramSet(doc, new MsDataFilePath(path)) ?? new ChromatogramSet(Path.GetFileName(path).Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; double maxHeight = 0; var results = document.Settings.MeasuredResults; Assert.AreEqual(1, document.MoleculePrecursorPairs.Count()); 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, testModeStr); var chromGroup = chromGroupInfo[0]; var expectedPeaks = ((asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only) ? 6 : 5); Assert.AreEqual(withDriftTimeFilter ? 3 : expectedPeaks, chromGroup.NumPeaks, testModeStr); // This will be higher if we don't filter on DT foreach (var tranInfo in chromGroup.TransitionPointSets) { maxHeight = Math.Max(maxHeight, tranInfo.MaxIntensity); } } Assert.AreEqual(withDriftTimeFilter? 5226 : 20075 , maxHeight, 1, testModeStr); // Without DT filtering, this will be much greater // 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(21.94865, (double)nodePep.GetMeasuredRetentionTime(0), .0001, testModeStr); Assert.AreEqual(1.0, (double)nodePep.GetPeakCountRatio(0), 0.0001, testModeStr); nPeptides++; } } Assert.AreEqual(1, nPeptides); if (withDriftTimePredictor || withDriftTimeFilter) { // Verify that the .imdb pr .blib file goes out in the share zipfile for (int complete = 0; complete <= 1; complete++) { var sharePath = testFilesDir.GetTestPath(complete==1?"share_complete.zip":"share_minimized.zip"); var share = new SrmDocumentSharing(document, docPath, sharePath, complete==1); using (var longWaitDlg = new LongWaitDlg { // ReSharper disable once LocalizableElement Text = "unit test WatersImsTest -- sharing document", }) { longWaitDlg.PerformWork(null, 1000, share.Share); Assert.IsFalse(longWaitDlg.IsCanceled); } var files = share.ListEntries().ToArray(); Assert.IsTrue(files.Contains(withDriftTimePredictor ? "scaled.imdb" : "mse-mobility.filtered-scaled.blib")); // And round trip it to make sure we haven't left out any new features in minimized imdb or blib files using (var longWaitDlg = new LongWaitDlg { // ReSharper disable once LocalizableElement Text = "unit test WatersImsTest", }) { longWaitDlg.PerformWork(null, 1000, share.Extract); Assert.IsFalse(longWaitDlg.IsCanceled); } using (TextReader reader = new StreamReader(share.DocumentPath)) { XmlSerializer documentSerializer = new XmlSerializer(typeof(SrmDocument)); var document2 = (SrmDocument) documentSerializer.Deserialize(reader); Assert.IsNotNull(document2); var im = document.Settings.GetIonMobilities(new MsDataFilePath(path)); var pep = document2.Molecules.First(); foreach (TransitionGroupDocNode nodeGroup in pep.Children) { double windowDT; var centerDriftTime = document.Settings.PeptideSettings.Prediction.GetDriftTime( pep, nodeGroup, im, out windowDT); Assert.AreEqual(3.86124, centerDriftTime.DriftTimeMsec(false) ?? 0, .0001, testModeStr); Assert.AreEqual(0.077224865797235934, windowDT, .0001, testModeStr); } } } } // Release file handles docContainer.Release(); testFilesDir.Dispose(); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); }
public bool OpenSharedFile(string zipPath) { try { var sharing = new SrmDocumentSharing(zipPath); using (var longWaitDlg = new LongWaitDlg { Text = Resources.SkylineWindow_OpenSharedFile_Extracting_Files, }) { longWaitDlg.PerformWork(this, 1000, sharing.Extract); if (longWaitDlg.IsCanceled) return false; } // Remember the directory containing the newly extracted file // as the active directory for the next open command. Settings.Default.ActiveDirectory = Path.GetDirectoryName(sharing.DocumentPath); return OpenFile(sharing.DocumentPath); } catch (ZipException zipException) { MessageDlg.ShowWithException(this, string.Format(Resources.SkylineWindow_OpenSharedFile_The_zip_file__0__cannot_be_read, zipPath), zipException); return false; } catch (Exception e) { var message = TextUtil.LineSeparate(string.Format( Resources.SkylineWindow_OpenSharedFile_Failure_extracting_Skyline_document_from_zip_file__0__, zipPath), e.Message); MessageDlg.ShowWithException(this, message, e); return false; } }