To align two sequences, pick the aligner you'd like to use, set it up with parameters and then call the Align method, passing your sequences.

using Bio;
using Bio.Algorithms.Alignment;
using Bio.SimilarityMatrices;

// Create two sequences; normally you'd have this already.
ISequence dna1 = new Sequence(Alphabets.AmbiguousDNA, "ACTGAAGGATATTA");
ISequence dna2 = new Sequence(Alphabets.AmbiguousDNA, "ACTGTCCTAGATATTA");

// Pick our aligner; there are several to choose from; all in the 
// Bio.Algorithms.Alignment namespace.
var algo = new Bio.Algorithms.Alignment.NeedlemanWunschAligner(); 

// Setup the aligner with appropriate parameters
algo.SimilarityMatrix = new SimilarityMatrix(
algo.GapOpenCost = -6;
algo.GapExtensionCost = -1;

// Execute the alignment.
var results = algo.Align(dna1, dna2);

// Display / Process the results.
Console.WriteLine("Pairwise Alignment: " + results.Count + " result entries");
foreach (IPairwiseSequenceAlignment ipsa in results) 
   // Note equiv: ipsa.ipsa.PairwiseAlignedSequences[0].ToString()
   Console.WriteLine("Processing Pairwise Alignments: " 
                                  + ipsa.PairwiseAlignedSequences.Count 
                                  + " entries");
   foreach (PairwiseAlignedSequence pas in ipsa.PairwiseAlignedSequences)
      Console.Write("Alignment Score:" + pas.Metadata["score"].ToString());

Last edited Sep 24, 2014 at 10:38 PM by jamesmhogan, version 4


jamesmhogan Sep 24, 2014 at 10:40 PM 
Yes, this seems to be correct. Updated now. There is an explicit qualification for some of the other types, and so they didn't produce errors.

hlyates Sep 24, 2014 at 2:41 AM 
I was getting an error with IPairwiseSequenceAlignment. I believe this tutorial should state "using Bio.Algorithms.Alignment" instead of "using Bio.Algorithms" for Xamarin studio. This resolves that issue.