|
| 1 | + |
| 2 | +# Load required packages |
| 3 | +suppressPackageStartupMessages({ |
| 4 | + library(argparse) |
| 5 | + library(qqman) |
| 6 | +}) |
| 7 | + |
| 8 | +# ---- ARGUMENT PARSING ---- |
| 9 | +parser <- ArgumentParser(description = "Run qqman on a PLINK .assoc file") |
| 10 | + |
| 11 | +parser$add_argument("-i", "--input", required = TRUE, |
| 12 | + help = "Input PLINK .assoc file") |
| 13 | +parser$add_argument("-m", "--manhattan", default = "manhattan_plot.png", |
| 14 | + help = "Output filename for Manhattan plot [default: manhattan_plot.png]") |
| 15 | +parser$add_argument("-q", "--qq", default = "qq_plot.png", |
| 16 | + help = "Output filename for Q-Q plot [default: qq_plot.png]") |
| 17 | + |
| 18 | +args <- parser$parse_args() |
| 19 | + |
| 20 | +# ---- LOAD DATA ---- |
| 21 | +assoc_data <- read.table(args$input, header = TRUE) |
| 22 | + |
| 23 | +# Validate required columns |
| 24 | +required_cols <- c("CHR", "BP", "SNP", "P") |
| 25 | +missing_cols <- setdiff(required_cols, colnames(assoc_data)) |
| 26 | +if (length(missing_cols) > 0) { |
| 27 | + stop(paste("Missing required columns in .assoc file:", paste(missing_cols, collapse = ", "))) |
| 28 | +} |
| 29 | + |
| 30 | +# ---- PLOTTING ---- |
| 31 | + |
| 32 | +# Manhattan plot |
| 33 | +png(args$manhattan, width = 1000, height = 600) |
| 34 | +manhattan(assoc_data, main = "Manhattan Plot") |
| 35 | +dev.off() |
| 36 | + |
| 37 | +# Q-Q plot |
| 38 | +png(args$qq, width = 600, height = 600) |
| 39 | +qq(assoc_data$P, main = "Q-Q Plot") |
| 40 | +dev.off() |
| 41 | + |
| 42 | +cat("Plots saved:\n") |
| 43 | +cat(" Manhattan plot:", args$manhattan, "\n") |
| 44 | +cat(" Q-Q plot:", args$qq, "\n") |
0 commit comments