Created
June 25, 2023 20:52
-
-
Save loukesio/1ac90db194408330a2356f5488f380df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| colorDNASequences <- function(dna_sequences) { | |
| # Define colors for bases | |
| base_colors <- c(A = "\033[31m", T = "\033[32m", G = "\033[34m", C = "\033[33m") # Red, Green, Blue, Yellow | |
| gap <- " " # Tiny gap between base pairs | |
| # Iterate over each DNA sequence | |
| for (dna_sequence in dna_sequences) { | |
| # Convert the sequence to uppercase to handle both upper and lower case letters | |
| sequence <- toupper(dna_sequence) | |
| # Iterate over each base in the sequence | |
| bases <- strsplit(sequence, "")[[1]] | |
| for (i in seq_along(bases)) { | |
| # Get the corresponding color for the base | |
| color <- base_colors[bases[i]] | |
| # Print the base surrounded by color with a gap | |
| cat(paste0(color, bases[i], "\033[0m", gap)) | |
| } | |
| cat("\n") # Print a new line after each sequence | |
| } | |
| } | |
| sequences <- c("CGCAGCGTAA", "CGTGTTGTAA", "CGGCAAGTAA", "CGTCGGGTAA", "CGATGCGTAA") | |
| sequences | |
| colorDNASequences(sequences) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment