private string IndexPositions(JasixIndex index) { // we need the location before accessing the line long linePosition = _reader.Position; index.BeginSection(JasixCommons.PositionsSectionTag, linePosition); Console.WriteLine($"section:{JasixCommons.PositionsSectionTag} starts at {linePosition}"); var previousChr = ""; var previousPos = 0; string line; while ((line = _reader.ReadLine()) != null) { if (line.OptimizedStartsWith(']')) { index.EndSection(JasixCommons.PositionsSectionTag, linePosition); Console.WriteLine($"section:{JasixCommons.PositionsSectionTag} ends at {linePosition}"); break; } line = line.TrimEnd(','); (string chr, int position, int end) = GetChromPosition(line); CheckSorting(chr, position, previousChr, previousPos); index.Add(chr, position, end, linePosition); linePosition = _reader.Position; previousChr = chr; previousPos = position; } return(line); }
public void CreateIndex() { var searchTag = $"\"{SectionToIndex}\":["; const string headerTag = "{\"header\":"; var index = new JasixIndex(); string line; //skipping lines before the sectionToIndex arrives while ((line = _reader.ReadLine()) != null) { if (line.StartsWith(headerTag)) { index.HeaderLine = ExtractHeader(line); } if (line.EndsWith(searchTag)) { break; } } // we need the location before accessing the line var fileLoc = _reader.Position; string previousChr = ""; int previousPos = 0; while ((line = _reader.ReadLine()) != null) { if (line.StartsWith("]")) { break; } line = line.TrimEnd(','); var chrPos = GetChromPosition(line); CheckFileSorted(chrPos.chr, chrPos.position, previousChr, previousPos); index.Add(chrPos.chr, chrPos.position, chrPos.end, fileLoc); fileLoc = _reader.Position; previousChr = chrPos.chr; previousPos = chrPos.position; } index.Write(_writeStream); Console.WriteLine(); var peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage(); var wallTimeSpan = _benchmark.GetElapsedTime(); Console.WriteLine(); if (peakMemoryUsageBytes > 0) { Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(peakMemoryUsageBytes)); } Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(wallTimeSpan)); }
public void BgzipTextWriter_EndToEnd() { var asterisks = new string('*', BlockGZipStream.BlockGZipFormatCommon.BlockSize); var observedLines = new List <string>(); var observedPositions = new List <long>(); using (var ms = new MemoryStream()) { using (var stream = new BlockGZipStream(ms, CompressionMode.Compress, true)) using (var writer = new BgzipTextWriter(stream)) { writer.Flush(); writer.WriteLine("BOB"); writer.WriteLine(); writer.Flush(); writer.Write("AB"); writer.Write(""); writer.Write("C"); writer.Write(" "); writer.WriteLine("123"); writer.WriteLine(asterisks); writer.WriteLine(asterisks); writer.WriteLine(asterisks); } ms.Position = 0; using (var reader = new BgzipTextReader(new BlockGZipStream(ms, CompressionMode.Decompress))) { while (true) { string line = reader.ReadLine(); observedPositions.Add(reader.Position); if (line == null) { break; } observedLines.Add(line); } } } Assert.Equal(6, observedLines.Count); Assert.Equal("BOB", observedLines[0]); Assert.Equal(0, observedLines[1].Length); Assert.Equal("ABC 123", observedLines[2]); Assert.Equal(asterisks, observedLines[3]); Assert.Equal(4, observedPositions[0]); Assert.Equal(5, observedPositions[1]); Assert.Equal(13, observedPositions[2]); Assert.Equal(43843598, observedPositions[3]); Assert.Equal(87097359, observedPositions[4]); }
public void JasixStreamReader() { var stream = ResourceUtilities.GetReadStream(Resources.TopPath("TinyAnnotated.json")); var lineCount = 0; using (var jasixReader = new BgzipTextReader(stream)) { while (jasixReader.ReadLine() != null) { lineCount++; } } Assert.Equal(4, lineCount); }