moved all test scripts for functions to tests/

This commit is contained in:
Tanushree Tunstall 2021-09-09 13:12:07 +01:00
parent 2ee66c770b
commit 03031d2eb6
15 changed files with 162 additions and 776 deletions

View file

@ -27,13 +27,44 @@ cat("\nMissing samples with lineage classification:", table(merged_df2$lineage =
}
# Add pretty lineage labels and mut_info_labels
class(merged_df2$lineage); table(merged_df2$lineage)
merged_df2$lineage_labels = gsub("lineage", "L", merged_df2$lineage)
table(merged_df2$lineage_labels)
class(merged_df2$lineage_labels)
merged_df2$lineage_labels = factor(merged_df2$lineage_labels, c("L1"
, "L2"
, "L3"
, "L4"
, "L5"
, "L6"
, "L7"
, "LBOV"
, "L1;L2"
, "L1;L3"
, "L1;L4"
, "L2;L3"
, "L2;L3;L4"
, "L2;L4"
, "L2;L6"
, "L2;LBOV"
, "L3;L4"
, "L4;L6"
, "L4;L7"
, ""))
class(merged_df2$lineage_labels); nlevels(merged_df2$lineage_labels)
##################################
# WF data: lineages with
# snp count
# total_samples
# snp diversity (perc)
##################################
sel_lineages = levels(as.factor(merged_df2$lineage))
sel_lineages = levels(merged_df2$lineage_labels)
lin_wf = data.frame(sel_lineages) #4, 1
total_snps_u = NULL
@ -41,12 +72,12 @@ total_samples = NULL
for (i in sel_lineages){
#print(i)
curr_total = length(unique(merged_df2$id)[merged_df2$lineage==i])
curr_total = length(unique(merged_df2$id)[merged_df2$lineage_labels==i])
#print(curr_total)
total_samples = c(total_samples, curr_total)
print(total_samples)
foo = merged_df2[merged_df2$lineage==i,]
foo = merged_df2[merged_df2$lineage_labels==i,]
print(paste0(i, "=======\n"))
print(length(unique(foo$mutationinformation)))
curr_count = length(unique(foo$mutationinformation))
@ -70,33 +101,29 @@ lin_wf
lin_wf$snp_diversity_f = round( (lin_wf$snp_diversity * 100), digits = 0)
lin_wf$snp_diversity_f = paste0(lin_wf$snp_diversity_f, "%")
# Lineage names
lin_wf$sel_lineages_f = gsub("lineage", "L", lin_wf$sel_lineages)
lin_wf
# Important: Check factors so that x-axis categ appear as you want
lin_wf$sel_lineages = factor(lin_wf$sel_lineages, c("L1"
, "L2"
, "L3"
, "L4"
, "L5"
, "L6"
, "L7"
, "LBOV"
, "L1;L2"
, "L1;L3"
, "L1;L4"
, "L2;L3"
, "L2;L3;L4"
, "L2;L4"
, "L2;L6"
, "L2;LBOV"
, "L3;L4"
, "L4;L6"
, "L4;L7"
, ""))
# Important: Relevel factors so that x-axis categ appear as you want
lin_wf$sel_lineages_f = factor(lin_wf$sel_lineages_f, c("L1"
, "L2"
, "L3"
, "L4"
, "L5"
, "L6"
, "L7"
, "LBOV"
, "L1;L2"
, "L1;L3"
, "L1;L4"
, "L2;L3"
, "L2;L3;L4"
, "L2;L4"
, "L2;L6"
, "L2;LBOV"
, "L3;L4"
, "L4;L6"
, "L4;L7"
, ""))
levels(lin_wf$sel_lineages_f)
levels(lin_wf$sel_lineages)
##################################
# LF data: lineages with
@ -106,7 +133,7 @@ levels(lin_wf$sel_lineages_f)
##################################
names(lin_wf)
tot_cols = ncol(lin_wf)
pivot_cols = c("sel_lineages", "sel_lineages_f", "snp_diversity", "snp_diversity_f")
pivot_cols = c("sel_lineages", "snp_diversity", "snp_diversity_f")
pivot_cols_n = length(pivot_cols)
expected_rows = nrow(lin_wf) * ( length(lin_wf) - pivot_cols_n )
@ -129,25 +156,25 @@ if ( nrow(lin_lf) == expected_rows ){
}
# Important: Relevel factors so that x-axis categ appear as you want
lin_lf$sel_lineages_f = factor(lin_lf$sel_lineages_f, c("L1"
, "L2"
, "L3"
, "L4"
, "L5"
, "L6"
, "L7"
, "LBOV"
, "L1;L2"
, "L1;L3"
, "L1;L4"
, "L2;L3"
, "L2;L3;L4"
, "L2;L4"
, "L2;L6"
, "L2;LBOV"
, "L3;L4"
, "L4;L6"
, "L4;L7"
, ""))
lin_lf$sel_lineages = factor(lin_lf$sel_lineages, c("L1"
, "L2"
, "L3"
, "L4"
, "L5"
, "L6"
, "L7"
, "LBOV"
, "L1;L2"
, "L1;L3"
, "L1;L4"
, "L2;L3"
, "L2;L3;L4"
, "L2;L4"
, "L2;L6"
, "L2;LBOV"
, "L3;L4"
, "L4;L6"
, "L4;L7"
, ""))
levels(lin_lf$sel_lineages_f)
levels(lin_lf$sel_lineages)