本文整理汇总了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);
}
}
}
示例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]);
}
}
}
示例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();
}
}
}
}
示例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]);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}