Changing Row Names of MultiAssayExperiment Assay
1
0
Entering edit mode
Dario Strbenac ★ 1.5k
@dario-strbenac-5916
Last seen 28 days ago
Australia

How may I change the row names of an assay to make it more compatible with other R analysis?

> class(cancerAssays)
[1] "MultiAssayExperiment"
> assay(cancerAssays, "microRNA")[1:5, 1:5]
                1     5     6    13    16
hsa-let-7a  11.95 12.26 12.93 12.85 11.29
hsa-let-7a*  6.09  6.12  6.16  6.12  6.05
hsa-let-7b   9.15 11.14 11.51 10.99  9.55
hsa-let-7b*  6.16  6.15  6.03  6.12  6.04
hsa-let-7c   8.38 10.14 10.49  9.77  8.43
> problematicNames <- rownames(assays(melanomaAssays)[["microRNA"]])
> rownames(assay(cancerAssays, "microRNA")) <- gsub('*', 'star', problematicNames, fixed = TRUE)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'assay<-' for signature '"MultiAssayExperiment", "character"'

It seems to me that the assay data is not overwriteable.

MultiAssayExperiment • 612 views
ADD COMMENT
4
Entering edit mode
nick.eagles ▴ 90
@nickeagles-24264
Last seen 18 months ago

Hello,

If I understand correctly, you can change that last line to:

rownames(cancerAssays[['microRNA']]) = gsub('*', 'star', problematicNames, fixed = TRUE)

This approach worked for me when running the example provided in the MultiAssayExperiment reference manual (under the "MultiAssayExperiment" tab) to produce a basic object, then attempting to change the rownames of one assay. I've provided my exact code at the bottom of this message if you're interested or can't reproduce the solution I've provided.

Best,

-Nick

P.S. I'm learning to help others

library('MultiAssayExperiment')
library('sessioninfo')

example("ExperimentList")

exprmap <- data.frame(primary = c("Jack", "Jill", "Barbara", "Bob"),colname = c("array1", "array2", "array3", "array4"),stringsAsFactors = FALSE)
methylmap <- data.frame(primary = c("Jack", "Jack", "Jill", "Barbara", "Bob"),colname = c("methyl1", "methyl2", "methyl3", "methyl4", "methyl5"),stringsAsFactors = FALSE)
rnamap <- data.frame(primary = c("Jack", "Jill", "Bob", "Barbara"),colname = c("samparray1", "samparray2", "samparray3", "samparray4"),stringsAsFactors = FALSE)
gistmap <- data.frame(primary = c("Jack", "Bob", "Jill"),colname = c("samp0", "samp1", "samp2"),stringsAsFactors = FALSE)

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

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

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

## Create a MultiAssayExperiment instance
mae <- MultiAssayExperiment(experiments = ExpList, colData = colDat,sampleMap = sampMap)

## Just to show what this object looks like now
mae
#A MultiAssayExperiment object of 4 listed
# experiments with user-defined names and respective classes.
# Containing an ExperimentList class object of length 4:
# [1] Affy: SummarizedExperiment with 5 rows and 4 columns
# [2] Methyl450k: matrix with 5 rows and 5 columns
# [3] RNASeqGene: matrix with 5 rows and 4 columns
# [4] GISTIC: RangedSummarizedExperiment with 5 rows and 3 columns
#Features:
# experiments() - obtain the ExperimentList instance
# colData() - the primary/phenotype DFrame
# sampleMap() - the sample availability DFrame
# `$`, `[`, `[[` - extract colData columns, subset, or experiment
# *Format() - convert into a long or wide DFrame
# assays() - convert ExperimentList to a SimpleList of matrices

## As a test, simply rename the rows of the "Affy" assay with integer values
rownames(mae[['Affy']]) = as.character(1:5)

## Check that the rownames are actually changed
assay(mae, 'Affy')
#  array1 array2 array3 array4
#1    101    106    111    116
#2    102    107    112    117
#3    103    108    113    118
#4    104    109    114    119
#5    105    110    115    120

## Reproducibility info
session_info()
#─ Session info ───────────────────────────────────────────────────────────────
# setting  value
# version  R version 4.0.2 Patched (2020-06-24 r78746)
# os       CentOS Linux 7 (Core)
# system   x86_64, linux-gnu
# ui       X11
# language (EN)
# collate  en_US.UTF-8
# ctype    en_US.UTF-8
# tz       US/Eastern
# date     2020-10-28
#
#─ Packages ───────────────────────────────────────────────────────────────────
# package              * version  date       lib source
# assertthat             0.2.1    2019-03-21 [2] CRAN (R 4.0.0)
# Biobase              * 2.48.0   2020-04-27 [2] Bioconductor
# BiocGenerics         * 0.34.0   2020-04-27 [2] Bioconductor
# bitops                 1.0-6    2013-08-17 [2] CRAN (R 4.0.0)
# cli                    2.1.0    2020-10-12 [2] CRAN (R 4.0.2)
# crayon                 1.3.4    2017-09-16 [2] CRAN (R 4.0.0)
# DelayedArray         * 0.14.1   2020-07-14 [2] Bioconductor
# fansi                  0.4.1    2020-01-08 [2] CRAN (R 4.0.0)
# GenomeInfoDb         * 1.24.2   2020-06-15 [2] Bioconductor
# GenomeInfoDbData       1.2.3    2020-05-18 [2] Bioconductor
# GenomicRanges        * 1.40.0   2020-04-27 [2] Bioconductor
# glue                   1.4.2    2020-08-27 [1] CRAN (R 4.0.2)
# IRanges              * 2.22.2   2020-05-21 [2] Bioconductor
# lattice                0.20-41  2020-04-02 [3] CRAN (R 4.0.2)
# Matrix                 1.2-18   2019-11-27 [3] CRAN (R 4.0.2)
# matrixStats          * 0.57.0   2020-09-25 [2] CRAN (R 4.0.2)
# MultiAssayExperiment * 1.14.0   2020-04-27 [1] Bioconductor
# RCurl                  1.98-1.2 2020-04-18 [2] CRAN (R 4.0.0)
# S4Vectors            * 0.26.1   2020-05-16 [2] Bioconductor
# sessioninfo          * 1.1.1    2018-11-05 [2] CRAN (R 4.0.0)
# SummarizedExperiment * 1.18.2   2020-07-09 [2] Bioconductor
# withr                  2.3.0    2020-09-22 [2] CRAN (R 4.0.2)
# XVector                0.28.0   2020-04-27 [2] Bioconductor
# zlibbioc               1.34.0   2020-04-27 [2] Bioconductor
#
#[1] /users/neagles/R/4.0
#[2] /jhpce/shared/jhpce/core/conda/miniconda3-4.6.14/envs/svnR-4.0/R/4.0/lib64/R/site-library
#[3] /jhpce/shared/jhpce/core/conda/miniconda3-4.6.14/envs/svnR-4.0/R/4.0/lib64/R/library
ADD COMMENT

Login before adding your answer.

Traffic: 474 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6