Skip to content

Commit a11ad47

Browse files
authored
Merge pull request #66 from uclahs-cds/nzeltser-fix-plotting-bug
Nzeltser fix plotting bug
2 parents bbe9bf5 + 3621b31 commit a11ad47

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

R/plot-pgs.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ create.pgs.density.plot <- function(
157157

158158
# prettify x-axis labels (handle exponential notation)
159159
basic.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
160-
stats::quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
160+
stats::quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
161161
log.scaled = FALSE,
162162
num.labels = 3,
163163
include.origin = FALSE
@@ -200,7 +200,7 @@ create.pgs.density.plot <- function(
200200
warning(paste0('Skipping colors for ', pgs.column, ' and ', phenotype, ' due to too many categories'));
201201
# plot all lines in black
202202
group.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
203-
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
203+
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
204204
log.scaled = FALSE,
205205
num.labels = 3,
206206
include.origin = FALSE
@@ -237,7 +237,7 @@ create.pgs.density.plot <- function(
237237
}
238238

239239
group.xaxis.formatting <- BoutrosLab.plotting.general::auto.axis(
240-
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9)),
240+
quantile(unlist(pgs.data.for.plotting), probs = c(0.1, 0.9), na.rm = TRUE),
241241
log.scaled = FALSE,
242242
num.labels = 3,
243243
include.origin = FALSE
19 Bytes
Binary file not shown.

tests/testthat/generate-test-data.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ alt.alleles <- rep('T', length(genotypes));
226226
alt.alleles[genotypes == 1] <- 'A';
227227
alt.alleles[genotypes == 2] <- 'A';
228228

229-
binary.phenotype <- rbinom(n.samples, size = 1, prob = 0.5); # random binary phenotype values
229+
binary.phenotype <- rbinom(n.samples + 1, size = 1, prob = 0.5); # random binary phenotype values
230230
binary.factor.phenotype <- factor(binary.phenotype, levels = c(0, 1), labels = c('control', 'case'));
231-
categorical.phenotype <- factor(sample(letters[1:5], n.samples, replace = TRUE)); # random categorical phenotype values
231+
categorical.phenotype <- factor(sample(letters[1:5], n.samples + 1, replace = TRUE)); # random categorical phenotype values
232232

233233
phenotype.test.data <- list(
234234
# vcf with 10 samples and 10 variants
@@ -249,8 +249,8 @@ phenotype.test.data <- list(
249249
beta = rnorm(10) # random beta values
250250
),
251251
phenotype.data = data.frame(
252-
Indiv = paste0('sample', 1:n.samples),
253-
continuous.phenotype = rnorm(n.samples), # random phenotype values
252+
Indiv = paste0('sample', 1:(n.samples + 1)), # add an extra sample with no genotype data
253+
continuous.phenotype = rnorm(n.samples + 1), # random phenotype values
254254
binary.phenotype = binary.phenotype,
255255
binary.factor.phenotype = binary.factor.phenotype,
256256
categorical.phenotype = categorical.phenotype

tests/testthat/test-pgs-statistics.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ test_that(
138138
pgs <- seq(0, 1, length.out = nrow(phenotype.test.data$phenotype.data));
139139
phenotype.columns <- c('continuous.phenotype', 'binary.phenotype');
140140
phenotype.data <- phenotype.test.data$phenotype.data[ , phenotype.columns];
141-
phenotype.data$binary.factor <- rep(c('a', 'b'), 5); # should be included in the regression
142-
phenotype.data$categorical.phenotype <- rep(c('a', 'b', 'c', 'd', 'e'), 2); # should not be included in the regression
143-
phenotype.data$binary.factor <- rep(c('a', 'b'), 5);
141+
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a'); # should be included in the regression
142+
phenotype.data$categorical.phenotype <- c(rep(c('a', 'b', 'c', 'd', 'e'), 2), 'f'); # should not be included in the regression
143+
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a');
144144

145145
# run function
146146
regression.data <- run.pgs.regression(pgs = pgs, phenotype.data = phenotype.data);
@@ -177,8 +177,8 @@ test_that(
177177
pgs <- seq(0, 1, length.out = nrow(phenotype.test.data$phenotype.data));
178178
phenotype.columns <- c('continuous.phenotype', 'binary.phenotype');
179179
phenotype.data <- phenotype.test.data$phenotype.data[ , phenotype.columns];
180-
phenotype.data$binary.factor <- rep(c('a', 'b'), 5); # should be included in the regression
181-
phenotype.data$categorical.phenotype <- rep(c('a', 'b', 'c', 'd', 'e'), 2); # should not be included in the regression
180+
phenotype.data$binary.factor <- c(rep(c('a', 'b'), 5), 'a'); # should be included in the regression
181+
phenotype.data$categorical.phenotype <- c(rep(c('a', 'b', 'c', 'd', 'e'), 2), 'f'); # should not be included in the regression
182182

183183
# run function
184184
regression.data <- run.pgs.regression(pgs = pgs, phenotype.data = phenotype.data);

0 commit comments

Comments
 (0)