Skip to content

Commit c199159

Browse files
author
Veera
committed
column names autodetection
1 parent 03b7883 commit c199159

7 files changed

Lines changed: 209 additions & 127 deletions

File tree

R/.#ggman.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
veera@hello908.local.69747

R/.Rhistory

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,3 @@
1-
get(gwas.sig)
2-
get(gwas.sig)
3-
deparse(substitute(gwas.sig))
4-
ggmanLabel(p1,labelDfm = gwas.sig)
5-
ggmanLabel(p1,labelDfm = gwas.sig)
6-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP1")
7-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP")
8-
names(gwasSig)
9-
names(gwas.sig)
10-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP")
11-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "SNP",type="hello")
12-
temp = data.frame(snp = c("rs88888"))
13-
temp
14-
ggmanLabel(p1,temp,snp="snp")
15-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "SNP")
16-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "SNP")
17-
library(ggman)
18-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "SNP")
19-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = paste0(CHR,":",BP))
20-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "BP")
21-
p1
22-
names(p1)
23-
p1$scales
24-
p1$mapping
25-
p1$theme
26-
p1$facet
27-
names(p1)
28-
p1$plot_env
29-
p1$guides
30-
ggmanLabel(p1,labelDfm = gwas.sig, snp = "SNP", label = "BP")
31-
ggmanHighlight(p1,highlights)
32-
ggmanHighlight(p1,highlights)
33-
ggmanHighlight(p1,highlights,colour="green")
34-
ggmanHighlight(p1,highlights,colour="green", size = 0.1)
35-
ggmanHighlight(p1,highlights,colour="green", size = 0.1)
36-
is.vector
37-
a = c(1,2,3)
38-
a
39-
is.vector(a)
40-
b = c("A","B","C")
41-
b
42-
is.vector(b)
43-
class(b)
44-
class(a)
45-
ls()
46-
temp
47-
ggmanHighlight(p1,highlight = c("rsaaaa"))
48-
ggmanHighlight(p1,highlight = c("rsaaaa"))
49-
ggmanHighlight(p1,highlight = c("rsaaaa"))
50-
ls()
51-
temp <- gwas.sig[gwas.sig$SNP %in% c("rsaaa"),]
52-
temp
53-
nrow(temp)
54-
ggmanHighlight(p1,highlight = c("rsaaaa"))
55-
ggmanHighlight(p1,highlights,colour="a"
56-
)
57-
ggmanHighlight(p1,highlights,colour="a"
58-
)
59-
head (gwas)
60-
ls()
61-
ggmanZoom(p1, chromosome = "chr1")
62-
ggmanZoom(p1, chromosome = "chr1")
63-
ggmanZoom(p1, chromosome = "1")
64-
ggmanZoom(p1, chromosome = c(1,2))
65-
ggmanZoom(p1, chromosome = 1,start.position="a")
66-
ggmanZoom(p1, chromosome = 1,start.position=1,end.posiiton = "b")
67-
ggmanZoom(p1, chromosome = 1,start.position=1,end.posiiton = "b")
68-
head(gwas)
69-
ggmanZoom(p1, chromosome = 1,start.position=1,end.posiiton = 100)
70-
ggmanZoom(p1, chromosome = 1,start.position=1,end.posiiton = 100)
71-
ggmanZoom(p1, chromosome = 1,start.position=1,end.position = 100)
72-
ggmanZoom(p1, chromosome = 1,start.position=1,end.position = 100)
73-
p2 = ggmanZoom(p1, chromosome = 1,start.position=1,end.position = 100)
74-
head(gwas.sig)
75-
head(gwa)
76-
head(gwas)
77-
ggmanHighlight(p2,highlight = c("rs1_0_M","rs1_1","rs1_2"))
78-
head(gwas.sig)
79-
head(gwas)
80-
ggplot(gwas[1:100,], aes(BP,P)) + geom_point()
81-
library(ggplot2)
82-
ggplot(gwas[1:100,], aes(BP,P)) + geom_point()
83-
ggplot(gwas[1:100,], aes(BP,P, colour = as.factor(CHR))) + geom_point()
84-
p1 = ggplot(gwas[1:100,], aes(BP,P, colour = as.factor(CHR))) + geom_point()
85-
p1 + ggplot(gwas[1:10,],aes(colour = BP))
86-
p1 + ggplot(gwas[1:10,],aes(colour = as.factor(BP)))+ geom_point()
87-
p1 + ggplot(gwas[1:10,],aes(colour = as.factor(BP)))+ geom_point(da)
88-
p1 + geom_point(data = gwas[1:10,], aes(colour = as.factor(BP)))
89-
p1 = ggplot(gwas[1:100,], aes(BP,P, fill = as.factor(CHR))) + geom_point()
90-
p1 = ggplot(gwas[1:100,], aes(BP,P, fill = as.factor(CHR))) + geom_point() + guides(fill = FALSE)
911
p1 = ggplot(gwas[1:100,], aes(BP,P, fill = as.factor(CHR))) + geom_point() + guides(fill = FALSE)
922
p1 + geom_point(data = gwas[1:10,], aes(colour = as.factor(BP)))
933
p1 + geom_point(data = gwas[1:10,], aes(colour = as.factor(BP))) + scale_fill_grey()
@@ -498,3 +408,93 @@ mySession = browserSession("UCSC")
498408
genome(mySession) = "mm10"
499409
myrange = GRanges("chr6", IRanges(20400587, 20403336))
500410
myrange
411+
pmatch
412+
a =c("chrom","Chrom","Chromosome","chromosome","CHROMOSOME","CHR")
413+
grep ("chr",a)
414+
grep ("chr",a, ignore.case=TRUE)
415+
grep ("chrom",a, ignore.case=TRUE)
416+
grep ("\bchrom",a, ignore.case=TRUE)
417+
grep ("\\bchrom",a, ignore.case=TRUE)
418+
grep ("\\bchrom\\b",a, ignore.case=TRUE)
419+
ls()
420+
dfmnames <- c("CHR","SNP","P","BP")
421+
search.names("chr")
422+
search.names("chr")
423+
search.names("snp")
424+
search.names("bp")
425+
search.names("p")
426+
search.names("p")
427+
search.names("p")
428+
dfmnames <- c("CHromosome","BP","Snp","Pvalue")
429+
search.names("p")
430+
search.names(c("p","pvalue"))
431+
search.names(c("pvalue","p"))
432+
search.names(c("pvalue","p","pvalue"))
433+
search.names(c("pvalue","p","pvalue"))
434+
search.names(c("chr"))
435+
search.names(c("chr","chrom"))
436+
search.names(c("chr","chrom","chromosome"))
437+
search.names("bp")
438+
dfmnames <- c("CHromosome","Base Pair","Snp","Pvalue")
439+
search.names("bp")
440+
search.names("base")
441+
search.names("basepair")
442+
dfmnames <- c("CHromosome","Base_pair","Snp","Pvalue")
443+
search.names("basepair")
444+
library(ggman)
445+
search.dfm.names(toy)
446+
dfmnames <- names(toy.gwas)
447+
search.dfm.names(toy.gwas)
448+
temp = search.dfm.names(toy.gwas)
449+
names(temp)
450+
temp = search.dfm.names(toy.gwas)
451+
temp
452+
names(temp)
453+
temp = search.dfm.names(toy.gwas)
454+
temp
455+
dfm.names <- c("bp","BP","basepair")
456+
dfmnames <- c("bp","BP","basepair")
457+
search.names("bp")
458+
dfmnames <- c("bp")
459+
search.names("bp")
460+
dfmnames <- c("bp","BP")
461+
search.names("bp")
462+
temp
463+
names(toy.gwas)
464+
names(toy.gwas)[1] <- "marker"
465+
names(toy.gwas)
466+
search.dfm.names(toy.gwas)
467+
dfmnames <- c("bp","BP")
468+
search.names("bp")
469+
temp = search.names("bp")
470+
class(temp)
471+
is.null(temp)
472+
search.dfm.names(toy.gwas)
473+
temp = search.dfm.names(toy.gwas)
474+
grep(NA,temp)
475+
grep("NA",temp)
476+
is.na(temp)
477+
which(is.na(temp))
478+
which(is.na(temp))
479+
names(temp)[which(is.na(temp))]
480+
names(toy.gwas)
481+
names(toy.gwas)[2] <- "brom"
482+
temp = search.dfm.names(toy.gwas)
483+
temp
484+
names(toy.gwas)[2] <- "brom"
485+
names(temp)[which(is.na(temp))]
486+
temp = names(temp)[which(is.na(temp))]
487+
paste(temp)
488+
ls()
489+
temp
490+
temp = search.dfm.names(toy.gwas)
491+
temp
492+
temp$bp
493+
temp["bp"]
494+
head(toy.gwas[,temp["bp"]])
495+
library(ggman)
496+
ggman(toy,gwas)
497+
ggman(toy,gwas)
498+
search.names()
499+
ggman(toy,gwas)
500+
ggman(toy.gwas)

R/check.input.ggman.R

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,46 @@ check.input.ggman <- function(){
2626
if(!any(class(gwas) == "data.frame")){
2727
stop("The gwas input is not a data frame")
2828
}
29-
## snp input
30-
if(class(snp) != "character"){
31-
stop("The snp input is not a character")
32-
}
33-
if(!snp %in% names(gwas)){
34-
stop(paste0("The column \'",snp,"\' is not present in the input data frame"))
35-
}
36-
## bp input
37-
if(class(bp) != "character"){
38-
stop("The bp input is not a character")
39-
}
40-
if(! bp %in% names(gwas)){
41-
stop(paste0("The column \'",bp,"\' is not present in the input data frame"))
42-
}
4329

44-
##chrom input
45-
if(class(chrom) != "character"){
46-
stop("The chrom input is not a character")
47-
}
48-
if(! chrom %in% names(gwas)){
49-
stop(paste0("The column \'",chrom,"\' is not present in the input data frame"))
50-
}
30+
dfmnames <- names(gwas)
5131

52-
## pvalue input
53-
if(class(pvalue) != "character"){
54-
stop("The pvalue input is not a character")
55-
}
56-
if(! pvalue %in% names(gwas)){
57-
stop(paste0("The column \'",pvalue,"\' is not present in the input data frame"))
58-
}
32+
##chrom input
33+
if(class(chrom) != "character"){
34+
stop("The chrom input is not a character")
35+
}
36+
if(! chrom %in% names(gwas)){
37+
stop(paste0("The column \'",chrom,"\' is not present in the input data frame"))
38+
}
39+
40+
41+
42+
if(class(snp) != "character"){
43+
stop("The snp input is not a character")
44+
}
45+
if(!snp %in% names(gwas)){
46+
stop(paste0("The column \'",snp,"\' is not present in the input data frame"))
47+
}
48+
49+
50+
51+
## bp input
52+
if(class(bp) != "character"){
53+
stop("The bp input is not a character")
54+
}
55+
if(! bp %in% names(gwas)){
56+
stop(paste0("The column \'",bp,"\' is not present in the input data frame"))
57+
}
58+
59+
60+
## pvalue input
61+
if(class(pvalue) != "character"){
62+
stop("The pvalue input is not a character")
63+
}
64+
if(! pvalue %in% names(gwas)){
65+
stop(paste0("The column \'",pvalue,"\' is not present in the input data frame"))
66+
}
5967

68+
6069
## sigline input
6170
if(!is.na(sigLine)){
6271
if(!is.numeric(sigLine)){

R/ggman.R

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ utils::globalVariables(c("index","marker","chrom_alt","group","xbreaks"))
7878
#' @export
7979
ggman <- function(gwas,
8080
clumps = NA,
81-
snp = "snp", bp = "bp", chrom = "chrom", pvalue = "pvalue",
81+
snp = NA, bp = NA, chrom = NA, pvalue = NA,
8282
sigLine = 8,
8383
lineColour = "red",
8484
pointSize = 0.1,
@@ -91,9 +91,45 @@ ggman <- function(gwas,
9191

9292
##define global variables to escape R CMD check
9393

94-
##check the inputs
94+
95+
dfmnames <- names(gwas)
96+
## chrom input
97+
if(is.na(chrom)){
98+
chrom <- search.names(c("chr","chrom","chromosome"), dfmnames)
99+
if(is.null(chrom)){
100+
stop("Couldn't find the chromosome column.
101+
Specify the name of the column with chromosome ids")
102+
}
103+
}
104+
105+
if(is.na(snp)){
106+
snp <- search.names(c("snp","rsid"), dfmnames)
107+
if(is.null(snp)){
108+
stop("Couldn't find the snp column.
109+
Specify the name of the column with snp ids")
110+
}
111+
}
112+
113+
if(is.na(bp)){
114+
bp <- search.names(c("bp","basepair","position","start"),dfmnames)
115+
if(is.null(bp)){
116+
stop("Couldn't find the bp column.
117+
Specify the name of the column with bp ids")
118+
}
119+
}
120+
if(is.na(pvalue)){
121+
pvalue <- search.names(c("p","pval","pvalue"), dfmnames)
122+
if(is.null(pvalue)){
123+
stop("Couldn't find the pvalue column.
124+
Specify the name of the column with pvalues")
125+
}
126+
}
127+
128+
129+
##check the inputs
95130
environment(check.input.ggman) <- environment()
96131
check.input.ggman()
132+
97133
dfm <- as.data.frame(gwas)
98134
dfm$chrom <- dfm[,chrom]
99135
dfm$bp <- as.numeric(as.character(dfm[,bp]))

R/search.dfm.names.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#' search.names
3+
#'
4+
#' @keywords internal
5+
#'
6+
#' @return Nothing; internal function
7+
#'
8+
search.names <- function(term,dfmnames){
9+
for(i in 1:length(term)){
10+
res <- grep(paste0("\\b",term[i],"\\b"),dfmnames, ignore.case = TRUE)
11+
if(length(res)>0){
12+
if(length(res)==1){
13+
return(dfmnames[res])
14+
}
15+
}
16+
}
17+
}
18+
19+
20+

man/ggman.Rd

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/search.names.Rd

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)