0
$\begingroup$

I'm working with a PTX dataset and I'm trying to calculate species fractions based on read count instead of cell count.

Would just be a matter of taking the raw counts matrix of cells x gene per sample per species, and summing the entire matrix, so you get a single "total counts" value per sample and per species? Then for each sample you'd calculate, for example: total human counts / (total human counts + total mouse counts)

scData <- scData_scTransform_PTX_only_res04_20PC_6000g_30mt_sb_removal_20210813_ann_exp0_counts
human <- grep(pattern = "^hg38-", x = rownames(x = scData), value = TRUE)
mouse <- grep(pattern = "^mm10-", x = rownames(x = scData), value = TRUE)
length(human)
length(mouse)
scData[["human_genes"]] <- PercentageFeatureSet(scData, pattern = "^hg38-")
scData[["mouse_genes"]] <- PercentageFeatureSet(scData, pattern = "^mm10-")

mouse.df_PTX <- as.data.frame(GetAssayData(scData, slot="data")[human,])
mouse.df_PTX <- as.data.frame(t(mouse.df_PTX))
x = as.data.frame(scData$nCount_SCT)
#mouse.df_PTX = merge(mouse.df_PTX, x)
mouse.df_PTX["total_UMI"] <- scData$nCount_SCT
mouse.df_PTX$Total_Reads_Per_Cell <- rowSums(mouse.df_PTX)
#merge.df = merge(mouse.df_mouse, x)
#mouse.df_mouse$Total_Reads_Per_Cell <- rowSums(mouse.df_mouse)
mouse.df_PTX$fraction = mouse.df_PTX$Total_Reads_Per_Cell/mouse.df_PTX$total_UMI

human.df_PTX <- as.data.frame(GetAssayData(scData, slot="data")[mouse,])
human.df_PTX <- as.data.frame(t(human.df_PTX))
x = as.data.frame(scData$nCount_SCT)
#human.df_PTX = merge(human.df_PTX, x)
human.df_PTX["total_UMI"] <- scData$nCount_SCT
human.df_PTX$Total_Reads_Per_Cell <- rowSums(human.df_PTX)
human.df_PTX$fraction = human.df_PTX$Total_Reads_Per_Cell/human.df_PTX$total_UMI
#x = as.data.frame(scData$nCount_SCT)
#merge.df = merge(human.df_mouse, x)
#human.df_mouse$fraction = human.df_mouse/merge.df

Would the above work? Does it make sense? How to calculate human reads per sample?

Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.