So you're finished with processing but you want to change minFrac. There must be an automated way to do this other than hand picking in excel!
You used the group.nearest method and would really like to get rid of some of the non reproducible groups. How can I do this before printing the diffreport.
Using the following function below and assuming that you still have an xcmsSet object saved or in the R console its easy. Example code follows using the faahko dataset.
post.minFrac<-function(object, minFrac=0.5){
ix.minFrac<-sapply(1:length(unique(sampclass(object))), function(x, object, mf){
meta<-groups(object)
minFrac.idx<-numeric(length=nrow(meta))
idx<-which(meta[,levels(sampclass(object))[x]] >= mf*length(which(levels(sampclass(object))[x] == sampclass(object)) ))
minFrac.idx[idx]<-1
return(minFrac.idx)
}, object, minFrac)
ix.minFrac<-as.logical(apply(ix.minFrac, 1, sum))
ix<-which(ix.minFrac == TRUE)
## return(ix)
object@groupidx<-object@groupidx[ix]
object@groups<-object@groups[ix,]
return(object)
}
The faahKO toy dataset:
library(faahKO) ## These files do not have this problem to correct for but just for an
cdfpath <- system.file("cdf", package = "faahKO")
cdffiles <- list.files(cdfpath, recursive = TRUE, full.names = TRUE)
xset<-xcmsSet(cdffiles)
gxset<-group(xset, method="nearest")
nrow(gxset@groups) == 1096 ## the number of features before minFrac
gxset<-post.minFrac(gxset)
nrow(gxset@groups) == 465 ## and after minFrac !