Exemple #1
0
        public void CreateAndQuery_multiple_chromosomes()
        {
            using (var stream = new MemoryStream())
                using (var writer = new ExtendedBinaryWriter(stream))
                {
                    var index = new RefMinorIndex(writer, GenomeAssembly.GRCh37, new DataSourceVersion("name", "1", DateTime.Now.Ticks), SaCommon.SchemaVersion);

                    index.Add(0, 100);
                    index.Add(0, 105);
                    index.Add(0, 110);
                    index.Add(0, 115);
                    index.Add(1, 200);
                    index.Add(1, 205);
                    index.Add(1, 210);
                    index.Add(2, 315);

                    index.Write(320);

                    (long location, int byteCount, int count) = index.GetFileRange(0);
                    Assert.Equal(100, location);
                    Assert.Equal(100, byteCount);
                    Assert.Equal(4, count);

                    (location, byteCount, count) = index.GetFileRange(1);
                    Assert.Equal(200, location);
                    Assert.Equal(115, byteCount);
                    Assert.Equal(3, count);

                    (location, byteCount, count) = index.GetFileRange(2);
                    Assert.Equal(315, location);
                    Assert.Equal(5, byteCount);
                    Assert.Equal(1, count);
                }
        }
Exemple #2
0
        public void ReadBack()
        {
            var stream = new MemoryStream();

            using (var writer = new ExtendedBinaryWriter(stream))
            {
                var index = new RefMinorIndex(writer, GenomeAssembly.GRCh37, new DataSourceVersion("name", "1", DateTime.Now.Ticks), SaCommon.SchemaVersion);

                index.Add(0, 100);
                index.Add(0, 105);
                index.Add(0, 110);
                index.Add(0, 115);
                index.Add(1, 200);
                index.Add(1, 205);
                index.Add(1, 210);
                index.Add(2, 315);

                index.Write(320);
            }
            var readStream = new MemoryStream(stream.ToArray())
            {
                Position = 0
            };

            using (var reader = new ExtendedBinaryReader(readStream))
            {
                var index = new RefMinorIndex(reader);
                (long location, int byteCount, int count) = index.GetFileRange(0);
                Assert.Equal(100, location);
                Assert.Equal(100, byteCount);
                Assert.Equal(4, count);

                (location, byteCount, count) = index.GetFileRange(1);
                Assert.Equal(200, location);
                Assert.Equal(115, byteCount);
                Assert.Equal(3, count);

                (location, byteCount, count) = index.GetFileRange(2);
                Assert.Equal(315, location);
                Assert.Equal(5, byteCount);
                Assert.Equal(1, count);
            }
        }
Exemple #3
0
        public void Write(IEnumerable <ISupplementaryDataItem> saItems)
        {
            var itemsMinHeap       = new MinHeap <ISupplementaryDataItem>(SuppDataUtilities.CompareTo);
            var chromIndex         = ushort.MaxValue;
            var currentEnsemblName = "";

            var benchmark = new Benchmark();

            foreach (var saItem in saItems)
            {
                if (chromIndex != saItem.Chromosome.Index)
                {
                    if (chromIndex != ushort.MaxValue)
                    {
                        //flushing out the remaining items in buffer
                        WriteUptoPosition(itemsMinHeap, int.MaxValue);
                        Console.WriteLine($"Chromosome {currentEnsemblName} completed in {Benchmark.ToHumanReadable(benchmark.GetElapsedTime())}");
                        benchmark.Reset();
                    }
                    chromIndex         = saItem.Chromosome.Index;
                    currentEnsemblName = saItem.Chromosome.EnsemblName;
                    _refProvider.LoadChromosome(saItem.Chromosome);
                }

                if (saItem.RefAllele != _refProvider.Sequence.Substring(saItem.Position - 1, saItem.RefAllele.Length))
                {
                    continue;
                }
                //the items come in sorted order of the pre-trimmed position.
                //So when writing out, we have to make sure that we do not write past this position.
                //Once a position has been seen in the stream, we can safely write all positions before that.
                var writeToPos = saItem.Position;

                saItem.Trim();
                itemsMinHeap.Add(saItem);
                WriteUptoPosition(itemsMinHeap, writeToPos);
            }
            //flushing out the remaining items in buffer
            WriteUptoPosition(itemsMinHeap, int.MaxValue);
            Console.WriteLine($"Chromosome {currentEnsemblName} completed in {Benchmark.ToHumanReadable(benchmark.GetElapsedTime())}");

            _refMinorIndex.Write(_stream.Position);
        }