internal void Write(ushort chromIndex, NsaReader nsaReader) { if (nsaReader == null) { return; } var dataBlocks = nsaReader.GetCompressedBlocks(chromIndex); var indexBlocks = nsaReader.GetIndexBlocks(chromIndex); var i = 0;//index of the index Blocks //cannot convert the dataBlocks into a list since that may take up GBs of memory (proportional to the nas file size) foreach (var dataBlock in dataBlocks) { if (i > indexBlocks.Count) { throw new IndexOutOfRangeException("Nsa Index have less blocks than the Nsa file. They have to be the same."); } var oldIndexBlock = indexBlocks[i]; _index.Add(chromIndex, oldIndexBlock.Start, oldIndexBlock.End, _writer.BaseStream.Position, oldIndexBlock.Length); dataBlock.WriteCompressedBytes(_writer); i++; } if (i < indexBlocks.Count) { throw new IndexOutOfRangeException("Nsa Index have more blocks than the Nsa file. They have to be the same."); } }
public void Query_chunks_in_same_chrom() { var stream = new MemoryStream(); var writer = new ExtendedBinaryWriter(stream); var version = new DataSourceVersion("dbsnp", "150", DateTime.Now.Ticks, "dbsnp ids"); var index = new NsaIndex(writer, GenomeAssembly.GRCh37, version, "dbsnp", true, true, SaCommon.SchemaVersion, false); index.Add(0, 100, 2000, 23457, 89320); index.Add(0, 2100, 4000, 112778, 58746); index.Add(0, 4100, 7000, 171525, 658794); (long start, int chunkCount) = index.GetFileRange(0, 150, 2120); Assert.Equal(23457, start); Assert.Equal(2, chunkCount); (start, chunkCount) = index.GetFileRange(0, 50, 98); Assert.Equal(-1, start); Assert.Equal(0, chunkCount); (start, chunkCount) = index.GetFileRange(0, 150, 2010); Assert.Equal(23457, start); Assert.Equal(1, chunkCount); (start, chunkCount) = index.GetFileRange(0, 2010, 4050); Assert.Equal(112778, start); Assert.Equal(1, chunkCount); (start, chunkCount) = index.GetFileRange(0, 4010, 4050); Assert.Equal(-1, start); Assert.Equal(0, chunkCount); (start, chunkCount) = index.GetFileRange(0, 7010, 7050); Assert.Equal(-1, start); Assert.Equal(0, chunkCount); }