Mercurial > repos > iuc > gwastools_manhattan_plot
annotate manhattan.R @ 0:c4bf5e913c2e draft default tip
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
author | iuc |
---|---|
date | Fri, 11 Oct 2019 17:31:09 -0400 |
parents | |
children |
rev | line source |
---|---|
0
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
1 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
2 |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
3 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
4 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
5 |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
6 suppressPackageStartupMessages({ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
7 library(GWASTools) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
8 library(optparse) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
9 }) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
10 option_list <- list( |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
11 make_option(c("-f", "--file"), type="character", help="RInput GWAS file"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
12 make_option("--pval", type="integer", help="Pvalue column"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
13 make_option("--chromosome", type="integer", help="Chromosome column"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
14 make_option("--ymin", type="double", help="Min y value"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
15 make_option("--ymax", type="double", help="Max y value"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
16 make_option("--trunc", help="Show truncation lines", action="store_true"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
17 make_option("--sig", type="double", help="Significance level for lines"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
18 make_option("--thin", type="double", help="Thinning value", action="store_true", dest="thin"), |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
19 make_option("--ppb", type="integer", help="Points per bin, if thinning value is specified", action="store_true")) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
20 args <- parse_args(OptionParser(option_list=option_list)) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
21 file <- args$file |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
22 data <- read.table(args$file, header=TRUE) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
23 pval <- data[,args$pval] |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
24 chromosome <- data[,args$chromosome] |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
25 if(!is.null(args$ymin) & !is.null(args$ymax)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
26 ylimit <- c(args$ymin,args$ymax) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
27 }else if(xor(!is.null(args$ymin), !is.null(args$ymax))){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
28 print("If specifying range, both ymin and ymax must be set") |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
29 ylimit <- NULL |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
30 }else{ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
31 ylimit <- NULL |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
32 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
33 if(is.null(args$trunc)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
34 trunc <- FALSE |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
35 }else{ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
36 trunc <- TRUE |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
37 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
38 if(!is.null(args$sig)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
39 sig <- args$sig |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
40 }else{ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
41 sig <- NULL |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
42 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
43 if(!is.null(args$thin)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
44 thin = args$thin |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
45 if(thin == 0){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
46 thin = NULL |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
47 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
48 }else{ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
49 thin <- FALSE |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
50 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
51 if(!is.null(thin) & !is.null(args$ppb)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
52 ppb = args$ppb |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
53 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
54 pdf("manhattan.pdf") |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
55 if(isFALSE(thin)){ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
56 manhattanPlot(pval, chromosome, ylim=ylimit, trunc.lines=trunc, signif=sig) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
57 }else{ |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
58 manhattanPlot(pval, chromosome, ylim=ylimit, trunc.lines=trunc, signif=sig, thinThreshold = thin, pointsPerBin = ppb) |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
59 } |
c4bf5e913c2e
"planemo upload commit b1883bac95e73fc6ffe2a36db3115ad5e5a1eba4"
iuc
parents:
diff
changeset
|
60 invisible(dev.off()) |