当前位置: 首页>>代码示例>>C#>>正文


C# Stream.OpenRead方法代码示例

本文整理汇总了C#中Stream.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.OpenRead方法的具体用法?C# Stream.OpenRead怎么用?C# Stream.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.OpenRead方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        /// <summary>
        /// Parses a list of biological sequence alignment texts from a reader.
        /// </summary>
        /// <param name="stream">A stream for a biological sequence alignment text, it will be closed at the end.</param>
        /// <returns>The list of parsed ISequenceAlignment objects.</returns>
        public IEnumerable<ISequenceAlignment> Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // No empty files allowed
            if (!stream.CanRead || stream.Length == 0)
            {
                throw new InvalidDataException(Properties.Resource.IONoTextToParse);
            }

            using (var reader = stream.OpenRead())
            {
                while (!reader.EndOfStream)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        ReadNextLine(reader);
                        continue;
                    }

                    yield return ParseOne(reader);
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:32,代码来源:ClustalWParser.cs

示例2: Parse

        /// <summary>
        /// Returns an IEnumerable of sequences in the stream being parsed.
        /// </summary>
        /// <param name="stream">Stream to parse.</param>
        /// <returns>Returns ISequence arrays.</returns>
        public IEnumerable<ISequence> Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            byte[] buffer = new byte[PlatformManager.Services.DefaultBufferSize];
            using (var reader = stream.OpenRead())
            {
                while (!reader.EndOfStream)
                {
                    var seq = this.ParseOne(reader, buffer);
                    if (seq != null)
                        yield return seq;
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:23,代码来源:FastAParser.cs

示例3: Parse

        /// <summary>
        /// Parses a list of biological sequence alignment texts from a reader.
        /// </summary>
        /// <param name="stream">A stream for a biological sequence alignment text.</param>
        /// <returns>The list of parsed ISequenceAlignment objects.</returns>
        public IEnumerable<ISequenceAlignment> Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var reader = stream.OpenRead())
            {
                // no empty files allowed
                if (reader.EndOfStream)
                {
                    throw new InvalidDataException(Properties.Resource.IONoTextToParse);
                }

                // Parse Header, Loop through the blocks and parse
                while (line != null)
                {
                    yield return ParseOne(reader);
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:27,代码来源:NexusParser.cs

示例4: ParseOne

        /// <summary>
        /// Parses a single biological sequence alignment text from a reader.
        /// </summary>
        /// <param name="stream">A stream for a biological sequence alignment text.</param>
        /// <returns>The parsed ISequenceAlignment object.</returns>
        public ISequenceAlignment ParseOne(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var reader = stream.OpenRead())
            {
                // no empty files allowed
                if (reader.EndOfStream)
                    throw new InvalidDataException(Properties.Resource.IONoTextToParse);

                return ParseOne(reader);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:21,代码来源:PhylipParser.cs

示例5: Parse

        /// <summary>
        /// Parses a Phylogenetic tree text from a reader into a PhylogeneticTree.
        /// </summary>
        /// <param name="stream">A stream for a Phylogenetic tree text.</param>
        /// <returns>A new PhylogeneticTree instance containing parsed data.</returns>
        public Tree Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var reader = stream.OpenRead())
            {
                return InternalParse(reader);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:17,代码来源:NewickParser.cs

示例6: Parse

        /// <summary>
        /// Read XML BLAST data from the reader, and build one or more
        /// BlastRecordGroup objects (each containing one or more
        /// BlastSearchRecord results).
        /// </summary>
        /// <param name="stream">The stream to pull the data from</param>
        /// <returns>A list of BLAST iteration objects</returns>
        public IEnumerable<BlastResult> Parse(Stream stream)
        {
            var records = new List<BlastResult>();
            var sb = new StringBuilder();
            long lineNumber = 1;

            using (var reader = stream.OpenRead())
            {
                string line = ReadNextLine(reader, false);

                while (!string.IsNullOrEmpty(line))
                {
                    if (line.StartsWith("RPS-BLAST", StringComparison.OrdinalIgnoreCase))
                    {
                        line = ReadNextLine(reader, false);
                        lineNumber++;
                        continue;
                    }
                    if (line.StartsWith("<?xml version", StringComparison.OrdinalIgnoreCase) &&
                        lineNumber > 1)
                    {
                        records.Add(ParseXML(sb));
                        sb = new StringBuilder();
                    }
                    sb.AppendLine(line);
                    line = ReadNextLine(reader, false);
                    lineNumber++;
                }

                if (sb.Length > 0)
                    records.Add(ParseXML(sb));

                if (records.Count == 0)
                    throw new FormatException(Properties.Resources.BlastNoRecords);
            }
            return records;
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:44,代码来源:BlastXmlParser.cs

示例7: Parse

        /// <summary>
        /// Parses a single GenBank text from a reader into a sequence.
        /// </summary>
        /// <returns>A new Sequence instance containing parsed data.</returns>
        public IEnumerable<ISequence> Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (StreamReader reader = stream.OpenRead())
            {
                string line = null;
                int noOfSequence = 0;
                do
                {
                    IAlphabet alphabet = this.Alphabet ?? Alphabets.DNA;
                    Sequence sequence = new Sequence(alphabet, string.Empty);
                    sequence.Metadata[Helper.GenBankMetadataKey] = new GenBankMetadata();

                    // parse the file
                    line = ParseHeaders(ref sequence, noOfSequence, line, reader);
                    line = ParseFeatures(line, ref sequence, reader);
                    ParseSequence(ref line, ref sequence, reader);
                    ISequence finalSequence = CopyMetadata(sequence);
                    noOfSequence++;

                    yield return finalSequence;
                }
                while (line != null);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:33,代码来源:GenBankParser.cs

示例8: ParseOne

        /// <summary>
        /// Parse a single sequence alignment from the stream.
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <returns>Sequence alignment</returns>
        public ISequenceAlignment ParseOne(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var reader = stream.OpenRead())
            {
                return ParseOne(reader);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:17,代码来源:NexusParser.cs

示例9: Parse

        /// <summary>
        ///     Parses a list of GFF sequences.
        /// </summary>
        /// <returns>The list of parsed ISequence objects.</returns>
        public IEnumerable<ISequence> Parse(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            this.sequences = new List<Tuple<ISequence, List<byte>>>();
            this.sequencesInHeader = new List<Tuple<ISequence, List<byte>>>();

            IAlphabet alphabet = this.Alphabet ?? Alphabets.DNA;
            this.commonSeq = new Sequence(alphabet, String.Empty);

            using (var reader = stream.OpenRead())
            {
                // The GFF spec says that all headers need to be at the top of the file.
                string line = this.ParseHeaders(reader);

                // A feature file with no features? May it never be.
                if (reader.EndOfStream)
                {
                    throw new InvalidOperationException(Resource.GFFNoFeatures);
                }

                while (line != null)
                {
                    line = this.ParseFeatures(reader, line);
                }

                this.CopyMetadata();

                return
                    this.sequences.Select(seq => new Sequence(seq.Item1.Alphabet, seq.Item2.ToArray()) {
                            ID = seq.Item1.ID,
                            Metadata = seq.Item1.Metadata
                        })
                        .Cast<ISequence>()
                        .ToList();
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:44,代码来源:GffParser.cs

示例10: ParseOne

        /// <summary>
        /// Returns an IEnumerable of sequences in the stream being parsed.
        /// </summary>
        /// <param name="stream">Stream to parse.</param>
        /// <returns>Returns a Sequence.</returns>
        public ISequence ParseOne(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            byte[] buffer = new byte[PlatformManager.Services.DefaultBufferSize];
            using (var reader = stream.OpenRead())
            {
                return this.ParseOne(reader, buffer);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:18,代码来源:FastAParser.cs

示例11: ParseRange

        /// <summary>
        ///     Parse a set of ISequenceRange objects from a stream.
        /// </summary>
        /// <param name="stream">The stream from which the sequence range is to be parsed.</param>
        /// <returns>The list of sequence ranges.</returns>
        public IList<ISequenceRange> ParseRange(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            var result = new List<ISequenceRange>();
            char[] splitters = { '\t' };

            using (StreamReader reader = stream.OpenRead())
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    // TODO: Handle Track definitions
                    if (line.StartsWith("track", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    string[] split = line.Split(splitters, StringSplitOptions.RemoveEmptyEntries);
                    if (split.Length < 3)
                    {
                        continue;
                    }

                    var range = new SequenceRange
                                {
                                    ID = split[0],
                                    Start = long.Parse(split[1], CultureInfo.InvariantCulture),
                                    End = long.Parse(split[2], CultureInfo.InvariantCulture)
                                };

                    // Optional parameters
                    // TODO: When implementing track definitions update this section for 'use{feature}' declarations
                    if (split.Length >= 4)
                    {
                        range.Metadata["Name"] = split[3];
                    }
                    if (split.Length >= 5)
                    {
                        range.Metadata["Score"] = int.Parse(split[4], CultureInfo.InvariantCulture);
                    }
                    if (split.Length >= 6)
                    {
                        range.Metadata["Strand"] = split[5][0];
                    }
                    if (split.Length >= 7)
                    {
                        range.Metadata["ThickStart"] = int.Parse(split[6], CultureInfo.InvariantCulture);
                    }
                    if (split.Length >= 8)
                    {
                        range.Metadata["ThickEnd"] = int.Parse(split[7], CultureInfo.InvariantCulture);
                    }
                    if (split.Length >= 9)
                    {
                        range.Metadata["ItemRGB"] = split[8];
                    }
                    if (split.Length >= 10)
                    {
                        range.Metadata["BlockCount"] = int.Parse(split[9], CultureInfo.InvariantCulture);
                    }
                    if (split.Length >= 11)
                    {
                        range.Metadata["BlockSizes"] = split[10];
                    }
                    if (split.Length >= 12)
                    {
                        range.Metadata["BlockStarts"] = split[11];
                    }

                    result.Add(range);
                }
            }

            return result;
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:84,代码来源:BedParser.cs

示例12: Parse

        /// <summary>
        /// Creates a text reader from the file name and calls Parse(TextReader reader).
        /// </summary>
        /// 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.
        /// <returns>A list of sparse sequences that were present in the file.</returns>
        public IEnumerable<ISequence> Parse(Stream stream)
        {
            // Check input arguments
            if (stream == null)
                throw new ArgumentNullException("stream");

            using (var reader = stream.OpenRead())
            {
                return this.Parse(reader);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:18,代码来源:XsvSparseParser.cs

示例13: Parse

        /// <summary>
        ///     Returns an IEnumerable of sequences in the stream being parsed.
        /// </summary>
        /// <param name="stream">Stream to parse.</param>
        /// <returns>Returns ISequence arrays.</returns>
        public IEnumerable<ISequence> Parse(Stream stream)
        {
            using (var sr = stream.OpenRead())
            {
                string fileLine = sr.ReadLine();

                if (this.ContainsHeader)
                {
                    fileLine = sr.ReadLine();
                }

                while (!string.IsNullOrEmpty(fileLine))
                {
                    yield return this.ParseLine(fileLine);
                    fileLine = sr.ReadLine();
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:23,代码来源:FieldTextFileParser.cs


注:本文中的Stream.OpenRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。