Esempio n. 1
0
        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());
        }
Esempio n. 2
0
 public static void MatchChromatograms(ResultsTestDocumentContainer docContainer,
     MsDataFileUri path1, MsDataFileUri path2, int delta, int missing,
     LockMassParameters lockMassParameters = null)
 {
     var doc = docContainer.Document;
     var listChromatograms = new List<ChromatogramSet>();
     foreach (var path in new[] { path1, path2 })
     {
         listChromatograms.Add(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();
     docResults = docContainer.Document;
     MatchChromatograms(docResults, 0, 1, delta, missing);
 }
Esempio n. 3
0
 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);
 }
 /// <summary>
 /// Import results from one or more data files.
 /// </summary>
 /// <param name="dataFiles">List of data file paths</param>
 /// <param name="lockMassParameters">For Waters lockmass correction</param>
 /// <param name="waitForLoadSeconds">Timeout in seconds</param>
 /// <param name="expectedErrorMessage">anticipated error dialog message, if any</param>
 public void ImportResults(string[] dataFiles, LockMassParameters lockMassParameters, int waitForLoadSeconds = 420, string expectedErrorMessage = null)
 {
     ImportResultsAsync(dataFiles, lockMassParameters);
     WaitForConditionUI(waitForLoadSeconds*1000,
         () => {
             var document = SkylineWindow.DocumentUI;
             return document.Settings.HasResults && document.Settings.MeasuredResults.IsLoaded;
         });
 }
Esempio n. 5
0
 private bool Equals(LockMassParameters other)
 {
     return LockmassPositive.Equals(other.LockmassPositive) && 
            LockmassNegative.Equals(other.LockmassNegative) &&
            LockmassTolerance.Equals(other.LockmassTolerance);
 }
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);
            double lockmassPositive;
            if (string.IsNullOrEmpty(textLockmassPositive.Text))
                lockmassPositive = 0;
            else if (!helper.ValidateDecimalTextBox(textLockmassPositive, 0, null, out lockmassPositive))
                return;
            double lockmassNegative;
            if (string.IsNullOrEmpty(textLockmassNegative.Text))
                lockmassNegative = 0;
            else if (!helper.ValidateDecimalTextBox(textLockmassNegative, 0, null, out lockmassNegative))
                return;
            double lockmassTolerance;
            if (string.IsNullOrEmpty(textLockmassTolerance.Text))
                lockmassTolerance = 0;
            else if (!helper.ValidateDecimalTextBox(textLockmassTolerance, LockMassParameters.LOCKMASS_TOLERANCE_MIN, LockMassParameters.LOCKMASS_TOLERANCE_MAX, out lockmassTolerance))
                return;

            Settings.Default.LockmassParameters = LockMassParameters = new LockMassParameters(lockmassPositive, lockmassNegative, lockmassTolerance);
            DialogResult = DialogResult.OK;
        }
Esempio n. 7
0
        private const string VAL_TRUE = "true"; // Not L10N

        #endregion Fields

        #region Methods

        public static string EncodePath(string filePath, string sampleName, int sampleIndex, LockMassParameters lockMassParameters,
            bool centroidMS1, bool centroidMS2)
        {
            var parameters = new List<string>();
            const string pairFormat = "{0}={1}"; // Not L10N
            string filePart;
            if (!(string.IsNullOrEmpty(sampleName) && -1 == sampleIndex))
            {
                // Info for distinguishing a single sample within a WIFF file.
                filePart = string.Format("{0}|{1}|{2}", filePath, sampleName ?? string.Empty, sampleIndex); // Not L10N
            }
            else
            {
                filePart = filePath;
            }

            if (lockMassParameters != null && !lockMassParameters.IsEmpty)
            {
                if (lockMassParameters.LockmassPositive.HasValue)
                    parameters.Add(string.Format(CultureInfo.InvariantCulture, pairFormat, TAG_LOCKMASS_POS, lockMassParameters.LockmassPositive.Value));
                if (lockMassParameters.LockmassNegative.HasValue)
                    parameters.Add(string.Format(CultureInfo.InvariantCulture, pairFormat, TAG_LOCKMASS_NEG, lockMassParameters.LockmassNegative.Value));
                if (lockMassParameters.LockmassTolerance.HasValue)
                    parameters.Add(string.Format(CultureInfo.InvariantCulture, pairFormat, TAG_LOCKMASS_TOL, lockMassParameters.LockmassTolerance.Value));
            }
            if (centroidMS1)
            {
                parameters.Add(string.Format(CultureInfo.InvariantCulture, pairFormat, TAG_CENTROID_MS1, VAL_TRUE)); // Not L10N
            }
            if (centroidMS2)
            {
                parameters.Add(string.Format(CultureInfo.InvariantCulture, pairFormat, TAG_CENTROID_MS2, VAL_TRUE)); // Not L10N
            }

            return parameters.Any() ? string.Format("{0}?{1}", filePart, string.Join("&", parameters)) : filePart; // Not L10N
        }
Esempio n. 8
0
 public override MsDataFileUri ChangeLockMassParameters(LockMassParameters lockMassParameters)
 {
     return new MsDataFilePath(FilePath, SampleName, SampleIndex, lockMassParameters, CentroidMs1, CentroidMs2);
 }
Esempio n. 9
0
 /// <summary>
 /// Returns a copy of itself with updated lockmass parameters
 /// </summary>
 public abstract MsDataFileUri ChangeLockMassParameters(LockMassParameters lockMassParameters);
Esempio n. 10
0
 public MsDataFilePath(string filePath, LockMassParameters lockMassParameters = null, 
     bool centroidMs1=false, bool centroidMs2=false)
     : this(filePath, null, -1, lockMassParameters, centroidMs1, centroidMs2)
 {
 }
Esempio n. 11
0
 public MsDataFilePath(string filePath, string sampleName, int sampleIndex, LockMassParameters lockMassParameters = null,
     bool centroidMs1 = false, bool centroidMs2 = false)
 {
     FilePath = filePath;
     SampleName = sampleName;
     SampleIndex = sampleIndex;
     LockMassParameters = lockMassParameters ?? LockMassParameters.EMPTY;
     CentroidMs1 = centroidMs1;
     CentroidMs2 = centroidMs2;
 }
Esempio n. 12
0
 public override MsDataFileUri ChangeLockMassParameters(LockMassParameters lockMassParameters)
 {
     return this;  // Chorus will have already performed lockmass correction
 }
 public void ImportResultsAsync(string[] dataFiles, LockMassParameters lockMassParameters, string expectedErrorMessage = null)
 {
     var importResultsDlg = ShowDialog<ImportResultsDlg>(SkylineWindow.ImportResults);
     RunUI(() =>
     {
         var filePaths = dataFiles.Select(dataFile => TestFilesDirs[0].GetTestPath(dataFile)).ToArray();
         importResultsDlg.NamedPathSets =
             importResultsDlg.GetDataSourcePathsFileReplicates(filePaths.Select(MsDataFileUri.Parse));
     });
     if (expectedErrorMessage != null)
     {
         var dlg = WaitForOpenForm<MessageDlg>();
         Assert.IsTrue(dlg.DetailMessage.Contains(expectedErrorMessage));
         dlg.CancelDialog();
     }
     else if (lockMassParameters == null)
     {
         OkDialog(importResultsDlg, importResultsDlg.OkDialog);
     }
     else
     {
         // Expect a Waters lockmass dialog to appear on OK
         WaitForConditionUI(() => importResultsDlg.NamedPathSets.Count() == dataFiles.Count());
         var lockmassDlg = ShowDialog<ImportResultsLockMassDlg>(importResultsDlg.OkDialog);
         RunUI(() =>
         {
             lockmassDlg.LockmassPositive = lockMassParameters.LockmassPositive ?? 0;
             lockmassDlg.LockmassNegative = lockMassParameters.LockmassNegative ?? 0;
             lockmassDlg.LockmassTolerance = lockMassParameters.LockmassTolerance ?? 0;
         });
         OkDialog(lockmassDlg, lockmassDlg.OkDialog);
     }
 }
 public void ImportResults(string dataFile, LockMassParameters lockMassParameters, int waitForLoadSeconds = 420, string expectedErrorMessage = null)
 {
     ImportResults(new[] { dataFile }, lockMassParameters, waitForLoadSeconds, expectedErrorMessage);
 }
Esempio n. 15
0
        private static void TestInstrumentInfo(string resultsPath, string docCurrentPath)
        {
            var docCurrent = ResultsUtil.DeserializeDocument(docCurrentPath);
            var docContainer = new ResultsTestDocumentContainer(docCurrent, docCurrentPath);
            string replicateName = Path.GetFileNameWithoutExtension(resultsPath);
            var lockMassParameters = new LockMassParameters(456.78, 567.89, 12.34);
            var listChromatograms = new List<ChromatogramSet> { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(resultsPath, lockMassParameters) }) };

            // Lockmass values are Waters only so don't expect them to be saved to the doc which has no Waters results
            // So test the serialization here
            var stringBuilder = new StringBuilder();
            using (var xmlWriter = XmlWriter.Create(stringBuilder))
            {
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("TestDocument");
                xmlWriter.WriteElements(listChromatograms, new XmlElementHelper<ChromatogramSet>());
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
            }
            var xmlReader = XmlReader.Create(new StringReader(stringBuilder.ToString()));
            xmlReader.ReadStartElement();
            var deserializedObjects = new List<ChromatogramSet>();
            xmlReader.ReadElements(deserializedObjects);
            Assert.AreEqual(1, deserializedObjects.Count);
            var compare = deserializedObjects[0];
            Assert.AreEqual(456.78, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassPositive.Value);
            Assert.AreEqual(567.89, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassNegative.Value);
            Assert.AreEqual(12.34, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassTolerance.Value);
            Assert.AreEqual(listChromatograms[0], compare);

            // We don't expect any new peptides/precursors/transitions added due to the imported results.
            var docCurrentResults = docContainer.ChangeMeasuredResults(new MeasuredResults(listChromatograms), 0, 0, 0);

            WriteDocument(docCurrentResults, docCurrentPath);

            docCurrentResults = ResultsUtil.DeserializeDocument(docCurrentPath);
            Assert.IsNotNull(docCurrentResults);
            AssertEx.IsDocumentState(docCurrentResults, 0, 7, 11, 22, 66);
            Assert.AreEqual(1, docCurrentResults.Settings.MeasuredResults.Chromatograms.Count);

            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(docCurrentPath);

            var replicateList = xdoc.SelectNodes("/srm_settings/settings_summary/measured_results/replicate");
            Assert.IsNotNull(replicateList);
            Assert.AreEqual(1, replicateList.Count);
            var replicate = replicateList.Item(0);
            Assert.IsNotNull(replicate);
            var attribs = replicate.Attributes;
            Assert.IsNotNull(attribs);
            Assert.AreEqual(replicateName, attribs.GetNamedItem(SrmDocument.ATTR.name).Value);

            var instrumentList = replicate.SelectNodes("sample_file/instrument_info_list/instrument_info");
            Assert.IsNotNull(instrumentList);
            Assert.AreEqual(1, instrumentList.Count);
            var instrumentInfo = instrumentList.Item(0);
            Assert.IsNotNull(instrumentInfo);
            Assert.IsNotNull(instrumentInfo.Attributes);

            // model
            var model = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.model.ToString());
            Assert.IsNotNull(model);
            Assert.IsNotNull(model.FirstChild);
            Assert.IsTrue(model.FirstChild.NodeType == XmlNodeType.Text);
            Assert.AreEqual("TSQ Vantage", model.FirstChild.Value);

            // ion source
            var ionsource = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.ionsource.ToString());
            Assert.IsNotNull(ionsource);
            Assert.IsNotNull(ionsource.FirstChild);
            Assert.AreEqual(ionsource.FirstChild.NodeType, XmlNodeType.Text);
            Assert.AreEqual("nanoelectrospray", ionsource.FirstChild.Value);

            // analyzer
            var analyzer = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.analyzer.ToString());
            Assert.IsNotNull(analyzer);
            Assert.IsNotNull(analyzer.FirstChild);
            Assert.AreEqual(analyzer.FirstChild.NodeType, XmlNodeType.Text);
            Assert.AreEqual("quadrupole/quadrupole/quadrupole", analyzer.FirstChild.Value);

            // dectector
            var detector = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.detector.ToString());
            Assert.IsNotNull(detector);
            Assert.IsNotNull(detector.FirstChild);
            Assert.AreEqual(detector.FirstChild.NodeType, XmlNodeType.Text);
            Assert.AreEqual("electron multiplier", detector.FirstChild.Value);
        }
Esempio n. 16
0
 public MsDataFileUri ChangeParameters(SrmDocument doc, LockMassParameters lockMassParameters)
 {
     return doc.Settings.TransitionSettings.FullScan.ApplySettings(ChangeLockMassParameters(lockMassParameters));
 }
 public static List<KeyValuePair<string, MsDataFileUri[]>> ChangeLockMassParameters(IList<KeyValuePair<string, MsDataFileUri[]>> namedResults, LockMassParameters lockMassParameters, SrmDocument doc)
 {
     var result = new List<KeyValuePair<string, MsDataFileUri[]>>();
     foreach (var namedResult in namedResults)
     {
         result.Add(ChangeLockMassParameters(namedResult, lockMassParameters, doc));
     }
     return result;
 }
Esempio n. 18
0
 public int CompareTo(LockMassParameters other)
 {
     if (ReferenceEquals(null, other)) 
         return -1;
     var result = Nullable.Compare(LockmassPositive, other.LockmassPositive);
     if (result != 0)
         return result;
     result = Nullable.Compare(LockmassNegative, other.LockmassNegative);
     if (result != 0)
         return result;
     return Nullable.Compare(LockmassTolerance, other.LockmassTolerance);
 }
 private static KeyValuePair<string, MsDataFileUri[]> ChangeLockMassParameters(KeyValuePair<string, MsDataFileUri[]> namedResult, LockMassParameters lockMassParameters, SrmDocument doc)
 {
     var result = new KeyValuePair<string, MsDataFileUri[]>(namedResult.Key, namedResult.Value);
     for (var i = 0; i < namedResult.Value.Length; i++)
     {
         var msDataFileUri = result.Value[i];
         if (lockMassParameters == null || lockMassParameters.IsEmpty || !msDataFileUri.IsWatersLockmassCorrectionCandidate())
             result.Value[i] = msDataFileUri.ChangeParameters(doc, LockMassParameters.EMPTY);
         else
             result.Value[i] = msDataFileUri.ChangeParameters(doc, lockMassParameters);
     }
     return result;
 }
Esempio n. 20
0
 public MsDataFileImpl(string path, int sampleIndex = 0, LockMassParameters lockmassParameters = null, bool simAsSpectra = false, bool srmAsSpectra = false, bool acceptZeroLengthSpectra = true, bool requireVendorCentroidedMS1 = false, bool requireVendorCentroidedMS2 = false)
 {
     // see note above on enabling performance measurement
     _perf = PerfUtilFactory.CreatePerfUtil("MsDataFileImpl " + // Not L10N 
         string.Format("{0},sampleIndex:{1},lockmassCorrection:{2},simAsSpectra:{3},srmAsSpectra:{4},acceptZeroLengthSpectra:{5},requireVendorCentroidedMS1:{6},requireVendorCentroidedMS2:{7}",  // Not L10N
         path, sampleIndex, !(lockmassParameters == null || lockmassParameters.IsEmpty), simAsSpectra, srmAsSpectra, acceptZeroLengthSpectra, requireVendorCentroidedMS1, requireVendorCentroidedMS2));
     using (_perf.CreateTimer("open")) // Not L10N
     {
         FilePath = path;
         _msDataFile = new MSData();
         _config = new ReaderConfig {simAsSpectra = simAsSpectra, srmAsSpectra = srmAsSpectra, acceptZeroLengthSpectra = acceptZeroLengthSpectra};
         _lockmassParameters = lockmassParameters;
         FULL_READER_LIST.read(path, _msDataFile, sampleIndex, _config);
         _requireVendorCentroidedMS1 = requireVendorCentroidedMS1;
         _requireVendorCentroidedMS2 = requireVendorCentroidedMS2;
     }
 }
Esempio n. 21
0
        public bool ImportResultsInDir(string sourceDir, Regex namingPattern, 
            LockMassParameters lockMassParameters,
            DateTime? importBefore, DateTime? importOnOrAfter,
            OptimizableRegression optimize, bool disableJoining)
        {
            var listNamedPaths = GetDataSources(sourceDir, namingPattern);
            if (listNamedPaths == null)
            {
                return false;
            }

            bool hasMultiple = listNamedPaths.SelectMany(pair => pair.Key).Count() > 1;
            if (hasMultiple || disableJoining)
            {
                // Join at the end
                _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(true));
            }

            // Import files one at a time
            foreach (var namedPaths in listNamedPaths)
            {
                string replicateName = namedPaths.Key;
                var files = namedPaths.Value;
                foreach (var file in files)
                {
                    if (!ImportResultsFile(file.ChangeParameters(_doc, lockMassParameters), replicateName, importBefore, importOnOrAfter, optimize))
                        return false;
                }
            }

            if (hasMultiple && !disableJoining)
            {
                // Allow joining to happen
                var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty));
                using (var docContainer = new ResultsMemoryDocumentContainer(null, _skylineFile) { ProgressMonitor = progressMonitor })
                {
                    _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(false));
                    if (!_doc.IsLoaded)
                    {
                        docContainer.SetDocument(_doc, null, true);
                        _doc = docContainer.Document;
                        // If not fully loaded now, there must have been an error.
                        if (!_doc.IsLoaded)
                            return false;
                    }
                }
            }

            return true;
        }
        public void NativeVsMz5ChromatogramPerformanceTest(string zipFile, string skyFile, string rawFile, 
            bool centroided=false,
            LockMassParameters lockMassParameters = null)
        {
            if (!RunPerfTests)
                return; // PerfTests only run when the global RunPerfTests flag is set
            _loopcount = LOOPS_AVG;

            // Caller may have disabled logging, but we depend on it for data gathering.
            using (new LogInfoLevel())
            {
                Log.AddMemoryAppender();
                for (var loop = 0; loop < _loopcount + 1; loop++) // one extra initial loop for warmup
                {
                    // compare mz5 and raw import times
                    TestFilesZip = "https://skyline.gs.washington.edu/perftests/" + zipFile;
                    var mz5File = Path.ChangeExtension(rawFile, "mz5");
                    TestFilesPersistent = new[] { rawFile, mz5File }; // list of files that we'd like to unzip alongside parent zipFile, and (re)use in place
                    _testFilesDir = new TestFilesDir(TestContext, TestFilesZip, null, TestFilesPersistent);
                    _baseSkyFile = _testFilesDir.GetTestPath(skyFile);
                    string nativeResults = _testFilesDir.GetTestPath(rawFile);
                    var rawfiles = new List<string>();
                    var mz5Results = Path.ChangeExtension(nativeResults, "mz5");
                    if (centroided)
                        rawfiles.Add(nativeResults); // First time through is centroided
                    rawfiles.Add(mz5Results);  // Then mz5
                    rawfiles.Add(nativeResults); // Then normal
                    MsDataFileImpl.PerfUtilFactory.IssueDummyPerfUtils = (loop == 0) && (_loopcount > 0); // turn on performance measurement after warmup loop
                    var centroidedThisPass = centroided;
                    var type = 0;
                    foreach (var resultspath in rawfiles)
                    {
                        _skyFile = _baseSkyFile.Replace(".sky", "_" + loop + "_" + type++ + ".sky");
                        _dataFile = resultspath;
                        _centroided = centroidedThisPass;
                        RunFunctionalTest();
                        centroidedThisPass = false;
                        _lockMassParameters = lockMassParameters;
                    }

                }
                DebugLog.Info("Done.");
                var logs = Log.GetMemoryAppendedLogEvents();
                var stats = PerfUtilFactory.SummarizeLogs(logs, TestFilesPersistent); // show summary, combining native per test and mz5 per test
                var report = stats.Replace(_testFilesDir.PersistentFilesDir.Replace(':', '_'), "");
                Console.Write(report); // Want this to appear in nightly log

                var log = new Log("Summary");
                log.Info(report);
            }
        }