private CanvasOutput RunSingleSample(string sampleId, CanvasResequencingInput input, IDirectoryLocation sampleSandbox)
        {
            if (!_annotationFileProvider.IsSupported(input.GenomeMetadata))
            {
                _logger.Info($"Skipping Canvas for sample {sampleId}: unsupported reference genome '{input.GenomeMetadata.Name}'");
                return(null);
            }

            if (!_annotationFileProvider.CustomDbSnpVcf(input.GenomeMetadata) && input.Vcf == null)
            {
                _logger.Info($"Skipping Canvas for sample {sampleId}. A dbSNP VCF file was not provided and no small variant VCF file is available");
                return(null);
            }

            StringBuilder commandLine = new StringBuilder("Germline-WGS");

            commandLine.Append(_singleSampleInputCommandLineBuilder.GetSingleSampleCommandLine(sampleId, input.Bam, input.GenomeMetadata, sampleSandbox));

            // use sample vcf by default (performance could be similar with dbSNP vcf though)
            var bAlleleVcf           = input.Vcf.VcfFile;
            var bAlleleVcfOptionName = SingleSampleCommonOptionsParser.SampleBAlleleVcfOptionName;

            if (_annotationFileProvider.CustomDbSnpVcf(input.GenomeMetadata))
            {
                bAlleleVcf           = _annotationFileProvider.GetDbSnpVcf(input.GenomeMetadata);
                bAlleleVcfOptionName = SingleSampleCommonOptionsParser.PopulationBAlleleVcfOptionName;
            }
            commandLine.Append($" --{bAlleleVcfOptionName} \"{bAlleleVcf}\"");


            IFileLocation ploidyBed = _canvasPloidyBedCreator.CreateGermlinePloidyBed(input.Vcf, input.GenomeMetadata, sampleSandbox);

            if (ploidyBed != null)
            {
                commandLine.Append($" --{SingleSampleCommonOptionsParser.PloidyBedOptionName} \"{ploidyBed}\"");
            }
            var canvasPartitionParam = $@"--commoncnvs {_annotationFileProvider.GetCanvasAnnotationFile(input.GenomeMetadata, "commoncnvs.bed")}";
            var moreCustomParameters = new Dictionary <string, string>();

            moreCustomParameters["CanvasPartition"] = canvasPartitionParam;
            commandLine.Append(_singleSampleInputCommandLineBuilder.GetCustomParameters(moreCustomParameters));
            commandLine = _singleSampleInputCommandLineBuilder.MergeCustomCanvasParameters(commandLine);

            UnitOfWork singleSampleJob = new UnitOfWork()
            {
                ExecutablePath = CrossPlatform.IsThisLinux() ? _runtimeExecutable.FullName : _canvasExe.FullName,
                CommandLine    = CrossPlatform.IsThisLinux() ? _canvasExe + " " + commandLine : commandLine.ToString(),
                LoggingFolder  = _workManager.LoggingFolder.FullName,
                LoggingStub    = "Canvas_" + sampleId,
            };

            _workManager.DoWorkSingleThread(singleSampleJob);
            return(GetCanvasOutput(sampleId, sampleSandbox));
        }
Пример #2
0
        private CanvasOutput RunSingleSample(string sampleId, CanvasTumorNormalEnrichmentInput input, IFileLocation bAlleleVcf, bool isDbSnpVcf, IFileLocation manifest, IDirectoryLocation sampleSandbox)
        {
            if (!_annotationFileProvider.IsSupported(input.GenomeMetadata))
            {
                _logger.Info($"Skipping Canvas for sample {sampleId}: unsupported reference genome '{input.GenomeMetadata.Name}'");
                return(null);
            }

            StringBuilder commandLine = new StringBuilder("Tumor-normal-enrichment");

            commandLine.Append(_singleSampleInputCommandLineBuilder.GetSingleSampleCommandLine(sampleId, input.TumorBam, input.GenomeMetadata, sampleSandbox));
            commandLine.Append($" --normal-bam \"{input.NormalBam.BamFile}\"");
            commandLine.Append($" --manifest \"{manifest}\"");
            var bAlleleVcfOptionName = isDbSnpVcf ?
                                       SingleSampleCommonOptionsParser.PopulationBAlleleVcfOptionName :
                                       SingleSampleCommonOptionsParser.SampleBAlleleVcfOptionName;

            commandLine.Append($" --{bAlleleVcfOptionName} {bAlleleVcf.WrapWithShellQuote()}");

            commandLine.Append($" --somatic-vcf \"{input.SomaticVcf.VcfFile}\"");

            IFileLocation ploidyBed = _canvasPloidyBedCreator.CreatePloidyBed(input.NormalVcf, input.GenomeMetadata, sampleSandbox);

            if (ploidyBed != null)
            {
                commandLine.Append($" --{SingleSampleCommonOptionsParser.PloidyBedOptionName} \"{ploidyBed}\"");
            }
            commandLine.Append(_singleSampleInputCommandLineBuilder.GetCustomParameters());
            commandLine = _singleSampleInputCommandLineBuilder.MergeCustomCanvasParameters(commandLine);
            UnitOfWork singleSampleJob = new UnitOfWork
            {
                ExecutablePath = CrossPlatform.IsThisLinux() ? _runtimeExecutable.FullName : _canvasExe.FullName,
                CommandLine    = CrossPlatform.IsThisLinux() ? _canvasExe + " " + commandLine : commandLine.ToString(),
                LoggingFolder  = _workManager.LoggingFolder.FullName,
                LoggingStub    = "Canvas_" + sampleId,
            };

            _workManager.DoWorkSingleThread(singleSampleJob);
            return(GetCanvasOutput(sampleId, sampleSandbox));
        }
        public CanvasSmallPedigreeOutput Run(CanvasSmallPedigreeInput input, IDirectoryLocation sampleSandbox)
        {
            if (!_annotationFileProvider.IsSupported(input.GenomeMetadata))
            {
                _logger.Info($"Skipping Canvas: unsupported reference genome '{input.GenomeMetadata.Name}'");
                return(null);
            }

            if (!_annotationFileProvider.CustomDbSnpVcf(input.GenomeMetadata) && input.Vcf == null)
            {
                _logger.Info($"Skipping Canvas. A dbSNP VCF file was not provided and no small variant VCF file is available");
                return(null);
            }

            var commandLine = new StringBuilder("SmallPedigree-WGS");

            commandLine.Append(GetMultiSampleCommandLine(input.Samples, input.GenomeMetadata, input.Vcf, sampleSandbox));

            // use sample vcf by default (performance could be similar with dbSNP vcf though)
            var bAlleleVcf           = input.Vcf.VcfFile;
            var bAlleleVcfOptionName = SingleSampleCommonOptionsParser.SampleBAlleleVcfOptionName;

            if (_annotationFileProvider.CustomDbSnpVcf(input.GenomeMetadata))
            {
                bAlleleVcf           = _annotationFileProvider.GetDbSnpVcf(input.GenomeMetadata);
                bAlleleVcfOptionName = SingleSampleCommonOptionsParser.PopulationBAlleleVcfOptionName;
            }
            commandLine.Append($" --{bAlleleVcfOptionName} \"{bAlleleVcf}\"");

            var ploidyInfos = input.Samples.SelectData(sample => sample.PloidyInfo);

            var ploidyVcf = _canvasPloidyVcfCreator.CreatePloidyVcf(ploidyInfos, input.GenomeMetadata, sampleSandbox);

            if (ploidyVcf != null)
            {
                commandLine.Append($" --{SmallPedigreeOptionsParser.PloidyVcfOptionName} \"{ploidyVcf.VcfFile}\"");
            }
            var canvasPartitionParam = $@"--commoncnvs {_annotationFileProvider.GetCanvasAnnotationFile(input.GenomeMetadata, "commoncnvs.bed")}";

            var moreCustomParameters = new Dictionary <string, string> {
                ["CanvasPartition"] = canvasPartitionParam
            };

            commandLine.Append(_singleSampleInputCommandLineBuilder.GetCustomParameters(moreCustomParameters));
            commandLine = _singleSampleInputCommandLineBuilder.MergeCustomCanvasParameters(commandLine);
            // use Proband or, when proband is not available, first sample as pedigree id
            var pedigreeId = input.Samples.Where(x => x.Value.SampleType == SampleType.Proband).Select(x => x.Key.Id).FirstOrDefault();

            if (pedigreeId.IsNullOrEmpty())
            {
                pedigreeId = input.Samples.First().Key.Id;
            }

            var singleSampleJob = new UnitOfWork()
            {
                ExecutablePath = CrossPlatform.IsThisLinux() ? _runtimeExecutable.FullName : _canvasExe.FullName,
                CommandLine    = CrossPlatform.IsThisLinux() ? _canvasExe + " " + commandLine : commandLine.ToString(),
                LoggingFolder  = _workManager.LoggingFolder.FullName,
                LoggingStub    = "Canvas_" + pedigreeId,
            };

            _workManager.DoWorkSingleThread(singleSampleJob);
            var sampleBams = input.Samples.SelectData(sample => sample.Bam);

            return(GetCanvasOutput(sampleBams, sampleSandbox));
        }
        private CanvasEnrichmentOutput RunSingleSample(string sampleId, CanvasEnrichmentInput input, IFileLocation dbSnpVcf, IFileLocation manifest, IDirectoryLocation sampleSandbox)
        {
            if (!_annotationFileProvider.IsSupported(input.GenomeMetadata))
            {
                _logger.Info($"Skipping Canvas for sample {sampleId}: unsupported reference genome '{input.GenomeMetadata.Name}'");
                return(null);
            }

            var           moreCustomParameters = new Dictionary <string, string>();
            StringBuilder commandLine          = new StringBuilder("Somatic-Enrichment");

            commandLine.Append(_singleSampleInputCommandLineBuilder.GetSingleSampleCommandLine(sampleId, input.Bam, input.GenomeMetadata, sampleSandbox));

            string sexChromosomeKaryotype = null;

            if (input.PloidyInfo.IsPloidyAvailable)
            {
                sexChromosomeKaryotype = input.PloidyInfo.IsXYMale.Value ? PloidyCorrector.PrettyPrintPloidy(1, 1)
                    : (input.PloidyInfo.IsXXFemale.Value ? PloidyCorrector.PrettyPrintPloidy(2, 0) : null);
            }
            string controlSexChromosomeKaryotype = null;

            if (input.IsCanvasNormalizePcaMode && input.PloidyInfo.IsPloidyAvailable)
            {
                IFileLocation pcaModelFile = input.PloidyInfo.IsXYMale.Value ? input.PcaModels.MaleModelFile
                    : (input.PloidyInfo.IsXXFemale.Value ? input.PcaModels.FemaleModelFile : null);
                if (pcaModelFile == null)
                {
                    string sampleSex = input.PloidyInfo.IsXYMale.Value ? "male"
                        : (input.PloidyInfo.IsXXFemale.Value ? "female" : "sex unknown");
                    _logger.Info($"Skipping Canvas for sample {sampleId}: PCA model file not available for {sampleSex} samples.");
                    return(null);
                }
                moreCustomParameters["CanvasNormalize"] = "-m PCA";
                commandLine.Append($" --control-binned \"{pcaModelFile}\"");
                commandLine.Append($" --control-bin-size 100"); // use a dummy bin size for now
                controlSexChromosomeKaryotype = sexChromosomeKaryotype;
            }
            else if (input.PrecomputedControl?.BinnedPath != null)
            {
                commandLine.Append($" --control-binned \"{input.PrecomputedControl.BinnedPath}\"");
                commandLine.Append($" --control-bin-size {input.PrecomputedControl.BinSize}");
                controlSexChromosomeKaryotype = input.PrecomputedControl.SexChromosomeKaryotype;
            }
            else
            {
                foreach (var normalBam in input.NormalBamPaths)
                {
                    commandLine.Append($" --control-bam \"{normalBam.BamFile}\"");
                }
            }
            if (controlSexChromosomeKaryotype != null)
            {
                var controlPloidyBed = sampleSandbox.GetFileLocation("control-ploidy.bed.gz");
                if (_canvasPloidyBedCreator.GeneratePloidyBedFileFromSexChromosomeKaryotype(input.GenomeMetadata, input.GenomeMetadata.Sequences.First().FastaPath,
                                                                                            controlSexChromosomeKaryotype, controlPloidyBed.FullName, sampleSandbox.FullName))
                {
                    commandLine.Append($" --{SomaticEnrichmentOptionsParser.ControlPloidyBedOptionName} \"{controlPloidyBed}\"");
                }
            }
            commandLine.Append($" --{SingleSampleCommonOptionsParser.PopulationBAlleleVcfOptionName} \"{dbSnpVcf}\"");
            commandLine.Append($" --manifest \"{manifest}\"");

            if (sexChromosomeKaryotype != null)
            {
                var ploidyBed = sampleSandbox.GetFileLocation("ploidy.bed.gz");
                if (_canvasPloidyBedCreator.GeneratePloidyBedFileFromSexChromosomeKaryotype(input.GenomeMetadata, input.GenomeMetadata.Sequences.First().FastaPath,
                                                                                            sexChromosomeKaryotype, ploidyBed.FullName, sampleSandbox.FullName))
                {
                    commandLine.Append($" --{SingleSampleCommonOptionsParser.PloidyBedOptionName} \"{ploidyBed}\"");
                }
            }

            if (input.PredefinedBinsFile != null)
            {
                moreCustomParameters["CanvasBin"] = $"-n={input.PredefinedBinsFile.WrapWithEscapedShellQuote()}";
            }
            commandLine.Append(_singleSampleInputCommandLineBuilder.GetCustomParameters(moreCustomParameters));
            commandLine = _singleSampleInputCommandLineBuilder.MergeCustomCanvasParameters(commandLine);

            UnitOfWork singleSampleJob = new UnitOfWork()
            {
                ExecutablePath = CrossPlatform.IsThisLinux() ? _runtimeExecutable.FullName : _canvasExe.FullName,
                CommandLine    = CrossPlatform.IsThisLinux() ? _canvasExe + " " + commandLine : commandLine.ToString(),
                LoggingFolder  = _workManager.LoggingFolder.FullName,
                LoggingStub    = "Canvas_" + sampleId,
            };

            _workManager.DoWorkSingleThread(singleSampleJob);
            return(GetCanvasOutput(sampleId, sampleSandbox));
        }
Пример #5
0
        private int GetBinSize(CanvasCallset callset, string bamPath, List <string> intermediateDataPaths,
                               string canvasReferencePath, string canvasBedPath)
        {
            string canvasBinPath  = Path.Combine(_canvasFolder, "CanvasBin.exe");
            string executablePath = canvasBinPath;

            if (CrossPlatform.IsThisMono())
            {
                executablePath = Utilities.GetMonoPath();
            }

            StringBuilder commandLine = new StringBuilder();

            if (CrossPlatform.IsThisMono())
            {
                commandLine.AppendFormat("{0} ", canvasBinPath);
            }
            commandLine.AppendFormat("-b \"{0}\" ", bamPath);
            commandLine.AppendFormat("-p "); // Paired-end input mode (Isaac or BWA output)
            commandLine.AppendFormat("-r \"{0}\" ", canvasReferencePath);

            foreach (string path in intermediateDataPaths)
            {
                commandLine.AppendFormat("-i \"{0}\" ", path);
            }

            commandLine.AppendFormat("-y "); // bin size only

            if (callset.IsEnrichment)        // manifest
            {
                if (!File.Exists(callset.TempManifestPath))
                {
                    NexteraManifestUtils.WriteNexteraManifests(callset.Manifest, callset.TempManifestPath);
                }
                commandLine.AppendFormat("-t \"{0}\" ", callset.TempManifestPath);
            }

            string outputStub = Path.Combine(Path.GetDirectoryName(callset.BinSizePath), Path.GetFileNameWithoutExtension(callset.BinSizePath));

            commandLine.AppendFormat("-f \"{0}\" -d {1} -o \"{2}\"", canvasBedPath, _countsPerBin, outputStub);

            UnitOfWork binJob = new UnitOfWork()
            {
                ExecutablePath = executablePath,
                LoggingFolder  = _workManager.LoggingFolder.FullName,
                LoggingStub    = Path.GetFileNameWithoutExtension(callset.BinSizePath),
                CommandLine    = commandLine.ToString()
            };

            if (_customParameters.ContainsKey("CanvasBin"))
            {
                binJob.CommandLine = Utilities.MergeCommandLineOptions(binJob.CommandLine, _customParameters["CanvasBin"], true);
            }
            _workManager.DoWorkSingleThread(binJob);

            int binSize;

            using (StreamReader reader = new StreamReader(callset.BinSizePath))
            {
                binSize = int.Parse(reader.ReadLine());
            }

            return(binSize);
        }