예제 #1
0
        public NsaReader(Stream dataStream, Stream indexStream, int blockSize = SaCommon.DefaultBlockSize)
        {
            _stream    = dataStream;
            _blockSize = blockSize;
            _reader    = new ExtendedBinaryReader(_stream);
            _block     = new NsaBlock(new Zstandard(), blockSize);

            _index        = new NsaIndex(indexStream);
            Assembly      = _index.Assembly;
            Version       = _index.Version;
            JsonKey       = _index.JsonKey;
            MatchByAllele = _index.MatchByAllele;
            IsArray       = _index.IsArray;
            IsPositional  = _index.IsPositional;

            if (_index.SchemaVersion != SaCommon.SchemaVersion)
            {
                throw new UserErrorException($"SA schema version mismatch. Expected {SaCommon.SchemaVersion}, observed {_index.SchemaVersion} for {JsonKey}");
            }

            _annotations      = new List <AnnotationItem>(64 * 1024);
            _annotationBuffer = new byte[1024 * 1024];
            _annotationStream = new MemoryStream(_annotationBuffer);
            _annotationReader = new ExtendedBinaryReader(_annotationStream);
        }
예제 #2
0
        public IEnumerable <NsaBlock> GetCompressedBlocks(ushort chromIndex)
        {
            var(location, blockCount) = _index.GetFileRange(chromIndex, 1, int.MaxValue);
            if (location == -1)
            {
                yield break;
            }

            _reader.BaseStream.Position = location;

            for (var i = 0; i < blockCount; i++)
            {
                var block = new NsaBlock(new Zstandard(), _blockSize);
                block.ReadCompressedBytes(_reader);
                yield return(block);
            }
        }