Browse Source

Adding functions gs_pop_get_children_recursive and gs_gate_interactive_regate2 and modifying gates_save by adding an "include" argument.

main
Marcel Costa 7 months ago
parent
commit
5008e3b73a
2 changed files with 37 additions and 2 deletions
  1. +2
    -1
      Analysis.R
  2. +35
    -1
      functionsCyto.R

+ 2
- 1
Analysis.R

@ -40,7 +40,7 @@ gates[["NKdim"]]<-gs_pop_get_gate(gs, "NKdim")
gs_gate_interactive(gs[["NKs-K562"]],
subset = "NKdim",
filterId = "CD107a+",
dims = list("CD107a", "CD56"), overlayGates = "CD107a+")
dims = list("CD107a", "CD56"))
gates[["CD107a+"]]<-gs_pop_get_gate(gs, "CD107a+")
gates<-gates_save(gs, file = "gates.rds")
@ -102,3 +102,4 @@ ggsave("Analysis.jpg")
save_gs(gs, "gs_analysis")
gs<-load_gs("gs_analysis/")

+ 35
- 1
functionsCyto.R

@ -233,9 +233,10 @@ LMD2FCS<-function(files, output.dir=NULL){
print("Conversión completada")
}
gates_save<-function(gs, file="gates.rds", save=T){
gates_save<-function(gs, file="gates.rds", save=T, include=NULL){
gates.list<-list()
pop_paths<-gs_get_pop_paths(gs)[gs_get_pop_paths(gs) != "root"]
if(!is.null(include)){pop_paths<-pop_paths[pop_paths %in% include]}
pop_paths<-lapply(pop_paths, function(x) rev(rev(strsplit(x, "/")[[1]])[1:2]))
for (gate in pop_paths){
parent<-if (gate[1] == ""){"root"}else{gate[1]}
@ -265,3 +266,36 @@ gates_apply<-function(gs, gates, exact=T){
recompute(gs)
return(gs)
}
gs_pop_get_children_recursive<-function(gs, pop){
childrens<-c()
n<-0
childrens<-c(childrens, gs_pop_get_children(gs, pop))
while(n != length(childrens)){
n<-length(childrens)
for (i in 1:length(childrens)){
childrens<-c(childrens, gs_pop_get_children(gs, childrens[i]))
}
childrens<-unique(childrens)
}
return(childrens)
}
gs_gate_interactive_regate2<-function(gs, filterId, sample=1, subset="root", ...){
dims<-list(names(gs_pop_get_gate(gs, filterId)[[1]]@parameters)[1],
names(gs_pop_get_gate(gs, filterId)[[1]]@parameters)[2])
childrens<-gs_pop_get_children_recursive(gs, filterId)
childrens_gate<-gates_save(gs, save=F, include=childrens)
gs_pop_add(gs, gs_pop_get_gate(gs, filterId), parent=subset, name="duplicated")
gs_gate_interactive(gs,
subset = subset,
filterId = filterId,
sample=sample,
dims = dims, regate=T, overlayGates = "duplicated")
gs_pop_remove(gs, "duplicated")
gates_apply(gs, childrens_gate)
}

Loading…
Cancel
Save