コード例 #1
0
        /// <summary>
        /// Reads a sequencePointer from a binary stream.
        /// </summary>
        /// <param name="stream">The stream to deserialize from.</param>
        /// <returns>The SequencePointer object.</returns>
        private static SequencePointer ReadPointer(FileStream stream)
        {
            SequencePointer pointer = new SequencePointer();
            BinaryReader    reader  = new BinaryReader(stream);

            pointer.StartingLine  = reader.ReadInt32();
            pointer.StartingIndex = reader.ReadInt64();
            pointer.EndingIndex   = reader.ReadInt64();
            string alphabetName = new string(reader.ReadChars(3));

            foreach (IAlphabet alphabet in Alphabets.All)
            {
                if (alphabet.Name.StartsWith(alphabetName, StringComparison.Ordinal))
                {
                    pointer.AlphabetName = alphabet.Name;
                    break;
                }
            }

            if (string.IsNullOrEmpty(pointer.AlphabetName))
            {
                throw new FileFormatException("alphabet");
            }

            return(pointer);
        }
コード例 #2
0
        /// <summary>
        /// Serialize an object to a binary outputStream.
        /// </summary>
        /// <param name="stream">The outputStream to serialize to.</param>
        /// <param name="pointer">Sequence pointer obejct to serialize</param>
        private static void WritePointer(FileStream stream, SequencePointer pointer)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(pointer.StartingLine);
            writer.Write(pointer.StartingIndex);
            writer.Write(pointer.EndingIndex);
            // Writing only first three chars of alphabet name
            writer.Write(pointer.AlphabetName.Substring(0, 3).ToCharArray());
        }
コード例 #3
0
        /// <summary>
        /// Gets the index of a qualitative sequence within the list.
        /// Throws a NotSupportedException when attempting to set the position
        /// since VirtualSequenceList is read-only.
        /// </summary>
        /// <param name="index">The zero-based index of the qualitative sequence in the list.</param>
        /// <returns>The qualitative sequence found at the specified index.</returns>
        public IQualitativeSequence this[int index]
        {
            get
            {
                QualitativeSequence virtualQualitativeSequence;

                if (_sequenceDictionary.ContainsKey(index))
                {
                    virtualQualitativeSequence = _sequenceDictionary[index].Target as QualitativeSequence;
                    if (virtualQualitativeSequence != null)
                    {
                        return(virtualQualitativeSequence);
                    }
                    _sequenceDictionary.Remove(index);
                }

                SequencePointer pointer = _sidecarProvider[index];

                // Get the alphabet from alphabet name.
                IAlphabet alphabet = Alphabets.All.Single(A => A.Name.Equals(pointer.AlphabetName));

                virtualQualitativeSequence = new QualitativeSequence(alphabet)
                {
                    ID = (_sequenceParser as FastQ.FastQParser).GetSequenceID(pointer),
                    VirtualQualitativeSequenceProvider =
                        new FileVirtualQualitativeSequenceProvider(_sequenceParser, pointer)
                };
                if (pointer.EndingIndex - pointer.StartingIndex < virtualQualitativeSequence.VirtualQualitativeSequenceProvider.BlockSize)
                {
                    virtualQualitativeSequence.VirtualQualitativeSequenceProvider.BlockSize = (int)(pointer.EndingIndex - pointer.StartingIndex);
                }

                virtualQualitativeSequence.IsReadOnly = CreateSequenceAsReadOnly;

                _sequenceDictionary.Add(index, new WeakReference(virtualQualitativeSequence, false));

                return(virtualQualitativeSequence);
            }
            set
            {
                throw new NotSupportedException(Properties.Resource.NotSupportedInVirtualSequence);
            }
        }
コード例 #4
0
        /// <summary>
        /// Indexer with which one can access the sequences in the indexed file.
        /// </summary>
        /// <param name="index">Zero based index of the SequencePointer to fetch.</param>
        /// <returns>SequencePointer object at the specified index.</returns>
        public SequencePointer this[int index]
        {
            get
            {
                if (index >= _header.SequenceCount || index < 0)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                _inputStream.Seek(_contentsOffset, SeekOrigin.Begin);

                // find the entry for the item at the given index
                _inputStream.Seek(index * PayloadBlockSize, SeekOrigin.Current);

                // Read the required sequence pointer
                SequencePointer loadedSequence = ReadPointer(_inputStream) as SequencePointer;

                return(loadedSequence);
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the Bio.IO.FileVirtualQualitativeSequenceProvider
        /// class to hold a sequence pointer with a parser.
        /// </summary>
        /// <param name="parser">A virtual parser object.</param>
        /// <param name="pointer">The sequence pointer.</param>
        public FileVirtualQualitativeSequenceProvider(IVirtualSequenceParser parser, SequencePointer pointer)
        {
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }

            _parser = parser;
            _count  = (int)(pointer.EndingIndex - pointer.StartingIndex);
            SequencePointerInstance = pointer;

            //set the default DV properties.
            _virtualData = new VirtualData <Sequence>
            {
                BlockSize         = FileLoadHelper.DefaultBlockSize,
                MaxNumberOfBlocks = FileLoadHelper.DefaultMaxNumberOfBlocks
            };
        }