序列区间

R 中的 Bioconductor 入门

Paula Andrea Martinez, PhD.

Data scientist

使用数值参数的 IRanges

# Loading IRanges
library(IRanges)

区间由 start 和 end 定义

myIRanges <- IRanges(start = 20, end = 30)
myIRanges
IRanges object with 1 range and 0 metadata columns:
   start       end     width
<integer> <integer> <integer>
[1]   20        30        11
R 中的 Bioconductor 入门
(myIRanges_width <- IRanges(start = c(1, 20), width = c(30, 11)))
 IRanges object with 2 ranges and 0 metadata columns:
         start       end     width    
      <integer> <integer> <integer>
[1]         1        30        30       
[2]        20        30        11
(myIRanges_end <- IRanges(start = c(1, 20), end = 30))
 IRanges object with 2 ranges and 0 metadata columns:
         start       end     width    
      <integer> <integer> <integer>
[1]         1        30        30       
[2]        20        30        11

公式:width = end - start + 1

R 中的 Bioconductor 入门

Rle——运行长度编码

  • Rle 表示运行长度编码
  • 计算并存储向量或因子的"长度"和"取值"
  • Rle 是通用 S4 容器,用于高效保存长重复向量
(some_numbers <- c(3, 2, 2, 2, 3, 3, 4, 2))
3 2 2 2 3 3 4 2
(Rle(some_numbers))
numeric-Rle of length 8 with 5 runs
Lengths: 1 3 2 1 1
Values : 3 2 3 4 2
R 中的 Bioconductor 入门

使用逻辑向量的 IRanges

IRanges(start = c(FALSE, FALSE, TRUE, TRUE))
 IRanges object with 1 range and 0 metadata columns:
      start       end     width
  <integer> <integer> <integer>
[1]       3         4         2
R 中的 Bioconductor 入门

使用逻辑 Rle 的 IRanges

gi <- c(TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE)
myRle <- Rle(gi)
logical-Rle of length 7 with 3 runs
Lengths:     2     2     3
Values :  TRUE FALSE  TRUE
IRanges(start = myRle)
IRanges object with 2 ranges and 0 metadata columns:
         start       end     width
      <integer> <integer> <integer>
[1]         1         2         2
[2]         5         7         3
R 中的 Bioconductor 入门

总结

IRanges 是分层数据结构,可包含元数据。

构建 IRanges 对象:

  • start、end 或 width 为数值向量(或 NULL)。
  • start 参数可为逻辑向量或逻辑 Rle 对象。
    • Rle 表示运行长度编码,存储高效。
    • IRanges 参数会被循环使用(自动填充)。
    • 序列区间公式:width = end - start + 1。
R 中的 Bioconductor 入门

让我们练习使用序列区间!

R 中的 Bioconductor 入门

Preparing Video For Download...