Exemple #1
0
        protected override void ProgramExecution()
        {
            if (!Console.IsOutputRedirected)
            {
                Console.WriteLine("Running Nirvana on {0}:", GetFileName());
            }

            var outputVcfPath      = ConfigurationSettings.OutputFileName + ".vcf.gz";
            var outputGvcfPath     = ConfigurationSettings.OutputFileName + ".genome.vcf.gz";
            var outputVariantsPath = ConfigurationSettings.OutputFileName + ".json.gz";

            using (var reader = GetVcfReader())
            {
                var booleanArguments = SetAnnotationFlags(reader.IsRcrsMitochondrion);
                var annotator        = GetAnnotator(reader.SampleNames, booleanArguments);

                if (annotator == null)
                {
                    throw new InvalidOperationException("Unable to perform annotation because no annotation sources could be created");
                }

                using (var jsonStreamWriter = GetJsonStreamWriter(outputVariantsPath))
                    using (var jsonWriter = GetJsonWriter(jsonStreamWriter, Date.GetTimeStamp, annotator, reader))
                        using (var vcfWriter = ConfigurationSettings.Vcf  ? new LiteVcfWriter(outputVcfPath, reader.HeaderLines, annotator.GetDataVersion(), annotator.GetDataSourceVersions())  : null)
                            using (var gvcfWriter = ConfigurationSettings.Gvcf ? new LiteVcfWriter(outputGvcfPath, reader.HeaderLines, annotator.GetDataVersion(), annotator.GetDataSourceVersions()) : null)
                            {
                                string vcfLine = null;
                                var    checker = new SortedVcfChecker();

                                try
                                {
                                    while (true)
                                    {
                                        vcfLine = reader.ReadLine();
                                        if (vcfLine == null)
                                        {
                                            break;
                                        }

                                        var fields = vcfLine.Split('\t');
                                        if (fields.Length < VcfCommon.MinNumColumns)
                                        {
                                            continue;
                                        }

                                        var variant = new VcfVariant(fields, vcfLine, reader.IsGatkGenomeVcf);
                                        checker.CheckVcfOrder(variant.ReferenceName);

                                        var annotatedVariant = annotator.Annotate(variant);

                                        var vcfOutput = GetVcfString(variant, annotatedVariant);
                                        WriteOutput(vcfOutput, annotatedVariant, vcfWriter, gvcfWriter, jsonWriter);
                                    }

                                    WriteOmim(annotator, jsonWriter);
                                }
                                catch (Exception e)
                                {
                                    // embed the vcf line
                                    e.Data["VcfLine"] = vcfLine;
                                    throw;
                                }
                            }

                annotator.FinalizeMetrics();
            }
        }
Exemple #2
0
        private ExitCodes ProgramExecution()
        {
            var sequenceProvider             = ProviderUtilities.GetSequenceProvider(_refSequencePath);
            var transcriptAnnotationProvider = ProviderUtilities.GetTranscriptAnnotationProvider(_inputCachePrefix, sequenceProvider);
            var saProvider             = ProviderUtilities.GetSaProvider(SupplementaryAnnotationDirectories);
            var conservationProvider   = ProviderUtilities.GetConservationProvider(SupplementaryAnnotationDirectories);
            var refMinorProvider       = ProviderUtilities.GetRefMinorProvider(SupplementaryAnnotationDirectories);
            var geneAnnotationProvider = ProviderUtilities.GetGeneAnnotationProvider(SupplementaryAnnotationDirectories);
            var plugins    = PluginUtilities.LoadPlugins(_pluginDirectory);
            var annotator  = ProviderUtilities.GetAnnotator(transcriptAnnotationProvider, sequenceProvider, saProvider, conservationProvider, geneAnnotationProvider, plugins);
            var recomposer = _disableRecomposition ? new NullRecomposer() : Recomposer.Create(sequenceProvider, _inputCachePrefix);
            var logger     = _outputFileName == "-" ? (ILogger) new NullLogger() : new ConsoleLogger();
            var metrics    = new PerformanceMetrics(logger);

            var dataSourceVersions = GetDataSourceVersions(plugins, transcriptAnnotationProvider, saProvider,
                                                           geneAnnotationProvider, conservationProvider);

            var vepDataVersion = transcriptAnnotationProvider.VepVersion + "." + CacheConstants.DataVersion + "." + SaDataBaseCommon.DataVersion;
            var jasixFileName  = _outputFileName + ".json.gz" + JasixCommons.FileExt;

            using (var outputWriter = ReadWriteUtilities.GetOutputWriter(_outputFileName))
                using (var vcfReader = ReadWriteUtilities.GetVcfReader(_vcfPath, sequenceProvider.RefNameToChromosome, refMinorProvider, _reportAllSvOverlappingTranscripts, recomposer))
                    using (var jsonWriter = new JsonWriter(outputWriter, _annotatorVersionTag, Date.CurrentTimeStamp, vepDataVersion, dataSourceVersions, sequenceProvider.GenomeAssembly.ToString(), vcfReader.GetSampleNames()))
                        using (var vcfWriter = _vcf ? new LiteVcfWriter(ReadWriteUtilities.GetVcfOutputWriter(_outputFileName), vcfReader.GetHeaderLines(), _annotatorVersionTag, vepDataVersion, dataSourceVersions) : null)
                            using (var gvcfWriter = _gvcf ? new LiteVcfWriter(ReadWriteUtilities.GetGvcfOutputWriter(_outputFileName), vcfReader.GetHeaderLines(), _annotatorVersionTag, vepDataVersion, dataSourceVersions) : null)
                                using (var jasixIndexCreator = new OnTheFlyIndexCreator(FileUtilities.GetCreateStream(jasixFileName)))
                                {
                                    if (!(outputWriter is BgzipTextWriter bgzipTextWriter))
                                    {
                                        throw new NullReferenceException("Unable to create the bgzip text writer.");
                                    }

                                    try
                                    {
                                        jasixIndexCreator.SetHeader(jsonWriter.Header);

                                        if (vcfReader.IsRcrsMitochondrion && annotator.GenomeAssembly == GenomeAssembly.GRCh37 ||
                                            annotator.GenomeAssembly == GenomeAssembly.GRCh38 ||
                                            _forceMitochondrialAnnotation)
                                        {
                                            annotator.EnableMitochondrialAnnotation();
                                        }

                                        int       previousChromIndex = -1;
                                        IPosition position;
                                        var       sortedVcfChecker = new SortedVcfChecker();

                                        while ((position = vcfReader.GetNextPosition()) != null)
                                        {
                                            sortedVcfChecker.CheckVcfOrder(position.Chromosome.UcscName);
                                            previousChromIndex = UpdatePerformanceMetrics(previousChromIndex, position.Chromosome, metrics);

                                            var annotatedPosition = annotator.Annotate(position);

                                            string json = annotatedPosition.GetJsonString();

                                            if (json != null)
                                            {
                                                WriteOutput(annotatedPosition, bgzipTextWriter.Position, jasixIndexCreator, jsonWriter, vcfWriter, gvcfWriter, json);
                                            }
                                            else
                                            {
                                                gvcfWriter?.Write(string.Join("\t", position.VcfFields));
                                            }

                                            metrics.Increment();
                                        }

                                        WriteGeneAnnotations(annotator.GetAnnotatedGenes(), jsonWriter);
                                    }
                                    catch (Exception e)
                                    {
                                        e.Data[ExitCodeUtilities.VcfLine] = vcfReader.VcfLine;
                                        throw;
                                    }
                                }

            metrics.ShowAnnotationTime();

            return(ExitCodes.Success);
        }