Exemplo n.º 1
0
        }                                                         // used to find overlap genes for now

        public PositionBuffer(ICodonInfoProvider codonInfoProvider, IIntervalForest <IGene> geneIntervalForest)
        {
            CodonInfoProvider  = codonInfoProvider;
            GeneIntervalForest = geneIntervalForest;
            CurrentChromosome  = new EmptyChromosome(string.Empty);
            BufferedPositions  = BufferedPositions.CreatEmptyBufferedPositions();
        }
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);
        }