PowerShell - nucleotide-count

This commit is contained in:
Xevion
2021-11-26 02:30:19 -06:00
parent 596aa4f029
commit b6f26a5279
7 changed files with 158 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
Function Get-NucleotideCount() {
<#
.SYNOPSIS
Given a single stranded DNA string, compute how many times each nucleotide occurs in the string.
.DESCRIPTION
The genetic language of every living thing on the planet is DNA.
DNA is a large molecule that is built from an extremely long sequence of individual elements called nucleotides.
4 types exist in DNA and these differ only slightly and can be represented as the following symbols: 'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' thymine.
The function counts the occurances of A, C, G and T in the supplied strand. It then outputs in the format:
A:0, C:0, G:0, T:0
.PARAMETER Strand
The DNA strand to count
.EXAMPLE
Get-NucleotideCount -Strand "ACGTAGCTT"
Retuns: A:2 C:2 G:2 T:3
#>
[CmdletBinding()]
Param(
[string]$Strand
)
if ($Strand -notmatch "^[ACGT]*$") {
Throw "Invalid DNA Strand"
}
$counts = @{"A" = 0; "C" = 0; "G" = 0; "T" = 0}
foreach ($char in $Strand.ToCharArray()) { $counts[$char.ToString()] += 1 }
return "A:$($counts['A']) C:$($counts['C']) G:$($counts['G']) T:$($counts['T'])"
}