Skip to content

Instantly share code, notes, and snippets.

@mtandon09
Last active February 7, 2021 02:23
Show Gist options
  • Save mtandon09/1f134d0088c1c4add89aa97a35bbc787 to your computer and use it in GitHub Desktop.
Save mtandon09/1f134d0088c1c4add89aa97a35bbc787 to your computer and use it in GitHub Desktop.
Acronym as Sequence Logo
rm(list=ls())
library(ggseqlogo)
set.seed(1234)
myletters <- "CCBR"
# myletters <- "NCBR"
letter_vec <- unlist(strsplit(toupper(myletters),""))
allletters <- unique(c("A","T","G","C",letter_vec))
custom_mat <- matrix(0,nrow=length(allletters), ncol=length(letter_vec))
rownames(custom_mat) <- allletters
big_size=1
for (pos_idx in 1:ncol(custom_mat)) {
# pos_idx=1
big_row=which(rownames(custom_mat) %in% letter_vec[pos_idx])
little_rows=which(rownames(custom_mat) %in% setdiff(c("A","T","G","C"), letter_vec[pos_idx]))
custom_mat[big_row,pos_idx] <- big_size
little_min_size=big_size*0.05
little_max_size=big_size*0.3
custom_mat[little_rows,pos_idx] <- -runif(length(little_rows), little_min_size, little_max_size)
}
# Generate sequence logo
ggseqlogo(custom_mat, method='custom', namespace=allletters) +
ylab("")+theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment