To execute a BLAST search request to NCBI, you use a IBlastWebHandler. This recipe shows how to use the NcbiWebHandler class, but you can pick a different BLAST service or even call your own with the same basic steps.

Assuming you have a sequence, or a set of sequences you want to look for you can execute the following code:

async Task<List<BlastResult>> DoBlast(IEnumerable<ISequence sequences)
{
   // Setup the Blast Request parameters. Must select the database and program.
   // Can have other parameters if necessary (such as email).
   BlastRequestParameters bp = new BlastRequestParameters(sequences) {
	Database = "nt",
	Program = BlastProgram.Megablast,
   };

   // Create the web handler.
   IBlastWebHandler webHandler = new NcbiBlastWebHandler();
   
   // Execute the request. Note the use of async / await here.
   // This returns a Stream with the XML data from NCBI.
   var response = await webHandler.ExecuteAsync(bp, CancellationToken.None);

   // Parse the results to an object graph. Can also consume the results directly
   // it comes back in XML form.
   IBlastParser blastParser = new BlastXmlParser();
   return blastParser.Parse(response).ToList();
}

The returning data will include the hits and high-scoring pairs.

Last edited Sep 6, 2016 at 4:51 PM by markjulmar, version 2

Comments

No comments yet.