How to do it...

Working programmatically with the Bioconductor classes can be done using the following steps:

  1. Create a new class inheriting from SummarizedExperiment:
setClass("BarcodedSummarizedExperiment",
contains = "SummarizedExperiment",
slots = c(barcode_id = "character", barcode_sequence = "character")
)
  1. Create a constructor function:
BarcodedSummarizedExperiment <- function(assays, rowRanges, colData, barcode_id, barcode_sequence){
new("BarcodedSummarizedExperiment",
SummarizedExperiment(assays=assays, rowRanges=rowRanges, colData=colData),
barcode_id = barcode_id,
barcode_sequence = barcode_sequence
)
}

  1. Add the required methods to the class:
setGeneric("barcode_id", function(x) standardGeneric("barcode_id"))
setMethod("barcode_id", "BarcodedSummarizedExperiment", function(x) x@barcode_id )
  1. Build an instance of the new class:
nrows <- 200
ncols <- 6
counts <- matrix(runif(nrows * ncols, 1, 1e4), nrows)
assays <- list(counts = counts)
rowRanges <- GRanges( rep(c("chr1", "chr2"), c(50, 150)),
IRanges(floor(runif(200, 1e5, 1e6)), width=100),
strand=sample(c("+", "-"), 200, TRUE),
feature_id=sprintf("ID%03d", 1:200)
)
colData <- DataFrame(
Treatment=rep(c("ChIP", "Input"), 3),
row.names=LETTERS[1:6]
)

my_new_barcoded_experiment <- BarcodedSummarizedExperiment(
assays = assays,
rowRanges = rowRanges,
colData = colData,
barcode_id = letters[1:6],
barcode_sequence = c("AT", "GC", "TA", "CG","GA", "TC")
)
  1. Call the new method:
barcode_id(my_new_barcoded_experiment)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.156.204