Skip to content

Commit

Permalink
fixed allele names in simulation and io tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonfparil committed Oct 28, 2024
1 parent 640ffbf commit f231684
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ _libs/
shell.nix
.*sqlite
.Rprofile
conda.yml
conda.yml
zellij.kdl
8 changes: 5 additions & 3 deletions R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,10 @@ fn_G_to_vcf = function(G, min_depth=100, max_depth=1000, verbose=FALSE) {
}
### Extract the names of the alternative alleles
if (is.null(G_alt)) {
vec_alleles_list = c("A", "T", "C", "G")
vec_alt = unlist(lapply(list_ids_chr_pos_all$vec_all, FUN=function(x){ sample(size=1, x=vec_alleles_list[grep(x, vec_alleles_list, ignore.case=TRUE, invert=TRUE)]) }))
# print("WARNING! Alternative alleles are unknown. Making psuedo-alleles.")
# vec_alleles_list = c("A", "T", "C", "G")
# vec_alt = unlist(lapply(list_ids_chr_pos_all$vec_all, FUN=function(x){ sample(size=1, x=vec_alleles_list[grep(x, vec_alleles_list, ignore.case=TRUE, invert=TRUE)]) }))
vec_alt = rep("N", times=ncol(G))
# vec_alt = rep("allele_alt", times=ncol(G))
} else {
### Convert the tabs in the loci-alleles names into dashes so as not to interfere with the VCF format
Expand Down Expand Up @@ -1512,7 +1514,7 @@ fn_filter_genotype = function(G, maf=0.01, sdev_min=0.0001,
)))
return(error)
}
if (sum(unique(list_ids_chr_pos_all$vec_all) %in% "allele_1") > 0) {
if (length(unique(list_ids_chr_pos_all$vec_all)) < 1) {
error = methods::new("gpError",
code=252,
message=paste0(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ test_that("fn_filter_genotype", {
expect_equal(sum(dim(G) == dim(G_filtered_1)), 2)
### Simulate SNP list for filtering
G = fn_load_genotype(list_sim$fname_geno_vcf, retain_minus_one_alleles_per_locus=FALSE)
colnames(G) = gsub("allele_1", "A", colnames(G)) ### Rename allele_1 and allele_alt to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("allele_alt", "T", colnames(G)) ### Rename allele_1 and allele_alt to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("allele_1", "A", colnames(G)) ### Rename allele_1 and N to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("N", "T", colnames(G)) ### Rename allele_1 and N to A and T, respectively to allow filtering using a SNP list
n_sim_missing = 100
mat_loci = matrix(unlist(strsplit(colnames(G), "\t")), byrow=TRUE, ncol=3)
vec_loci = unique(paste0(mat_loci[,1], "\t", mat_loci[,2]))
Expand All @@ -174,8 +174,8 @@ test_that("fn_filter_genotype", {
expect_equal(sum(abs(G_filtered_3 - G_filtered_2_split_G) < 1e-12), prod(dim(G_filtered_3)))
### Using additional filtering by sparsity (only works if G has missing data)
G = fn_load_genotype(list_sim$fname_geno_vcf, min_depth=10, max_depth=500)
colnames(G) = gsub("allele_1", "A", colnames(G)) ### Rename allele_1 and allele_alt to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("allele_alt", "T", colnames(G)) ### Rename allele_1 and allele_alt to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("allele_1", "A", colnames(G)) ### Rename allele_1 and N to A and T, respectively to allow filtering using a SNP list
colnames(G) = gsub("N", "T", colnames(G)) ### Rename allele_1 and N to A and T, respectively to allow filtering using a SNP list
G_filtered_4 = fn_filter_genotype(G=G, maf=0.05, max_n_alleles=1, fname_snp_list=fname_snp_list,
max_sparsity_per_locus=0.5,
frac_topmost_sparse_loci_to_remove=0.01,
Expand Down
12 changes: 12 additions & 0 deletions zellij.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
layout {
pane split_direction="vertical" {
pane split_direction="horizontal" {
pane
pane
}
pane
}
pane size=2 borderless=true {
plugin location="zellij:status-bar"
}
}

0 comments on commit f231684

Please sign in to comment.