Intervalos de sequência

Introdução ao Bioconductor em R

Paula Andrea Martinez, PhD.

Data scientist

IRanges com argumentos numéricos

# Carregando IRanges
library(IRanges)

Um intervalo é definido por start e 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
Introdução ao Bioconductor em R
(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

Equação: width = end - start + 1

Introdução ao Bioconductor em R

Rle - run length encoding

  • Rle significa Run length encoding
  • Calcula e armazena os comprimentos e valores de um vetor ou fator
  • Rle é um contêiner S4 geral para salvar vetores repetitivos longos com eficiência
(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
Introdução ao Bioconductor em R

IRanges com vetor lógico

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
Introdução ao Bioconductor em R

IRanges com Rle lógico

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
Introdução ao Bioconductor em R

Em resumo

IRanges são estruturas de dados hierárquicas que podem conter metadados.

Para construir objetos IRanges:

  • start, end ou width como vetores numéricos (ou NULL).
  • start como vetor lógico ou objeto Rle lógico.
    • Rle significa Run length encoding e é eficiente em armazenamento.
    • Argumentos de IRanges são reciclados (preenchem lacunas).
    • Equação do intervalo de sequência: width = end - start + 1.
Introdução ao Bioconductor em R

Vamos praticar usando intervalos de sequência!

Introdução ao Bioconductor em R

Preparing Video For Download...