Violin plot (Monocle 3) - Troubleshooting
1
0
Entering edit mode
14 months ago

I am trying to generate some violin plots in monocle on a cell dataset object. Basically, I'm trying to visualize expression of certain marker genes in different clusters of a cell dataset object.

I tried to follow this online documentation using the plot_genes_violin function in monocle3 but it's giving me an error (see attached screenshot). Does anyone have any ideas on how I can troubleshoot this error or if there is a different way to run this in ggplot?

#cell dataset object = cds
cds_subset <- cds[row.names(subset(rowData(cds),
                     gene_short_name %in% c("Podxl", "Nphs1", "Nphs2"))),]
plot_genes_violin(cds_subset)

enter image description here

Monocle3 • 1.3k views
ADD COMMENT
0
Entering edit mode

Please do not paste screenshots of plain text content, it is counterproductive. You should copy paste the content directly here (using the code formatting option shown below).

code_formatting

ADD REPLY
0
Entering edit mode
14 months ago
bk11 ★ 3.0k

I have not tested it though. Can you try this-

your_genes=c("Podxl", "Nphs1", "Nphs2")
cds_subset <- cds[rowData(cds)$gene_short_name %in% your_genes,]

plot_genes_violin(cds_subset, group_cells_by="embryo.time.bin", ncol=2) +
      theme(axis.text.x=element_text(angle=45, hjust=1)) #in group_cells_by please choose what you want to group by.
ADD COMMENT
0
Entering edit mode

I'm still seeing errors:

First I tried the code you mentioned except I use clusters instead of embryo.time.bin since this is a column in my colData(cds).

plot_genes_violin(cds_subset, group_cells_by="clusters", ncol=2) + theme(axis.text.x=element_text(angle=45, hjust=1))
Error in plot_genes_violin(cds_subset, group_cells_by = "clusters", ncol = 2) :  unused argument (group_cells_by = "clusters")

Then, I tried this code again without the group_cells_by portion

plot_genes_violin(cds_subset) 
Error in cds_subset@expressionFamily@vfamily %in% c("negbinomial", "negbinomial.size") :  no slot of name "expressionFamily" for this object of class "cell_data_set"

Is it possible there is a bug in this code?

I'm also wondering if there is a way to generate violin plots using ggplot.

ADD REPLY
0
Entering edit mode

No there is no bug in this. Please see carefully what the error message tells to you.

ADD REPLY
0
Entering edit mode

I see the error message but I'm confused on what it's telling me.

ADD REPLY
0
Entering edit mode

What is the output to:

help.search('plot_genes_violin', agrep=FALSE, ignore.case=FALSE, fields=c('name'))
lsf.str()
sessionInfo()
ADD REPLY
0
Entering edit mode

I m not sure why you have problem there. I do not encounter any problem. May be your gene list are not present in your source object. Please see below how I would do it and it works fine. I m using tutorial from monocle3.

library(monocle3)
library(dplyr) # imported for some downstream data manipulation

expression_matrix <- readRDS(url("https://depts.washington.edu:/trapnell-lab/software/monocle3/celegans/data/cao_l2_expression.rds"))
cell_metadata <- readRDS(url("https://depts.washington.edu:/trapnell-lab/software/monocle3/celegans/data/cao_l2_colData.rds"))
gene_annotation <- readRDS(url("https://depts.washington.edu:/trapnell-lab/software/monocle3/celegans/data/cao_l2_rowData.rds"))

cds <- new_cell_data_set(expression_matrix,
                         cell_metadata = cell_metadata,
                         gene_metadata = gene_annotation)
cds
class: cell_data_set 
dim: 20271 42035 
metadata(1): cds_version
assays(1): counts
rownames(20271): WBGene00000001 WBGene00000002 ... WBGene00269394 WBGene00269421
rowData names(1): gene_short_name
colnames(42035): cele-001-001.CATGACTCAA cele-001-001.AAGACGGCCA ...
  cele-010-092.GTATTAAGTT cele-010-092.GAAGTCCGTC
colData names(5): plate cao_cluster cao_cell_type cao_tissue Size_Factor
reducedDimNames(0):
mainExpName: NULL
altExpNames(0):

test_genes <- c("che-1",
                    "hlh-17",
                    "nhr-6",
                    "dmd-6",
                    "ceh-36",
                    "ham-1")
cds_subset <- cds[rowData(cds)$gene_short_name %in% test_genes,]

colData(cds_subset)
    DataFrame with 42035 rows and 5 columns
                           plate cao_cluster          cao_cell_type             cao_tissue Size_Factor
                        <factor>    <factor>            <character>            <character>   <numeric>
cele-001-001.CATGACTCAA      001          20   Unclassified neurons                Neurons    0.236833
cele-001-001.AAGACGGCCA      001          6                Germline                  Gonad    1.299291
cele-001-001.GCCAACGCCA      001          13 Intestinal/rectal mu.. Intestinal/rectal mu..    1.368367
cele-001-001.ATAGGAGTAC      001          27      Vulval precursors                     NA    0.324000
cele-001-001.CTCGTCTAGG      001          2            Coelomocytes           Coelomocytes    0.781219

plot_genes_violin(cds_subset, group_cells_by="plate", ncol=2) +
  theme(axis.text.x=element_text(angle=45, hjust=1)) 

enter image description here

ADD REPLY
0
Entering edit mode

The error message tells me there is the possibility of a conflicting function called plot_genes_violin that accepts one parameter and errors out with the named parameter that the expected plot_genes_violin function accepts without complaint.

ADD REPLY

Login before adding your answer.

Traffic: 1476 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