序列範圍

R 中的 Bioconductor 入門

Paula Andrea Martinez, PhD.

Data scientist

以數值參數建立 IRanges

# Loading IRanges
library(IRanges)

一個範圍由 startend 定義

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 代表 Run length encoding(連續長度編碼)
  • 計算並儲存向量或 factor 的「長度」與「值」
  • 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 物件:

  • startendwidth 為數值向量(或 NULL)。
  • start 參數可為邏輯向量或邏輯 Rle 物件。
    • Rle 表示連續長度編碼,儲存效率高。
    • IRanges 的參數會重複使用(自動補齊)。
    • 序列範圍公式:width = end - start + 1
R 中的 Bioconductor 入門

一起來練習使用序列範圍!

R 中的 Bioconductor 入門

Preparing Video For Download...