Skip to content

Commit 87b96df

Browse files
committed
major update to version 0.4
1 parent 969efc6 commit 87b96df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1833
-4095
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
.Rproj.user
22
.Rhistory
33
.RData
4+
plotly_credentials
5+
NEWS.Rmd
6+
README.html
7+
test.r
8+
version_info

NEWS.html

Lines changed: 0 additions & 101 deletions
This file was deleted.

NEWS.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
2+
13
### Features and Fixes
4+
#### version 0.4 (1/25/2015)
5+
* added missing values validation
6+
* added plotly interface
7+
* O-PLS feature selection validation
8+
* removed view and updated manage
9+
* added custom icons and CSS
10+
* added responsive navigation bar
211
#### version 0.3.2 (11/01/14)
3-
* fixed repeated measures ANOVA
4-
12+
* fixed repeated measures ANOVA
513
#### version 0.3.1 (10/09/14)
614
* fixed fold change calculation bug
7-
815
#### version 0.3.0 (09/24/14)
916
* added normalization module
1017
* added pathway enrichment analysis module under Biochemical
@@ -14,4 +21,3 @@
1421
* added new plot types, stats and fixed minor bugs in the PLot module
1522
* disabled multi Y O/PLS (temporary?) and added O/PLS-DA stats
1623
* new progress indicator
17-

R/Devium Cluster Analysis.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ devium.heatmap<-function(data, class.factor=NULL, class.color=NULL, heatmap.colo
1616

1717
# calculate correlations
1818
if(!type=="none"& !type == "z.scale" ){
19-
tmp<-devium.calculate.correlations(tmp.data,type=type)
19+
tmp<-devium.calculate.correlations(tmp.data,type=type,results="matrix")
2020
tmp.data<-tmp$cor
2121
tmp.data.pvalue<-tmp$p.value
2222

R/Devium PLS and OPLS.r

Lines changed: 122 additions & 82 deletions
Large diffs are not rendered by default.

R/Devium Statistics.r

Lines changed: 99 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
#calculate area under the curve (AUC) for multiple groups
2+
multi.group.AUC<-function(data,subject.id,sample.type, time){
3+
library(pracma)
4+
#too lazy to rename objects from older fxn
5+
subject.id<-as.factor(subject.id)
6+
fact<-as.factor(sample.type) #sample type factor
7+
tme<-as.factor(time) #time
8+
9+
#split objects
10+
tmp.data<-split(data.frame(data),fact)
11+
tmp.time<-split(tme,fact)
12+
tmp.subs<-split(as.character(subject.id),fact)
13+
14+
group.AUC<-lapply(1:nlevels(fact),function(i){
15+
ddata<-tmp.data[[i]]
16+
ttime<-tmp.time[[i]]
17+
subs<-tmp.subs[[i]]
18+
19+
#calculate AUC
20+
AUC<-sapply(1:length(ddata),function(i)
21+
{
22+
23+
obj<-split(as.data.frame(ddata[[i]]),subs)
24+
#subtract baseline (first level of time) to correct negative AUC
25+
tmp.time<-split(ttime,subs)
26+
base.time<-levels(ttime)[1]
27+
base.obj<-lapply(1:length(obj),function(j)
28+
{
29+
tmp<-as.numeric(as.matrix(unlist(obj[[j]])))
30+
tmp-tmp[tmp.time[[j]]==base.time]
31+
})
32+
tmp<-split(as.data.frame(ttime),subs)
33+
#x11()
34+
#plot(as.numeric(as.matrix(do.call("cbind",tmp))),as.numeric(as.matrix(do.call("cbind",base.obj))))
35+
out<-as.data.frame(sapply(1:length(obj),function(j)
36+
{
37+
x<-as.numeric(as.matrix(unlist(tmp[[j]])))
38+
o<-order(x) # need to be in order else AUC will be wrong!
39+
y<-as.numeric(as.matrix(unlist(base.obj[[j]])))
40+
trapz(x[o],y[o])
41+
}))
42+
colnames(out)<-colnames(data[i])
43+
out
44+
})
45+
tmp<-do.call("cbind",AUC)
46+
rownames(tmp)<-paste(levels(fact)[i],names(split(as.data.frame(ttime),subs)),sep="_")
47+
tmp
48+
})
49+
res<-do.call("rbind",group.AUC)
50+
colnames(res)<-colnames(data)
51+
return(res)
52+
}
53+
154
#function to convert pattern to a single char objects name
255
rename <- function(x, pattern, replace="_"){
356
#strangely sapply will not work without effort here
@@ -9,7 +62,6 @@ rename <- function(x, pattern, replace="_"){
962
return(x)
1063
}
1164

12-
1365
# relative standard deviation
1466
#redo calc.stat using dplyr
1567
calc.rsd<-function(data,factor,sig.figs=2){
@@ -134,7 +186,7 @@ anova.formula.list<-function(data,formula,meta.data){
134186
}
135187

136188
#ANOVA with repeated measures and post hoc
137-
aov.formula.list<-function(data,formula,meta.data=factor,post.hoc=TRUE,repeated=NULL,p.adjust="BH"){
189+
aov.formula.list<-function(data,formula,meta.data=factor,post.hoc=TRUE,repeated=NULL,FDR="BH"){
138190
#formula = formula excluding repeated terms
139191
#meta data = all factors
140192
#repeated name of factor for repeated measures
@@ -147,6 +199,7 @@ aov.formula.list<-function(data,formula,meta.data=factor,post.hoc=TRUE,repeated=
147199
results<-list(p.value=vector("list",ncol(data)),post.hoc=vector("list",ncol(data)))
148200
for(i in 1:ncol(data)){
149201
model<-tryCatch(aov(as.formula(paste("data[,",i,"]~",formula,sep="")),data=tmp.data), error=function(e){NULL})
202+
150203
#get p-values
151204
if(!is.null(repeated)){
152205
names<-attr(model$Within$terms,'term.labels')
@@ -157,6 +210,7 @@ aov.formula.list<-function(data,formula,meta.data=factor,post.hoc=TRUE,repeated=
157210
p.values<-data.frame(t(summary(model)[[1]][1:length(names),5,drop=FALSE]))
158211
dimnames(p.values)<-list(colnames(data)[i],names)
159212
}
213+
160214
#pairwise t-tests (repeated) or TukeyHSD
161215
if(post.hoc){
162216
if(!is.null(repeated)){
@@ -184,11 +238,16 @@ aov.formula.list<-function(data,formula,meta.data=factor,post.hoc=TRUE,repeated=
184238
post.h<-NULL
185239
}
186240

241+
187242
results$p.value[[i]]<-p.values
188243
results$post.hoc[[i]]<-post.h
189244

190245
}
191-
return(list(p.values=do.call("rbind",results$p.value),post.hoc=do.call("rbind",results$post.hoc)))
246+
tmp<-do.call("rbind",results$p.value)
247+
FDR.p<-sapply(1:ncol(tmp), function(i) p.adjust(tmp[,i],method=FDR))
248+
colnames(FDR.p)<-colnames(tmp)
249+
p.vals<-data.frame(p.values=tmp,FDR.p.values=FDR.p)
250+
return(list(p.values=p.vals,post.hoc=do.call("rbind",results$post.hoc)))
192251

193252
}
194253

@@ -258,35 +317,40 @@ stats.summary <- function(data,comp.obj,formula,sigfigs=3,log=FALSE,rel=1,do.sta
258317
}
259318

260319
#function to carry out covariate adjustments
261-
#-------------------------
262320
covar.adjustment<-function(data,formula){
263-
#set up that formula objects need to exists in the global environment --- fix this
264-
#data--> subjects as rows, measurements as columns
265-
#formula <- ~ character vector
266-
#lm will be iteratively fit on each variable
267-
#model residuals + preadjusted column median will be returned
268-
data<-as.data.frame(data)
269-
names(data)<-colnames(data)
270-
output<-list()
271-
n<-ncol(data)
272-
output<-lapply(1:n,function(i)
273-
{
274-
tryCatch(tmp<-as.formula(c(paste(paste("data$'",colnames(data)[i],"'~",sep=""),paste(formula,sep="+"),sep=""))),
275-
error= function(e){tmp<-as.formula(c(paste(paste("data[,i]","~",sep=""),paste(formula,sep="+"),sep="")))})
276-
fit<-lm(tmp,data=data)$residuals
277-
matrix(fit,,1)
278-
})
279-
out<-data.frame(do.call("cbind",output))
280-
tryCatch(dimnames(out)<-dimnames(data), error=function(e){NULL}) # no clue why this throws errors randomly
281-
#add back pre-adjustment column min to all
282-
min<-apply(out,2,min, na.rm=T)
283-
adj.out<-do.call("cbind",sapply(1:ncol(out),function(i)
284-
{
285-
out[,i,drop=F] + abs(min[i])
286-
}))
287-
return(adj.out)
288-
}
289-
321+
#set up that formula objects need to exists in the global environment --- fix this
322+
#data--> subjects as rows, measurements as columns
323+
#formula <- ~ character vector
324+
#lm will be iteratively fit on each variable
325+
#model residuals + preadjusted column median will be returned
326+
327+
#convert all to numeric
328+
tmp<-dimnames(data)
329+
data<-data.frame(do.call("cbind",lapply(data,as.numeric)))
330+
dimnames(data)<-tmp
331+
output<-list()
332+
n<-ncol(data)
333+
output<-lapply(1:n,function(i)
334+
{
335+
tryCatch(tmp<-as.formula(c(paste(paste("data$'",colnames(data)[i],"'~",sep=""),paste(formula,sep="+"),sep=""))),
336+
error= function(e){tmp<-as.formula(c(paste(paste("data[,i]","~",sep=""),paste(formula,sep="+"),sep="")))})
337+
fit<-lm(tmp,data=data)$residuals
338+
#need to account for missing values
339+
tmp<-data[,i]
340+
tmp[!is.na(tmp)]<-fit
341+
matrix(tmp,,1)
342+
})
343+
out<-data.frame(do.call("cbind",output))
344+
tryCatch(dimnames(out)<-dimnames(data), error=function(e){NULL}) # no clue why this throws errors randomly
345+
#add back pre-adjustment column min to all
346+
min<-apply(out,2,min, na.rm=T)
347+
adj.out<-do.call("cbind",sapply(1:ncol(out),function(i)
348+
{
349+
out[,i,drop=F] + abs(min[i])
350+
}))
351+
return(adj.out)
352+
}
353+
290354
#helper function for getting statistics for making box plots
291355
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,conf.interval=.95, .drop=TRUE) {
292356
require(plyr)
@@ -462,14 +526,15 @@ simple.lme<-function(data,factor,subject,FDR="BH", progress=TRUE,interaction=FAL
462526
#multi-LME with formula interface (also see simple.lme) # note random term should be +(1|random.term)
463527
formula.lme<-function(data,formula,FDR="BH", progress=TRUE){
464528
#data = data.frame of values to test and test factors
465-
#factor = object to be tested
466-
#subject = identifier for repeated measures
529+
467530
check.get.packages(c("lme4","car"))
468531
#not sure how to ignore test factors in data, cause error in loop
469532

470533
if (progress == TRUE){ pb <- txtProgressBar(min = 0, max = ncol(data), style = 3)} else {pb<-NULL}
471534
lmer.p.values<-do.call("rbind",lapply(1:ncol(data), function(i){
472535
if (progress == TRUE){setTxtProgressBar(pb, i)}
536+
#avoid factor error, should avoid anova error below
537+
if(is.factor(data[,i])| is.character(data[,i])) data[,i]<-fixlf(data[,i])
473538
mod<-tryCatch(lmer(as.formula(paste0("data[,",i,"]~", formula)), data=data),error=function(e){NULL})
474539
if(is.null(mod)){1} else {
475540
res<-Anova(mod)
@@ -608,6 +673,7 @@ multi.pairwise.mann.whitney<-function(data,factor,progress=TRUE,FDR="BH",qvalue=
608673
res
609674
}))
610675
}
676+
611677
#Tests
612678
test<-function(){
613679

R/Devium common functions.R

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ afixln<-function(a,keep.factors=FALSE){
2626
return(obj)
2727
}
2828

29-
3029
#convert all columns of a data.frame or matrix to numeric (encoding characters) optional preserving factors
3130
afixlnf<-function(a,factors=TRUE){
3231

@@ -80,6 +79,7 @@ fixlt<-function(obj) {
8079
}
8180

8281
#remove unused levels in factors
82+
#before droplevels
8383
fixfactors<-function(obj) {
8484
#check what can be numeric
8585
# fct<-apply(apply(apply(tmp,2,as.numeric),2,is.na),2,all) # a better way must exist?
@@ -91,7 +91,6 @@ fixfactors<-function(obj) {
9191
return(obj)
9292
}
9393

94-
9594
#import from clipboard
9695
read.excel <- function(type="with.dimnames") {
9796
#assume row and colnames are included but may not be unique
@@ -234,9 +233,8 @@ devium.data.format<-function(obj, type){
234233
}
235234

236235
#format binbase output (data with meta data structure)
237-
format.binbase.output<-function(data)
238-
{
239-
236+
format.binbase.output<-function(data){
237+
#first row must have some ID
240238
#data = name as string
241239
object<-get(data)#need to adjust for first row taken as column names
242240
#format data object
@@ -274,12 +272,13 @@ format.binbase.output<-function(data)
274272
# need to break factors
275273

276274
#return results as a list
277-
list(data=tmp.data,row.metadata=row.meta,col.metadata=col.meta)
275+
list(data=data.frame(tmp.data),row.metadata=data.frame(row.meta),col.metadata=data.frame(col.meta))
278276
}
279277

278+
280279
#return objects to excel
281280
return.to.Excel<-function(workbook.path="new",return.obj.list,return.name=names(return.obj.list),workbook.name=NULL)
282-
{
281+
{
283282
check.get.packages(c("XLConnect"))
284283

285284
#load workbok
@@ -348,7 +347,7 @@ list.placement.full<-function(data.list,list.names,direction,start.col,start.row
348347

349348
# accesory fxn to list.placement.full
350349
list.object.dim.full<-function(data.list,list.names)
351-
{
350+
{
352351
l.dim<-list()
353352
n<-length(data.list)
354353
i<-1
@@ -518,8 +517,7 @@ unique.id<-function(obj)
518517
}
519518

520519
#function to check for packages and attempt to download if not found
521-
check.get.packages<-function(pkg)
522-
{
520+
check.get.packages<-function(pkg){
523521
options(warn=-1)
524522

525523
# #make sure bio conductor is one of the repositories
@@ -588,7 +586,7 @@ check.get.packages<-function(pkg)
588586

589587
#function to extract objects based on reference
590588
extract.on.index<-function(database,index=database[,1,drop=FALSE],what,extract.on="row")
591-
{
589+
{
592590
# the merge function should be used instead
593591
if(extract.on=="col"){database<-t(database)}
594592
#assume top row are column names
@@ -843,22 +841,18 @@ source.local.dir<-function(wd){
843841
setwd(o.dir)
844842
}
845843

846-
##merge two data sets based on a common index column
847-
## all unique levels of the index are preserved in the final object
848-
## i.e. no variables are dropped
849-
merge.all.col<-function(data1,data2,by="name"){
850-
#merge 2 data sets by column retaining all unique and in common rows
851-
full.mat<-unique(c(data1$name,data2$name))
852-
rownames(data1)<-make.unique(data1$name)
853-
rownames(data2)<-make.unique(data2$name)
854-
merge1<-data1[full.mat,]
855-
merge2<-data2[full.mat,]
856-
merged<-data.frame(cbind(merge1,merge2))
857-
merged
844+
#adapt writeClipboard for data frames
845+
#there is a built in version of this with write.table
846+
writeClip<-function(obj, delimit="|"){
847+
# add dimnames to data for export
848+
# collapse column wise on space
849+
obj<-data.frame(row=c("",as.character(rownames(obj))),rbind(colnames(obj),as.matrix(obj)))
850+
writeClipboard(join.columns(obj,delimit))
858851
}
859852

860853

861854

862855

863856

864857

858+

0 commit comments

Comments
 (0)