Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active March 16, 2017 12:39
Show Gist options
  • Save explodecomputer/52cec336daba269722969cb0b0ed3fbe to your computer and use it in GitHub Desktop.
Save explodecomputer/52cec336daba269722969cb0b0ed3fbe to your computer and use it in GitHub Desktop.
example plink
library(data.table)
arguments <- commandArgs(T)
chipfile <- arguments[1]
pcfile <- arguments[2]
qcovfile <- arguments[3]
dcovfile <- arguments[4]
outfile <- arguments[5]
filelist <- c(chipfile, pcfile, qcovfile, dcovfile)
filelist <- filelist[filelist != "NULL"]
l <- lapply(filelist, function(x) {
a <- fread(x)
message(x, ": ", nrow(a), " samples")
names(a)[1] <- "V1"
names(a)[2] <- "V2"
return(a)
})
# keep 10 PCs only
l[[2]] <- l[[2]][,1:12]
out <- merge(l[[1]], l[[2]], by=c("V1", "V2"))
if(length(l) > 2)
{
n <- length(l)
for(i in 3:n)
{
out <- merge(out, l[[i]], by=c("V1", "V2"))
}
}
stopifnot(all(names(out)[1:2] == c("V1", "V2")))
names(out)[1:2] <- c("FID", "IID")
message("Samples remaining: ", nrow(out))
write.table(out, file=outfile, row=FALSE, col=TRUE, quote=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment