mapToList: Convert map from data.frame or DataFrame to list and vice...

Description Usage Arguments Value Functions Examples

View source: R/mapToList.R

Description

The mapToList function provides a convenient way of reordering a data.frame to a list. The listToMap function does the opposite by taking a list and converting it to DataFrame.

Usage

1
2
3
listToMap(listmap)

mapToList(dfmap, assayCol = "assay")

Arguments

listmap

A named list object containing DataFrames with "primary" and "colname" columns

dfmap

A data.frame or DataFrame object with identifiers in the first column

assayCol

A character vector of length one indicating the assay names column

Value

A DataFrame class object of names

A list object of DataFrames for each assay

Functions

Examples

1
2
3
4
5
6
7
example("MultiAssayExperiment")

## Create a sampleMap from a list using the listToMap function
sampMap <- listToMap(maplist)

## The inverse operation is also available
maplist <- mapToList(sampMap)

Example output

Loading required package: SummarizedExperiment
Loading required package: MatrixGenerics
Loading required package: matrixStats

Attaching package:MatrixGenericsThe following objects are masked frompackage:matrixStats:

    colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
    colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
    colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
    colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
    colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
    colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
    colWeightedMeans, colWeightedMedians, colWeightedSds,
    colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
    rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
    rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
    rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
    rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
    rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
    rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
    rowWeightedSds, rowWeightedVars

Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package:BiocGenericsThe following objects are masked frompackage:parallel:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked frompackage:stats:

    IQR, mad, sd, var, xtabs

The following objects are masked frompackage:base:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

Loading required package: S4Vectors

Attaching package:S4VectorsThe following object is masked frompackage:base:

    expand.grid

Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.


Attaching package:BiobaseThe following object is masked frompackage:MatrixGenerics:

    rowMedians

The following objects are masked frompackage:matrixStats:

    anyMissing, rowMedians


MltAsE> ## Run the example ExperimentList
MltAsE> example("ExperimentList")

ExprmL> ## Create an empty ExperimentList instance
ExprmL> ExperimentList()
ExperimentList class object of length 0:
 
ExprmL> ## Create array matrix and AnnotatedDataFrame to create an ExpressionSet class
ExprmL> arraydat <- matrix(data = seq(101, length.out = 20), ncol = 4,
ExprmL+     dimnames = list(
ExprmL+         c("ENST00000294241", "ENST00000355076",
ExprmL+         "ENST00000383706","ENST00000234812", "ENST00000383323"),
ExprmL+         c("array1", "array2", "array3", "array4")
ExprmL+     ))

ExprmL> colDat <- data.frame(slope53 = rnorm(4),
ExprmL+     row.names = c("array1", "array2", "array3", "array4"))

ExprmL> ## SummarizedExperiment constructor
ExprmL> exprdat <- SummarizedExperiment::SummarizedExperiment(arraydat,
ExprmL+     colData = colDat)

ExprmL> ## Create a sample methylation dataset
ExprmL> methyldat <- matrix(data = seq(1, length.out = 25), ncol = 5,
ExprmL+     dimnames = list(
ExprmL+         c("ENST00000355076", "ENST00000383706",
ExprmL+           "ENST00000383323", "ENST00000234812", "ENST00000294241"),
ExprmL+         c("methyl1", "methyl2", "methyl3",
ExprmL+           "methyl4", "methyl5")
ExprmL+     ))

ExprmL> ## Create a sample RNASeqGene dataset
ExprmL> rnadat <- matrix(
ExprmL+     data = sample(c(46851, 5, 19, 13, 2197, 507,
ExprmL+         84318, 126, 17, 21, 23979, 614), size = 20, replace = TRUE),
ExprmL+     ncol = 4,
ExprmL+     dimnames = list(
ExprmL+         c("XIST", "RPS4Y1", "KDM5D", "ENST00000383323", "ENST00000234812"),
ExprmL+         c("samparray1", "samparray2", "samparray3", "samparray4")
ExprmL+     ))

ExprmL> ## Create a mock RangedSummarizedExperiment from a data.frame
ExprmL> rangedat <- data.frame(chr="chr2", start = 11:15, end = 12:16,
ExprmL+     strand = c("+", "-", "+", "*", "."),
ExprmL+     samp0 = c(0,0,1,1,1), samp1 = c(1,0,1,0,1), samp2 = c(0,1,0,1,0),
ExprmL+     row.names = c(paste0("ENST", "00000", 135411:135414), "ENST00000383323"))

ExprmL> rangeSE <- SummarizedExperiment::makeSummarizedExperimentFromDataFrame(rangedat)

ExprmL> ## Combine to a named list and call the ExperimentList constructor function
ExprmL> assayList <- list(Affy = exprdat, Methyl450k = methyldat, RNASeqGene = rnadat,
ExprmL+                 GISTIC = rangeSE)

ExprmL> ## Use the ExperimentList constructor
ExprmL> ExpList <- ExperimentList(assayList)

MltAsE> ## Create sample maps for each experiment
MltAsE> exprmap <- data.frame(
MltAsE+     primary = c("Jack", "Jill", "Barbara", "Bob"),
MltAsE+     colname = c("array1", "array2", "array3", "array4"),
MltAsE+     stringsAsFactors = FALSE)

MltAsE> methylmap <- data.frame(
MltAsE+     primary = c("Jack", "Jack", "Jill", "Barbara", "Bob"),
MltAsE+     colname = c("methyl1", "methyl2", "methyl3", "methyl4", "methyl5"),
MltAsE+     stringsAsFactors = FALSE)

MltAsE> rnamap <- data.frame(
MltAsE+     primary = c("Jack", "Jill", "Bob", "Barbara"),
MltAsE+     colname = c("samparray1", "samparray2", "samparray3", "samparray4"),
MltAsE+     stringsAsFactors = FALSE)

MltAsE> gistmap <- data.frame(
MltAsE+     primary = c("Jack", "Bob", "Jill"),
MltAsE+     colname = c("samp0", "samp1", "samp2"),
MltAsE+     stringsAsFactors = FALSE)

MltAsE> ## Combine as a named list and convert to a DataFrame
MltAsE> maplist <- list(Affy = exprmap, Methyl450k = methylmap,
MltAsE+     RNASeqGene = rnamap, GISTIC = gistmap)

MltAsE> ## Create a sampleMap
MltAsE> sampMap <- listToMap(maplist)

MltAsE> ## Create an example phenotype data
MltAsE> colDat <- data.frame(sex = c("M", "F", "M", "F"), age = 38:41,
MltAsE+     row.names = c("Jack", "Jill", "Bob", "Barbara"))

MltAsE> ## Create a MultiAssayExperiment instance
MltAsE> mae <- MultiAssayExperiment(experiments = ExpList, colData = colDat,
MltAsE+     sampleMap = sampMap)
Warning message:
system call failed: Cannot allocate memory 

MultiAssayExperiment documentation built on Nov. 8, 2020, 8:10 p.m.