Search in a GInteraction object which interactions correspond ti a target list and return a list of index or filter a matrices list according to target and a selection function.
Usage
FilterInteractions(
matrices.lst = NULL,
interarctions.gni = NULL,
target.lst = NULL,
selection.fun = function() {
Reduce(intersect, interarctions.ndx_lst)
}
)
Arguments
- matrices.lst
<List[matrix]>: The matrices list to filter. If is not NULL, the function will return the filtred matrices list, else return a list of index.
- interarctions.gni
<GInteractions>: The GInteraction object on which compute the filter.
- target.lst
<List>: A nammed list that describe the target.
- selection.fun
<function>: A function that described how the target must be cross. (Defaul intersection of all targets)
Examples
# Data
data(Beaf32_Peaks.gnr)
data(HiC_Ctrl.cmx_lst)
# Index Beaf32
Beaf32_Index.gnr <- IndexFeatures(
gRange.gnr_lst = list(Beaf = Beaf32_Peaks.gnr),
chromSize.dtf = data.frame(seqnames = c("2L", "2R"), seqlengths = c(23513712, 25286936)),
binSize.num = 100000
)
# Beaf32 <-> Beaf32 Pairing
Beaf_Beaf.gni <- SearchPairs(indexAnchor.gnr = Beaf32_Index.gnr)
Beaf_Beaf.gni <- Beaf_Beaf.gni[seq_len(2000)] # subset 2000 first for exemple
# Matrices extractions center on Beaf32 <-> Beaf32 point interaction
interactions_PF.mtx_lst <- ExtractSubmatrix(
feature.gn = Beaf_Beaf.gni,
hic.cmx_lst = HiC_Ctrl.cmx_lst,
referencePoint.chr = "pf"
)
# Create a target
target.lst <- list(
anchor.Beaf.name = c("Beaf32_108", "Beaf32_814"),
distance = function(dist) {
dist < 300000
}
)
# We target the Beaf32<->Beaf32 interactions that are less than 300Kb away
# and have peak Beaf32_2 and Beaf32_191 as anchors (i.e. left).
# Create a selection
selection.fun <- function() {
intersect(anchor.Beaf.name, distance)
}
# We select the Beaf32<->Beaf32 interactions that satisfy both targeting
# criteria (intersection).
# Filtration on InteractionSet (Beaf32 <-> Beaf32 Pairs)
FilterInteractions(
interarctions.gni = Beaf_Beaf.gni,
target.lst = target.lst,
selection.fun = NULL
) |> str(max.level = 1)
#> List of 2
#> $ anchor.Beaf.name: int [1:30] 10 78 147 215 284 352 421 489 558 626 ...
#> $ distance : int [1:56] 1 2 3 138 139 140 141 275 276 277 ...
# Returns a named list (the names match the targeting criteria).
# Each element is an index vector of Beaf32<->Beaf32 interactions
# that satisfy the given criteria.
# Filtration on Matrices List (Beaf32 <-> Beaf32 Extracted matrices)
FilterInteractions(
matrices.lst = interactions_PF.mtx_lst,
target.lst = target.lst,
selection.fun = NULL
) |> str(max.level = 1)
#> List of 2
#> $ anchor.Beaf.name: int [1:12] 1 69 126 194 251 319 376 444 501 569 ...
#> $ distance : int [1:15] 1 2 126 127 253 379 380 504 505 506 ...
# Return the same kind of result.
# Add the selection on InteractionSet Filtration
FilterInteractions(
interarctions.gni = Beaf_Beaf.gni,
target.lst = target.lst,
selection.fun = selection.fun
) |> str(max.level = 1)
#> int [1:3] 1106 1243 1380
# This return the intersection of the index vector that satisfy both
# targeting criteria.
# Add the selection on Matrices List Filtration
FilterInteractions(
matrices.lst = interactions_PF.mtx_lst,
target.lst = target.lst,
selection.fun = selection.fun
) |> str(max.level = 1)
#> List of 2
#> $ 2L:11_2L:11: num [1:21, 1:21] 93476 NA NA NA NA ...
#> $ 2L:11_2L:12: num [1:21, 1:21] 29913 135797 NA NA NA ...
#> - attr(*, "interactions")=Formal class 'GInteractions' [package "InteractionSet"] with 6 slots
#> - attr(*, "resolution")= num 1e+05
#> - attr(*, "referencePoint")= chr "pf"
#> - attr(*, "matriceDim")= num 21
#> - attr(*, "target")=List of 2
#> - attr(*, "selection")=function ()
#> ..- attr(*, "srcref")= 'srcref' int [1:8] 34 18 36 1 18 1 34 36
#> .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x55bae7aa4288>
# This return the filtred matrices.lst, i.e the matrices.lst for which
# the Beaf32<->Beaf32 interactions satisfy both targeting criteria.
# Filtration with InteractionsSet as filtration criteria
target.lst <- list(interactions = Beaf_Beaf.gni[seq_len(2)])
FilterInteractions(
interarctions.gni = Beaf_Beaf.gni,
target.lst = target.lst,
selection.fun = NULL
) |> str(max.level = 1)
#> Named int [1:3] 1 2 138
#> - attr(*, "names")= chr [1:3] "interactions1" "interactions2" "interactions3"
# Filtration with GRanges as filtration criteria
target.lst <- list(first = InteractionSet::anchors(Beaf_Beaf.gni)[["first"]][seq_len(2)])
FilterInteractions(
interarctions.gni = Beaf_Beaf.gni,
target.lst = target.lst,
selection.fun = NULL
) |> str(max.level = 1)
#> Named int [1:30] 1 2 138 139 275 276 412 413 549 550 ...
#> - attr(*, "names")= chr [1:30] "first1" "first2" "first3" "first4" ...