/// <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(); } }
/// <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); } } }
/// <summary> /// Write a collection of ISequenceAlignments to a file. /// </summary> /// <param name="stream">The name of the file to write the formatted sequence alignments.</param> /// <param name="sequenceAlignments">The sequenceAlignments to write.</param> /// <param name="Header">The sequenceAlignments to write.</param> public void Format(Stream stream, List <SAMAlignedSequence> sequenceAlignments, SAMAlignmentHeader Header) { if (stream == null) { throw new ArgumentNullException("stream"); } if (sequenceAlignments == null) { throw new ArgumentNullException("sequenceAlignments"); } using (var writer = stream.OpenWrite()) { if (Header != null) { WriteHeader(writer, Header); } foreach (IAlignedSequence alignedSequence in sequenceAlignments) { WriteSAMAlignedSequence(writer, alignedSequence); } } }
/// <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(); } }
/// <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]); } }
/// <summary> /// Writes a set of entries. /// </summary> /// <param name="stream">Stream to write to.</param> /// <param name="sequences">The data to write.</param> public void Format(Stream stream, IEnumerable <ISequence> sequences) { if (sequences == null) { throw new ArgumentNullException("sequences"); } // Stream is closed at the end. using (StreamWriter writer = stream.OpenWrite()) { foreach (ISequence sequence in sequences) { this.Write(writer, sequence, (long)sequence.Metadata[XsvSparseParser.MetadataOffsetKey]); } } }
/// <summary> /// Writes the specified 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 left open at the end.</param> /// <param name="data">Sequence to write.</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()) { Write(writer, data); } }
/// <summary> /// Writes the specified QualitativeSequence in FastQ format to the file. /// </summary> /// <param name="stream">Stream to write to</param> /// <param name="qualitativeSequence">QualitativeSequence to write.</param> public void Format(Stream stream, IQualitativeSequence qualitativeSequence) { if (stream == null) { throw new ArgumentNullException("stream"); } if (qualitativeSequence == null) { throw new ArgumentNullException("qualitativeSequence"); } using (var writer = stream.OpenWrite()) { this.Format(writer, qualitativeSequence); } }
/// <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); } } }
/// <summary> /// Writes a set of entries. /// </summary> /// <param name="stream">Stream to write to.</param> /// <param name="annotations">The data to write.</param> public void Format(Stream stream, IEnumerable <WiggleAnnotation> annotations) { if (stream == null) { throw new ArgumentNullException("stream"); } if (annotations == null) { throw new ArgumentNullException("annotations"); } using (var writer = stream.OpenWrite()) { foreach (var entry in annotations) { WriteOne(writer, entry); } } }
/// <summary> /// Write a collection of ISequences to a stream. /// </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">Stream to write to</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"); } using (var writer = stream.OpenWrite()) { foreach (ISequence sequence in sequences) { WriteHeaders(sequence, writer); WriteFeatures(sequence, writer); WriteSequence(sequence, writer); } writer.Flush(); } }
/// <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]); } } }
/// <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]); } } }
/// <summary> /// Writes a set of entries. /// </summary> /// <param name="stream">Stream to write to.</param> /// <param name="sequences">The data to write.</param> public void Format(Stream stream, IEnumerable<ISequence> sequences) { if (sequences == null) { throw new ArgumentNullException("sequences"); } // Stream is closed at the end. using (StreamWriter writer = stream.OpenWrite()) { foreach (ISequence sequence in sequences) { this.Write(writer, sequence, (long)sequence.Metadata[XsvSparseParser.MetadataOffsetKey]); } } }
/// <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); } }
/// <summary> /// Write a collection of ISequences to a stream. /// </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">Stream to write to</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"); } using (var writer = stream.OpenWrite()) { foreach (ISequence sequence in sequences) { WriteHeaders(sequence, writer); WriteFeatures(sequence, writer); WriteSequence(sequence, writer); } writer.Flush(); } }
/// <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); } } }
/// <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(); } } } }
/// <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(); } } } }
/// <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(); } }