Skip to content

Instantly share code, notes, and snippets.

@federicomarini
Last active April 20, 2023 09:54
Show Gist options
  • Save federicomarini/4a543eebc7e7091d9169111f76d59de1 to your computer and use it in GitHub Desktop.
Save federicomarini/4a543eebc7e7091d9169111f76d59de1 to your computer and use it in GitHub Desktop.

Revisions

  1. federicomarini revised this gist Apr 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion iSEE_plug.R
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,6 @@ wrapup_for_iSEE <- function(dds, res) {
    }

    # next, launch iSEE directly on the se object!

    se <- wrapup_for_iSEE(dds,res)
    library(iSEE)
    iSEE(se)
  2. federicomarini revised this gist Apr 17, 2019. 1 changed file with 31 additions and 16 deletions.
    47 changes: 31 additions & 16 deletions iSEE_plug.R
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,43 @@
    # one needs this as well
    library(SingleCellExperiment)
    library(DESeq2)

    wrapup_for_iSEE <- function(dds, res) {

    # dds to vst
    vst <- vst(dds)

    sce <- SingleCellExperiment(

    # initialize the container
    se <- SummarizedExperiment(
    assays = List(
    counts = counts(dds),
    normcounts = counts(dds,normalized = TRUE),
    vst_counts = assay(vst)
    )
    )

    # adding colData
    colData(sce) <- colData(dds)

    # adding rowData
    rowData(sce) <- res

    # log operations to have the rowData ready to use
    rowData(sce)$log10_baseMean <- log10(rowData(sce)$baseMean)
    rowData(sce)$log10_pvalue <- -log10(rowData(sce)$pvalue)
    # adding colData, taken directly from the DESeqDataSet object
    colData(se) <- colData(dds)

    # extract contrast info
    this_contrast <- sub(".*p-value: (.*)","\\1",mcols(res, use.names=TRUE)["pvalue","description"])

    return(sce)
    }
    # getting the rowData from the dds itself
    rdd <- rowData(dds)

    # modifying in advance the DESeqResults object
    res$log10_baseMean <- log10(res$baseMean)
    res$log10_pvalue <- -log10(res$pvalue)
    # and for the rowData
    rdd$log10_dispersion <- log10(rdd$dispersion)

    # adding rowData to se
    rowData(se)[[paste0("DESeq2_",gsub(" ","_",this_contrast))]] <- res

    # merging in the existing rowData slot
    rowData(se) <- cbind(rowData(se), rdd)

    return(se)
    }

    # next, launch iSEE directly on the se object!

    library(iSEE)
    iSEE(se)
  3. federicomarini created this gist Apr 12, 2019.
    28 changes: 28 additions & 0 deletions iSEE_plug.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # one needs this as well
    library(SingleCellExperiment)

    wrapup_for_iSEE <- function(dds, res) {

    # dds to vst
    vst <- vst(dds)

    sce <- SingleCellExperiment(
    assays = List(
    counts = counts(dds),
    normcounts = counts(dds,normalized = TRUE),
    vst_counts = assay(vst)
    )
    )

    # adding colData
    colData(sce) <- colData(dds)

    # adding rowData
    rowData(sce) <- res

    # log operations to have the rowData ready to use
    rowData(sce)$log10_baseMean <- log10(rowData(sce)$baseMean)
    rowData(sce)$log10_pvalue <- -log10(rowData(sce)$pvalue)

    return(sce)
    }