adding legend forlogo plot

This commit is contained in:
Tanushree Tunstall 2022-01-14 10:18:01 +00:00
parent 426a5cb0b5
commit 3b7cea3c47
4 changed files with 60 additions and 55 deletions

View file

@ -32,13 +32,15 @@
#================== #==================
# NOTE: my_logo_col # NOTE: my_logo_col
# Can be one of these: 'chemistry', 'hydrophobicity', 'clustalx', 'taylor' # Can be one of these: 'chemistry', 'hydrophobicity', 'clustalx', 'taylor'
# if 'chemistry' or 'hydrophobicity' --> then bg is grey with black font # if 'chemistry' or 'hydrophobicity' --> then bg is grey with black font (x, y and labels)
# if 'clustalx'or 'taylor' --> then bg is black with white font # if 'clustalx'or 'taylor' --> then bg is black with white font (x, y and labels)
#, theme_bgc = #, theme_bgc =
#, xfont_bgc = #, xfont_bgc =
#, yfont_bgc = #, yfont_bgc =
#, xtt_col =
#, ytt_col =
# ADD legend for hydrophobicity # ADD legend for hydrophobicity: done
# ADD option to remove empty positions # ADD option to remove empty positions
LogoPlotCustomH <- function(plotdf LogoPlotCustomH <- function(plotdf
@ -57,10 +59,12 @@ LogoPlotCustomH <- function(plotdf
#, yfont_bgc #, yfont_bgc
, y_ats = 22 , y_ats = 22
, y_tangle = 0 , y_tangle = 0
, x_tts = 25 # title size , x_tts = 20 # title size
, y_tts = 20 , y_tts = 23
, leg_pos = "none" #, xtt_col =
#, leg_pos = c(0.8, 0.9) #, ytt_col =
, leg_pos = "none" # can be top, left, right and bottom or c(0.8, 0.9)
, leg_dir = "horizontal" #can be vertical or horizontal
, leg_ts = 15 # leg text size , leg_ts = 15 # leg text size
, leg_tts = 16 # leg title size , leg_tts = 16 # leg title size
) )
@ -72,12 +76,7 @@ LogoPlotCustomH <- function(plotdf
logo_df = plotdf logo_df = plotdf
if (y_axis_log){ logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname)]
log_colname = paste0("log_", y_axis_colname)
logo_df[log_colname] = log_value(logo_df[y_axis_colname])
}
logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname, log_colname)]
#================== #==================
# logo data: OR # logo data: OR
@ -99,21 +98,26 @@ LogoPlotCustomH <- function(plotdf
#================== #==================
# logo data: logOR # logo data: logOR
#================== #==================
logo_data_plot2_logor = logo_df[, c(x_axis_colname, symbol_colname, log_colname)] if (y_axis_log){
wide_df2_logor = as.matrix(logo_data_plot2_logor %>% spread(x_axis_colname, log_colname, fill = 0.0)) log_colname = paste0("log_", y_axis_colname)
class(wide_df2_logor) logo_df[log_colname] = log_value(logo_df[y_axis_colname])
logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname,log_colname )]
rownames(wide_df2_logor) = wide_df2_logor[,1] logo_data_plot2_logor = logo_df[, c(x_axis_colname, symbol_colname, log_colname)]
dim(wide_df2_logor)
#wide_df2_logor = subset(wide_df_logor, select = -c(1) ) wide_df2_logor = as.matrix(logo_data_plot2_logor %>% spread(x_axis_colname, log_colname, fill = 0.0))
wide_df2_logor = wide_df2_logor[,-1] class(wide_df2_logor)
str(wide_df2_logor)
colnames(wide_df2_logor) rownames(wide_df2_logor) = wide_df2_logor[,1]
position_logor = as.numeric(colnames(wide_df2_logor)) dim(wide_df2_logor)
wide_df2_logor = wide_df2_logor[,-1]
str(wide_df2_logor)
colnames(wide_df2_logor)
position_logor = as.numeric(colnames(wide_df2_logor))
}
###################################### ######################################
# Generating plots with given y_axis # Generating plots with given y_axis
@ -123,10 +127,11 @@ LogoPlotCustomH <- function(plotdf
if (my_logo_col %in% c('clustalx','taylor')) { if (my_logo_col %in% c('clustalx','taylor')) {
cat("\nSelected colour scheme:", my_logo_col cat("\nSelected colour scheme:", my_logo_col
, "\nUsing black theme\n") , "\nUsing black theme\n")
theme_bgc = "black" theme_bgc = "black"
xfont_bgc = "white" xfont_bgc = "white"
yfont_bgc = "black" yfont_bgc = "white"
xtt_col = "white"
ytt_col = "white"
} }
if (my_logo_col %in% c('chemistry', 'hydrophobicity')) { if (my_logo_col %in% c('chemistry', 'hydrophobicity')) {
@ -135,7 +140,8 @@ LogoPlotCustomH <- function(plotdf
theme_bgc = "grey" theme_bgc = "grey"
xfont_bgc = "black" xfont_bgc = "black"
yfont_bgc = "black" yfont_bgc = "black"
xtt_col = "black"
ytt_col = "black"
} }
LogoPlot = ggseqlogo(wide_df2_or LogoPlot = ggseqlogo(wide_df2_or
@ -152,10 +158,12 @@ LogoPlotCustomH <- function(plotdf
, hjust = 1 , hjust = 1
, vjust = 0 , vjust = 0
, colour = yfont_bgc) , colour = yfont_bgc)
, axis.title.y = element_text(size = x_tts) , axis.title.x = element_text(size = x_tts
, axis.title.x = element_text(size = y_tts) , colour = xtt_col)
#, legend.position = "bottom") + , axis.title.y = element_text(size = y_tts
, colour = ytt_col)
, legend.position = leg_pos , legend.position = leg_pos
, legend.direction = leg_dir
, plot.background = element_rect(fill = theme_bgc))+ , plot.background = element_rect(fill = theme_bgc))+
#, legend.text = element_text(size = leg_ts) #, legend.text = element_text(size = leg_ts)
#, legend.title = element_text(size = leg_tts))+ #, legend.title = element_text(size = leg_tts))+
@ -165,7 +173,6 @@ LogoPlotCustomH <- function(plotdf
, limits = factor(1:length(position_or))) + , limits = factor(1:length(position_or))) +
ylab(y_lab) ylab(y_lab)
#print(logo_or)
return(LogoPlot) return(LogoPlot)
} }

View file

@ -7,21 +7,20 @@ LogoPlotCustomH (plotdf = merged_df3
, x_axis_colname = "position" , x_axis_colname = "position"
, y_axis_colname = "or_mychisq" , y_axis_colname = "or_mychisq"
, symbol_colname = "mutant_type" , symbol_colname = "mutant_type"
, y_axis_log = T , y_axis_log = F
, log_value = log10 , log_value = log10
, my_logo_col = 'hydrophobicity' , my_logo_col = 'chemistry'
#, theme_bgc
# , xfont_bgc
# , yfont_bgc
, x_lab = "Position" , x_lab = "Position"
, y_lab = "Odds Ratio" , y_lab = "Odds Ratio"
, x_ats = 12 # text size , x_ats = 12 # text size
, x_tangle = 90 # text angle , x_tangle = 90 # text angle
, y_ats = 22 , y_ats = 22
, y_tangle = 0 , y_tangle = 0
, x_tts = 25 # title size , x_tts = 20 # title size
, y_tts = 20 , y_tts = 23
, leg_pos = "none" #, leg_pos = c(0.05,-0.12)
, leg_pos = "top"
, leg_dir = "horizontal"
, leg_ts = 15 # leg text size , leg_ts = 15 # leg text size
, leg_tts = 16 # leg title size , leg_tts = 16 # leg title size
) )

View file

@ -69,25 +69,25 @@ svg(plot_logo_or, width = 30 , height = 6)
logo_or = ggseqlogo(wide_df_or logo_or = ggseqlogo(wide_df_or
, method = "custom" , method = "custom"
, seq_type = "aa") + ylab("my custom height") + , seq_type = "aa") + ylab("my custom height") +
theme( axis.text.x = element_text(size = 12 theme( axis.text.x = element_text(size = x_ats
, angle = 90 , angle = x_tangle
, hjust = 1 , hjust = 1
, vjust = 0.4) , vjust = 0.4)
, axis.text.y = element_text(size = 22 , axis.text.y = element_text(size = y_ats
, angle = 0 , angle = y_tangle
, hjust = 1 , hjust = 1
, vjust = 0) , vjust = 0)
, axis.title.y = element_text(size = 25) , axis.title.y = element_text(size = x_tts)
, axis.title.x = element_text(size = 20) , axis.title.x = element_text(size = y_tts)
#, legend.position = "bottom") + #, legend.position = "bottom") +
, legend.position = "none")+ , legend.position = leg_pos)+
#, legend.text = element_text(size = 15) #, legend.text = element_text(size = leg_ts)
#, legend.title = element_text(size = 15))+ #, legend.title = element_text(size = leg_tts))+
scale_x_discrete("Position" scale_x_discrete(x_lab
#, breaks #, breaks
, labels = position_or , labels = position_or
, limits = factor(1:length(position_or))) + , limits = factor(1:length(position_or))) +
ylab("Odds Ratio") ylab(y_lab)
print(logo_or) print(logo_or)
#dev.off() #dev.off()

View file

@ -30,7 +30,6 @@ wc -l TEST2.csv
sed -E 's/>.*//g' TEST2.csv | sed '/^$/d' > TEST3.csv sed -E 's/>.*//g' TEST2.csv | sed '/^$/d' > TEST3.csv
wc -l TEST3.csv wc -l TEST3.csv
# doubles the no as it adds the mut info # doubles the no as it adds the mut info
python3 mutate.py -v -o /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/TEST.csv /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/pnca_mut_map.csv /home/tanu/git/Data/pyrazinamide/input/pnca.fasta python3 mutate.py -v -o /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/TEST.csv /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/pnca_mut_map.csv /home/tanu/git/Data/pyrazinamide/input/pnca.fasta