Esempio n. 1
0
        public void AddGroupedObjectValues_TwoTimes()
        {
            var sb   = StringBuilderCache.Acquire();
            var json = new JsonObject(sb);

            var descriptions  = new[] { "test1", "test2" };
            var descriptions2 = new[] { "test3" };

            var points = new Point[2];

            points[0] = new Point(1, 2);
            points[1] = new Point(3, 4);

            var points2 = new Point[1];

            points2[0] = new Point(5, 6);

            json.AddGroupedObjectValues("first", descriptions, points, points2);
            json.AddGroupedObjectValues("second", descriptions2, points2);

            const string expectedResult = "\"first\":{\"test1\":[{\"X\":1,\"Y\":2},{\"X\":3,\"Y\":4}],\"test2\":[{\"X\":5,\"Y\":6}]},\"second\":{\"test3\":[{\"X\":5,\"Y\":6}]}";
            var          observedResult = StringBuilderCache.GetStringAndRelease(sb);

            Assert.Equal(expectedResult, observedResult);
        }
Esempio n. 2
0
        public void AddGroupedObjectValues_MismatchedDescriptionCount()
        {
            Assert.Throws <ArgumentException>(delegate
            {
                var sb   = StringBuilderCache.Acquire();
                var json = new JsonObject(sb);

                var descriptions = new[] { "test1", "test2" };
                var points2      = new Point[1];
                points2[0]       = new Point(5, 6);

                json.AddGroupedObjectValues("second", descriptions, points2);
            });
        }
Esempio n. 3
0
        public void AddGroupedObjectValues_NullDescriptions()
        {
            var sb   = StringBuilderCache.Acquire();
            var json = new JsonObject(sb);

            var points2 = new Point[1];

            points2[0] = new Point(5, 6);

            json.AddGroupedObjectValues("second", null, points2);
            var observedResult = StringBuilderCache.GetStringAndRelease(sb);

            Assert.Equal(string.Empty, observedResult);
        }
Esempio n. 4
0
        public void AddGroupedObjectValues_OneNullGroup()
        {
            var sb   = StringBuilderCache.Acquire();
            var json = new JsonObject(sb);

            var descriptions = new[] { "test1", "test2" };
            var points2      = new Point[1];

            points2[0] = new Point(5, 6);

            json.AddGroupedObjectValues("second", descriptions, points2, null as Point[]);

            const string expectedResult = "\"second\":{\"test1\":[{\"X\":5,\"Y\":6}]}";
            var          observedResult = StringBuilderCache.GetStringAndRelease(sb);

            Assert.Equal(expectedResult, observedResult);
        }
Esempio n. 5
0
        public string GetJsonString(string originalChromName)
        {
            var sb         = StringBuilderCache.Acquire();
            var jsonObject = new JsonObject(sb);

            // data section
            sb.Append(JsonObject.OpenBrace);

            jsonObject.AddStringValue("vid", Variant.VariantId);
            jsonObject.AddStringValue("chromosome", originalChromName);
            jsonObject.AddIntValue("begin", Variant.Start);
            jsonObject.AddIntValue("end", Variant.End);
            jsonObject.AddBoolValue("isReferenceMinorAllele", Variant.IsRefMinor);

            if (!Variant.IsRefMinor)
            {
                jsonObject.AddStringValue("refAllele",
                                          string.IsNullOrEmpty(Variant.RefAllele) ? "-" : Variant.RefAllele);
                jsonObject.AddStringValue("altAllele",
                                          string.IsNullOrEmpty(Variant.AltAllele) ? "-" : Variant.AltAllele);
            }
            else
            {
                jsonObject.AddStringValue("refAllele",
                                          string.IsNullOrEmpty(Variant.AltAllele) ? "-" : Variant.AltAllele);
            }

            var variantType = GetVariantType(Variant.Type);

            jsonObject.AddStringValue("variantType", variantType.ToString());
            jsonObject.AddBoolValue("isDecomposedVariant", Variant.IsDecomposed);
            if (variantType.ToString() != "SNV")
            {
                jsonObject.AddBoolValue("isRecomposedVariant", Variant.IsRecomposed);
            }
            jsonObject.AddStringValue("hgvsg", HgvsgNotation);

            jsonObject.AddDoubleValue("phylopScore", PhylopScore);

            if (RegulatoryRegions?.Count > 0)
            {
                jsonObject.AddObjectValues("regulatoryRegions", RegulatoryRegions);
            }
            if (SupplementaryAnnotations.Count > 0)
            {
                AddSAstoJsonObject(jsonObject);
            }
            foreach (var pluginData in PluginDataSet)
            {
                jsonObject.AddStringValue(pluginData.Name, pluginData.GetJsonString(), false);
            }

            if (OverlappingGenes.Count > 0)
            {
                jsonObject.AddStringValues("overlappingGenes", OverlappingGenes);
            }
            if (OverlappingTranscripts.Count > 0)
            {
                jsonObject.AddObjectValues("overlappingTranscripts", OverlappingTranscripts);
            }

            if (EnsemblTranscripts?.Count > 0 || RefSeqTranscripts?.Count > 0)
            {
                jsonObject.AddGroupedObjectValues("transcripts", TranscriptLabels, RefSeqTranscripts, EnsemblTranscripts);
            }

            sb.Append(JsonObject.CloseBrace);
            return(StringBuilderCache.GetStringAndRelease(sb));
        }