To save a set of sequences to a file, you need a file formatter. You can identify the available formatters for sequences using the SequenceFormatters class by either filename or format name:
const string Filename = "output.fa";
ISequenceFormatter formatter = SequenceFormatters.FindFormatterByFileName(Filename);

If it returns null, then the formatter could not be identified by the filename. You can also create a formatter directly if you know exactly what format you want to use, for example to use Fasta:
ISequenceFormatter formatter = new Bio.IO.FastA.FastAFormatter();

Once you have the formatter and the sequences you can persist either to a Stream by calling the Write method, or use the platform-specific extension methods to work with the file APIs available for your platform, for example to work with a desktop app:
bool WriteToFile(string filename, IEnumerable<ISequence> sequences)
   ISequenceFormatter formatter = SequenceFormatters.FindFormatterByFileName(filename);
   if (formatter == null) return false;

   using (formatter.Open(filename)) {

Last edited Jun 16, 2014 at 8:07 PM by markjulmar, version 1


No comments yet.