Exemple #1
0
        public void TestColumnsFromResultsTables()
        {
            SrmDocument srmDocument = ResultsUtil.DeserializeDocument("silac_1_to_4.sky", GetType());

            using (Database database = new Database())
            {
                database.AddSrmDocument(srmDocument);
                SimpleReport report = new SimpleReport
                {
                    Columns = new[]
                    {
                        new ReportColumn(typeof(DbTransitionResult),
                                         "PrecursorResult", "PeptideResult", "ProteinResult", "ReplicateName"),
                        new ReportColumn(typeof(DbTransition), "Precursor", "Peptide", "Protein", "Name"),
                        new ReportColumn(typeof(DbTransition), "Precursor", "Peptide", "Sequence"),
                        new ReportColumn(typeof(DbTransitionResult), "Area"),
                    },
                };
                ColumnSet columnSet = ColumnSet.GetTransitionsColumnSet(database.GetSchema());
                TreeView  treeView  = new TreeView();
                treeView.Nodes.AddRange(columnSet.GetTreeNodes().ToArray());
                List <NodeData> columnInfos;
                columnSet.GetColumnInfos(report, treeView, out columnInfos);
                Assert.AreEqual(report.Columns.Count, columnInfos.Count);
                SimpleReport reportCompare = (SimpleReport)columnSet.GetReport(columnInfos, null);
                Assert.IsTrue(ArrayUtil.EqualsDeep(report.Columns, reportCompare.Columns));
            }
        }
Exemple #2
0
        protected void DoTest()
        {
            if (TestFilesZipPaths != null)
            {
                TestFilesDirs = new TestFilesDir[TestFilesZipPaths.Length];
                for (int i = 0; i < TestFilesZipPaths.Length; i++)
                {
                    TestFilesDirs[i] = new TestFilesDir(TestContext, TestFilesZipPaths[i], TestDirectoryName,
                                                        TestFilesPersistent, IsExtractHere(i));
                }
            }

            File.Copy(_baseSkyFile, _skyFile, true);
            Stopwatch loadStopwatch = new Stopwatch();

            loadStopwatch.Start();
            var doc = ResultsUtil.DeserializeDocument(_skyFile);

            doc = ConnectLibrarySpecs(doc, _skyFile);
            using (var docContainer = new ResultsTestDocumentContainer(doc, _skyFile))
            {
                var chromSets = new[]
                {
                    new ChromatogramSet(_replicateName, new[]
                                        { new MsDataFilePath(_dataFile, null, _centroided, _centroided), }),
                };
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                docContainer.AssertComplete();
            }
            loadStopwatch.Stop();

            DebugLog.Info("{0} load time = {1}", _dataFile, loadStopwatch.ElapsedMilliseconds);
        }
Exemple #3
0
        private static ResultsTestDocumentContainer MinimizeCacheFile(SrmDocument document,
                                                                      ChromCacheMinimizer.Settings settings, string skyFilePath)
        {
            Assert.IsNotNull(skyFilePath);  // For ReSharper
            string skydFilePath = Path.ChangeExtension(skyFilePath, ChromatogramCache.EXT);
            ChromCacheMinimizer chromCacheMinimizer = document.Settings.MeasuredResults.GetChromCacheMinimizer(document);

            using (var fs = new FileSaver(skydFilePath))
                using (var fsScans = new FileSaver(skydFilePath + ChromatogramCache.SCANS_EXT, true))
                    using (var fsPeaks = new FileSaver(skydFilePath + ChromatogramCache.PEAKS_EXT, true))
                        using (var fsScores = new FileSaver(skydFilePath + ChromatogramCache.SCORES_EXT, true))
                        {
                            fs.Stream = File.OpenWrite(fs.SafeName);
                            chromCacheMinimizer.Minimize(settings, null, fs.Stream,
                                                         fsScans.FileStream, fsPeaks.FileStream, fsScores.FileStream);
                            fs.Commit();
                        }
            using (var writer = new XmlTextWriter(skyFilePath, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            })
            {
                var ser = new XmlSerializer(typeof(SrmDocument));
                ser.Serialize(writer, document);

                writer.Flush();
                writer.Close();
            }
            var container = new ResultsTestDocumentContainer(document, skyFilePath, false);

            Assert.IsTrue(container.SetDocument(ResultsUtil.DeserializeDocument(skyFilePath), document, true));
            return(container);
        }
        /// <summary>
        /// Generate the daily returns plot using the python libraries.
        /// </summary>
        public override string Render()
        {
            var backtestReturns = ResultsUtil.EquityPoints(_backtest);
            var liveReturns     = ResultsUtil.EquityPoints(_live);

            var backtestSeries = new Series <DateTime, double>(backtestReturns.Keys, backtestReturns.Values);
            var liveSeries     = new Series <DateTime, double>(liveReturns.Keys, liveReturns.Values);

            // The following two operations are equivalent to the Pandas `DataFrame.resample(...)` method
            var backtestResampled = backtestSeries.PercentChange().ResampleEquivalence(date => date.Date, s => s.Sum()) * 100;
            var liveResampled     = liveSeries.PercentChange().ResampleEquivalence(date => date.Date, s => s.Sum()) * 100;

            var base64 = "";

            using (Py.GIL())
            {
                var backtestList = new PyList();
                backtestList.Append(backtestResampled.Keys.ToList().ToPython());
                backtestList.Append(backtestResampled.Values.ToList().ToPython());

                var liveList = new PyList();
                liveList.Append(liveResampled.Keys.ToList().ToPython());
                liveList.Append(liveResampled.Values.ToList().ToPython());

                base64 = Charting.GetDailyReturns(backtestList, liveList);

                backtestList.Dispose();
                liveList.Dispose();
            }

            return(base64);
        }
        public void WatersLockmassCmdlinePerfTest()
        {
            if (IsPerfTest && !RunPerfTests)
            {
                return; // Don't want to run this lengthy test right now
            }

            TestFilesZip        = "https://skyline.gs.washington.edu/perftests/PerfTestLockmass.zip";
            TestFilesPersistent = new[] { "ID19638_01_UCA195_2533_082715.raw" }; // List of files that we'd like to unzip alongside parent zipFile, and (re)use in place
            TestFilesDir        = new TestFilesDir(TestContext, TestFilesZip, "CmdlineTest", TestFilesPersistent);

            var skyfile = GetTestPath("2533_FattyAcids.sky");

            var          rawPath          = GetTestPath(TestFilesPersistent[0]);
            const double lockmassNegative = 554.2615;

            // Exercise the commandline
            var outPathUncorrected = TestFilesDir.GetTestPath("cmdlineTestUncorrected.sky");
            var outPathCorrected   = TestFilesDir.GetTestPath("cmdlineTestCorrected.sky");

            RunCommand("--in=" + skyfile,
                       "--import-file=" + rawPath,
                       "--out=" + outPathUncorrected);
            FileEx.SafeDelete(Path.ChangeExtension(skyfile, ChromatogramCache.EXT));
            var cmdDocUncorrected = ResultsUtil.DeserializeDocument(outPathUncorrected);

            RunCommand("--in=" + skyfile,
                       "--import-file=" + rawPath,
                       "--import-lockmass-negative=" + lockmassNegative,
                       "--out=" + outPathCorrected);
            var cmdDocCorrected = ResultsUtil.DeserializeDocument(outPathCorrected);

            ComparePeaks(cmdDocCorrected, cmdDocUncorrected);
        }
        public void TestMeasuredDriftValues()
        {
            var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest
            // Open document with some peptides but no results
            var         docPath      = testFilesDir.GetTestPath("BlibDriftTimeTest.sky");
            SrmDocument docOriginal  = ResultsUtil.DeserializeDocument(docPath);
            var         docContainer = new ResultsTestDocumentContainer(docOriginal, docPath);
            var         doc          = docContainer.Document;

            // Import an mz5 file that contains drift info
            const string replicateName = "ID12692_01_UCA168_3727_040714";
            var          chromSets     = new[]
            {
                new ChromatogramSet(replicateName, new[]
                                    { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714.mz5")), }),
            };
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));

            Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true));
            docContainer.AssertComplete();
            var document = docContainer.Document;

            document = document.ChangeSettings(document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, DriftTimePredictor.EMPTY)));

            // Verify ability to extract predictions from raw data
            var newPred = document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults(
                document, docContainer.DocumentFilePath);
            var result = newPred.MeasuredDriftTimePeptides;

            Assert.AreEqual(TestSmallMolecules? 2: 1, result.Count);
            const double expectedDT     = 4.0019;
            var          expectedOffset = .4829;

            Assert.AreEqual(expectedDT, result.Values.First().DriftTimeMsec(false).Value, .001);
            Assert.AreEqual(expectedOffset, result.Values.First().HighEnergyDriftTimeOffsetMsec, .001);

            // Check ability to update, and to preserve unchanged
            var revised = new Dictionary <LibKey, DriftTimeInfo>();
            var libKey  = result.Keys.First();

            revised.Add(libKey, new DriftTimeInfo(4, 0.234));
            var libKey2 = new LibKey("DEADEELS", 2);

            revised.Add(libKey2, new DriftTimeInfo(5, 0.123));
            document =
                document.ChangeSettings(
                    document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, new DriftTimePredictor("test", revised, null, null, 40))));
            newPred = document.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor(
                document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults(
                    document, docContainer.DocumentFilePath)).DriftTimePredictor;
            result = newPred.MeasuredDriftTimePeptides;
            Assert.AreEqual(TestSmallMolecules ? 3 : 2, result.Count);
            Assert.AreEqual(expectedDT, result[libKey].DriftTimeMsec(false).Value, .001);
            Assert.AreEqual(expectedOffset, result[libKey].HighEnergyDriftTimeOffsetMsec, .001);
            Assert.AreEqual(5, result[libKey2].DriftTimeMsec(false).Value, .001);
            Assert.AreEqual(0.123, result[libKey2].HighEnergyDriftTimeOffsetMsec, .001);


            docContainer.Release();
        }
    public async Task AddTeamAsync(AddTeam cmd)
    {
        // Check if the team already exists
        var teamGrain = GrainFactory.GetGrain <ITeamGrain>(cmd.TeamId);
        var exists    = await teamGrain.TeamExistAsync();

        if (!exists)
        {
            await PublishErrorAsync(new ErrorHasOccurred((int)Results.TeamDoesNotExist, nameof(AddTeam), cmd.TraceId, cmd.InvokerUserId));
        }

        // Check other preconditions
        var result = ResultsUtil.Eval(
            State.TournamentExists(),
            State.TeamIsNotAdded(cmd.TeamId),
            State.LessThanEightTeams());

        var task = result switch
        {
            Results.Unit => PersistPublishAsync(new TeamAdded(cmd.TeamId, cmd.TournamentId, cmd.TraceId, cmd.InvokerUserId)),
            Results x => PublishErrorAsync(new ErrorHasOccurred((int)x, x.ToString(), cmd.TraceId, cmd.InvokerUserId))
        };

        await task;
    }
Exemple #8
0
        private static ResultsTestDocumentContainer InitMatchDocContainer(TestFilesDir testFilesDir)
        {
            string      docPath = testFilesDir.GetTestPath("modmatch.sky");
            SrmDocument doc     = ResultsUtil.DeserializeDocument(docPath);

            return(new ResultsTestDocumentContainer(doc, docPath));
        }
Exemple #9
0
        /// <summary>
        /// Generate the rolling sharpe using the python libraries.
        /// </summary>
        public override string Render()
        {
            var backtestPoints = ResultsUtil.EquityPoints(_backtest);
            var livePoints     = ResultsUtil.EquityPoints(_live);

            var backtestRollingSharpe = Rolling.Sharpe(new Series <DateTime, double>(backtestPoints), 6).DropMissing();
            var liveRollingSharpe     = Rolling.Sharpe(new Series <DateTime, double>(livePoints), 6).DropMissing();

            var base64 = "";

            using (Py.GIL())
            {
                var backtestList = new PyList();
                var liveList     = new PyList();

                backtestList.Append(backtestRollingSharpe.Keys.ToList().ToPython());
                backtestList.Append(backtestRollingSharpe.Values.ToList().ToPython());

                liveList.Append(liveRollingSharpe.Keys.ToList().ToPython());
                liveList.Append(liveRollingSharpe.Values.ToList().ToPython());

                base64 = Charting.GetRollingSharpeRatio(backtestList, liveList);
            }

            return(base64);
        }
Exemple #10
0
        public void Wiff2ResultsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string      docPath = testFilesDir.GetTestPath("OnyxTOFMS.sky");
            SrmDocument doc     = ResultsUtil.DeserializeDocument(docPath);

            //AssertEx.IsDocumentState(doc, 0, 1, 1, 4);

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                const string replicateName = "Wiff2Test";
                string       extRaw        = ExtensionTestContext.ExtAbWiff2;
                string       suffix        = ExtensionTestContext.CanImportAbWiff2 ? "" : "-sample-centroid";
                var          chromSets     = new[]
                {
                    new ChromatogramSet(replicateName, new[]
                                        { new MsDataFilePath(TestFilesDir.GetVendorTestData(TestFilesDir.VendorDir.ABI, "swath.api" + suffix + extRaw)), }),
                };
                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                docContainer.AssertComplete();
                docResults = docContainer.Document;
                //AssertResult.IsDocumentResultsState(docResults, replicateName,
                //    doc.MoleculeCount, doc.MoleculeTransitionGroupCount, 0, doc.MoleculeTransitionCount, 0);
            }

            testFilesDir.Dispose();
        }
Exemple #11
0
        private SrmDocument CreateStudy7Doc()
        {
            SrmDocument docStudy7 = ResultsUtil.DeserializeDocument("Study7.sky", GetType());

            AssertEx.IsDocumentState(docStudy7, 0, 7, 11, 22, 66);
            return(docStudy7);
        }
Exemple #12
0
        public void ConsoleMProphetModelTest()
        {
            var          testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            const string docName      = "mProphetModel.sky";
            var          docPath      = testFilesDir.GetTestPath(docName);
            const string modelName    = "testModel";

            // with mods and invalid cutoff score
            var output = RunCommand("--in=" + docPath,
                                    "--reintegrate-model-name=" + modelName,
                                    "--reintegrate-create-model",
                                    "--reintegrate-overwrite-peaks",
                                    "--save"
                                    );

            AssertEx.Contains(output, string.Format(Resources.CommandLine_CreateScoringModel_Creating_scoring_model__0_, modelName));
            var doc = ResultsUtil.DeserializeDocument(docPath);

            foreach (var peakFeatureCalculator in MProphetPeakScoringModel.GetDefaultCalculators(doc))
            {
                // Not all of the default calculators for the document are valid
                if (peakFeatureCalculator is MQuestRetentionTimePredictionCalc ||
                    peakFeatureCalculator is MQuestRetentionTimeSquaredPredictionCalc ||
                    peakFeatureCalculator is MQuestIntensityCorrelationCalc ||
                    peakFeatureCalculator is NextGenProductMassErrorCalc ||
                    peakFeatureCalculator is NextGenCrossWeightedShapeCalc ||
                    peakFeatureCalculator is LegacyIdentifiedCountCalc)
                {
                    continue;
                }

                AssertEx.Contains(output, peakFeatureCalculator.Name);
            }
            AssertEx.Contains(output, string.Format(Resources.CommandLine_SaveFile_File__0__saved_, docName));
        }
        private static SrmDocument InitExplicitRTDocument(TestFilesDir testFilesDir, string fileName, out string docPath)
        {
            docPath = testFilesDir.GetTestPath(fileName);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            return(doc);
        }
Exemple #14
0
        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);
            }
        }
        /// <summary>
        /// The generated output string to be injected
        /// </summary>
        public override string Render()
        {
            if (_live == null)
            {
                return(_backtest?.TotalPerformance?.PortfolioStatistics?.SharpeRatio.ToString("F1") ?? "-");
            }

            var equityPoints = ResultsUtil.EquityPoints(_live);
            var performance  = DeedleUtil.PercentChange(new Series <DateTime, double>(equityPoints).ResampleEquivalence(date => date.Date, s => s.LastValue()));

            if (performance.ValueCount == 0)
            {
                return("-");
            }

            var sixMonthsAgo        = performance.LastKey().AddDays(-180);
            var trailingPerformance = performance.Where(series => series.Key >= sixMonthsAgo && series.Key.DayOfWeek != DayOfWeek.Saturday && series.Key.DayOfWeek != DayOfWeek.Sunday)
                                      .Values
                                      .ToList();

            if (trailingPerformance.Count < 7 || Statistics.Statistics.AnnualStandardDeviation(trailingPerformance) == 0)
            {
                return("-");
            }

            return(Statistics.Statistics.SharpeRatio(trailingPerformance, 0.0).ToString("F2"));
        }
Exemple #16
0
        private static void CheckDocument(string docPath, string[] rawPaths, int importCount)
        {
            var doc = ResultsUtil.DeserializeDocument(docPath);

            Assert.IsTrue(doc.Settings.HasResults);
            Assert.AreEqual(SAMPLE_NAMES.Count * importCount, doc.Settings.MeasuredResults.Chromatograms.Count);
            for (int i = 0; i < SAMPLE_NAMES.Count; i++)
            {
                for (int j = 1; j <= importCount; j++)
                {
                    var chromIndex      = i + SAMPLE_NAMES.Count * (j - 1);
                    var chromatogramSet = doc.Settings.MeasuredResults.Chromatograms[chromIndex];

                    var replicateName = SAMPLE_NAMES[i] + (j > 1 ? j.ToString() : "");
                    Assert.AreEqual(replicateName, chromatogramSet.Name);

                    Assert.AreEqual(1, chromatogramSet.MSDataFilePaths.Count());
                    var msDataFilePath = chromatogramSet.MSDataFilePaths.First() as MsDataFilePath;
                    Assert.IsNotNull(msDataFilePath);
                    Assert.AreEqual(i, msDataFilePath.SampleIndex);
                    Assert.AreEqual(SAMPLE_NAMES[i], msDataFilePath.SampleName);
                    Assert.AreEqual(rawPaths[j - 1], msDataFilePath.FilePath);
                }
            }
        }
        private void TestSchemaValidation(Stream schemaFile, string doc08Path, string docCurrentPath)
        {
            // get the schema
            XmlTextReader schemaReader = new XmlTextReader(schemaFile);
            XmlSchema     schema       = XmlSchema.Read(schemaReader, ValidationCallBack);

            // create the validation settings
            XmlReaderSettings readerSettings = new XmlReaderSettings
            {
                ValidationType = ValidationType.Schema
            };

            readerSettings.Schemas.Add(schema);
            readerSettings.ValidationFlags        |= XmlSchemaValidationFlags.ReportValidationWarnings;
            readerSettings.ValidationEventHandler += ValidationCallBack;

            // Read the Skyline version 0.8 document
            XmlReader reader = XmlReader.Create(doc08Path, readerSettings);

            // Read the file with a validating reader
            while (reader.Read())
            {
            }
            reader.Close();
            // The document should not validate.
            Assert.IsTrue(_errorCount > 0);


            var doc08 = ResultsUtil.DeserializeDocument(doc08Path);

            Assert.IsNotNull(doc08);
            AssertEx.IsDocumentState(doc08, 0, 7, 11, 22, 66);



            // Save the document.
            // IMPORTANT: update the default modifications first.
            doc08.Settings.UpdateDefaultModifications(true);
            WriteDocument(doc08, docCurrentPath);

            Assert.IsTrue(File.Exists(docCurrentPath));
            var docCurrent = ResultsUtil.DeserializeDocument(docCurrentPath);

            Assert.IsNotNull(docCurrent);
            AssertEx.IsDocumentState(docCurrent, 0, 7, 11, 22, 66);

            AssertEx.DocumentCloned(doc08, docCurrent); // Make sure that the documents are the same


            _errorCount = 0;
            reader      = XmlReader.Create(docCurrentPath, readerSettings);
            // Read the file with a validating reader
            while (reader.Read())
            {
            }
            reader.Close();
            // The document should validate without any errors.
            Assert.AreEqual(0, _errorCount);
        }
Exemple #18
0
        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);
            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().SetDiscardUnmatchedChromatograms(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.SetDiscardUnmatchedChromatograms(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.SetDiscardUnmatchedChromatograms(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);
            docContainer.Release();
        }
        private static SrmDocument InitUnmixedDocument(TestFilesDir testFilesDir, out string docPath)
        {
            docPath = testFilesDir.GetTestPath("Site20_Study9p_unmixed.sky");
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 1, 4, 8, 24);
            return(doc);
        }
Exemple #20
0
        private SrmDocument InitRefineDocumentSprg()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestData\Refine.zip");
            var          doc          = ResultsUtil.DeserializeDocument(testFilesDir.GetTestPath("sprg_all_charges-mini.sky"));

            AssertEx.IsDocumentState(doc, null, 1, 3, 6, 54);
            return(doc);
        }
Exemple #21
0
        private SrmDocument InitRefineDocumentIprg()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestData\Refine.zip");
            var          doc          = ResultsUtil.DeserializeDocument(testFilesDir.GetTestPath("iPRG 2015 Study-mini.sky"));

            AssertEx.IsDocumentState(doc, null, 1, 4, 6, 18);
            return(doc);
        }
Exemple #22
0
        private static SrmDocument InitAgilentDocument(TestFilesDir testFilesDir, out string docPath)
        {
            docPath = testFilesDir.GetTestPath("Bovine_std_curated_seq_small2.sky");
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 4, 5, 20);
            return(doc);
        }
        private static SrmDocument InitAgilentMseDocument(TestFilesDir testFilesDir, string fileName, out string docPath)
        {
            docPath = testFilesDir.GetTestPath(fileName);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 1, 14, 14, 45);  // int revision, int groups, int peptides, int tranGroups, int transitions
            return(doc);
        }
        private static SrmDocument InitThermoDocument(TestFilesDir testFilesDir, out string docPath)
        {
            docPath = testFilesDir.GetTestPath("Site20_Study9p.sky");
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 2, 10, 18, 54);
            return(doc);
        }
Exemple #25
0
        private static SrmDocument InitWatersDocument(TestFilesDir testFilesDir, string fileName, out string docPath)
        {
            docPath = testFilesDir.GetTestPath(fileName);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 1, 12, 12, 24);
            return(doc);
        }
Exemple #26
0
        private static SrmDocument InitShimadzuDocument(TestFilesDir testFilesDir, out string docPath)
        {
            docPath = testFilesDir.GetTestPath("Alan_BSA_new.sky");
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 1, 15, 72);
            return(doc);
        }
Exemple #27
0
        private static SrmDocument InitRefineDocument(TestFilesDir testFilesDir)
        {
            string      docPath = testFilesDir.GetTestPath("SRM_mini.sky");
            SrmDocument doc     = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 4, 36, 38, 334);
            return(doc);
        }
        /// <summary>
        /// Generate the top N drawdown plot using the python libraries.
        /// </summary>
        public override string Render()
        {
            var backtestPoints = ResultsUtil.EquityPoints(_backtest);
            var livePoints     = ResultsUtil.EquityPoints(_live);

            var liveSeries     = new Series <DateTime, double>(livePoints.Keys, livePoints.Values);
            var strategySeries = DrawdownCollection.NormalizeResults(_backtest, _live);

            var seriesUnderwaterPlot = DrawdownCollection.GetUnderwater(strategySeries).DropMissing();
            var liveUnderwaterPlot   = backtestPoints.Count == 0 ? seriesUnderwaterPlot : seriesUnderwaterPlot.After(backtestPoints.Last().Key);
            var drawdownCollection   = DrawdownCollection.FromResult(_backtest, _live, periods: 5);

            var base64 = "";

            using (Py.GIL())
            {
                var backtestList = new PyList();

                if (liveUnderwaterPlot.IsEmpty)
                {
                    backtestList.Append(seriesUnderwaterPlot.Keys.ToList().ToPython());
                    backtestList.Append(seriesUnderwaterPlot.Values.ToList().ToPython());
                }
                else
                {
                    backtestList.Append(seriesUnderwaterPlot.Before(liveUnderwaterPlot.FirstKey()).Keys.ToList().ToPython());
                    backtestList.Append(seriesUnderwaterPlot.Before(liveUnderwaterPlot.FirstKey()).Values.ToList().ToPython());
                }

                var liveList = new PyList();
                liveList.Append(liveUnderwaterPlot.Keys.ToList().ToPython());
                liveList.Append(liveUnderwaterPlot.Values.ToList().ToPython());

                var worstList = new PyList();
                var previousDrawdownPeriods = new List <KeyValuePair <DateTime, DateTime> >();

                foreach (var group in drawdownCollection.Drawdowns)
                {
                    // Skip drawdown periods that are overlapping
                    if (previousDrawdownPeriods.Where(kvp => (group.Start >= kvp.Key && group.Start <= kvp.Value) || (group.End >= kvp.Key && group.End <= kvp.Value)).Any())
                    {
                        continue;
                    }

                    var worst = new PyDict();
                    worst.SetItem("Begin", group.Start.ToPython());
                    worst.SetItem("End", group.End.ToPython());
                    worst.SetItem("Total", group.PeakToTrough.ToPython());

                    worstList.Append(worst);
                    previousDrawdownPeriods.Add(new KeyValuePair <DateTime, DateTime>(group.Start, group.End));
                }

                base64 = Charting.GetDrawdown(backtestList, liveList, worstList);
            }

            return(base64);
        }
Exemple #29
0
        public void GenerateDecoysTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\SimpleDecoys.zip");

            string      docPath         = testFilesDir.GetTestPath("SimpleDecoys.sky");
            SrmDocument simpleDecoysDoc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(simpleDecoysDoc, 0, 1, 18, 18, 56);

            // First check right number of decoy peptide groups and transtions are generated
            var refineSettings = new RefinementSettings();
            int numDecoys      = simpleDecoysDoc.PeptideCount;
            var decoysDoc      = refineSettings.GenerateDecoys(simpleDecoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM);

            ValidateDecoys(simpleDecoysDoc, decoysDoc, false);

            // Second call to generate decoys to make sure that it removes the original Decoys group and generates a completely new one.
            var newDecoysDoc = refineSettings.GenerateDecoys(decoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM);

            Assert.AreNotEqual(decoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy),
                               newDecoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy));

            // MS1 document with precursors and variable modifications, shuffled
            docPath = testFilesDir.GetTestPath("Ms1FilterTutorial.sky");
            SrmDocument variableDecoysDoc = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(variableDecoysDoc, 0, 11, 50, 51, 153);
            numDecoys = variableDecoysDoc.PeptideCount;
            var decoysVariableShuffle = refineSettings.GenerateDecoys(variableDecoysDoc, numDecoys, DecoyGeneration.SHUFFLE_SEQUENCE);

            ValidateDecoys(variableDecoysDoc, decoysVariableShuffle, true);

            // Document with explicit modifications, reversed
            SrmDocument docStudy7 = ResultsUtil.DeserializeDocument("Study7.sky", GetType());

            AssertEx.IsDocumentState(docStudy7, 0, 7, 11, 22, 66);
            numDecoys = docStudy7.PeptideCount;
            var decoysExplicitReverse = refineSettings.GenerateDecoys(docStudy7, numDecoys, DecoyGeneration.REVERSE_SEQUENCE);

            ValidateDecoys(docStudy7, decoysExplicitReverse, true);

            // Random mass shifts with precursors (used to throw an exception due to bad range check that assumed product ions only)
            while (true)
            {
                // As this is random we may need to make a few attempts before we get the values we need
                SrmDocument doc = ResultsUtil.DeserializeDocument(testFilesDir.GetTestPath("precursor_decoy_test.sky"));
                AssertEx.IsDocumentState(doc, null, 1, 1, 2, 6);
                numDecoys = 2;
                var decoysRandom = refineSettings.GenerateDecoys(doc, numDecoys, DecoyGeneration.ADD_RANDOM);
                // Verify that we successfully set a precursor transition decoy mass outside the allowed range of product transitions
                if (decoysRandom.PeptideTransitions.Any(x => x.IsDecoy &&
                                                        (x.Transition.DecoyMassShift > Transition.MAX_PRODUCT_DECOY_MASS_SHIFT ||
                                                         x.Transition.DecoyMassShift < Transition.MIN_PRODUCT_DECOY_MASS_SHIFT)))
                {
                    break;
                }
            }
        }
        public void FullScanPrecursorTransitionsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"Test\FullScanPrecursor.zip");

            string      docPath = testFilesDir.GetTestPath("FullScanPrecursor.sky");
            SrmDocument doc     = ResultsUtil.DeserializeDocument(docPath);

            AssertEx.IsDocumentState(doc, 0, 1, 4, 5, 52);
            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                var mitoLibSpec = new BiblioSpecLiteSpec("mito2", testFilesDir.GetTestPath("mito2.blib"));
                doc = docContainer.ChangeLibSpecs(new[] { mitoLibSpec });
                Assert.IsTrue(doc.IsLoaded);

                // Switch to only precursor ions
                var docPrecOnly = doc.ChangeSettings(doc.Settings.ChangeTransitionFilter(filter =>
                                                                                         filter.ChangePeptideIonTypes(new[] { IonType.precursor })));
                // All precursors should have 3 precursor transitions (M, M+1 and M+2)
                AssertEx.IsDocumentState(docPrecOnly, 3, 1, 4, 5, 15);
                Assert.IsFalse(docPrecOnly.PeptideTransitions.Any(nodeTran => nodeTran.Transition.IonType != IonType.precursor));

                // Use low resolution MS1 filtering
                var docLowMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs =>
                                                                                                         fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, null)
                                                                                                         .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, 0.5, null)));
                // All precursors should have one precursor transition
                AssertEx.IsDocumentState(docLowMs1, 4, 1, 4, 5, 5);

                // Add y-ions to low resolution filtering
                var docLowMs1Y = docLowMs1.ChangeSettings(docLowMs1.Settings.ChangeTransitionFilter(filter =>
                                                                                                    filter.ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y })));
                AssertEx.IsDocumentState(docLowMs1Y, 5, 1, 4, 5, 33);

                // Turn off MS1 filtering
                var docNoMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs =>
                                                                                                        fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null)));
                // One of the precursors should have no transitions, since its spectrum has no precursor match
                AssertEx.IsDocumentState(docNoMs1, 4, 1, 4, 5, 4);

                // Turn off MS/MS library matching
                var docNoLibMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib =>
                                                                                                        lib.ChangePick(TransitionLibraryPick.none)));
                // All precursors should have a single precursor transition
                AssertEx.IsDocumentState(docNoLibMatch, 5, 1, 4, 5, 5);

                // Use library plus filter matching
                var docLibPlusMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib =>
                                                                                                          lib.ChangePick(TransitionLibraryPick.all_plus)));
                // All precursors should have a single precursor transition
                AssertEx.IsDocumentState(docLibPlusMatch, 5, 1, 4, 5, 5);

                // Release the library stream, and dispose of the directory
                docContainer.ChangeLibSpecs(new LibrarySpec[0]);
            }
            testFilesDir.Dispose();
        }