Esempio n. 1
0
        public AnnotationResources(string refSequencePath, string inputCachePrefix, List <string> saDirectoryPaths, List <SaUrls> customAnnotations, string pluginDirectory, bool disableRecomposition, bool forceMitochondrialAnnotation)
        {
            SequenceProvider = ProviderUtilities.GetSequenceProvider(refSequencePath);

            var annotationFiles = new AnnotationFiles();

            saDirectoryPaths?.ForEach(x => annotationFiles.AddFiles(x));
            customAnnotations?.ForEach(x => annotationFiles.AddFiles(x));

            TranscriptAnnotationProvider = ProviderUtilities.GetTranscriptAnnotationProvider(inputCachePrefix, SequenceProvider);
            SaProvider             = ProviderUtilities.GetNsaProvider(annotationFiles);
            ConservationProvider   = ProviderUtilities.GetConservationProvider(annotationFiles);
            RefMinorProvider       = ProviderUtilities.GetRefMinorProvider(annotationFiles);
            GeneAnnotationProvider = ProviderUtilities.GetGeneAnnotationProvider(annotationFiles);
            Plugins = PluginUtilities.LoadPlugins(pluginDirectory);

            Annotator = ProviderUtilities.GetAnnotator(TranscriptAnnotationProvider, SequenceProvider, SaProvider,
                                                       ConservationProvider, GeneAnnotationProvider, Plugins);

            Recomposer = disableRecomposition
                ? new NullRecomposer()
                : Phantom.Recomposer.Recomposer.Create(SequenceProvider, TranscriptAnnotationProvider);
            DataSourceVersions = GetDataSourceVersions(Plugins, TranscriptAnnotationProvider, SaProvider,
                                                       GeneAnnotationProvider, ConservationProvider).ToList();
            VepDataVersion = TranscriptAnnotationProvider.VepVersion + "." + CacheConstants.DataVersion + "." +
                             SaCommon.DataVersion;

            ForceMitochondrialAnnotation = forceMitochondrialAnnotation;
        }
Esempio n. 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);
        }