Exemplo n.º 1
0
        public AnnotationResources(string refSequencePath, string inputCachePrefix, List <string> saDirectoryPaths, List <SaUrls> customAnnotations,
                                   string customStrTsvPath, bool disableRecomposition, bool forceMitochondrialAnnotation, bool useLegacyVids, PerformanceMetrics metrics)
        {
            Metrics = metrics;
            PerformanceMetrics.ShowInitializationHeader();

            SequenceProvider = ProviderUtilities.GetSequenceProvider(refSequencePath);

            var annotationFiles = new AnnotationFiles();

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

            ProteinConservationProvider = ProviderUtilities.GetProteinConservationProvider(annotationFiles);
            ProteinConservationProvider?.Load();

            metrics.Cache.Start();
            TranscriptAnnotationProvider = ProviderUtilities.GetTranscriptAnnotationProvider(inputCachePrefix, SequenceProvider, ProteinConservationProvider);
            metrics.ShowCacheLoad();

            SaProvider             = ProviderUtilities.GetNsaProvider(annotationFiles);
            ConservationProvider   = ProviderUtilities.GetConservationProvider(annotationFiles);
            LcrProvider            = ProviderUtilities.GetLcrProvider(annotationFiles);
            RefMinorProvider       = ProviderUtilities.GetRefMinorProvider(annotationFiles);
            GeneAnnotationProvider = ProviderUtilities.GetGeneAnnotationProvider(annotationFiles);

            IRepeatExpansionProvider repeatExpansionProvider = GetRepeatExpansionProvider(SequenceProvider.Assembly,
                                                                                          SequenceProvider.RefNameToChromosome, SequenceProvider.RefIndexToChromosome.Count, customStrTsvPath);

            MitoHeteroplasmyProvider = MitoHeteroplasmyReader.GetProvider();

            Annotator = new Annotator(TranscriptAnnotationProvider, SequenceProvider, SaProvider, ConservationProvider, LcrProvider, GeneAnnotationProvider,
                                      repeatExpansionProvider);

            if (useLegacyVids)
            {
                VidCreator = new LegacyVariantId(SequenceProvider.RefNameToChromosome);
            }
            else
            {
                VidCreator = new VariantId();
            }

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

            ForceMitochondrialAnnotation = forceMitochondrialAnnotation;
        }
Exemplo n.º 2
0
        public static ExitCodes Annotate(Stream headerStream, Stream inputVcfStream, Stream outputJsonStream,
                                         Stream outputJsonIndexStream, AnnotationResources annotationResources, IVcfFilter vcfFilter,
                                         bool ignoreEmptyChromosome)
        {
            var metrics = annotationResources.Metrics;

            PerformanceMetrics.ShowAnnotationHeader();

            IChromosome currentChromosome = new EmptyChromosome("dummy");
            int         numVariants       = 0;
            IMitoHeteroplasmyProvider mitoHeteroplasmyProvider = MitoHeteroplasmyReader.GetProvider();

            using (var vcfReader = GetVcfReader(headerStream, inputVcfStream, annotationResources, vcfFilter, mitoHeteroplasmyProvider))
                using (var jsonWriter = new JsonWriter(outputJsonStream, outputJsonIndexStream, annotationResources, Date.CurrentTimeStamp, vcfReader.GetSampleNames(), false))
                {
                    try
                    {
                        CheckGenomeAssembly(annotationResources, vcfReader);
                        SetMitochondrialAnnotationBehavior(annotationResources, vcfReader);

                        IPosition position;

                        while ((position = vcfReader.GetNextPosition()) != null)
                        {
                            IChromosome chromosome = position.Chromosome;
                            if (ignoreEmptyChromosome && chromosome.IsEmpty())
                            {
                                continue;
                            }

                            if (chromosome.Index != currentChromosome.Index)
                            {
                                if (!currentChromosome.IsEmpty())
                                {
                                    metrics.ShowAnnotationEntry(currentChromosome, numVariants);
                                }

                                numVariants = 0;

                                metrics.Preload.Start();
                                annotationResources.PreLoad(chromosome);
                                metrics.Preload.Stop();

                                metrics.Annotation.Start();
                                currentChromosome = chromosome;
                            }

                            var annotatedPosition = position.Variants != null?annotationResources.Annotator.Annotate(position) : null;

                            string json = annotatedPosition?.GetJsonString();
                            if (json != null)
                            {
                                jsonWriter.WritePosition(annotatedPosition.Position, json);
                            }

                            numVariants++;
                        }

                        jsonWriter.WriteGenes(annotationResources.Annotator.GetGeneAnnotations());
                    }
                    catch (Exception e)
                    {
                        e.Data[ExitCodeUtilities.VcfLine] = vcfReader.VcfLine;
                        throw;
                    }
                }

            if (!currentChromosome.IsEmpty())
            {
                metrics.ShowAnnotationEntry(currentChromosome, numVariants);
            }

            metrics.ShowSummaryTable();

            return(ExitCodes.Success);
        }