我正在尝试使用 Scanpy Python 包来分析一些单细胞数据。我以 Pandas 数据框的形式读取计数矩阵(.tsv 文件),其中基因作为列,行作为不同的细胞。每行包含单个细胞的不同基因的计数。我想从 Pandas 数据框中创建一个 AnnData 对象...有人知道我该怎么做吗?不幸的是,我无法提供数据集。
这对我来说很难解释,因此我仅举一个例子。我在下面有两个向量(a和b)。
a <- c("cat","dog","banana","yogurt","dog")
b <- c("salamander","worm","dog","banana","cat","yellow","blue")
Run Code Online (Sandbox Code Playgroud)
我想要以下结果:
[1] 0 0 2 1 1 0 0
Run Code Online (Sandbox Code Playgroud)
其中结果的每个元素是b的每个元素出现在向量a中的次数。
do.call("c",lapply(b,function(x){sum(x == a)}))
Run Code Online (Sandbox Code Playgroud)
这给了我我想要的,但是我需要一个矢量化/更快的版本,因为我正在处理> 20,000条记录。任何帮助表示赞赏!
我正在尝试从 bootswatch 主题网站将我的 R Shiny 应用程序的主题更改为“Minty”: https: //bootswatch.com/。但是,当我在代码中使用闪亮主题参数时,运行应用程序时不会调整主题。任何帮助表示赞赏。
更新:我能够使用下面的建议使主题正常工作,但它在颜色和导航栏方面看起来并不相似。
我已经使用 ggplot 很长时间了,并且在 R 中使用它非常舒服。我现在正在学校使用 Python,我最难理解这个错误。当我尝试使用 scale_color_manual 将颜色手动分配给名为“CellTypeOther”的具有唯一值 0/1 的变量时,我不断收到以下错误:
NameError: name 'c' is not defined
Run Code Online (Sandbox Code Playgroud)
这是我创建 ggplot 的代码:
from plotnine import *
plot = (
ggplot(Y_tsne,aes(x = 'X',y = 'Y'))
+ geom_point(aes(color = 'CellTypeOther'),alpha = 0.4,size = 2)
+ scale_color_manual(c("blue","red"))
)
Run Code Online (Sandbox Code Playgroud)
没有最后一行,情节渲染得很好。有没有人对可能发生的事情有任何线索?我不能分享我的数据,因为它很敏感。
重要说明:我正在使用 plotnine Python 模块来利用 ggplot2。
我下面有一个简单的 Shiny 应用程序(愚蠢的示例),它仅显示由 renderTable 生成的表格:
library(shiny)
ui <- fluidPage(
titlePanel("Issue"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
tableOutput("example")
)
)
)
server <- function(input, output) {
output$example <- renderTable({
data.frame(
"a" = 1,
"b" = paste("hello","there",sep = "\n"),
"c" = 3
)
},bordered = TRUE)
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
结果表如下所示:
我希望在渲染的表格中的“hello”和“there”之间有一个新行。换句话说,我希望“there”位于新行,但仍与“hello”位于同一单元格内。任何帮助表示赞赏。谢谢!
亲切的问候,艾斯
r ×4
python ×2
shiny ×2
bootswatch ×1
ggplot2 ×1
pandas ×1
plotnine ×1
scanpy ×1
shinythemes ×1