Created
June 25, 2023 21:37
-
-
Save loukesio/7a3a15de24b10da4fa849a0f2b7d4371 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 background colors for bases | |
| base_backgrounds <- c(A = "\033[41m", T = "\033[42m", G = "\033[44m", C = "\033[43m") # Red, Green, Blue, Yellow background | |
| # 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 current base and background color | |
| base <- bases[i] | |
| background_color <- base_backgrounds[base] | |
| # Print the base surrounded by color with black foreground and background color | |
| cat(paste0("\033[30m", background_color, base, "\033[0m")) | |
| } | |
| 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