checked logo_multiple_muts.R with the new sourcing script for data

This commit is contained in:
Tanushree Tunstall 2021-06-24 16:43:23 +01:00
parent 6bbc3328b9
commit 0e15c05d8b
6 changed files with 120 additions and 296 deletions

View file

@ -110,9 +110,6 @@ cat("No. of rows in my_data:", nrow(logo_data)
#=======================================================================
#%% logo plots from dataframe
#############
# PLOTS
#############
foo = logo_data[, c("position"
, "mutant_type","duet_scaled", "or_mychisq"
, "mut_prop_polarity", "mut_prop_water")]
@ -150,6 +147,76 @@ rownames(wide_df_logor_m)
colnames(wide_df_logor_m)
position_logor = as.numeric(colnames(wide_df_logor_m))
#===============================
# logo data: multiple nsSNPs (>1)
#=================================
#require(data.table)
# get freq count of positions so you can subset freq<1
setDT(logo_data)[, mut_pos_occurrence := .N, by = .(position)]
table(logo_data$position)
table(logo_data$mut_pos_occurrence)
max_mut = max(table(logo_data$position))
# extract freq_pos > 1
my_data_snp = logo_data[logo_data$mut_pos_occurrence!=1,]
u = unique(my_data_snp$position)
max_mult_mut = max(table(my_data_snp$position))
if (nrow(my_data_snp) == nrow(logo_data) - table(logo_data$mut_pos_occurrence)[[1]] ){
cat("PASS: positions with multiple muts extracted"
, "\nNo. of mutations:", nrow(my_data_snp)
, "\nNo. of positions:", length(u)
, "\nMax no. of muts at any position", max_mult_mut)
}else{
cat("FAIL: positions with multiple muts could NOT be extracted"
, "\nExpected:",nrow(logo_data) - table(logo_data$mut_pos_occurrence)[[1]]
, "\nGot:", nrow(my_data_snp) )
}
cat("\nNo. of sites with only 1 mutations:", table(logo_data$mut_pos_occurrence)[[1]])
#--------------------------------------
# matrix for_mychisq mutant type
# frequency of mutant type by position
#---------------------------------------
table(my_data_snp$mutant_type, my_data_snp$position)
tab_mt = table(my_data_snp$mutant_type, my_data_snp$position)
class(tab_mt)
# unclass to convert to matrix
tab_mt = unclass(tab_mt)
tab_mt = as.matrix(tab_mt, rownames = T)
# should be TRUE
is.matrix(tab_mt)
rownames(tab_mt) #aa
colnames(tab_mt) #pos
#-------------------------------------
# matrix for wild type
# frequency of wild type by position
#-------------------------------------
tab_wt = table(my_data_snp$wild_type, my_data_snp$position); tab_wt
tab_wt = unclass(tab_wt)
# remove wt duplicates
wt = my_data_snp[, c("position", "wild_type")]
wt = wt[!duplicated(wt),]
tab_wt = table(wt$wild_type, wt$position); tab_wt # should all be 1
rownames(tab_wt)
rownames(tab_wt)
identical(colnames(tab_mt), colnames(tab_wt))
identical(ncol(tab_mt), ncol(tab_wt))
########################################################################
# End of script
########################################################################