CanvasDiploidCaller.CanvasDiploidCaller.CallVariants C# (CSharp) Метод

CallVariants() публичный Метод

public CallVariants ( string variantFrequencyFile, string inFile, string outFile, string ploidyBedPath, string referenceFolder, string sampleName, string truthDataPath ) : int
variantFrequencyFile string
inFile string
outFile string
ploidyBedPath string
referenceFolder string
sampleName string
truthDataPath string
Результат int
        public int CallVariants(string variantFrequencyFile, string inFile, string outFile, string ploidyBedPath, string referenceFolder, string sampleName,
            string truthDataPath)
        {
            if (!string.IsNullOrEmpty(truthDataPath))
            {
                this.CNOracle = new CopyNumberOracle();
                this.CNOracle.LoadKnownCN(truthDataPath);
            }

            this.Segments = CanvasSegment.ReadSegments(inFile);
            this.TempFolder = Path.GetDirectoryName(inFile);
            if (this.Segments.Count == 0)
            {
                Console.WriteLine("CanvasDiploidCaller: No segments loaded; no CNV calls will be made.");
                CanvasSegment.WriteSegments(outFile, this.Segments, referenceFolder, sampleName, null, null);
                return 0;
            }
            PloidyInfo ploidy = null;
            if (!string.IsNullOrEmpty(ploidyBedPath)) ploidy = PloidyInfo.LoadPloidyFromBedFile(ploidyBedPath);

            // load MAF
            this.MeanCoverage = CanvasIO.LoadVariantFrequencies(variantFrequencyFile, this.Segments);
            int medianVariantCoverage = AggregateVariantCoverage(ref this.Segments);

            // Create new models for different copy number states
            this.InitializePloidies();

            // Compute statistics on the copy number two regions
            float[] diploidCounts = AggregateCounts(ref this.Segments);
            DiploidCoverage = CanvasCommon.Utilities.Mean(diploidCounts);
            CoverageWeightingFactor = CoverageWeighting / DiploidCoverage;

            // new coverage model
            this.Model = new CoverageModel();
            Model.DiploidCoverage = DiploidCoverage;
            List<SegmentInfo> segments = new List<SegmentInfo>();
            foreach (CanvasSegment segment in this.Segments)
            {
                SegmentInfo info = new SegmentInfo();
                info.Segment = segment;
                List<double> MAF = new List<double>();
                foreach (float value in segment.VariantFrequencies) MAF.Add(value > 0.5 ? 1 - value : value);

                if (MAF.Count > 0)
                {
                    info.MAF = CanvasCommon.Utilities.Median(MAF);

                }
                else
                {
                    info.MAF = -1;
                }

                info.Coverage = CanvasCommon.Utilities.Median(segment.Counts);

                if (this.Segments.Count > 100)
                {
                    info.Weight = segment.End - segment.Begin;
                }
                else
                {
                    info.Weight = segment.BinCount;
                }
                segments.Add(info);
            }

            // Assign copy number and major chromosome count for each segment
            bool useGaussianMixtureModel = false; // For now, this is set false, since we saw weird performance on chrY (CANV-115):
            if (useGaussianMixtureModel)
            {
                // optimize model covariance
                double likelihood = FitGaussians(Model, segments);
                AssignPloidyCallsGaussianMixture();
            }
            else
            {
                AssignPloidyCallsDistance(Model, segments, medianVariantCoverage);
            }

            // Merge neighboring segments that got the same copy number call.
            CanvasSegment.MergeSegments(ref this.Segments);
            CanvasSegment.AssignQualityScores(this.Segments, CanvasSegment.QScoreMethod.LogisticGermline);
            List<string> extraHeaders = new List<string>();
            string coverageOutputPath = CanvasCommon.Utilities.GetCoverageAndVariantFrequencyOutputPath(outFile);
            CanvasSegment.WriteCoveragePlotData(this.Segments, Model.DiploidCoverage, ploidy, coverageOutputPath, referenceFolder);

            if (this.CNOracle != null)
            {
                this.GenerateReportVersusKnownCN();
            }

            if (ploidy != null && !string.IsNullOrEmpty(ploidy.HeaderLine)) extraHeaders.Add(ploidy.HeaderLine);
            CanvasSegment.WriteSegments(outFile, this.Segments, referenceFolder, sampleName, extraHeaders, ploidy);
            return 0;
        }

Usage Example

Пример #1
0
        static int Main(string[] args)
        {
            CanvasCommon.Utilities.LogCommandLine(args);
            string inFile  = null;
            string outFile = null;
            string variantFrequencyFile = null;
            string ploidyBedPath        = null;
            string referenceFolder      = null;
            string sampleName           = "SAMPLE";
            bool   needHelp             = false;
            string truthDataPath        = null;

            string qualityScoreConfigPath = Path.Combine(Utilities.GetAssemblyFolder(typeof(Program)), "QualityScoreParameters.json");

            var p = new OptionSet()
            {
                { "i|infile=", "file containing bins, their counts, and assigned segments (obtained from CanvasPartition.exe)", v => inFile = v },
                { "v|varfile=", "file containing variant frequencies (obtained from CanvasSNV.exe)", v => variantFrequencyFile = v },
                { "o|outfile=", "file name prefix to ouput copy number calls to outfile.vcf", v => outFile = v },
                { "r|reference=", "reference genome folder that contains GenomeSize.xml", v => referenceFolder = v },
                { "n|sampleName=", "sample name for output VCF header (optional)", v => sampleName = v },
                { "p|ploidyBed=", "bed file specifying reference ploidy (e.g. for sex chromosomes) (optional)", v => ploidyBedPath = v },
                { "d|dbsnpvcf", "flag indicating a dbSNP VCF file is used to generate the variant frequency file (Obsolete)", v => { } },
                { "h|help", "show this message and exit", v => needHelp = v != null },
                { "s|qscoreconfig=", $"parameter configuration path (default {qualityScoreConfigPath})", v => qualityScoreConfigPath = v },
                { "t|truth=", "path to vcf/bed with CNV truth data (optional)", v => truthDataPath = v },
            };

            List <string> extraArgs = p.Parse(args);

            if (extraArgs.Count > 0)
            {
                Console.WriteLine("* Error: I don't understand the argument '{0}'", extraArgs[0]);
                needHelp = true;
            }
            if (needHelp)
            {
                ShowHelp(p);
                return(0);
            }

            if (inFile == null || outFile == null || string.IsNullOrEmpty(variantFrequencyFile) || string.IsNullOrEmpty(referenceFolder))
            {
                ShowHelp(p);
                return(0);
            }

            if (!File.Exists(inFile))
            {
                Console.WriteLine("CanvasDiploidCaller.exe: File {0} does not exist! Exiting.", inFile);
                return(1);
            }

            if (!File.Exists(variantFrequencyFile))
            {
                Console.WriteLine("Canvas error: File {0} does not exist! Exiting.", variantFrequencyFile);
                return(1);
            }

            if (!File.Exists(Path.Combine(referenceFolder, "GenomeSize.xml")))
            {
                Console.WriteLine("CanvasDiploidCaller.exe: File {0} does not exist! Exiting.", Path.Combine(referenceFolder, "GenomeSize.xml"));
                return(1);
            }

            FileLocation qscoreConfigFile = new FileLocation(qualityScoreConfigPath);

            CanvasCommon.QualityScoreParameters qscoreParametersJson = Deserialize <CanvasCommon.QualityScoreParameters>(qscoreConfigFile);

            // Set parameters:
            var logger = new Logger(new[] { Console.Out }, new[] { Console.Error });
            CanvasDiploidCaller caller = new CanvasDiploidCaller(logger, qscoreParametersJson);

            return(caller.CallVariants(variantFrequencyFile, inFile, outFile, ploidyBedPath, referenceFolder, sampleName, truthDataPath));
        }
All Usage Examples Of CanvasDiploidCaller.CanvasDiploidCaller::CallVariants