added function and test for aa_prop_bp.R

This commit is contained in:
Tanushree Tunstall 2021-06-14 09:22:05 +01:00
parent 140bdc6d96
commit 2a8133898f
2 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,22 @@
library(ggplot2)
library(tidyverse)
library(data.table)
########################################################################
# TASK: barplots to colour nssnps by chosen aa_property
########################################################################
aa_prop_bp <- function(plotdf
, position_colname
, fill_colname
, fill_colours
, leg_name = "LEGEND"){
mp = ggplot(df, aes(x = as.factor(eval(parse(text = pos_colname)))
#, y = ..count..
, fill = eval(parse(text = fill_colname))
)) +
geom_bar(position = 'identity') +
scale_fill_manual(values = fill_colours
, name = leg_name)
return(mp)
}

View file

@ -0,0 +1,62 @@
library(ggplot2)
library(tidyverse)
library(data.table)
setwd("~/git/LSHTM_analysis/scripts/plotting/functions")
getwd()
#############################################################
#===========================================
# load functions, data, dirs, hardocded vars
# that will be used in testing the functions
#===========================================
source("../plotting_data.R")
infile = "/home/tanu/git/Data/streptomycin/output/"
pd_df = plotting_data(infile)
my_df = pd_df[[1]]
my_df_u = pd_df[[2]]
my_df_u_lig = pd_df[[3]]
dup_muts = pd_df[[4]]
source("../plotting_globals.R")
drug = "streptomycin"
gene = "gid"
import_dirs(drug, gene)
#=====================
# functions to test
#=====================
source("stability_count_bp.R")
source("position_count_bp.R")
#################################################################
##############################################
# read a sample file containing muts and prop
###############################################
df<- read.csv(file.choose())
setDT(df)[, pos_count := .N, by = .(position)]
foo = data.frame(df$position, df$pos_count)
#snpsBYpos_df <- df %>%
# group_by(position) %>%
# summarize(snpsBYpos = mean(pos_count))
# subset df without duplicates for position
df2 = df[!duplicated(df$position)]
##################################################################
# ---------------------------------------
# barplot for nssnps, coloured by aa prop
# ---------------------------------------
pos_colname = "position"
aa_prop_colname = "mut_prop_water"
aa_prop_colours = c("black", "blue")
my_legname = "aa_prop: water"
# call function
aa_prop_bp(plotdf = df
, position_colname = pos_colname
, fill_colname = aa_prop_colname
, fill_colours = aa_prop_cols
, leg_name = my_legname)
#===============================================================