To load sequences from a file-based format you need a parser. Given a filename you can locate the parser associated with it pretty easily:
// Find the parser
const string Filename = @"4_raw.fasta";

ISequenceParser parser = SequenceParsers.FindParserByFileName(Filename);
if (parser == null) {
   Console.WriteLine("Unable to locate parser for {0}", Filename);

You can also deliberately create the parser if you know the exact type you want:
ISequenceParser parser = new Bio.IO.FastA.FastAParser(); 

Once you have the parser, you can then either pass it a Stream from your given platform, or use the extension methods to work with files or IStorageFile on Windows 8. Here's an example of opening a file and parsing out all the sequences and capturing them in a list:
// Parse the file.
List<ISequence> sequences;
using (parser.Open(Filename)) 
   sequences = parser.Parse().ToList();

Notice the use of the using block, this will ensure the file is closed as soon as the data is read, parsed and turned into the list. You should follow this paradigm when you are working with files to conserve resources.

Last edited Jun 16, 2014 at 7:50 PM by markjulmar, version 4


No comments yet.