Ejemplo n.º 1
0
        public void Begin_end_section_and_readback()
        {
            var          index   = new JasixIndex();
            const string section = "section1";

            index.BeginSection(section, 0);
            Assert.Throws <UserErrorException>(() => index.BeginSection(section, 1));
            index.EndSection(section, 100);
            Assert.Throws <UserErrorException>(() => index.EndSection(section, 101));

            Assert.Equal(0, index.GetSectionBegin(section));
            Assert.Equal(100, index.GetSectionEnd(section));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        private void IndexHeader(JasixIndex index)
        {
            string searchTag = $"\"{JasixCommons.PositionsSectionTag}\":[";
            string headerTag = $"{{\"{JasixCommons.HeaderSectionTag}\":";
            string line;

            long previousPosition = _reader.Position;

            while ((line = _reader.ReadLine()) != null)
            {
                if (line.StartsWith(headerTag))
                {
                    index.BeginSection(JasixCommons.HeaderSectionTag, previousPosition);
                    Console.WriteLine($"section:{JasixCommons.HeaderSectionTag} starts at {previousPosition}");
                }

                if (line.EndsWith(searchTag))
                {
                    {
                        index.EndSection(JasixCommons.HeaderSectionTag, previousPosition);
                        Console.WriteLine($"section:{JasixCommons.HeaderSectionTag} ends at {previousPosition}");
                    }
                    break;
                }

                previousPosition = _reader.Position;
            }
        }
Ejemplo n.º 5
0
        private void IndexGenes(string lastLine, JasixIndex index)
        {
            if (lastLine == null)
            {
                return;
            }
            do
            {
                long linePosition = _reader.Position;

                if (lastLine.EndsWith($",\"{JasixCommons.GenesSectionTag}\":["))
                {
                    index.BeginSection(JasixCommons.GenesSectionTag, _reader.Position);
                    Console.WriteLine($"section:{JasixCommons.GenesSectionTag} starts at {_reader.Position}");
                }

                if (lastLine.EndsWith("]}"))
                {
                    index.EndSection(JasixCommons.GenesSectionTag, linePosition);
                    Console.WriteLine($"section:{JasixCommons.GenesSectionTag} ends at {linePosition}");
                    break;
                }
            } while ((lastLine = _reader.ReadLine()) != null);
        }
Ejemplo n.º 6
0
 public void BeginSection(string sectionName, long fileLocation)
 {
     _jasixIndex.BeginSection(sectionName, fileLocation);
 }