Skip to content

Commit aff6561

Browse files
committed
Add more comments
1 parent e628ede commit aff6561

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

R/methSeg.R

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# segmentation functions
22

3+
#' # Segment methylation calls.
4+
#' Run fastseg GRanges object `obj`
5+
#' with additional parameters in `...`.
36
.run.fastseg = function(obj, ...){
47

58
dots <- list(...)
@@ -35,7 +38,12 @@
3538
return(seg.res)
3639
}
3740

38-
41+
#' # Use mixture modeling for the density function estimated
42+
#' # and BIC criterion used to decide the optimum number of components
43+
#' # in mixture modeling.
44+
#' Run mclust::densityMclust using GRanges object `seg.res`, look for description
45+
#' of `join.neighbours`, `initialize.on.subset` and other parameters
46+
#' in methylKit methSeg.
3947
.run.mclust = function(seg.res, diagnostic.plot=TRUE, join.neighbours=FALSE,
4048
initialize.on.subset=1, ...){
4149

@@ -197,7 +205,7 @@ methSeg<-function(obj, diagnostic.plot=TRUE, join.neighbours=FALSE,
197205
initialize.on.subset=1,
198206
mc.cores=1, ...){
199207

200-
# 1. Run segmentation
208+
# 1. Run segmentation using fastseg
201209

202210
if(mc.cores==1){
203211

@@ -252,6 +260,8 @@ methSeg<-function(obj, diagnostic.plot=TRUE, join.neighbours=FALSE,
252260
# Split the input object based on chromosome
253261
# run methSeg on chromosomes (Could be in parallel or not)
254262
seg.res.list <- mclapply(chrs, function(chr){
263+
264+
# Run segmentation
255265
seg.res = .run.fastseg(obj[seqnames(obj)==chr])
256266
}, mc.cores=mc.cores)
257267

@@ -264,8 +274,8 @@ methSeg<-function(obj, diagnostic.plot=TRUE, join.neighbours=FALSE,
264274

265275
.run.fastseg.tabix = function(gr0, class0, ...){
266276

267-
# adjust colnames of input GRanges to
268-
# methylKit naming convention
277+
# rename names of meta columns of input GRanges `gr0` to
278+
# methylKit naming convention (such as e.g. coverage, numCs, numTs)
269279
df2getcolnames = as.data.frame(gr0[1])
270280
df2getcolnames$width = NULL
271281
print(class0)
@@ -275,9 +285,11 @@ methSeg<-function(obj, diagnostic.plot=TRUE, join.neighbours=FALSE,
275285
# destrand
276286
strand(gr0) <- "*"
277287

288+
# Run segmentation
278289
.run.fastseg(gr0, ...)
279290
}
280291

292+
# Run segmentation for each chromosome
281293
seg.res <- applyTbxByChr(obj@dbpath,
282294
return.type = "GRanges",
283295
FUN = .run.fastseg.tabix,
@@ -287,7 +299,8 @@ methSeg<-function(obj, diagnostic.plot=TRUE, join.neighbours=FALSE,
287299
}
288300
}
289301

290-
# 2. Density Estimation via Model-Based Clustering
302+
# 2. Density Estimation via Model-Based Clustering using
303+
# mclust::densityMclust function
291304

292305
if( length(seg.res) > 1 ){
293306
seg.res = .run.mclust(seg.res,

0 commit comments

Comments
 (0)