Exemple #1
0
        public override IParsingResult <List <TOut> > Parse(SuccessfulResultCollection input)
        {
            var multipleValues = input.Get(Info);
            var outputs        = new List <TOut>();

            foreach (var values in multipleValues)
            {
                var option1Result = GetOptionResult(0, values, _option1);
                var option2Result = GetOptionResult(1, values, _option2);
                var option3Result = GetOptionResult(2, values, _option3);
                if (!option1Result.Success)
                {
                    return(ParsingResult <List <TOut> > .FailedResult(option1Result.ErrorMessage));
                }
                if (!option2Result.Success)
                {
                    return(ParsingResult <List <TOut> > .FailedResult(option2Result.ErrorMessage));
                }
                if (!option3Result.Success)
                {
                    return(ParsingResult <List <TOut> > .FailedResult(option3Result.ErrorMessage));
                }
                var result = _parse(option1Result.Result, option2Result.Result, option3Result.Result);
                if (!result.Success)
                {
                    return(ParsingResult <List <TOut> > .FailedResult(result.ErrorMessage));
                }
                outputs.Add(result.Result);
            }
            if (_required && outputs.Empty())
            {
                return(ParsingResult <List <TOut> > .FailedResult($"{Info.Name} is a required option"));
            }
            return(ParsingResult <List <TOut> > .SuccessfulResult(outputs));
        }
Exemple #2
0
        public override IParsingResult <ExclusiveFileOptionResult> Parse(SuccessfulResultCollection parseInput)
        {
            var result1 = parseInput.Get(_option1);
            var result2 = parseInput.Get(_option2);

            if (result1 != null && result2 != null)
            {
                return(ParsingResult <ExclusiveFileOptionResult> .FailedResult($"Please specify either option {_option1.Info.Name} or option {_option2.Info.Name}, but not both"));
            }
            if (_isRequired && result1 == null && result2 == null)
            {
                return(ParsingResult <ExclusiveFileOptionResult> .FailedResult($"Either option {_option1.Info.Name} or option {_option2.Info.Name} must be specified"));
            }
            IFileLocation result = null;
            FileOption    option = null;

            if (result1 != null)
            {
                result = result1;
                option = _option1;
            }
            if (result2 != null)
            {
                result = result2;
                option = _option2;
            }
            return(ParsingResult <ExclusiveFileOptionResult> .SuccessfulResult(new ExclusiveFileOptionResult(result, option)));
        }
Exemple #3
0
        public override IParsingResult <BaseOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var helpResult    = parseInput.Get(Help);
            var versionResult = parseInput.Get(Version);

            return(ParsingResult <BaseOptions> .SuccessfulResult(new BaseOptions(helpResult, versionResult)));
        }
Exemple #4
0
        public override ParsingResult <IModeRunner> Parse(SuccessfulResultCollection parseInput)
        {
            CommonOptions        commonOptions        = parseInput.Get(CommonOptionsParser);
            SmallPedigreeOptions smallPedigreeOptions = parseInput.Get(SmallPedigreeOptionsParser);

            return(ParsingResult <IModeRunner> .SuccessfulResult(new SmallPedigreeWgsRunner(commonOptions, smallPedigreeOptions)));
        }
Exemple #5
0
        public IParsingResult <IModeLauncher> Parse(
            MainParser main, ILogger logger, ISettings settings, ICheckpointRunner checkpointRunner,
            IWorkDoer workDoer, string[] args, TextWriter standardWriter, TextWriter errorWriter)
        {
            var results = main.GetParseResults(args);

            var parsingResult = checkpointRunner.RunCheckpoint("Validate input", () =>
            {
                if (!results.Validate(out IParsingResult <IModeLauncher> failedResult))
                {
                    return(ParsingResult <T> .FailedResult(failedResult.ErrorMessage));
                }
                var successfulResults = new SuccessfulResultCollection(results);
                var commonOptions     = successfulResults.Get(MainParser.CommonOptionsParser);
                return(GetSerializedResult(successfulResults, commonOptions));
            });

            if (!parsingResult.Success)
            {
                ShowError(main, logger.Error, parsingResult.ErrorMessage);
                return(ParsingResult <IModeLauncher> .FailedResult(parsingResult));
            }
            var runner = GetRunner(parsingResult.Result);

            return(ParsingResult <IModeLauncher> .SuccessfulResult(new ModeLauncher(logger, settings, checkpointRunner, workDoer, runner, args, main.GetVersion(), Name)));
        }
        public override ParsingResult <SomaticEnrichmentOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var bam            = parseInput.Get(Bam);
            var manifest       = parseInput.Get(Manifest);
            var controlBams    = parseInput.Get(ControlBams);
            var controlBinned  = parseInput.Get(ControlBinned);
            var controlBinSize = parseInput.Get(ControlBinSize);
            var controlPloidy  = parseInput.Get(ControlPloidyBed);

            var controlBinnedBools = new List <bool> {
                controlBinned != null, controlBinSize != null, controlPloidy != null
            };

            if (controlBams.Any() && controlBinnedBools.Any(controlBinnedBool => controlBinnedBool))
            {
                return(ParsingResult <SomaticEnrichmentOptions> .FailedResult($"Error: option {ControlBams.Info.Name} cannot be combined with any of {ControlBinned.Info.Name}, {ControlBinSize.Info.Name}, {ControlPloidyBed.Info.Name} "));
            }

            if (controlBinned != null && controlBinSize == null)
            {
                return(ParsingResult <SomaticEnrichmentOptions> .FailedResult($"Error: {ControlBinSize.Info.Name} is required when using the {ControlBinned.Info.Name} option"));
            }

            return(ParsingResult <SomaticEnrichmentOptions> .SuccessfulResult(
                       new SomaticEnrichmentOptions(
                           bam,
                           manifest,
                           controlBams,
                           controlBinned,
                           controlBinSize.HasValue ? (int)controlBinSize.Value : 0,
                           controlPloidy)));
        }
Exemple #7
0
        public ParsingResult <IModeLauncher> Parse(string[] args, TextWriter standardWriter, TextWriter errorWriter)
        {
            if (args.Empty() || !_modeParsers.ContainsKey(args[0]))
            {
                return(GetMissingModeResult(args, standardWriter, errorWriter));
            }
            var mode    = _modeParsers[args[0]];
            var options = new OptionCollection <IModeLauncher> {
                BaseOptionsParser, mode
            };
            var result = options.Parse(args.Skip(1));
            ParsingResult <IModeLauncher> failedResult;

            if (!result.RemainingArgs.Any() && HandleBaseOptions(result.Get(BaseOptionsParser).Result, standardWriter, mode))
            {
                return(ParsingResult <IModeLauncher> .SuccessfulResult(new NullModeLauncher()));
            }

            if (!result.Validate(out failedResult))
            {
                errorWriter.WriteLine(failedResult.ErrorMessage);
                errorWriter.WriteLine();
                ShowHelp(errorWriter, mode);
                return(failedResult);
            }
            var runner = result.Get(mode).Result;

            return(ParsingResult <IModeLauncher> .SuccessfulResult(new ModeLauncher(runner, args, GetVersion(), mode.Name)));
        }
Exemple #8
0
        public override IParsingResult <GermlineWgsInput> GetSerializedResult(SuccessfulResultCollection result, CommonOptions commonOptions)
        {
            var singleSampleCommonOptions = result.Get(SingleSampleCommonOptionsParser);
            var bam = result.Get(Bam);

            return(ParsingResult <GermlineWgsInput> .SuccessfulResult(new GermlineWgsInput(commonOptions, singleSampleCommonOptions, bam)));
        }
Exemple #9
0
        public void CanSerializeSuccessfulParsingResult()
        {
            var parsingResult = ParsingResult <string> .SuccessfulResult("success");

            var serializedResult = _tester.RoundTrip(parsingResult);

            Assert.Equal("success", serializedResult.Result);
        }
        public override ParsingResult <IModeRunner> Parse(SuccessfulResultCollection parseInput)
        {
            CommonOptions             commonOptions             = parseInput.Get(CommonOptionsParser);
            SingleSampleCommonOptions singleSampleCommonOptions = parseInput.Get(SingleSampleCommonOptionsParser);
            TumorNormalOptions        tumorNormalOptions        = parseInput.Get(TumorNormalOptionsParser);

            return(ParsingResult <IModeRunner> .SuccessfulResult(new TumorNormalWgsRunner(commonOptions, singleSampleCommonOptions, tumorNormalOptions)));
        }
Exemple #11
0
        public override ParsingResult <IModeRunner> Parse(SuccessfulResultCollection parseInput)
        {
            CommonOptions             commonOptions             = parseInput.Get(CommonOptionsParser);
            SingleSampleCommonOptions singleSampleCommonOptions = parseInput.Get(SingleSampleCommonOptionsParser);
            var bam = parseInput.Get(Bam);

            return(ParsingResult <IModeRunner> .SuccessfulResult(new GermlineWgsRunner(commonOptions, singleSampleCommonOptions, bam)));
        }
Exemple #12
0
        public override IParsingResult <TumorNormalWgsInput> GetSerializedResult(SuccessfulResultCollection result, CommonOptions commonOptions)
        {
            var singleSampleCommonOptions         = result.Get(SingleSampleCommonOptionsParser);
            TumorNormalOptions tumorNormalOptions = result.Get(TumorNormalOptionsParser);

            return(ParsingResult <TumorNormalWgsInput> .SuccessfulResult(
                       new TumorNormalWgsInput(commonOptions, singleSampleCommonOptions, tumorNormalOptions)));
        }
        public override ParsingResult <TumorNormalOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var tumorBam   = parseInput.Get(TumorBam);
            var somaticVcf = parseInput.Get(SomaticVcf);

            return(ParsingResult <TumorNormalOptions> .SuccessfulResult(
                       new TumorNormalOptions(tumorBam, somaticVcf)));
        }
        public override IParsingResult <SomaticEnrichmentInput> GetSerializedResult(SuccessfulResultCollection result, CommonOptions commonOptions)
        {
            SomaticEnrichmentOptions  somaticEnrichmentOptions  = result.Get(SomaticEnrichmentOptionsParser);
            SingleSampleCommonOptions singleSampleCommonOptions = result.Get(SingleSampleCommonOptionsParser);

            return(ParsingResult <SomaticEnrichmentInput> .SuccessfulResult(
                       new SomaticEnrichmentInput(commonOptions, somaticEnrichmentOptions, singleSampleCommonOptions)));
        }
        public override ParsingResult <IModeRunner> Parse(SuccessfulResultCollection parseInput)
        {
            CommonOptions             commonOptions             = parseInput.Get(CommonOptionsParser);
            SomaticEnrichmentOptions  somaticEnrichmentOptions  = parseInput.Get(SomaticEnrichmentOptionsParser);
            SingleSampleCommonOptions singleSampleCommonOptions = parseInput.Get(SingleSampleCommonOptionsParser);

            return(ParsingResult <IModeRunner> .SuccessfulResult(new SomaticEnrichmentRunner(commonOptions, singleSampleCommonOptions, somaticEnrichmentOptions)));
        }
        public override ParsingResult <IModeRunner> Parse(SuccessfulResultCollection parseInput)
        {
            CommonOptions             commonOptions             = parseInput.Get(CommonOptionsParser);
            SingleSampleCommonOptions singleSampleCommonOptions = parseInput.Get(SingleSampleCommonOptionsParser);
            TumorNormalOptions        tumorNormalOptions        = parseInput.Get(TumorNormalOptionsParser);
            var normalBam = parseInput.Get(NormalBam);
            var manifest  = parseInput.Get(Manifest);

            return(ParsingResult <IModeRunner> .SuccessfulResult(new TumorNormalEnrichmentRunner(commonOptions, singleSampleCommonOptions, tumorNormalOptions, normalBam, manifest)));
        }
Exemple #17
0
        public override IParsingResult <TumorNormalEnrichmentInput> GetSerializedResult(SuccessfulResultCollection result, CommonOptions commonOptions)
        {
            SingleSampleCommonOptions singleSampleCommonOptions = result.Get(SingleSampleCommonOptionsParser);
            TumorNormalOptions        tumorNormalOptions        = result.Get(TumorNormalOptionsParser);
            var normalBam = result.Get(NormalBam);
            var manifest  = result.Get(Manifest);

            return(ParsingResult <TumorNormalEnrichmentInput> .SuccessfulResult(
                       new TumorNormalEnrichmentInput(commonOptions, singleSampleCommonOptions, tumorNormalOptions, normalBam, manifest)));
        }
        public override ParsingResult <string> Parse(SuccessfulResultCollection parseInput)
        {
            string value = parseInput.Get(this);

            if (value == null)
            {
                return(ParsingResult <string> .FailedResult($"Error: {Name} is a required option"));
            }
            return(ParsingResult <string> .SuccessfulResult(value));
        }
Exemple #19
0
        public override IParsingResult <TOut> Parse(SuccessfulResultCollection parseInput)
        {
            var multipleValues = parseInput.Get(PositionalOption);

            if (multipleValues.Count > 1)
            {
                return(ParsingResult <TOut> .FailedResult($"{PositionalOption.Info.Name} can be specified only once"));
            }
            return(ParsingResult <TOut> .SuccessfulResult(multipleValues.SingleOrDefault()));
        }
Exemple #20
0
        public override ParsingResult <List <string> > Parse(SuccessfulResultCollection parseInput)
        {
            List <string> value = parseInput.Get(this);

            if (!value.Any())
            {
                return(ParsingResult <List <string> > .FailedResult($"Error: {Name} is a required option"));
            }
            return(ParsingResult <List <string> > .SuccessfulResult(value));
        }
Exemple #21
0
        public override IParsingResult <IDirectoryLocation> Parse(string value)
        {
            IDirectoryLocation location = value == null ? null : new DirectoryLocation(value);

            if (location == null || location.Exists)
            {
                return(ParsingResult <IDirectoryLocation> .SuccessfulResult(location));
            }
            return(ParsingResult <IDirectoryLocation> .FailedResult($"Error: {location} does not exist"));
        }
Exemple #22
0
        public override IParsingResult <IDirectoryLocation> Parse(string value)
        {
            IDirectoryLocation location = value == null ? null : new DirectoryLocation(value);

            if (location != null && !ActionExtensions.Try(() => location.Create(), out Exception e))
            {
                return(ParsingResult <IDirectoryLocation> .FailedResult($"Error: failed to create directory {location}. Exception: {e}"));
            }
            return(ParsingResult <IDirectoryLocation> .SuccessfulResult(location));
        }
Exemple #23
0
        public override IParsingResult <SingleSampleCommonOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var  bAlleleSites = parseInput.Get(BAlleleSites);
            bool isDbSnpVcf   = bAlleleSites.MatchedOption.Equals(PopulationBAlleleSites);
            var  ploidyVcf    = parseInput.Get(PloidyVcf);
            var  sampleName   = parseInput.Get(SampleName);

            return(ParsingResult <SingleSampleCommonOptions> .SuccessfulResult(
                       new SingleSampleCommonOptions(
                           bAlleleSites.Result,
                           isDbSnpVcf,
                           ploidyVcf,
                           sampleName)));
        }
        public override IParsingResult <SmallPedigreeOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var bams          = parseInput.Get(Bams);
            var ploidyVcf     = parseInput.Get(PloidyVcf);
            var bAlleleSites  = parseInput.Get(BAlleleSites);
            var commonCnvsBed = parseInput.Get(CommonCnvsBed);

            IParsingResult <SmallPedigreeOptions> failedResult;

            if (HasMoreThanOneSameSampleType(bams, out failedResult))
            {
                return(failedResult);
            }
            return(ParsingResult <SmallPedigreeOptions> .SuccessfulResult(new SmallPedigreeOptions(bams, commonCnvsBed, bAlleleSites.Result, bAlleleSites.MatchedOption.Equals(PopulationBAlleleSites), ploidyVcf)));
        }
Exemple #25
0
        public override ParsingResult <List <T> > Parse(SuccessfulResultCollection input)
        {
            var values  = input.Get(Info);
            var results = new List <T>();

            foreach (var value in values)
            {
                var result = _valueOption.Parse(value);
                if (!result.Success)
                {
                    return(ParsingResult <List <T> > .FailedResult(result.ErrorMessage));
                }
                results.Add(result.Result);
            }
            return(ParsingResult <List <T> > .SuccessfulResult(results));
        }
Exemple #26
0
 public virtual IParsingResult <T> Parse(string value)
 {
     if (value == null)
     {
         return(ParsingResult <T> .SuccessfulResult(_defaultValue));
     }
     try
     {
         T parsedValue = ConvertInternal(value);
         return(ParsingResult <T> .SuccessfulResult(parsedValue));
     }
     catch (Exception)
     {
         return(ParsingResult <T> .FailedResult($"Error parsing {Info.Name} option: failed to convert {value} to {typeof(T)}"));
     }
 }
Exemple #27
0
 public virtual ParsingResult <T> Parse(string value)
 {
     if (value == null)
     {
         return(ParsingResult <T> .SuccessfulResult(_defaultValue));
     }
     try
     {
         T parsedValue = (T)Convert.ChangeType(value, GetUnderlyingType(typeof(T)));
         return(ParsingResult <T> .SuccessfulResult(parsedValue));
     }
     catch (Exception)
     {
         return(ParsingResult <T> .FailedResult($"Error parsing {Info.Name} option: failed to convert {value} to {typeof(T)}"));
     }
 }
 private static IParsingResult <SmallPedigreeSampleOptions> Parse(IFileLocation bam, SampleType sampleType, string sampleName)
 {
     if (sampleName == null)
     {
         Action a = () =>
         {
             BamReader.WrapException(bam, reader =>
             {
                 sampleName = reader.GetReadGroupSample();
             });
         };
         if (!a.Try(out Exception e))
         {
             return(ParsingResult <SmallPedigreeSampleOptions> .FailedResult(e.Message));
         }
     }
     return(ParsingResult <SmallPedigreeSampleOptions> .SuccessfulResult(new SmallPedigreeSampleOptions(sampleName, sampleType, bam)));
 }
Exemple #29
0
        public override IParsingResult <CommonOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var    output           = parseInput.Get(Output);
            var    wholeGenomeFasta = parseInput.Get(WholeGenomeFasta);
            var    kmerFasta        = parseInput.Get(KmerFasta);
            var    filterBed        = parseInput.Get(FilterFile);
            var    customParameters = parseInput.Get(CustomParameters);
            string startCheckpoint  = parseInput.Get(StartCheckpoint);
            string stopCheckpoint   = parseInput.Get(StopCheckpoint);

            return(ParsingResult <CommonOptions> .SuccessfulResult(
                       new CommonOptions(
                           output,
                           wholeGenomeFasta,
                           kmerFasta,
                           filterBed,
                           customParameters,
                           startCheckpoint,
                           stopCheckpoint)));
        }
Exemple #30
0
        public override ParsingResult <SmallPedigreeOptions> Parse(SuccessfulResultCollection parseInput)
        {
            var bams            = parseInput.Get(Bams);
            var sampleNameToBam = MapSampleNameToBam(bams);
            var ploidyVcf       = parseInput.Get(PloidyVcf);
            var bAlleleSites    = parseInput.Get(BAlleleSites);
            var mother          = parseInput.Get(Mother);
            var father          = parseInput.Get(Father);
            var proband         = parseInput.Get(Proband);
            var commonCnvsBed   = parseInput.Get(CommonCnvsBed);

            List <SmallPedigreeSampleOptions> samples = new List <SmallPedigreeSampleOptions>();

            foreach (var sample in sampleNameToBam)
            {
                var sampleType = GetSampleType(sample.Key, mother, father, proband);
                samples.Add(new SmallPedigreeSampleOptions(sample.Key, sampleType, sample.Value));
            }

            return(ParsingResult <SmallPedigreeOptions> .SuccessfulResult(new SmallPedigreeOptions(samples, commonCnvsBed, bAlleleSites.Result, bAlleleSites.MatchedOption.Equals(PopulationBAlleleSites), ploidyVcf)));
        }