Slingshot | 查看单个轨迹

之前的文章写了Slingshot的简单用法,可以从整体看单细胞轨迹,但是不太容易看单个轨迹到底是哪些细胞群,实现方法:

1.运行Slingshot

sds <- slingshot(Embeddings(sc, "umap"), 
                 clusterLabels = sc$Cluster,
                 start.clus = c("1"),#起始和终点均可选
                 stretch = 0)
#line图
col1 <- colorRampPalette(brewer.pal(8,'Accent'))(11)
plot(Embeddings(sc, "umap"),col = col1[sc$Cluster],pch=16,asp=1)
lines(SlingshotDataSet(sds), lwd=2, type = 'lineages', col = 'black')

#平滑曲线
lin1 <- getLineages(sds, clusterLabels = "Cluster", 
                    start.clus = c("1"),reducedDim = "UMAP")
crv1 <- getCurves(lin1)
plot(Embeddings(sc, "umap"),col = col1[sc$Cluster],pch=16,asp=1)
lines(SlingshotDataSet(crv1), lwd = 3, col = 'black')

首先还是先运行slingshot,跟之前不同的是,这里建议使用Embeddings提取降维后的坐标信息,而不是sc直接转化为SingleCellExperiment,得到如下图。

2.查看单个轨迹

单个轨迹在sds文件的metadata里,可以看到有4条轨迹,根据拟时序顺序排列好的。

sds@metadata[["lineages"]]
# $Lineage1
# [1] "1" "0" "5" "7" "9" "6" "3"

# $Lineage2
# [1] "1" "0" "5" "7" "9" "6" "2"

# $Lineage3
# [1] "1" "0" "5" "8"

# $Lineage4
# [1] "1" "0" "5" "4"

3.提取单个轨迹作图

可以看到每个轨迹有哪些cluster,按照拟时序顺序由深到浅。

 也可以提取slingPseudotime,用ggplot2作图,看得更明显一点。

 参考:Pseudotime analysis with slingshot (bustools.github.io)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单版的愤怒的小鸟游戏。 首先,需要安装 Pygame 库。可以通过以下命令在终端中安装: ```python pip install pygame ``` 然后,创建一个名为 "angry_birds.py" 的 Python 文件,输入以下代码: ```python import pygame import random # 初始化 Pygame pygame.init() # 游戏窗口大小 WINDOW_WIDTH = 800 WINDOW_HEIGHT = 600 # 颜色定义 WHITE = (255, 255, 255) BLACK = (0, 0, 0) GREEN = (0, 255, 0) # 创建游戏窗口 screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pygame.display.set_caption("Angry Birds") # 加载小鸟图片 bird_image = pygame.image.load("bird.png") bird_rect = bird_image.get_rect() bird_x = 100 bird_y = 450 # 加载猪图片 pig_image = pygame.image.load("pig.png") pig_rect = pig_image.get_rect() pig_x = 600 pig_y = 450 # 加载弹弓图片 slingshot_image = pygame.image.load("slingshot.png") slingshot_rect = slingshot_image.get_rect() slingshot_x = 80 slingshot_y = 430 # 初始化速度和加速度 velocity = 0 acceleration = 0.1 # 初始化是否发射小鸟的标志位 fire_bird = False # 游戏主循环 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: if not fire_bird: # 计算小鸟发射的速度和角度 dx = bird_x - slingshot_x dy = bird_y - slingshot_y angle = -1 * math.atan2(dy, dx) velocity = math.sqrt(dx ** 2 + dy ** 2) / 20 fire_bird = True # 填充背景颜色 screen.fill(WHITE) # 画弹弓 screen.blit(slingshot_image, (slingshot_x, slingshot_y)) if not fire_bird: # 画小鸟 screen.blit(bird_image, (bird_x, bird_y)) else: # 计算小鸟的位置 bird_x += velocity * math.cos(angle) bird_y -= velocity * math.sin(angle) - 0.5 * acceleration * (velocity ** 2) velocity -= acceleration # 画小鸟 screen.blit(bird_image, (bird_x, bird_y)) # 判断小鸟是否与猪碰撞 if bird_rect.colliderect(pig_rect): print("You win!") running = False # 判断小鸟是否飞出屏幕 if bird_x < -50 or bird_x > WINDOW_WIDTH + 50 or bird_y > WINDOW_HEIGHT + 50: print("Game over!") running = False # 画猪 screen.blit(pig_image, (pig_x, pig_y)) # 更新屏幕 pygame.display.update() # 退出 Pygame pygame.quit() ``` 这个游戏中,你需要控制弹弓发射小鸟,使其击中右侧的猪。具体操作为:按住鼠标左键拖动弹弓,松开鼠标左键发射小鸟。 在运行游戏之前,需要准备好 "bird.png"、"pig.png" 和 "slingshot.png" 这三个图片文件,并与 Python 文件保存在同一个目录下。可以自己画或者从网络上下载。 运行游戏时,可以在终端中输入以下命令: ```python python angry_birds.py ``` 希望这个简单版的愤怒的小鸟游戏对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值