[Genabel-commits] r1896 - pkg/MultiABEL/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 5 12:28:54 CET 2014
Author: shenxia
Date: 2014-12-05 12:28:54 +0100 (Fri, 05 Dec 2014)
New Revision: 1896
Modified:
pkg/MultiABEL/R/MultiMeta.R
pkg/MultiABEL/R/MultiRep.R
pkg/MultiABEL/R/Multivariate.R
Log:
v. 1.0-2; lines shortened; curly brackets added around "if" - "else" body; phdata() used instead of @phdata for stability.
Modified: pkg/MultiABEL/R/MultiMeta.R
===================================================================
--- pkg/MultiABEL/R/MultiMeta.R 2014-12-02 08:12:52 UTC (rev 1895)
+++ pkg/MultiABEL/R/MultiMeta.R 2014-12-05 11:28:54 UTC (rev 1896)
@@ -50,7 +50,9 @@
}
common <- common[common %in% rownames(reslist[[i]])]
}
- if (length(common) == 0) stop('no variant exists in all studies!')
+ if (length(common) == 0) {
+ stop('no variant exists in all studies!')
+ }
cat(' OK\n')
cat('meta-analysis ...')
pmat <- matrix(NA, length(common), k + 1)
Modified: pkg/MultiABEL/R/MultiRep.R
===================================================================
--- pkg/MultiABEL/R/MultiRep.R 2014-12-02 08:12:52 UTC (rev 1895)
+++ pkg/MultiABEL/R/MultiRep.R 2014-12-05 11:28:54 UTC (rev 1896)
@@ -103,7 +103,9 @@
cat(' OK\n')
if (ncol(training.geno) != 1) {
cat('replication analysis ...\n')
- } else cat('replication analysis ...')
+ } else {
+ cat('replication analysis ...')
+ }
for (k in 1:ncol(training.geno)) {
m0 <- lm(training.geno[,k] ~ Y0)
training.coef[,k] <- m0$coef[-1]
@@ -112,8 +114,14 @@
cy <- Y1 %*% training.coef[,k]
mrep <- lm(cy ~ test.geno[,k])
reptab[k,] <- c(summary(mrep)$coef[2,c(1:2, 4)], summary(mrep)$r.squared)
- if (ncol(training.geno) != 1) progress(k/ncol(training.geno)*100)
+ if (ncol(training.geno) != 1) {
+ progress(k/ncol(training.geno)*100)
+ }
}
- if (ncol(training.geno) == 1) cat(' OK\n') else cat('\n')
+ if (ncol(training.geno) == 1) {
+ cat(' OK\n')
+ } else {
+ cat('\n')
+ }
return(list(replication = reptab, training.coef = training.coef, test.coef = test.coef))
}
Modified: pkg/MultiABEL/R/Multivariate.R
===================================================================
--- pkg/MultiABEL/R/Multivariate.R 2014-12-02 08:12:52 UTC (rev 1895)
+++ pkg/MultiABEL/R/Multivariate.R 2014-12-05 11:28:54 UTC (rev 1896)
@@ -60,28 +60,50 @@
`Multivariate` <- function(gwaa.data = NULL, phenofile = NULL, genofile = NULL, outfile = 'Multivariate_GWAS_results.txt',
trait.cols, covariate.cols = NULL, cuts = 20, ...) {
cat('loading data ...')
- if (length(trait.cols) == 1) stop('select multiple traits to analyze!')
+ if (length(trait.cols) == 1) {
+ stop('select multiple traits to analyze!')
+ }
if (!is.null(phenofile) & !is.null(genofile)) {
pheno <- read.table(phenofile, header = TRUE)
geno <- databel(genofile)
- if (nrow(pheno) != nrow(geno)) stop('sizes of phenofile and genofile do not match!')
+ if (nrow(pheno) != nrow(geno)) {
+ stop('sizes of phenofile and genofile do not match!')
+ }
GenABEL <- FALSE
cat(' OK\n')
} else if (!is.null(gwaa.data)) {
- if (!is.null(phenofile)) pheno <- read.table(phenofile, header = TRUE) else pheno <- gwaa.data at phdata
+ if (!is.null(phenofile)) {
+ pheno <- read.table(phenofile, header = TRUE)
+ } else {
+ pheno <- phdata(gwaa.data)
+ }
GenABEL <- TRUE
cat(' OK\n')
} else {
stop('insufficient data input!')
}
cat('initializing analysis ...')
- if (!GenABEL) res <- matrix(NA, ncol(geno), 5) else res <- matrix(NA, ncol(gwaa.data at gtdata), 5)
+ if (!GenABEL) {
+ res <- matrix(NA, ncol(geno), 5)
+ } else {
+ res <- matrix(NA, ncol(gwaa.data at gtdata), 5)
+ }
colnames(res) <- c('MANOVA.stat', 'F.stat', 'df.num', 'df.den', 'P.F')
- if (!GenABEL) rownames(res) <- colnames(geno) else rownames(res) <- gwaa.data at gtdata@snpnames
+ if (!GenABEL) {
+ rownames(res) <- colnames(geno)
+ } else {
+ rownames(res) <- gwaa.data at gtdata@snpnames
+ }
Y <- as.matrix(pheno[,trait.cols])
X <- matrix(1, nrow(Y), 1)
- if (!is.null(covariate.cols)) X <- cbind(X, as.matrix(pheno[,covariate.cols]))
- if (!GenABEL) nsnp <- ncol(geno) else nsnp <- ncol(gwaa.data at gtdata)
+ if (!is.null(covariate.cols)) {
+ X <- cbind(X, as.matrix(pheno[,covariate.cols]))
+ }
+ if (!GenABEL) {
+ nsnp <- ncol(geno)
+ } else {
+ nsnp <- ncol(gwaa.data at gtdata)
+ }
if (cuts != 1) {
cutpoints <- round(seq(1, nsnp, length = cuts + 1))
starts <- cutpoints[1:cuts]
@@ -93,17 +115,31 @@
cat(' OK\n')
if (cuts != 1) {
cat('multivariate GWA scan ...\n')
- } else cat('multivariate GWA scan ...')
+ } else {
+ cat('multivariate GWA scan ...')
+ }
for (k in 1:cuts) {
idx <- starts[k]:ends[k]
- if (!GenABEL) g <- databel2matrix(geno[,idx]) else g <- as.double(gwaa.data at gtdata[,idx])
+ if (!GenABEL) {
+ g <- databel2matrix(geno[,idx])
+ } else {
+ g <- as.double(gwaa.data at gtdata[,idx])
+ }
for (j in 1:ncol(g)) {
stats <- try(summary(manova(Y ~ 0 + X + g[,j]), ...)$stats, silent = TRUE)
- if (!inherits(stats, 'try-error')) res[idx[j],] <- stats[nrow(stats) - 1,-1]
+ if (!inherits(stats, 'try-error')) {
+ res[idx[j],] <- stats[nrow(stats) - 1,-1]
+ }
}
- if (cuts != 1) progress(k/cuts*100)
+ if (cuts != 1) {
+ progress(k/cuts*100)
+ }
}
- if (cuts == 1) cat(' OK\n') else cat('\n')
+ if (cuts == 1) {
+ cat(' OK\n')
+ } else {
+ cat('\n')
+ }
cat('writing results ...')
write.table(res, outfile, row.names = TRUE, col.names = TRUE, quote = FALSE, sep = '\t')
cat(' OK\n')
More information about the Genabel-commits
mailing list