Skip to content

Commit

Permalink
latest files
Browse files Browse the repository at this point in the history
  • Loading branch information
xlucpu committed Sep 28, 2020
1 parent c1d64b2 commit 3e01221
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
50 changes: 41 additions & 9 deletions R/compClinvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,51 @@ compClinvar <- function(moic.res = NULL,
if(!is.element(strata, colnames(dat))) {
stop("fail to find this strata in var2comp. Consider using NULL by default.")
}
stabl <- jstable::CreateTableOne2(vars = setdiff(colnames(dat), strata),
strata = strata,
data = dat,
factorVars = factorVars,
nonnormal = nonnormalVars,
exact = exactVars,
includeNA = includeNA,
showAllLevels = TRUE,
...)

warn <- NULL
tryCatch(stabl <-
jstable::CreateTableOne2(vars = setdiff(colnames(dat), strata),
strata = strata,
data = dat,
factorVars = factorVars,
nonnormal = nonnormalVars,
exact = exactVars,
includeNA = includeNA,
showAllLevels = TRUE,
...),
warning=function(w) {
warn <<- append(warn, conditionMessage(w))}
)
if(grepl("NA", warn, fixed = TRUE)) { # if get warning, probably due to the failure of computing exact p value in large data
set.seed(19991018)
stabl <- jstable::CreateTableOne2(vars = setdiff(colnames(dat), strata),
strata = strata,
data = dat,
factorVars = factorVars,
nonnormal = nonnormalVars,
exact = exactVars,
includeNA = includeNA,
showAllLevels = TRUE,
argsExact = list(simulate.p.value = T), # use simulated P values then
...)
} else {
stabl <- jstable::CreateTableOne2(vars = setdiff(colnames(dat), strata),
strata = strata,
data = dat,
factorVars = factorVars,
nonnormal = nonnormalVars,
exact = exactVars,
includeNA = includeNA,
showAllLevels = TRUE,
...)
}

# trim output
comtable <- as.data.frame(stabl)
comtable <- cbind.data.frame(var = rownames(stabl), comtable)
rownames(comtable) <- NULL; colnames(comtable)[1] <- " "
comtable[is.na(comtable)] <- ""
comtable <- comtable[,setdiff(colnames(comtable),"sig")] # remove significance
#print(comtable)

if(is.null(tab.name)) {
Expand Down
6 changes: 4 additions & 2 deletions R/getClustNum.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ getClustNum <- function(data = NULL,
par(bty="o", mgp = c(1.9,.33,0), mar=c(3.1,3.1,2.1,3.1)+.1, las=1, tcl=-.25)
plot(NULL, NULL,
xlim = c(min(try.N.clust),max(try.N.clust)),
ylim = c(min(optk1), max(optk1)),
#ylim = c(min(optk1), max(optk1)),
ylim = c(0,1),
xlab = "Number of Multi-Omics Clusters",ylab = "")
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "#EAE9E9",border = FALSE)
grid(col = "white", lty = 1, lwd = 1.5)
Expand All @@ -137,7 +138,8 @@ getClustNum <- function(data = NULL,
par(new = TRUE, xpd = FALSE)
plot(NULL,NULL,
xlim = c(min(try.N.clust),max(try.N.clust)),
ylim = c(min(optk2$gap), max(optk2$gap)),
#ylim = c(min(optk2$gap), max(optk2$gap)),
ylim = c(0,1),
xlab = "",ylab = "",xaxt = "n",yaxt = "n")
points(try.N.clust, optk2$gap, pch = 19, col = ggplot2::alpha("#E51718",0.8), cex = 1.5)
lines(try.N.clust, optk2$gap, col = "#E51718", lwd = 2, lty = 4)
Expand Down
8 changes: 6 additions & 2 deletions R/pRRophetic.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ calcPhenotype <- function(trainingExprData, trainingPtype, testExprData, batchCo
{

# check if the supplied data are of the correct classes
if(class(testExprData) != "matrix") stop("ERROR: \"testExprData\" must be a matrix.");
if(class(trainingExprData) != "matrix") stop("ERROR: \"trainingExprData\" must be a matrix.");
if(class(testExprData)[1] != "matrix") stop("ERROR: \"testExprData\" must be a matrix.");
if(class(trainingExprData)[1] != "matrix") stop("ERROR: \"trainingExprData\" must be a matrix.");
if(class(trainingPtype) != "numeric") stop("ERROR: \"trainingPtype\" must be a numeric vector.");
if(ncol(trainingExprData) != length(trainingPtype)) stop("The training phenotype must be of the same length as the number of columns of the training expressin matrix.");

Expand Down Expand Up @@ -567,6 +567,10 @@ pRRopheticPredict <- function(testMatrix, drug, tissueType="all", batchCorrect="
{
cgpTrainData <- getCGPinfo(drug, tissueType, dataset) # get the IC50 and expression data for this drug/tissueType

if(!all(!duplicated(colnames(cgpTrainData$trainDataOrd)))) { # duplicated gene expression in the same cell lines
cgpTrainData$trainDataOrd <- cgpTrainData$trainDataOrd[,!duplicated(colnames(cgpTrainData$trainDataOrd))]
}

predictedPtype <- calcPhenotype(cgpTrainData$trainDataOrd, cgpTrainData$ic50sOrd, testMatrix, batchCorrect=batchCorrect, powerTransformPhenotype=powerTransformPhenotype, removeLowVaryingGenes=removeLowVaryingGenes, minNumSamples=minNumSamples, selection=selection, printOutput=printOutput, removeLowVaringGenesFrom=removeLowVaringGenesFrom)

return(predictedPtype)
Expand Down

0 comments on commit 3e01221

Please sign in to comment.