5 Processing of tetraploid-complemented TKO embryos

setwd(here::here())
library("metacell")
library("tgstat")
library("tgconfig")
library("Matrix")
library("dplyr")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
scdb_init("scrna_db/", force_reinit = T)
## initializing scdb to scrna_db/
mat <- scdb_mat("tko_tetra")

5.0.0.1 Remove extraembryonic ectoderm and parietal endoderm cells

source("scripts/pipeline/remove_exe_ectoderm_and_parietal_endo_cls.R")
mat <- remove_exe_ectoderm_and_parietal_endoderm(mat_query = mat)

5.0.0.2 Merge cells with the wildtype atlas

source("scripts/pipeline/merge_umi_mat_with_wt10_umi_mat.R")
mat_new <- merge_umi_mat_with_wt10(scmat = mat)
scdb_add_mat(id = "tko_tetra_wt10", mat = mat_new)

5.0.0.3 Generate single-cell balanced kNN-graph

This step needs the file
data/tet_tko.bad_genes.txt

source("scripts/pipeline/gen_cgraph.R")
## initializing scdb to scrna_db/
gen_cgraph(mat_nm = "tko_tetra_wt10", force_recompute_cgraph = F)
## [1] TRUE

5.0.0.4 Transfer cell type annotation to TKO cells

source("scripts/pipeline/transfer_cell_type_annotation.R")
transfer_color_chimera_tetraploid(mat_nm = "tko_tetra_wt10")

5.0.0.5 Time tetraploid-complemented embryos based on their injected TKO cells

source("scripts/pipeline/transfer_time_annotation.R")
## Loading required package: slam
## Loading required package: sparsesvd
source("scripts/pipeline/tetraploid_timing.R")
tetra_timing("tko_tetra_wt10")

5.0.0.6 Export infered time and cell type into table

source("scripts/pipeline/create_metadata.R")
create_tko_tetraploid_metadata()

5.0.0.7 Generate a separate UMI matrix and metacell object for the TKO cells

source("scripts/pipeline/generat_ko_mat.R")
generate_ko_mat_tetraploid()
source("scripts/pipeline/generic_mc.R")
tgconfig::override_params(config_file = "config/tet_chim.yaml", package = "metacell")

bad_genes <- read.table("data/tet_tko.bad_genes.txt", sep = "\t", stringsAsFactors = F)
bad_genes <- bad_genes[, 1]

mat_nm <- "tko_tetra_ko"

generate_mc(mat_nm, add_bad_genes = bad_genes)
# Run the line below if you want to transfer cell type annotation from the WT atlas to the tko_tetra_ko metacell object
#
# wt_atlas <- mcell_gen_atlas(
#     mat_id = "sing_emb_wt10",
#     mc_id = "sing_emb_wt10_recolored",
#     gset_id = "sing_emb_wt10",
#     mc2d_id = "sing_emb_wt10_recolored"
# )

# cmp <- mcell_proj_on_atlas(
#     mat_id = "tko_tetra_ko",
#     mc_id = "tko_tetra_ko",
#     atlas = wt_atlas,
#     fig_cmp_dir = paste0("figs/atlas_projection_", "tko_tetra_ko"), recolor_mc_id = "tko_tetra_ko", ten2mars = F
# )
tgconfig::set_param(param = "mcell_mc2d_T_edge", value = 0.03, package = "metacell")
mcell_mc2d_force_knn(mc2d_id = "tko_tetra_ko", mc_id = "tko_tetra_ko", graph_id = "tko_tetra_ko", graph_parametric = T, feats_gset = "tko_tetra_ko")
## got 67 feat genes for mc graph construction
mcell_mc2d_plot("tko_tetra_ko")
## png 
##   2