示例#1
0
        public void SkippedBinsAreIgnoredInStats()
        {
            var outputDirectory = Path.GetRandomFileName().ToDirectoryInfo();
            var alternatingBins = ImmutableList <(uint size, bool skip)> .Empty
                                  .Add((1, true))
                                  .Add((100000, false))
                                  .Add((200000, true))
                                  .Add((300000, false));

            var inputSpecs = InputSpec.GenerateDefaultInputSpecs(true)
                             .Select(i => InputSpec.Create(i.VariantType, alternatingBins,
                                                           1, 1, i.ExcludedFilters, i.IncludedFilters, i.IncludedRegions))
                             .ToDictionary(i => i.VariantType, i => i);
            var wittyerSettings = WittyerSettings.Create(outputDirectory, TinyTruth, TinyQuery,
                                                         ImmutableList <ISamplePair> .Empty, EvaluationMode.SimpleCounting,
                                                         inputSpecs);

            var(_, query, truth) = MainLauncher.GenerateResults(wittyerSettings).EnumerateSuccesses().First();
            var results = MainLauncher.GenerateSampleMetrics(truth, query, false, inputSpecs);

            Assert.Equal(1U, results.OverallStats[StatsType.Event].QueryStats.TrueCount);
            Assert.Equal(1U, results.OverallStats[StatsType.Event].QueryStats.FalseCount);
            Assert.Equal(0.5, results.EventLevelRecallOverall.First(typeRecallTuple => typeRecallTuple.type == WittyerType.CopyNumberGain).recall);

            var numberOfBinsReportedOn = results.EventLevelRecallPerBin.First().perBinRecall.Count();

            Assert.Equal(2, numberOfBinsReportedOn);
        }
示例#2
0
        public void CrossType_Bases_Works()
        {
            var outputDirectory = Path.GetRandomFileName().ToDirectoryInfo();
            var inputSpecs      = InputSpec.GenerateDefaultInputSpecs(false)
                                  .Select(i => InputSpec.Create(i.VariantType, i.BinSizes,
                                                                10000, i.PercentDistance, i.ExcludedFilters, i.IncludedFilters,
                                                                IncludeBedFile.CreateFromBedFile(TinyBed)))
                                  .ToDictionary(i => i.VariantType, i => i);
            var wittyerSettings = WittyerSettings.Create(outputDirectory, TinyTruth, TinyQuery,
                                                         ImmutableList <ISamplePair> .Empty, EvaluationMode.CrossTypeAndSimpleCounting,
                                                         inputSpecs);

            var(_, query, truth) = MainLauncher.GenerateResults(wittyerSettings)
                                   .EnumerateSuccesses().First();
            var results = MainLauncher.GenerateSampleMetrics(truth, query, false, inputSpecs);

            MultiAssert.Equal(4U, results.OverallStats[StatsType.Event].QueryStats.TrueCount);
            MultiAssert.Equal(1451995U, results.OverallStats[StatsType.Base].QueryStats.TrueCount);
            MultiAssert.Equal(1451995U, results.OverallStats[StatsType.Base].TruthStats.TrueCount);
            MultiAssert.AssertAll();
        }
示例#3
0
        public void OverlapWorks_InsBnd([NotNull] string truthVar, [NotNull] string queryVar, string type)
        {
            const string sampleName = "blah";
            var          vcfVariantParserSettings = VcfVariantParserSettings.Create(new List <string> {
                sampleName
            });
            var        baseVariant   = VcfVariant.TryParse(truthVar, vcfVariantParserSettings).GetOrThrow();
            const bool isCrossTypeOn = true;
            var        wittyerType   = WittyerType.Parse(type);
            var        inputSpecs    = InputSpec
                                       .GenerateCustomInputSpecs(!isCrossTypeOn, new[] { wittyerType }, percentDistance: PercentDistance)
                                       .ToDictionary(s => s.VariantType, s => s);

            if (wittyerType == WittyerType.Insertion)
            {
                var inputSpec = inputSpecs[wittyerType];
                inputSpecs[wittyerType] = InputSpec.Create(wittyerType, inputSpec.BinSizes,
                                                           100, inputSpec.PercentDistance,
                                                           inputSpec.ExcludedFilters, inputSpec.IncludedFilters, null);
            }

            var bndSet    = new Dictionary <IGeneralBnd, IVcfVariant>();
            var errorList = new List <string>();
            var truthV    = (IMutableWittyerBnd)WittyerVcfReader.CreateVariant(baseVariant, baseVariant.Samples.First().Value, true, sampleName,
                                                                               inputSpecs, bndSet, errorList, isCrossTypeOn);

            baseVariant = VcfVariant.TryParse(queryVar, vcfVariantParserSettings).GetOrThrow();
            var queryV = (IMutableWittyerBnd)WittyerVcfReader.CreateVariant(baseVariant, baseVariant.Samples.First().Value, false, sampleName,
                                                                            inputSpecs, bndSet, errorList, isCrossTypeOn);
            var tree = TruthForest.Create(sampleName, VcfHeader.CreateBuilder(VcfVersion.FourPointOne).Build());

            tree.AddTarget(truthV);
            OverlappingUtils.DoOverlapping(tree.BpInsTrees, queryV, OverlappingUtils.IsBndAlleleMatch, isCrossTypeOn, true);
            queryV.Finalize(WitDecision.FalsePositive, EvaluationMode.CrossTypeAndSimpleCounting, null);
            truthV.Finalize(WitDecision.FalseNegative, EvaluationMode.CrossTypeAndSimpleCounting, null);
            Assert.Equal(WitDecision.TruePositive, queryV.Sample.Wit);
            Assert.Equal(WitDecision.TruePositive, truthV.Sample.Wit);
        }
示例#4
0
        public void SvWorksWithSimpleCount()
        {
            if (MiscUtils.IsRunningAnyLinux)
            {
                return;                              // currently failing on linux :(
            }
            //var insertionSpec = InputSpecs[WittyerVariantType.Insertion];
            var insertionSpec = InputSpec.Create(WittyerType.Insertion,
                                                 WittyerConstants.DefaultBins.SetItem(0, (50, false)),
                                                 WittyerConstants.DefaultBpOverlap, 0.05, WittyerConstants.DefaultExcludeFilters,
                                                 WittyerConstants.DefaultIncludeFilters, null);
            var outputDirectory = Path.GetRandomFileName().ToDirectoryInfo();
            var wittyerSettings = WittyerSettings.Create(outputDirectory, SomaticTruth,
                                                         SomaticQuery, ImmutableList <ISamplePair> .Empty, EvaluationMode.SimpleCounting,
                                                         InputSpecs.SetItem(WittyerType.Insertion, insertionSpec));

            var results = MainLauncher.GenerateResults(wittyerSettings).Select(i => i.GetOrThrow()).ToList();

            var(_, query, truth) = results.First();

            MultiAssert.Equal(((IMutableWittyerResult)query).NumEntries,
                              (uint)WittyerVcfWriter.ProcessVariants(query, false).Count());
            MultiAssert.Equal(((IMutableWittyerResult)truth).NumEntries,
                              (uint)WittyerVcfWriter.ProcessVariants(truth, true).Count());

            var testStrings = WittyerVcfWriter.GenerateVcfStrings(query, null, null).Where(line => !line.StartsWith(VcfConstants.Header.Prefix));

            MultiAssert.True(testStrings.All(s => ParseVariantGetTag(s, WitDecision.FalsePositive)));
            testStrings = WittyerVcfWriter.GenerateVcfStrings(null, truth, null).Where(line => !line.StartsWith(VcfConstants.Header.Prefix));
            MultiAssert.True(testStrings.All(s => ParseVariantGetTag(s, WitDecision.FalseNegative)));

            var actualStats = GeneralStats.Create(results,
                                                  wittyerSettings.Mode == EvaluationMode.Default, wittyerSettings.InputSpecs, EmptyCmd).PerSampleStats
                              .First();
            var expectedStats = JsonConvert.DeserializeObject <GeneralStats>(File.ReadAllText(SvJsonSc.FullName))
                                .PerSampleStats.First();

            var expectedOverallEventStats = expectedStats.OverallStats.Single(x => x.StatsType.Equals(StatsType.Event));
            var actualOverallEventStats   = actualStats.OverallStats.Single(x => x.StatsType.Equals(StatsType.Event));

            MultiAssert.Equal(expectedOverallEventStats.QueryFpCount, actualOverallEventStats.QueryFpCount);
            MultiAssert.Equal(expectedOverallEventStats.QueryTpCount, actualOverallEventStats.QueryTpCount);
            MultiAssert.Equal(expectedOverallEventStats.QueryTotalCount, actualOverallEventStats.QueryTotalCount);
            MultiAssert.Equal(expectedOverallEventStats.TruthTpCount, actualOverallEventStats.TruthTpCount);
            MultiAssert.Equal(expectedOverallEventStats.TruthFnCount, actualOverallEventStats.TruthFnCount);
            MultiAssert.Equal(expectedOverallEventStats.TruthTotalCount, actualOverallEventStats.TruthTotalCount);

            var expectedInsertionStats = expectedStats.DetailedStats
                                         .Single(s => s.VariantType == WittyerType.Insertion.Name).PerBinStats;
            var actualInsertionStats = actualStats.DetailedStats
                                       .Single(s => s.VariantType == WittyerType.Insertion.Name).PerBinStats;

            foreach (var(expectedInsBinStat, actualInsBinStat) in expectedInsertionStats.Zip(actualInsertionStats,
                                                                                             (a, b) => (a, b)))
            {
                var expectedSingleStat = expectedInsBinStat.Stats.Single();
                var actualSingleStat   = actualInsBinStat.Stats.Single();
                if (!expectedSingleStat.Equals(actualSingleStat))
                {
                    MultiAssert.Equal(string.Empty, expectedInsBinStat.Bin);
                }
                MultiAssert.Equal(expectedSingleStat, actualSingleStat);
            }

            MultiAssert.AssertAll();
        }