【问题标题】:Generate Gene Plot for HG19 in R在 R 中为 HG19 生成基因图
【发布时间】:2017-01-22 23:11:15
【问题描述】:

因此,给定来自 HumanGenome19 项目 (hg19) 的矩阵,我想生成一个图,其中将绘制基因及其链。

来自hg19 的数据如下所示:

GENE CHR txStart txEnd Size STRAND
RBBP8 chr18 2050000 42016610 113940 -
CCND3 chr18 41902670 42016610 113940 -
GGNBP1 chr18 33551475 33556803 5328 +
LINC00336 chr18 33553882 33561115 7233 -
PGM3 chr18 83874592 83903655 29063 -
PGM3 chr18 83874592 83903012 28420 -
PGM3 chr18 83874592 83903012 28420 -

+ 表示基因将绘制在right 方向,而- 表示left

你知道任何 R 包可以在给定HG 数据的情况下生成如下图吗?

另外,我不关心基因在Y-axis 上的位置,它们应该被定位以便名称清晰易读。

免责声明:情节,不回应我列出的数据。

【问题讨论】:

  • 箭头倾斜的长度是否与某事相对应?比如基因大小?
  • 看看tengfei.name/ggbio ...也许小插图的第7章可能会给你一个提示
  • @JustGettinStarted 是的。
  • @Drey 这是一个通用库。它看起来非常适合其他类型的情节,但我想要完成的具体情节。
  • 看看sthda.com/english/wiki/ggbio-visualize-genomic-data 第二部分显示的情节与您的非常相似

标签: r plot


【解决方案1】:

我不知道如何为您的数据执行此操作,因为范围很广。我使用arrows 为假数据制作了一个类似的图。但是,如果您不进行进一步修改,这可能无法正常工作。

数据

mydata = structure(list(GENE = structure(c(5L, 1L, 2L, 3L, 4L, 4L, 4L), .Label = c("CCND3", 
"GGNBP1", "LINC00336", "PGM3", "RBBP8"), class = "factor"), CHR = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L), .Label = "chr18", class = "factor"), 
    txStart = c(20500000L, 20780190L, 20982780L, 21218290L, 21533530L, 
    21851180L, 22073300L), txEnd = c(20557770L, 20806930L, 21140420L, 
    21299010L, 22513330L, 21863505L, 22162610L), Size = c(57770L, 
    26740L, 157640L, 80720L, 979800L, 12325L, 89310L), STRAND = structure(c(1L, 
    1L, 2L, 1L, 1L, 1L, 1L), .Label = c("-", "+"), class = "factor")), .Names = c("GENE", 
"CHR", "txStart", "txEnd", "Size", "STRAND"), class = "data.frame", row.names = c(NA, 
-7L))

代码

graphics.off()
windows(width = 10, height = 7)
plot(x = c(min(mydata$txStart), max(mydata$txEnd)), y = c(0,nrow(mydata)+1),
    type = "p", pch = NA, axes = FALSE, xlab = "Chromosome ## Mb", ylab = "")

# Divide range of genes into 4 groups to add ticks and labels in next step
x_label = seq(min(mydata$txStart),max(mydata$txEnd),(max(mydata$txEnd) - min(mydata$txStart))/4)

#add labels at 4 different places on x-axis
axis(1, at = x_label, labels = paste(as.character(round(x_label/1000000),2)," Mb",sep =""))

y_pos = 1 #Starting vertical position of genes
for (i in 1:nrow(mydata)){
    #use arrows from txStart to txEnd. Based on STRAND value, this may have to change with if else
    arrows(x0 = mydata$txStart[i], x1 = mydata$txEnd[i], y0 = y_pos, y1 = y_pos, length = 0.05)

    #Obtain x position to put gene label
    x_pos = mydata$txStart[i] + (mydata$txEnd[i] - mydata$txStart[i])/2
    gene_label = paste(mydata$GENE[i])

    #Add gene label
    text(x_pos, y_pos, bquote(italic(.(gene_label))), pos = 3, col = "darkgrey", cex = 0.8)
    y_pos = y_pos + 1 #Comment this if you want all genes on the same level
}

情节

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2017-08-02
    • 1970-01-01
    • 2021-11-18
    • 2011-06-15
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多