C# for Bioinformatics: An Introduction


C# can be used for bioinformatics tasks, although languages like Python and R are more commonly used in this field. In this example, we'll demonstrate a basic DNA sequence analysis using C#.


Sample DNA Sequence Analysis Code


Here's a basic example of C# code to analyze a DNA sequence:


using System;
class Program
{
static void Main()
{
string dnaSequence = "ATCGTAGCTAGCATCGATCG";
int gcContent = CalculateGCContent(dnaSequence);
Console.WriteLine("GC Content: " + gcContent + "%");
}
static int CalculateGCContent(string sequence)
{
int gcCount = 0;
for (int i = 0; i < sequence.Length; i++)
{
char nucleotide = sequence[i];
if (nucleotide == 'G' || nucleotide == 'C')
{
gcCount++;
}
}
return (gcCount * 100) / sequence.Length;
}
}