File: makeSummarizedExperimentFromDataFrame.R

package info (click to toggle)
r-bioc-summarizedexperiment 1.12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,752 kB
  • sloc: sh: 3; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (5)
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
### =========================================================================
### makeSummarizedExperimentFromDataFrame()
### -------------------------------------------------------------------------

### 'df' must be a data.frame or DataFrame object.
makeSummarizedExperimentFromDataFrame <-
    function(df,
             ...,
             seqinfo = NULL,
             starts.in.df.are.0based = FALSE)
    {
        rowRanges <- makeGRangesFromDataFrame(
            df,
            ...,
            keep.extra.columns = FALSE,
            seqinfo = seqinfo,
            starts.in.df.are.0based = starts.in.df.are.0based)

        # Find column names for rowRanges
        granges_cols <-
            GenomicRanges:::.find_GRanges_cols(names(df), ...)

        rangedNames <- names(df)[na.omit(granges_cols)]
        idx <- match(rangedNames, names(df))
        counts <- as.matrix(df[, -idx, drop = FALSE])

        if (!is(as.vector(counts), "numeric"))
            stop("failed to coerce non-range columns to 'numeric'")

        SummarizedExperiment(
            assays=SimpleList(counts), rowRanges=rowRanges)
    }