-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing_plot.R
36 lines (29 loc) · 1.03 KB
/
missing_plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
##########
# Author: Ben Anderson
# Date: Nov 2021
# Description: assess/plot the amount of missing data per sample in a VCF (arg1)
##########
# parse the command line
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
stop("Missing argument for VCF file", call. = FALSE)
} else {
vcf_file <- args[1]
}
# load the library, analyse the VCF, and plot missing data per sample
suppressMessages(library(vcfR))
myvcf <- read.vcfR(vcf_file, verbose = FALSE)
gt <- extract.gt(myvcf, element = "GT")
missing <- apply(gt, MARGIN = 2, function(x) { sum(is.na(x)) })
missing <- 100 * missing / nrow(myvcf)
pdf("missing.pdf", width = 40, height = 20)
par(mar = c(20, 4, 4, 2))
par(fig = c(0, 0.9, 0, 1))
barplot(missing, las = 2, cex.axis = 2, ylim = c(0, max(missing) + 0.1 * max(missing)))
par(fig = c(0.85, 1, 0, 1), new = TRUE)
boxplot(missing, axes = FALSE, ylim = c(0, max(missing) + 0.1 * max(missing)))
mtext("Percent missing data per sample", side = 3,
outer = TRUE, line = -4, cex = 4)
invisible(dev.off())
# summarise
summary(missing)