File: SE2DGEList.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 (34 lines) | stat: -rw-r--r-- 1,277 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
26
27
28
29
30
31
32
33
34
SE2DGEList <- function(object)
#	Given any SummarizedExperiment data object, extract basic information needed
#	and convert it into a DGEList object
#	Yunshun Chen, Gordon Smyth
#	18 March 2020. Last modified 23 March 2020.
{
	if(!is(object,"SummarizedExperiment"))
		stop("object is not of the SummarizedExperiment class")

	if(!requireNamespace("SummarizedExperiment",quietly=TRUE))
		stop("SummarizedExperiment package required but is not installed (or can't be loaded)")

#	Check 'assays'
	if( !("counts" %in% SummarizedExperiment::assayNames(object)) ) stop("object doesn't contain counts")
	counts <- SummarizedExperiment::assay(object,"counts")

	if(!is.null(rownames(object))) rownames(counts) <- rownames(object)
	if(!is.null(colnames(object))) colnames(counts) <- colnames(object)

	genes <- samples <- NULL

#	Check 'colData'
	if(ncol(SummarizedExperiment::colData(object))){
		samples <- as.data.frame(SummarizedExperiment::colData(object))
	}

#	Check 'rowData'
	if(is(SummarizedExperiment::rowRanges(object), "GRanges")) 
		genes <- as.data.frame(SummarizedExperiment::rowRanges(object))
	else if(ncol(SummarizedExperiment::rowData(object)))
		genes <- as.data.frame(SummarizedExperiment::rowData(object))

	DGEList(counts=counts, samples=samples, genes=genes)
}