public void Gene_in_gene_annotation_database_get_annotated()
        {
            var annotatedGene = new AnnotatedGene("A2M",
                                                  new IGeneAnnotationSource[] { new GeneAnnotationSource("omim", new[] { "{\"mimNumber\":103950,\"description\":\"Alpha-2-macroglobulin\",\"phenotypes\":[{\"mimNumber\":614036,\"phenotype\":\"Alpha-2-macroglobulin deficiency\",\"mapping\":\"mapping of the wildtype gene\",\"inheritances\":[\"Autosomal dominant\"]}", "{\"mimNumber\":104300,\"phenotype\":\"Alzheimer disease, susceptibility to\",\"mapping\":\"molecular basis of the disorder is known\",\"inheritances\":[\"Autosomal dominant\"],\"comments\":\"contribute to susceptibility to multifactorial disorders or to susceptibility to infection\"}]}" }, true) });

            var ms     = new MemoryStream();
            var header = new SupplementaryAnnotationHeader("", DateTime.Now.Ticks, 1, new IDataSourceVersion[] { }, GenomeAssembly.Unknown);

            using (var writer = new GeneDatabaseWriter(ms, header, true))
            {
                writer.Write(annotatedGene);
            }

            ms.Position = 0;
            var reader = new GeneDatabaseReader(ms);

            var geneAnnotationProvider = new GeneAnnotationProvider(reader);

            var observedAnnotation  = geneAnnotationProvider.Annotate("A2M");
            var observedAnnotation2 = geneAnnotationProvider.Annotate("A2M2L");

            Assert.NotNull(observedAnnotation);
            Assert.Null(observedAnnotation2);
            Assert.Single(observedAnnotation.Annotations);
            Assert.Equal("omim", observedAnnotation.Annotations[0].DataSource);
        }
Exemplo n.º 2
0
        private void Flush()
        {
            var nullGene = AnnotatedGene.CreateEmptyGene();

            nullGene.Write(_writer);
            _stream.Flush();
        }
Exemplo n.º 3
0
        public void SerializeJson()
        {
            var geneAnnotation1 = new Mock <IGeneAnnotationSource>();
            var geneAnnotation2 = new Mock <IGeneAnnotationSource>();
            var geneAnnotations = new [] { geneAnnotation1.Object, geneAnnotation2.Object };

            geneAnnotation1.SetupGet(x => x.DataSource).Returns("annotation1");
            geneAnnotation1.Setup(x => x.JsonStrings).Returns(new[]
            {
                "{\"mimNumber\":603024,\"description\":\"AT rich interactive domain 1A, SWI-like\",\"phenotypes\":[{\"mimNumber\":614607,\"phenotype\":\"Coffin-Siris syndrome 2\",\"mapping\":\"molecular basis of the disorder is known\",\"inheritances\":[\"Autosomal dominant\"]}]}",
                "{\"mimNumber\":300531,\"description\":\"Sprouty, Drosophila, homolog of, 3\"}"
            });
            geneAnnotation1.SetupGet(x => x.IsArray).Returns(true);

            geneAnnotation2.SetupGet(x => x.DataSource).Returns("annotation2");
            geneAnnotation2.Setup(x => x.JsonStrings).Returns(new[] { "0.154" });
            geneAnnotation2.SetupGet(x => x.IsArray).Returns(false);


            var annotatedGene = new AnnotatedGene("Gene1", geneAnnotations);

            const string expectedLine = "{\"name\":\"Gene1\",\"annotation1\":[{\"mimNumber\":603024,\"description\":\"AT rich interactive domain 1A, SWI-like\",\"phenotypes\":[{\"mimNumber\":614607,\"phenotype\":\"Coffin-Siris syndrome 2\",\"mapping\":\"molecular basis of the disorder is known\",\"inheritances\":[\"Autosomal dominant\"]}]},{\"mimNumber\":300531,\"description\":\"Sprouty, Drosophila, homolog of, 3\"}],\"annotation2\":0.154}";

            var sb = StringBuilderCache.Acquire();

            annotatedGene.SerializeJson(sb);
            Assert.Equal(expectedLine, StringBuilderCache.GetStringAndRelease(sb));
        }
Exemplo n.º 4
0
        private static IEnumerable <IAnnotatedGene> GetAnnotatedGenes(IReadOnlyList <GeneTsvReader> geneReaders)
        {
            if (geneReaders == null)
            {
                return(null);
            }

            var geneAnnotations = new Dictionary <string, IAnnotatedGene>();

            foreach (var reader in geneReaders)
            {
                foreach (var annotatedGene in reader.GetItems() ?? Enumerable.Empty <IAnnotatedGene>())
                {
                    var geneName = annotatedGene.GeneName;
                    if (!geneAnnotations.TryAdd(geneName, annotatedGene))
                    {
                        geneAnnotations[geneName] = new AnnotatedGene(geneName, geneAnnotations[geneName].Annotations.Concat(annotatedGene.Annotations).ToArray());
                    }
                }
            }

            return(geneAnnotations.Values);
        }