Created
March 30, 2020 20:58
-
-
Save kieranrcampbell/323b07efc55e837a02853266feb6ac60 to your computer and use it in GitHub Desktop.
parse Jackson 2020 data to SingleCellExperiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suppressPackageStartupMessages({ | |
library(tidyverse) | |
library(SingleCellExperiment) | |
library(argparser) | |
}) | |
select <- dplyr::select | |
mutate <- dplyr::mutate | |
arrange <- dplyr::arrange | |
rename <- dplyr::rename | |
filter <- dplyr::filter | |
## Initial analysis on BaselTMA_SP41_257_X3Y1 | |
write_one_sce <- function(core_test, df_sc, df_loc, output_dir) { | |
message(paste("Writting core", core_test)) | |
df_loc <- filter(df_loc, core == core_test) | |
df_count <- df_sc %>% | |
filter(core == core_test) %>% | |
select(id, channel, mc_counts) %>% | |
spread(channel, mc_counts) | |
df_count_loc <- inner_join(df_loc, df_count, by = "id") | |
## Parse to an SCE | |
ids <- df_count_loc$id | |
# bad heuristic -- antibodies have space in name | |
df_count_only <- select_at(df_count_loc, vars(contains(" "))) %>% | |
as.matrix() | |
df_pd <- select_at(df_count_loc, vars(-contains(" "))) %>% | |
as.data.frame() | |
## Cell names | |
rownames(df_pd) <- rownames(df_count_only) <- ids | |
sce <- SingleCellExperiment( | |
assays = list(logcounts = t(df_count_only)), | |
colData = df_pd | |
) | |
saveRDS(sce, file.path(output_dir, paste0(core_test, ".RData"))) | |
} | |
p <- arg_parser("Read Jackson 2020 data") | |
p <- add_argument(p, "--input_sc", "Input SC_dat.csv") | |
p <- add_argument(p, "--input_loc", "Input location csv") | |
p <- add_argument(p, "--output_dir", "Output directory") | |
argv <- parse_args(p) | |
df_sc <- read_csv(argv$input_sc) | |
df_loc <- read_csv(argv$input_loc) | |
cores <- sort(unique(df_sc$core)) | |
for(core in cores) { | |
write_one_sce(core, df_sc, df_loc, argv$output_dir) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment