Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuod committed Jun 1, 2018
2 parents 19c86d3 + fc3051f commit a428b96
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
49 changes: 37 additions & 12 deletions R/Wavelet_screaming.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,19 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
#n= n ind, c= number of confounder
#lev_res: lev of resolution for the wavelet filtering
#sigma_b= Para of prior, should be <1 advised 0.2




#To ensure the length not to be 0
Y <- as.vector(Y)
sigma_b <- sigma_b



# INPUT CHECKS
print("Input dimensions:")
if(!is.numeric(Y) | length(Y)==0){
stop("ERROR: Y is not a numeric vector")
stop("ERROR: Y is not a numeric vector")

} else {
print(sprintf("%i phenotypes detected", length(Y)))
if(all(Y %in% c(0,1))){
Expand All @@ -126,7 +133,7 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
print("Continuous phenotype detected")
}
}

# Writing the design matrix
if(missing(confounder)) {
print("no covariates provided, using intercept only")
Expand All @@ -138,6 +145,18 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
confounder <- cbind(rep(1,length(Y)),confounder)
}


print("Input dimensions:")
print(sprintf("Y: %i vector", length(Y)))
print(sprintf("loci: %i x %i", nrow(loci), ncol(loci)))
print(sprintf("bp: %i vector", length(bp)))



if(missing(coeftype))
{
coeftype <-"d"
}
# Check genotype matrix
if(missing(loci) | !is.numeric(loci)){
stop("ERROR: genotype matrix missing or not numeric")
Expand All @@ -146,12 +165,14 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
} else {
print(sprintf("%i SNPs for %i samples detected", nrow(loci), ncol(loci)))
}
# Check position vector

# Check position vector
if(!is.numeric(bp) | !is.vector(bp)){
stop("ERROR: must provide numeric position vector")
} else {
print(sprintf("positions for %i SNPs read", length(bp)))
print(sprintf("positions for %i SNPs read", length(bp)))


}

# Clean missing samples from all inputs
Expand Down Expand Up @@ -252,7 +273,7 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
N_obllikli = sum(logden)
O_obllikli = N_obllikli


for(iter in 0:niter){
pi = pp/(2^(gi))
logpi = log(pi)
Expand All @@ -277,10 +298,15 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
p_vec <-c(p_vec,pi)
}
return(p_vec)



}


###############
#Paralelisation
###############
if(para==TRUE)
{
cl <-makeCluster(detectCores(all.tests=TRUE)-1, type = "SOCK")
Expand Down Expand Up @@ -337,10 +363,10 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
#Modeling
##########
print("Computing Bayes Factors")
W <- as.matrix(confounder, ncol=ncol(confounder))
W <- as.matrix(confounder, ncol=ncol(confounder))
n = nrow(W)
q = ncol(W)

# L <- as.matrix(Y , ncol=ncol(Y)) #reversed regression
L <- as.matrix(Y,ncol=1)

Expand All @@ -356,8 +382,7 @@ Wavelet_screaming <- function(Y,loci,bp,confounder,lev_res,sigma_b,coeftype="d",
my_bf <- function( y ){
y <- as.matrix(y,ncol=1)
log.R = -0.5*n*log(1 - (t(y) %*% HB %*% y) / (t(y) %*% PW %*% y ))
# one can check:
# log.T = -0.5*log(det( t(X) %*% X * sigma_b * sigma_b + diag(p)))

bf = exp(log.T + log.R)
return(c(bf))
}
Expand Down
5 changes: 4 additions & 1 deletion R/plot_WS.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ plot_WS <- function(res,bp,lev_res,fill,dg)
{
dg=3
}

if(missing(bp))
{
bp=c(0,1)
}

res <- res[-c(1:(lev_res+2))]

Expand Down
Binary file added data/logT.RData
Binary file not shown.
26 changes: 18 additions & 8 deletions man/Wavelet_screaming.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/slice_definition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a428b96

Please sign in to comment.