コード例 #1
0
        private static (Stream jsonStream, Stream jasixStream) GetNirvanaJsonStreamWithoutGenes(int chromNumber)
        {
            var jsonStream  = new MemoryStream();
            var jasixStream = new MemoryStream();

            using (var bgZipStream = new BlockGZipStream(jsonStream, CompressionMode.Compress, true))
                using (var writer = new BgzipTextWriter(bgZipStream))
                    using (var jasixIndex = new JasixIndex())
                    {
                        writer.Write(NirvanaHeader);
                        writer.Flush();
                        jasixIndex.BeginSection(JasixCommons.PositionsSectionTag, writer.Position);
                        for (int i = 100 * chromNumber; i < 123 * chromNumber; i++)
                        {
                            writer.WriteLine($"{{\"chromosome\":\"chr{chromNumber}\",\"position\":{i}}},");
                            if (i % 50 == 0)
                            {
                                writer.Flush();  //creating another block
                            }
                        }
                        writer.WriteLine($"{{\"chromosome\":\"chr{chromNumber}\",\"position\":{100 *chromNumber +25}}}");
                        writer.Flush();
                        jasixIndex.EndSection(JasixCommons.PositionsSectionTag, writer.Position);

                        writer.Write(NirvanaFooter);
                        jasixIndex.Write(jasixStream);
                    }

            jsonStream.Position  = 0;
            jasixStream.Position = 0;
            return(jsonStream, jasixStream);
        }
コード例 #2
0
ファイル: IndexCreator.cs プロジェクト: zhouhufeng/Nirvana
        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));
        }
コード例 #3
0
ファイル: IndexTests.cs プロジェクト: wook2014/Nirvana
        public void Write_and_read_back()
        {
            var index = new JasixIndex();

            index.Add("chr1", 100, 101, 100000, "1");
            index.Add("chr1", 105, 109, 100050, "1");
            index.Add("chr1", 150, 1000, 100075, "1");//large variant
            index.Add("chr1", 160, 166, 100100, "1");
            index.Add("chr2", 100, 100, 100150, "2");
            index.Add("chr2", 102, 105, 100200, "2");

            var writeStream = new MemoryStream();

            using (writeStream)
            {
                index.Write(writeStream);
            }

            var readStream = new MemoryStream(writeStream.ToArray());

            readStream.Seek(0, SeekOrigin.Begin);

            JasixIndex readBackIndex;

            using (readStream)
            {
                readBackIndex = new JasixIndex(readStream);
            }

            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 100, 102));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 103, 104));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 120, 124));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 158, 160));
            Assert.Equal(100150, readBackIndex.GetFirstVariantPosition("chr2", 103, 105));

            //checking large variants
            Assert.Null(readBackIndex.LargeVariantPositions("chr1", 100, 149));
            var largeVariants = readBackIndex.LargeVariantPositions("chr1", 100, 201);

            Assert.NotNull(largeVariants);
            Assert.Single(largeVariants);
            Assert.Equal(100075, largeVariants[0]);
        }
コード例 #4
0
        public void IndexWriteRead()
        {
            var index = new JasixIndex();

            index.Add("chr1", 100, 101, 100000);
            index.Add("chr1", 105, 109, 100050);
            index.Add("chr1", 150, 1000, 100075);//large variant
            index.Add("chr1", 160, 166, 100100);
            index.Add("chr2", 100, 100, 100150);
            index.Add("chr2", 102, 105, 100200);

            var tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            using (var writer = FileUtilities.GetCreateStream(tempFile))
            {
                index.Write(writer);
            }

            JasixIndex readBackIndex;

            using (var stream = FileUtilities.GetReadStream(tempFile))
            {
                readBackIndex = new JasixIndex(stream);
            }
            File.Delete(tempFile);

            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 100, 102));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 103, 104));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 120, 124));
            Assert.Equal(100000, readBackIndex.GetFirstVariantPosition("chr1", 158, 160));
            Assert.Equal(100150, readBackIndex.GetFirstVariantPosition("chr2", 103, 105));

            //checking large variants
            Assert.Null(readBackIndex.LargeVariantPositions("chr1", 100, 149));
            var largeVariants = readBackIndex.LargeVariantPositions("chr1", 100, 201);

            Assert.NotNull(largeVariants);
            Assert.Single(largeVariants);
            Assert.Equal(100075, largeVariants[0]);
        }
コード例 #5
0
        public void CreateIndex()
        {
            var index = new JasixIndex();

            IndexHeader(index);

            string lastLine = IndexPositions(index);

            IndexGenes(lastLine, index);

            index.Write(_writeStream);

            Console.WriteLine();

            long 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));
        }
コード例 #6
0
 public void Dispose()
 {
     _jasixIndex.Write(_indexStream);
     _indexStream.Flush();
     _indexStream.Dispose();
 }
コード例 #7
0
 public void Flush()
 {
     _jasixIndex.Write(_indexStream);
     _indexStream.Flush();
 }