Created
August 16, 2023 16:35
-
-
Save acvill/6ff28b24196d0c1135806d11ef1a8a14 to your computer and use it in GitHub Desktop.
Given a DNA string with ambiguous IUPAC characters, print all the possible unambiguous DNA strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make_unambiguous <- function(dna) { | |
require(tidyverse) | |
require(S4Vectors) | |
iupac <- tibble(code = c("A", "C", "G", "T", | |
"R", "Y", "S", "W", | |
"K", "M", "B", "D", | |
"H", "V", "N"), | |
base = c("A", "C", "G", "T", | |
"AG", "CT", "GC", "AT", | |
"GT", "AC", "CGT", "AGT", | |
"ACT", "ACG", "ACGT")) | |
tibble(dna) |> | |
separate_rows(dna, sep = '(?<=.)(?=.)') |> | |
left_join(iupac, by = c("dna" = "code")) |> | |
pull(base) |> | |
str_split("") |> | |
expand.grid(stringsAsFactors = FALSE) |> | |
unite(col = sequence, sep = "") |> | |
as_vector() | |
} | |
make_unambiguous(dna = "AAYGANAGYCARAGYAAR") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bioinformatics.stackexchange.com/a/21315/3967