示例#1
0
        public string GetJsonString()
        {
            if (AnnotatedVariants == null || AnnotatedVariants.Length == 0)
            {
                return(null);
            }

            var sb         = StringBuilderCache.Acquire();
            var jsonObject = new JsonObject(sb);

            sb.Append(JsonObject.OpenBrace);

            string originalChromName = Position.VcfFields[0];

            jsonObject.AddStringValue("chromosome", originalChromName);
            jsonObject.AddIntValue("position", Position.Start);

            if (Position.HasShortTandemRepeat)
            {
                jsonObject.AddStringValue("repeatUnit", Position.InfoData?.RepeatUnit);
                jsonObject.AddIntValue("refRepeatCount", Position.InfoData?.RefRepeatCount);
            }

            if (Position.HasStructuralVariant)
            {
                jsonObject.AddIntValue("svEnd", Position.InfoData?.End);
            }

            jsonObject.AddStringValue("refAllele", Position.RefAllele);
            jsonObject.AddStringValues("altAlleles", Position.AltAlleles);

            jsonObject.AddDoubleValue("quality", Position.Quality);

            jsonObject.AddStringValues("filters", Position.Filters);

            jsonObject.AddIntValues("ciPos", Position.InfoData?.CiPos);
            jsonObject.AddIntValues("ciEnd", Position.InfoData?.CiEnd);
            jsonObject.AddIntValue("svLength", Position.InfoData?.SvLength);

            jsonObject.AddDoubleValue("strandBias", Position.InfoData?.StrandBias, JsonCommon.FrequencyRoundingFormat);
            jsonObject.AddIntValue("jointSomaticNormalQuality", Position.InfoData?.JointSomaticNormalQuality);
            jsonObject.AddDoubleValue("recalibratedQuality", Position.InfoData?.RecalibratedQuality);

            jsonObject.AddStringValue("cytogeneticBand", CytogeneticBand);

            if (Position.Samples != null && Position.Samples.Length > 0)
            {
                jsonObject.AddStringValues("samples", Position.Samples.Select(s => s.GetJsonString()), false);
            }

            if (SupplementaryIntervals != null && SupplementaryIntervals.Any())
            {
                AddSuppIntervalToJsonObject(jsonObject);
            }

            jsonObject.AddStringValues("variants", AnnotatedVariants.Select(v => v.GetJsonString(originalChromName)), false);

            sb.Append(JsonObject.CloseBrace);
            return(StringBuilderCache.GetStringAndRelease(sb));
        }
示例#2
0
        public void AddIntValues_TwoTimes()
        {
            var sb   = StringBuilderCache.Acquire();
            var json = new JsonObject(sb);

            var ints  = new[] { 1, 2, 3 };
            var ints2 = new[] { 4, 5, 6 };

            json.AddIntValues("test1", ints);
            json.AddIntValues("test2", ints2);

            const string expectedResult = "\"test1\":[1,2,3],\"test2\":[4,5,6]";
            var          observedResult = StringBuilderCache.GetStringAndRelease(sb);

            Assert.Equal(expectedResult, observedResult);
        }
示例#3
0
        public void AddIntValues_NullArray()
        {
            var sb   = StringBuilderCache.Acquire();
            var json = new JsonObject(sb);

            json.AddIntValues("test1", null);
            var observedResult = StringBuilderCache.GetStringAndRelease(sb);

            Assert.Equal(string.Empty, observedResult);
        }