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


C# Stream.OpenWrite方法代码示例

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


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

示例1: Format

        /// <summary>
        /// Writes an ISequenceAlignment to the location specified by the stream.
        /// </summary>
        /// <param name="stream">The Stream used to write the formatted sequence alignment text.</param>
        /// <param name="sequenceAlignment">The sequence alignment to format.</param>
        public void Format(Stream stream, ISequenceAlignment sequenceAlignment)
        {
            if (sequenceAlignment == null)
            {
                throw new ArgumentNullException(Properties.Resource.ParameterNameSequenceAlignment);
            }

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

            using (var writer = stream.OpenWrite())
            {
                SAMAlignmentHeader header = sequenceAlignment.Metadata[Helper.SAMAlignmentHeaderKey] as SAMAlignmentHeader;
                if (header != null)
                {
                    WriteHeader(writer, header);
                }

                foreach (IAlignedSequence alignedSequence in sequenceAlignment.AlignedSequences)
                {
                    WriteSAMAlignedSequence(writer, alignedSequence);
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:31,代码来源:SAMFormatter.cs

示例2: Write

        /// <summary>
        /// Formats a (sparse) contig to a character-separated value file,
        /// writing the consensus first, followed by the sequence separator,
        /// and each assembled sequences followed by the sequence separator.
        /// The consensus has an offset of 0, while the assembled sequences have the
        /// offset as present in AssembledSequence.Position.
        /// </summary>
        /// <param name="stream">Stream to write to, it is left open at the end.</param>
        /// <param name="contig">The contig to format as a set of sparse sequences.</param>
        public void Write (Stream stream, Contig contig) 
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

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

            // Write the consensus sequence out.
            base.Format(stream, contig.Consensus);

            // Write out the contigs.
            using (StreamWriter writer = stream.OpenWrite(leaveOpen: true))
            {
                foreach (Contig.AssembledSequence aSeq in contig.Sequences)
                {
                    this.Write(writer, aSeq.Sequence, (long)aSeq.Sequence.Metadata[XsvSparseParser.MetadataOffsetKey]);
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:33,代码来源:XsvContigFormatter.cs

示例3: Format

        /// <summary>
        ///     Writes out a list of ISequenceRange objects to a specified
        ///     stream. The stream is closed at the end.
        /// </summary>
        /// <param name="stream">The stream where the formatted data is to be written.</param>
        /// <param name="ranges">The range collection to be formatted.</param>
        public void Format(Stream stream, IList<ISequenceRange> ranges)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("writer");
            }

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

            // TODO: Need support for tracks and for optional metadata columns

            // Open the output stream - we leave the underlying stream open.
            using (StreamWriter writer = stream.OpenWrite())
            {
                int lineCount = 0;
                foreach (ISequenceRange range in ranges)
                {
                    writer.Write(range.ID);
                    writer.Write('\t');
                    writer.Write(range.Start);
                    writer.Write('\t');
                    writer.Write(range.End);

                    if (range.Metadata.Count > 0)
                    {
                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("Name"))
                        {
                            writer.Write(range.Metadata["Name"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("Score"))
                        {
                            writer.Write(range.Metadata["Score"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("Strand"))
                        {
                            writer.Write(range.Metadata["Strand"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("ThickStart"))
                        {
                            writer.Write(range.Metadata["ThickStart"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("ThickEnd"))
                        {
                            writer.Write(range.Metadata["ThickEnd"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("ItemRGB"))
                        {
                            writer.Write(range.Metadata["ItemRGB"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("BlockCount"))
                        {
                            writer.Write(range.Metadata["BlockCount"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("BlockSizes"))
                        {
                            writer.Write(range.Metadata["BlockSizes"]);
                        }

                        writer.Write('\t');
                        if (range.Metadata.ContainsKey("BlockStarts"))
                        {
                            writer.Write(range.Metadata["BlockStarts"]);
                        }
                    }

                    writer.WriteLine();

                    // Flush every 500 lines.
                    if (lineCount++ % 500 == 0)
                    {
                        writer.Flush();
                    }
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:99,代码来源:BedFormatter.cs

示例4: Format

        /// <summary>
        /// Writes a single data entry.
        /// </summary>
        /// <param name="stream">Stream to write to.</param>
        /// <param name="data">The data to write.</param>
        public void Format(Stream stream, ISequence data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            // Stream is left open at the end.
            using (StreamWriter writer = stream.OpenWrite())
            {
                this.Write(writer, data, (long)data.Metadata[XsvSparseParser.MetadataOffsetKey]);
            }

        }
开发者ID:cpatmoore,项目名称:bio,代码行数:19,代码来源:XsvSparseFormatter.cs

示例5: Format

        /// <summary>
        /// Writes an ISequence to the specified stream.
        /// </summary>
        /// <param name="stream">Stream to write to</param>
        /// <param name="data">The sequence to format.</param>
        public void Format(Stream stream, ISequence data)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

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

            using (var writer = stream.OpenWrite())
            {
                this.Format(data, writer);
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:22,代码来源:GenBankFormatter.cs

示例6: Format

        /// <summary>
        /// Writes a PhylogeneticTree to the writer.
        /// </summary>
        /// <param name="stream">The Stream used to write the formatted Phylogenetic tree text, it will remain open.</param>
        /// <param name="tree">PhylogeneticTree to format.</param>
        public void Format(Stream stream, Tree tree)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(string.Format
                    (CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name,
                    "Tree object is null"));
            }

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

            var stringBuilder = new StringBuilder();
            this.Write(tree.Root, null, ref stringBuilder);

            // Append end char ";"
            stringBuilder.Append(";");

            using (var writer = stream.OpenWrite())
            {
                writer.Write(stringBuilder.ToString());
                writer.Flush();
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:31,代码来源:NewickFormatter.cs

示例7: Format

        /// <summary>
        /// Writes the Multiple sequence in FastA format to the file.
        /// Note that if the sequence contains more than the MaxSymbolsAllowedPerLine 
        /// value then it will split the symbols in the specified sequence in to multiple lines, 
        /// where each line will contain maximum of MaxSymbolsAllowedPerLine symbols.
        /// </summary>
        /// <param name="stream">Stream to write to, it will be closed at the end.</param>
        /// <param name="sequences">Sequences to write.</param>
        public void Format(Stream stream, IEnumerable<ISequence> sequences)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

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

            using (var writer = stream.OpenWrite())
            {
                foreach (ISequence sequence in sequences)
                {
                    Write(writer, sequence);
                }
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:28,代码来源:FastAFormatter.cs

示例8: Format

        /// <summary>
        ///     Write a collection of ISequences to a file.
        /// </summary>
        /// <remarks>
        ///     This method is overridden to format file-scope metadata that applies to all
        ///     metadata that applies to all of the sequences in the file.
        /// </remarks>
        /// <param name="stream">Writer</param>
        /// <param name="sequences">The sequences to write</param>
        public void Format(Stream stream, IEnumerable<ISequence> sequences)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

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

            // Try to cast for performance, otherwise create a new list; we enumerate
            // this many times so we need to make sure it's all available in memory.
            IList<ISequence> data = sequences as IList<ISequence> ?? sequences.ToList();

            using (StreamWriter writer = stream.OpenWrite())
            {
                this.WriteHeaders(data, writer);
                foreach (ISequence sequence in data)
                {
                    this.WriteFeatures(sequence, writer);
                }

                writer.Flush();
            }
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:36,代码来源:GffFormatter.cs


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