コード例 #1
0
        public void NoChangeAfterDeserializeReserializeDeserialize()
        {
            var defaultConfigFilePath = Path.Combine(Environment.CurrentDirectory, "Config-default.json");
            var text = File.ReadAllText(defaultConfigFilePath);
            var deserializedWittyerConfigObject =
                JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(text,
                                                                         InputSpecConverter.Create());

            var reserialized = JsonConvert.SerializeObject(deserializedWittyerConfigObject, Formatting.Indented);
            var deserializeReserializeDeserializedWittyerConfigObject =
                JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(reserialized,
                                                                         InputSpecConverter.Create());

            Assert.True(deserializedWittyerConfigObject.IsScrambledEquals(deserializeReserializeDeserializedWittyerConfigObject));
        }
コード例 #2
0
        public void CanSuccessfullyParseSkippedBins()
        {
            var skippedBinsConfig = Path.Combine(ConfigsFolder, "Config-just-cng-skipped-bins.json");
            var text = File.ReadAllText(skippedBinsConfig);
            var deserializedWittyerConfigObject =
                JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(text,
                                                                         InputSpecConverter.Create());
            var copyNumberGainInputSpec =
                deserializedWittyerConfigObject.First(inputSpec => inputSpec.VariantType == WittyerType.CopyNumberGain);
            var bins         = copyNumberGainInputSpec.BinSizes;
            var expectedBins = ImmutableList <(uint size, bool skip)> .Empty
                               .Add((1, true))
                               .Add((1000, false))
                               .Add((5000, true))
                               .Add((10000, false))
                               .Add((20000, true));

            Assert.Equal(bins, expectedBins);
        }
コード例 #3
0
 public void ParsingIsCaseSensitive()
 {
     Assert.Throws <JsonSerializationException>(() => JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(
                                                    File.ReadAllText(Path.Combine(ConfigsFolder, "Config-just-deletion-weirdcase.json")),
                                                    InputSpecConverter.Create()));
 }
コード例 #4
0
        public void UsingDefaultConfigFileProducesSameInputSpecsAsCommandLineDefaults()
        {
            var defaultConfigFilePath        = Path.Combine(Environment.CurrentDirectory, "Config-default.json");
            var defaultInputSpecsCommandLine = InputSpec
                                               .GenerateDefaultInputSpecs(true, WittyerType.AllTypes.OrderBy(s => s.Name))
                                               .ToImmutableDictionary(x => x.VariantType, x => x);
            var defaultInputSpecsConfig = JsonConvert
                                          .DeserializeObject <IEnumerable <InputSpec> >(File.ReadAllText(defaultConfigFilePath),
                                                                                        InputSpecConverter.Create()).OrderBy(x => x.VariantType.Name)
                                          .ToImmutableDictionary(x => x.VariantType, x => x);

            foreach (var(key, value) in defaultInputSpecsConfig)
            {
                if (!defaultInputSpecsCommandLine.TryGetValue(key, out var value2))
                {
                    MultiAssert.Equal(string.Empty, key.ToString());
                }
                if (!value.Equals(value2))
                {
                    MultiAssert.Equal(value, value2);
                }
            }
            MultiAssert.AssertAll();
        }
コード例 #5
0
 public void ConfigFileDuplicateThrowsException()
 {
     Assert.Throws <JsonReaderException>(() =>
                                         JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(File.ReadAllText(Path.Combine(ConfigsFolder, "Config-duplicate-field.txt")),
                                                                                                  InputSpecConverter.Create()));
 }
コード例 #6
0
        public void InvalidConfigFileThrowsException(string configFileName, string expectedExceptionMessage)
        {
            var exception = Assert.Throws <JsonSerializationException>(() =>
                                                                       JsonConvert.DeserializeObject <IEnumerable <InputSpec> >(File.ReadAllText(Path.Combine(ConfigsFolder, configFileName)),
                                                                                                                                InputSpecConverter.Create()));

            Assert.Equal(expectedExceptionMessage, exception.Message.Replace("\r\n", "\n"));
        }
コード例 #7
0
                internal static IWittyerSettings ParsePrivate(string[] args)
                {
                    var parameters  = new WittyerParameters();
                    var ndeskParser = new NdeskOptionParser(parameters, args);
                    var unparsed    = ndeskParser.UnparsedArgs;

                    if (unparsed.Count > 0)
                    {
                        Console.WriteLine("Warning: Unparsed args: " + string.Join(" ", unparsed));
                    }

                    if (parameters._isDisplayVersion.Argument)
                    {
                        Console.WriteLine($"witty.er {CurrentVersion}");
                        Console.WriteLine(parameters.AdditionalHelpHeader);
                        Environment.Exit(0);
                    }

                    if (parameters._configFile.IsArgumentAssigned)
                    {
                        if (parameters._configOptions.Any(x => x.IsArgumentAssigned))
                        {
                            Console.Error.WriteLine(
                                "Config file argument cannot be used in combination with arguments for bin sizes, basepair distance, " +
                                "percent distance, included filters, excluded filters, variant types, or include bed. Exiting.");
                            Environment.Exit(1);
                        }

                        var fi = parameters._configFile.Argument;
                        if (!fi.ExistsNow())
                        {
                            Console.WriteLine(
                                $"Config file {fi.FullName} did not exist! Generating default config file in its place. Rerun with exactly same command line and it will work this time.");
                            File.WriteAllText(fi.FullName, InputSpec.GenerateDefaultInputSpecs(
                                                  parameters.Mode == EvaluationMode.CrossTypeAndSimpleCounting).SerializeToString());
                            Environment.Exit(0);
                        }

                        var configText = File.ReadAllText(parameters._configFile.Argument.FullName);
                        if (string.IsNullOrWhiteSpace(configText))
                        {
                            Console.Error.WriteLine("Bad Config file passed in at " + fi.FullName);
                            Environment.Exit(1);
                        }

                        parameters.InputSpecs = JsonConvert
                                                .DeserializeObject <IEnumerable <InputSpec> >(configText, InputSpecConverter.Create())
                                                .ToImmutableDictionary(x => x.VariantType, x => x);
                    }
                    else
                    {
                        var generatedSpecs = InputSpec.GenerateCustomInputSpecs(
                            parameters.Mode != EvaluationMode.CrossTypeAndSimpleCounting,
                            parameters._variantTypes.Argument, parameters._binSizes.Argument,
                            parameters._basepairDistance.Argument, parameters._percentDistance.Argument,
                            parameters._excludedFilters.Argument,
                            parameters._includedFilters.Argument, parameters._bedFile.Argument);

                        if (!parameters._basepairDistance.IsArgumentAssigned) // keep default
                        {
                            generatedSpecs = generatedSpecs.Select(i =>
                                                                   i.VariantType == WittyerType.Insertion
                                    ? InputSpec.Create(i.VariantType, i.BinSizes, DefaultInsertionSpec.BasepairDistance,
                                                       i.PercentDistance, i.ExcludedFilters, i.IncludedFilters, i.IncludedRegions)
                                    : i);
                        }
                        parameters.InputSpecs = generatedSpecs.ToImmutableDictionary(s => s.VariantType, s => s);
                    }

                    if (parameters.Mode == EvaluationMode.CrossTypeAndSimpleCounting &&
                        parameters.InputSpecs.Keys.Any(s => s.IsCopyNumberVariant))
                    {
                        Console.WriteLine(
                            $"Warning: {WittyerType.CopyNumberGain} and/or {WittyerType.CopyNumberLoss}" +
                            $" setting given when using {EvaluationMode.CrossTypeAndSimpleCounting}" +
                            " mode!  This setting will be ignored.");
                    }

                    ValidateRequiredParameters(parameters._inputVcf);
                    ValidateRequiredParameters(parameters._truthVcf);
                    return(parameters);
                }