File: modelMatrixMeth.R

package info (click to toggle)
r-bioc-edger 3.40.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,484 kB
  • sloc: cpp: 1,425; ansic: 1,109; sh: 21; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
modelMatrixMeth <- function(object, ...)
#	Create expanded model matrix (aka design matrix) for edgeR analysis of BS-seq methylation counts.
#	Gordon Smyth
#	Created 26 Dec 2017.
{
#	If object isn't already a design matrix, create the design matrix from treatments at the sample level
	if(is.matrix(object)) {
		design.treatments <- object
	} else {
		design.treatments <- model.matrix(object, ...)
	}

#	Design matrix for samples
#	Allow for two observations (methylated and unmethylated counts) for each sample
	nsamples <- nrow(design.treatments)
	Sample <- gl(nsamples,2L)
	design.samples <- model.matrix(~0+Sample)

#	Expand design.treatments for meth & unmeth counts
	design.treatments <- design.treatments[as.integer(Sample),]

#	Combine with treatments applying to methylation effects
	Methylation <- gl(2L,1L,2L*nsamples)
	cbind(design.samples, (Methylation==1L) * design.treatments)
}