コード例 #1
0
        private PiscesOptionsParser GetParsedApplicationOptions(string arguments)
        {
            var parsedOptions = new PiscesOptionsParser();

            parsedOptions.ParseArgs(arguments.Split(' '), false);
            return(parsedOptions);
        }
コード例 #2
0
        public void InvalidVcfOutputFolder()
        {
            Assert.False(Directory.Exists("56:\\Illumina\\OutputFolder"));
            var outputFolder = Path.Combine("56:\\Illumina\\OutputFolder");

            string bamChr19         = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr19.bam");
            string bamChr17Chr19    = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr17Chr19.bam");
            string bamChr17Chr19Dup = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr17Chr19_removedSQlines.bam");

            string intervalsChr19 = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr19.picard");

            string intervalsChr17 = Path.Combine(TestPaths.LocalTestDataDirectory, "chr17only.picard");

            string genomeChr19 = Path.Combine(TestPaths.SharedGenomesDirectory, "chr19");


            var appOptions = new PiscesApplicationOptions
            {
                BAMPaths        = new[] { bamChr19, bamChr17Chr19, bamChr17Chr19Dup },
                IntervalPaths   = new[] { intervalsChr17, intervalsChr19, null },
                GenomePaths     = new[] { genomeChr19 },
                OutputDirectory = outputFolder
            };

            var parser = new PiscesOptionsParser()
            {
                Options = appOptions
            };

            Assert.Throws <ArgumentException>(() => parser.ValidateAndSetDerivedValues());
        }
コード例 #3
0
        public void PopulateBAMPaths()
        {
            var BAMFolder = TestPaths.SharedBamDirectory;
            //Happy Path
            var options_1 = new PiscesApplicationOptions()
            {
                BAMPaths      = BamProcessorParsingUtils.UpdateBamPathsWithBamsFromFolder(BAMFolder),
                GenomePaths   = new[] { _existingGenome },
                IntervalPaths = new[] { _existingInterval }
            };

            Assert.NotNull(options_1.BAMPaths);
            Assert.True(options_1.BAMPaths.Length > 0);

            //no bam files found
            var options_3 = new PiscesApplicationOptions()
            {
                GenomePaths = new[] { _existingGenome },
            };

            var parser = new PiscesOptionsParser()
            {
                Options = options_3
            };

            Assert.Null(options_3.BAMPaths);

            Assert.Throws <ArgumentException>(() => parser.ValidateAndSetDerivedValues());
        }
コード例 #4
0
        //if I was not in a hurry, we could refactor this into the Config class and let it be re-used by Scylla and VQR...
        private static VcfWriterConfig GetWriterConfigToMatchInputVcf(string vcfIn)
        {
            List <string> vcfHeaderLines;

            using (var reader = new VcfReader(vcfIn))
            {
                vcfHeaderLines = reader.HeaderLines;
            }


            PiscesOptionsParser piscesOptionsParser = VcfConsumerAppParsingUtils.GetPiscesOptionsFromVcfHeader(vcfHeaderLines);

            if (piscesOptionsParser.ParsingFailed)
            {
                Logger.WriteToLog("Unable to parse the original Pisces commandline");
                throw new ArgumentException("Unable to parse the input vcf header: " + vcfIn);
            }

            VariantCallingParameters variantCallingParams = piscesOptionsParser.PiscesOptions.VariantCallingParameters;
            VcfWritingParameters     vcfWritingParams     = piscesOptionsParser.PiscesOptions.VcfWritingParameters;
            BamFilterParameters      bamFilterParams      = piscesOptionsParser.PiscesOptions.BamFilterParameters;

            var config = new VcfWriterConfig(variantCallingParams, vcfWritingParams, bamFilterParams, null, false, false);

            return(config);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: zhaohongqiangsoliva/Pisces
 public Program(string programDescription, string commandLineExample, string programAuthors, string programName,
                IVersionProvider versionProvider = null) : base(programDescription, commandLineExample,
                                                                programAuthors, programName, versionProvider = null)
 {
     _options         = new PiscesApplicationOptions();
     _appOptionParser = new PiscesOptionsParser();
 }
コード例 #6
0
        private static void CheckHeader(AlleleReader reader)
        {
            string piscesCmd       = reader.HeaderLines.FirstOrDefault(str => str.Contains("##Pisces_cmdline")).Split("\"\"")[1];
            var    appOptionParser = new PiscesOptionsParser();

            appOptionParser.ParseArgs(piscesCmd.Split(null));

            // Check if VCF is diploid
            if (appOptionParser.PiscesOptions.VariantCallingParameters.PloidyModel == PloidyModel.DiploidByAdaptiveGT ||
                appOptionParser.PiscesOptions.VariantCallingParameters.PloidyModel == PloidyModel.DiploidByThresholding)
            {
                throw new VariantReaderException("Adaptive Genotyper should be used with VCFs that are called as somatic " +
                                                 "VCFs by Pisces.  Please check the input VCF file.");
            }

            // Check if VCF is crushed
            else if (appOptionParser.PiscesOptions.VcfWritingParameters.ForceCrush == true)
            {
                throw new VariantReaderException("Adaptive Genotyper should be used with uncrushed VCFs.  Please check the input VCF file.");
            }

            // Check if GVCF or --minvq 0
            else if (!appOptionParser.PiscesOptions.VcfWritingParameters.OutputGvcfFile &&
                     (appOptionParser.PiscesOptions.VariantCallingParameters.MinimumVariantQScore > 0 ||
                      appOptionParser.PiscesOptions.VariantCallingParameters.MinimumFrequency > 0.02))
            {
                throw new VariantReaderException("Adaptive Genotyper should be used with GVCFs or with option -minvq 0.  Please" +
                                                 " check in the input VCF file.");
            }
        }
コード例 #7
0
        private void ExecuteValidationTest(Action <PiscesApplicationOptions> testSetup, bool shouldPass)
        {
            var options = GetBasicOptions();

            testSetup(options);
            var parser = new PiscesOptionsParser()
            {
                Options = options
            };

            if (shouldPass)
            {
                parser.ValidateAndSetDerivedValues();
            }
            else
            {
                Assert.Throws <ArgumentException>(() => parser.ValidateAndSetDerivedValues());
            }
        }
コード例 #8
0
        public void Validate()
        {
            // ---------------------
            // verify default should be valid
            // ---------------------
            var option = GetBasicOptions();
            var parser = new PiscesOptionsParser()
            {
                Options = option
            };

            parser.ValidateAndSetDerivedValues();

            // ---------------------
            // verify log folder
            // ---------------------
            Assert.Equal(Path.Combine(TestPaths.SharedBamDirectory, "PiscesLogs"), option.LogFolder);

            // ---------------------------------------------------
            // BAMPath(s) should be specified.
            // ---------------------------------------------------
            ExecuteValidationTest((o) => { o.BAMPaths = new[] { _existingBamPath }; }, true);
            ExecuteValidationTest((o) => { o.BAMPaths = new[] { "bampath1.bam" }; }, false);
            ExecuteValidationTest((o) => { o.BAMPaths = null; }, false);


            // ---------------------------------------------------
            // BAMFolder
            // Folder should exist (given as the first string in BAMPaths)
            // 1 Genome Path should be specified when BAMFolder is specified.
            // Atmost 1 Interval Path should be specified when BAMFolder is specified.
            // Threading by chromosome is not supported when BAMFolder is specified.
            // ---------------------------------------------------
            ExecuteValidationTest(o =>
            {
                o.BAMPaths    = new string[] { @"C:\NonexistantBAMFolder" };
                o.GenomePaths = new[] { _existingGenome };
            }, false);
            ExecuteValidationTest(o =>
            {
                o.BAMPaths    = new string[] { TestPaths.SharedBamDirectory };
                o.GenomePaths = new[] { "folder1", "folder2" };
            }, false);
            ExecuteValidationTest(o =>
            {
                o.BAMPaths      = new string[] { TestPaths.SharedBamDirectory };
                o.GenomePaths   = new[] { _existingGenome };
                o.IntervalPaths = new[] { "file1.intervals", "file2.intervals" };
            }, false);
            ExecuteValidationTest(o =>
            {
                o.BAMPaths      = BamProcessorParsingUtils.UpdateBamPathsWithBamsFromFolder(TestPaths.SharedBamDirectory);
                o.GenomePaths   = new[] { _existingGenome };
                o.IntervalPaths = new[] { _existingInterval };
            }, true);

            // ---------------------
            // BAM Paths
            // Duplicate BAMPaths detected.
            // BAM Path does not exist.
            // ---------------------
            ExecuteValidationTest((o) => { o.BAMPaths = new string[0]; }, false);
            ExecuteValidationTest((o) => { o.BAMPaths = new[] { _existingBamPath, _existingBamPath }; }, false);
            ExecuteValidationTest((o) => { o.BAMPaths = new[] { "nonexistant.bam" }; }, false);

            // genome paths
            ExecuteValidationTest((o) => { o.GenomePaths = null; }, false);
            ExecuteValidationTest((o) => { o.GenomePaths = new string[0]; }, false);
            ExecuteValidationTest((o) => { o.GenomePaths = new[] { _existingGenome, _existingGenome }; }, false);
            ExecuteValidationTest((o) => { o.GenomePaths = new[] { "nonexistant" }; }, false);
            ExecuteValidationTest((o) =>
            {
                o.BAMPaths    = new[] { _existingBamPath, _existingBamPath2 };
                o.GenomePaths = new[] { _existingGenome, _existingGenome };
            }, true);  // dup genomes ok

            // intervals
            ExecuteValidationTest((o) => { o.IntervalPaths = new[] { _existingInterval, _existingInterval }; }, false);
            ExecuteValidationTest((o) => { o.IntervalPaths = new[] { "nonexistant.picard" }; }, false);
            ExecuteValidationTest((o) =>
            {
                o.BAMPaths      = new[] { _existingBamPath, _existingBamPath2 };
                o.IntervalPaths = new[] { _existingInterval, _existingInterval };
            }, true);  // dup intervals ok
            ExecuteValidationTest((o) =>
            {
                o.BAMPaths      = new[] { _existingBamPath, _existingBamPath2 };
                o.IntervalPaths = new[] { _existingInterval, _existingInterval, _existingInterval };
            }, false);

            // ---------------------
            // verify parameters
            // ---------------------
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScore = 0; }, true);
            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.MinimumVariantQScore       = 100;
                o.VariantCallingParameters.MinimumVariantQScoreFilter = 100;
            }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScore = -1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScore = 101; }, false);

            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.MaximumVariantQScore       = 0;
                o.VariantCallingParameters.MinimumVariantQScore       = 0;
                o.VariantCallingParameters.MinimumVariantQScoreFilter = 0;
            }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MaximumVariantQScore = 100; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MaximumVariantQScore = -1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MaximumVariantQScore = 101; }, true);

            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.MinimumVariantQScore = 50;
                o.VariantCallingParameters.MaximumVariantQScore = 49;
            }, false);

            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.MinimumVariantQScore       = 50;
                o.VariantCallingParameters.MaximumVariantQScore       = 50;
                o.VariantCallingParameters.MinimumVariantQScoreFilter = 50;
            }, true);

            ExecuteValidationTest((o) => { o.BamFilterParameters.MinimumBaseCallQuality = 0; }, true);
            ExecuteValidationTest((o) => { o.BamFilterParameters.MinimumBaseCallQuality = -1; }, false);

            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequency = 0f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequency = 1f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequency = -0.99f; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequency = 1.01f; }, false);

            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScoreFilter = o.VariantCallingParameters.MinimumVariantQScore; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScoreFilter = o.VariantCallingParameters.MaximumVariantQScore; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScoreFilter = o.VariantCallingParameters.MinimumVariantQScore - 1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumVariantQScoreFilter = o.VariantCallingParameters.MaximumVariantQScore + 1; }, false);

            ExecuteValidationTest((o) => { o.VariantCallingParameters.ForcedNoiseLevel = 0; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.ForcedNoiseLevel = -50; }, false);

            ExecuteValidationTest((o) => { o.MaxSizeMNV = 0; }, true);                                     // ok if not calling mnv
            ExecuteValidationTest((o) => { o.MaxGapBetweenMNV = -1; }, true);                              // ok if not calling mnv
            ExecuteValidationTest((o) => { o.OutputDirectory = TestPaths.LocalTestDataDirectory; }, true); // True for valid path
            ExecuteValidationTest((o) =>
            {
                o.CallMNVs   = true;
                o.MaxSizeMNV = 1;
            }, true);
            ExecuteValidationTest((o) =>
            {
                o.CallMNVs   = true;
                o.MaxSizeMNV = 0;
            }, false);
            ExecuteValidationTest((o) =>
            {
                o.CallMNVs   = true;
                o.MaxSizeMNV = GlobalConstants.RegionSize;
            }, true);
            ExecuteValidationTest((o) =>
            {
                o.CallMNVs   = true;
                o.MaxSizeMNV = GlobalConstants.RegionSize + 1;
            }, false);

            ExecuteValidationTest((o) =>
            {
                o.CallMNVs         = true;
                o.MaxGapBetweenMNV = 0;
            }, true);
            ExecuteValidationTest((o) =>
            {
                o.CallMNVs         = true;
                o.MaxGapBetweenMNV = -1;
            }, false);

            ExecuteValidationTest((o) => { o.BamFilterParameters.MinimumMapQuality = 0; }, true);
            ExecuteValidationTest((o) => { o.BamFilterParameters.MinimumMapQuality = -1; }, false);

            ExecuteValidationTest((o) => { o.VariantCallingParameters.StrandBiasAcceptanceCriteria = 0f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.StrandBiasAcceptanceCriteria = -0.01f; }, false);

            ExecuteValidationTest((o) => { o.MaxNumThreads = 1; }, true);
            ExecuteValidationTest((o) => { o.MaxNumThreads = 0; }, false);

            //FilteredVariantFrequency Scenarios
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequencyFilter = 0; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequencyFilter = 1f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequencyFilter = -1; o.VariantCallingParameters.MinimumFrequency = -1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.MinimumFrequencyFilter = 1.1f; }, false);


            //FilteredLowGenomeQuality Scenarios
            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.PloidyModel = PloidyModel.DiploidByThresholding;
                o.VariantCallingParameters.LowGenotypeQualityFilter = 0;
            }, true);
            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.PloidyModel = PloidyModel.DiploidByThresholding;
                o.VariantCallingParameters.LowGenotypeQualityFilter = 100;
            }, true);
            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.PloidyModel = PloidyModel.DiploidByThresholding;
                o.VariantCallingParameters.LowGenotypeQualityFilter = -1;
            }, false);
            ExecuteValidationTest((o) =>
            {
                o.VariantCallingParameters.PloidyModel = PloidyModel.DiploidByThresholding;
                o.VariantCallingParameters.LowGenotypeQualityFilter = 101;
            }, true);


            ExecuteValidationTest((o) => { o.VariantCallingParameters.LowGenotypeQualityFilter = 0; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.LowGenotypeQualityFilter = 100; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.LowGenotypeQualityFilter = -1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.LowGenotypeQualityFilter = 101; }, true);

            //FilteredIndelRepeats Scenarios
            ExecuteValidationTest((o) => { o.VariantCallingParameters.IndelRepeatFilter = 0; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.IndelRepeatFilter = 10; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.IndelRepeatFilter = -1; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.IndelRepeatFilter = 11; }, false);

            //FilteredLowDepth Scenarios
            ExecuteValidationTest(o =>
            {
                o.VariantCallingParameters.LowDepthFilter  = 0;
                o.VariantCallingParameters.MinimumCoverage = 0;
            }, true);
            ExecuteValidationTest(o =>
            {
                o.VariantCallingParameters.LowDepthFilter  = 1;
                o.VariantCallingParameters.MinimumCoverage = 0;
            }, true);
            ExecuteValidationTest(o =>
            {
                o.VariantCallingParameters.LowDepthFilter  = -1;
                o.VariantCallingParameters.MinimumCoverage = 0;
            }, false);

            //Priors path
            ExecuteValidationTest((o) => { o.PriorsPath = _existingBamPath; }, true);
            ExecuteValidationTest((o) => { o.PriorsPath = Path.Combine(TestPaths.LocalTestDataDirectory, "Nonexistant.txt"); }, false);

            // Thread by chr
            ExecuteValidationTest(o =>
            {
                o.ThreadByChr      = true;
                o.ChromosomeFilter = "chr1";
            }, false);

            // Validate ncfilter
            ExecuteValidationTest((o) => { o.VariantCallingParameters.NoCallFilterThreshold = 0f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.NoCallFilterThreshold = 1f; }, true);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.NoCallFilterThreshold = -1f; }, false);
            ExecuteValidationTest((o) => { o.VariantCallingParameters.NoCallFilterThreshold = 2f; }, false);
        }