/// <summary> /// Parses a range of sequence items starting from the specified index in the sequence. /// </summary> /// <param name="startIndex">The zero-based index at which to begin parsing.</param> /// <param name="count">The number of symbols to parse.</param> /// <param name="seqPointer">The sequence pointer of that sequence.</param> /// <returns>The parsed sequence.</returns> public ISequence ParseRange(int startIndex, int count, SequencePointer seqPointer) { if (string.IsNullOrEmpty(_fileName)) { throw new NotSupportedException(Resource.DataVirtualizationNeedsInputFile); } if (startIndex < 0) { throw new ArgumentOutOfRangeException("startIndex"); } if (count <= 0) { throw new ArgumentOutOfRangeException("count"); } IAlphabet alphabet = Alphabets.All.Single(A => A.Name.Equals(seqPointer.AlphabetName)); Sequence sequence = new Sequence(alphabet) { IsReadOnly = false }; int start = (int)seqPointer.StartingIndex + startIndex; if (start >= seqPointer.EndingIndex) { return(null); } int includesNewline = seqPointer.StartingLine * Environment.NewLine.Length; int len = (int)(seqPointer.EndingIndex - seqPointer.StartingIndex); using (BioTextReader bioReader = new BioTextReader(_fileName)) { string str = bioReader.ReadBlock(startIndex, seqPointer.StartingIndex + includesNewline, count, len); sequence.InsertRange(0, str); } // default for partial load sequence.IsReadOnly = true; return(sequence); }
/// <summary> /// Parses a range of sequence items starting from the specified index in the sequence. /// </summary> /// <param name="startIndex">The zero-based index at which to begin parsing.</param> /// <param name="count">The number of symbols to parse.</param> /// <param name="seqPointer">The sequence pointer of that sequence.</param> /// <returns>The parsed sequence.</returns> public ISequence ParseRange(int startIndex, int count, SequencePointer seqPointer) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex"); } if (0 >= count) { throw new ArgumentOutOfRangeException("count"); } IAlphabet alphabet = Alphabets.All.Single(A => A.Name.Equals(seqPointer.AlphabetName)); Sequence sequence = new Sequence(alphabet); sequence.IsReadOnly = false; int start = (int)seqPointer.StartingIndex + startIndex; if (start >= seqPointer.EndingIndex) { return(null); } int includesNewline = seqPointer.StartingLine * Environment.NewLine.Length; int len = (int)(seqPointer.EndingIndex - seqPointer.StartingIndex); using (BioTextReader bioReader = new BioTextReader(_fileName)) { string sequenceString = bioReader.ReadBlock(startIndex, seqPointer.StartingIndex + includesNewline, count, len); sequence.InsertRange(0, sequenceString); } // default for partial load sequence.IsReadOnly = true; return(sequence); }