Ejemplo n.º 1
0
        private void ReadIntervalScores(PhylopInterval interval)
        {
            if (interval == null)
            {
                return;
            }

            var filePosition = interval.FilePosition;

            //going to the file location that contains this interval.
            if (filePosition != -1)
            {
                _reader.BaseStream.Position = filePosition;
            }
            else
            {
                return;
            }

            var length           = _reader.ReadInt32();
            var compressedScores = _reader.ReadBytes(length);

            int requiredBufferSize = _qlz.GetDecompressedLength(compressedScores, length);

            if (requiredBufferSize > _scoreBytes.Length)
            {
                _scoreBytes = new byte[requiredBufferSize];
            }

            var uncompressedLength = _qlz.Decompress(compressedScores, length, _scoreBytes, _scoreBytes.Length);

            BytesToScores(uncompressedLength, _scoreBytes, _scores);

            _scoreCount = uncompressedLength / 2;
        }
Ejemplo n.º 2
0
        private int FindInterval(int position)
        {
            if (_currentIntervalIndex != -1)
            {
                var interval = _phylopIntervals[_currentIntervalIndex];
                if (interval.ContainsPosition(position))
                {
                    return(_currentIntervalIndex);
                }
            }

            var pointInterval = new PhylopInterval(position, 1, 1);// overload construtor for points

            var containingIntervalIndex = _phylopIntervals.BinarySearch(pointInterval);

            // The zero-based index of item in the sorted List<T>, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count.
            if (containingIntervalIndex == -1)
            {
                // smaller than the first position of the first interval
                return(-1);// empty string represe
            }

            if (containingIntervalIndex < 0)
            {
                containingIntervalIndex = ~containingIntervalIndex - 1;
            }

            return(containingIntervalIndex);
        }
Ejemplo n.º 3
0
        private void StartNewInterval(string line)
        {
            var words     = line.Split();
            var chromName = words[1].Split('=')[1];

            // checking if the writer needs to be initiated/re-initiated
            if (_writer == null)
            {
                OpenWriter(chromName);
            }

            if (chromName != _refSeqName)
            {
                CloseWriter();
                OpenWriter(chromName);
            }

            // dumping existing interval
            if (_currentInterval != null)
            {
                WriteInterval(_currentInterval, _writer);
            }

            var start = Convert.ToInt32(words[2].Split('=')[1]);
            var step  = Convert.ToInt16(words[3].Split('=')[1]);

            _currentInterval = new PhylopInterval(start, 0, step);
        }
Ejemplo n.º 4
0
        private void Clear()
        {
            _scoreCount           = 0;
            _currentInterval      = null;
            _intervalListOffset   = -1;
            _intervalListPosition = -1;

            _chromosomeIntervals.Clear();
        }
Ejemplo n.º 5
0
        private void LoadChromosomeIntervals()
        {
            var currentPos = _reader.BaseStream.Position;

            _reader.BaseStream.Position = _intervalListPosition;

            CheckGuard();

            var intervalCount = _reader.ReadInt32();

            for (var i = 0; i < intervalCount; i++)
            {
                var chromosomeInterval = new PhylopInterval(_reader);
                _phylopIntervals.Add(chromosomeInterval);
            }

            _reader.BaseStream.Position = currentPos;
        }
Ejemplo n.º 6
0
        private void AddScore(short score)
        {
            UpdateMinMaxScore(score);
            _scores[_scoreCount++] = score;

            if (_scoreCount < _intervalLength)
            {
                return;
            }

            // buffer full, its time to compress and write it out to file
            var latestInterval = _currentInterval;

            WriteInterval(_currentInterval, _writer);

            _currentInterval = new PhylopInterval(latestInterval.Begin + latestInterval.Length, 0, 1);
            _scoreCount      = 0;
        }
Ejemplo n.º 7
0
        private void WriteInterval(PhylopInterval interval, ExtendedBinaryWriter writer)
        {
            if (_scoreCount == 0)
            {
                return;
            }
            ScoresToBytes(_scoreBytes, _scores, _scoreCount);

            var compressedSize = _compressor.Compress(_scoreBytes, _scoreCount * 2, _compressedBuffer, _compressedBuffer.Length);

            // finalizing the file position for this chromosome interval
            interval.FilePosition   = _writer.BaseStream.Position;
            _currentInterval.Length = _scoreCount;
            _chromosomeIntervals.Add(interval);

            _scoreCount = 0;

            WriteScores(writer, _compressedBuffer, compressedSize);
        }