シーケンス範囲

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はRun length encoding(ランレングス符号化)の略
  • ベクトルまたは因子の長さと値を計算・格納
  • 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オブジェクトをしようできますUse。
    • Rleはランレングス符号化で、メモリ効率が良い。
    • IRangesの引数はリサイクルされます。
    • シーケンス範囲の計算式: width = end - start + 1。
Rで始めるBioconductor入門

シーケンス範囲を練習しましょう!

Rで始めるBioconductor入門

Preparing Video For Download...