Esempio n. 1
0
        /// <summary>
        /// Parses a list of sequences using a BioTextReader.
        /// </summary>
        /// <remarks>
        /// This method should be overridden by any parsers that need to process file-scope
        /// metadata that applies to all of the sequences in the file.
        /// </remarks>
        /// <param name="bioReader">bio text reader</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequences should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequences's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The list of parsed ISequence objects.</returns>
        protected IList <ISequence> Parse(BioTextReader bioReader, bool isReadOnly)
        {
            _lineCount        = 0;
            _sequenceCount    = 0;
            _lineLength       = 0;
            _sequenceBeginsAt = 1;

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

            // no empty files allowed
            if (!bioReader.HasLines)
            {
                string message = Resource.Parser_NoTextErrorMessage;
                Trace.Report(message);
                throw new InvalidOperationException(message);
            }

            // Check if DV is enabled and sidecar creation is possible
            if (!string.IsNullOrEmpty(bioReader.FileName) && IsDataVirtualizationEnabled && SidecarFileProvider.IsIndexFileExists(bioReader.FileName))
            {
                while (bioReader.HasLines)
                {
                    // Parse and forget as the list is now maintained by DV using sequence pointers
                    ParseOne(bioReader, isReadOnly);
                }

                // Create sidecar
                SidecarFileProvider provider = SidecarFileProvider.CreateIndexFile(bioReader.FileName, _sequencePointers);

                VirtualSequenceList virtualSequences =
                    new VirtualSequenceList(provider, this, _sequencePointers.Count)
                {
                    CreateSequenceAsReadOnly = isReadOnly
                };

                _sequencePointers.Clear();

                return(virtualSequences);
            }
            else
            {
                List <ISequence> sequences = new List <ISequence>();

                while (bioReader.HasLines)
                {
                    sequences.Add(ParseOne(bioReader, isReadOnly));
                }

                return(sequences);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parses a list of biological sequence data from a BioTextReader.
        /// </summary>
        /// <param name="bioReader">BioTextReader instance for a biological sequence data.</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting QualitativeSequences should be in readonly mode or not.
        /// If this flag is set to true then the resulting QualitativeSequences's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The list of parsed IQualitativeSequence objects.</returns>
        new protected IList <IQualitativeSequence> Parse(BioTextReader bioReader, bool isReadOnly)
        {
            if (bioReader == null)
            {
                throw new ArgumentNullException("bioReader");
            }


            // no empty files allowed
            if (!bioReader.HasLines)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, Resource.IONoTextToParse);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            if (!string.IsNullOrEmpty(bioReader.FileName) &&
                IsDataVirtualizationEnabled && SidecarFileProvider.IsIndexFileExists(bioReader.FileName))
            {
                while (bioReader.HasLines)
                {
                    ParseOne(bioReader, isReadOnly);
                }

                // Create sidecar
                SidecarFileProvider provider = SidecarFileProvider.CreateIndexFile(bioReader.FileName, _sequencePointers);

                VirtualQualitativeSequenceList virtualSequences =
                    new VirtualQualitativeSequenceList(provider, this, _sequencePointers.Count)
                {
                    CreateSequenceAsReadOnly = isReadOnly
                };

                _sequencePointers.Clear();

                return(virtualSequences);
            }
            else
            {
                List <IQualitativeSequence> qualSequences = new List <IQualitativeSequence>();

                while (bioReader.HasLines)
                {
                    qualSequences.Add(ParseOne(bioReader, isReadOnly));
                }

                return(qualSequences);
            }
        }