private void WriteHeader(string annotator, string creationTime, string genomeAssembly, int schemaVersion, string vepDataVersion, IEnumerable <IDataSourceVersion> dataSourceVersions, string[] sampleNames) { _jasixIndexCreator?.BeginSection(JasixCommons.HeaderSectionTag, _bgzipTextWriter.Position); var sb = StringBuilderCache.Acquire(); var jsonObject = new JsonObject(sb); sb.Append($"{{\"{JasixCommons.HeaderSectionTag}\":{{"); jsonObject.AddStringValue("annotator", annotator); jsonObject.AddStringValue("creationTime", creationTime); jsonObject.AddStringValue("genomeAssembly", genomeAssembly); jsonObject.AddIntValue("schemaVersion", schemaVersion); jsonObject.AddStringValue("dataVersion", vepDataVersion); jsonObject.AddObjectValues("dataSources", dataSourceVersions); if (sampleNames != null) { jsonObject.AddStringValues("samples", sampleNames); } sb.Append($"}},\"{JasixCommons.PositionsSectionTag}\":[\n"); _writer.Write(StringBuilderCache.GetStringAndRelease(sb)); _writer.Flush(); _jasixIndexCreator?.EndSection(JasixCommons.HeaderSectionTag, _bgzipTextWriter.Position - 1); }
public void Add_one_chrom() { var position1 = new Mock <IPosition>(); position1.SetupGet(x => x.Chromosome).Returns(ChromosomeUtilities.Chr1); position1.SetupGet(x => x.Start).Returns(100); position1.SetupGet(x => x.RefAllele).Returns("A"); position1.SetupGet(x => x.AltAlleles).Returns(new [] { "C" }); var memStream = new MemoryStream(); using (var indexCreator = new OnTheFlyIndexCreator(memStream)) { indexCreator.BeginSection("positions", 100); indexCreator.Add(position1.Object, 2588); indexCreator.EndSection("positions", 2699); } var readStream = new MemoryStream(memStream.ToArray()); readStream.Seek(0, SeekOrigin.Begin); var index = new JasixIndex(readStream); Assert.Equal(100, index.GetSectionBegin("positions")); Assert.Equal(2588, index.GetFirstVariantPosition("chr1", 100, 102)); }
// due to the flush, the end of a section will point to the next to last block for a section. // e.g. if positions start at block 2 and end at block 10, blocks 2..9 contains positions. private void BeginSection(string section) { if (_bgzipTextWriter == null) { return; } _bgzipTextWriter.Flush(); _jasixIndexCreator.BeginSection(section, _bgzipTextWriter.Position); }