-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpositions.R
42 lines (28 loc) · 1.02 KB
/
positions.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
37
38
39
40
41
42
# Some SNPs might not be on this chromosome
# Some might be out of order
# Most will probably have the wrong physical position
#R --no-save --args ${chrdata}.bim ${refroot}.markers ${chrdata}.newpos < ${positionsR}
args <- commandArgs(T)
datname <- args[1]
refname <- args[2]
outname <- args[3]
dat <- read.table(datname)
ref <- read.table(refname, header=T)
ref <- subset(ref, select=c(id, position, a0, a1))
# SNPs absent from reference chromosome
missingsnps <- as.character(dat$V2[! dat$V2 %in% ref$id])
if(length(missingsnps) > 0)
{
write.table(missingsnps, file=paste(outname, ".missingsnps", sep=""), row=F, col=F, qu=F)
dat <- subset(dat, ! V2 %in% missingsnps)
}
# SNPs in the wrong position, ignore order this will be handled by plink
dat$V2 <- as.character(dat$V2)
ref$id <- as.character(ref$id)
a <- merge(dat, ref, by.x="V2", by.y="id", all.x=T)
a <- a[order(a$V4), ]
stopifnot(all(a$V1 == dat$V1))
stopifnot(all(!is.na(a$V2)))
a <- a[, c(1,7)]
write.table(a, outname, row=F, col=F, qu=F)
# now run plink --update-map