-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcellDeconvolution.R
More file actions
46 lines (34 loc) · 1.84 KB
/
Copy pathcellDeconvolution.R
File metadata and controls
46 lines (34 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
###########################################################################################################################
# Author: Rebekka Koeck
# Lab: Cellular Genomic Medicine, Clinical Genetics, Maastricht University (Medical Centre +)
# script purpose: cell composition prediction based on reference data
# input: preprocessed (methylumiNoob) beta values (.csv), sample annotation (.csv), reference data (see supporting data
# directory)
# Supporting data reference: Yuan V, Hui D, Yin Y, Penaherrera MS, Beristain AG, Robinson WP. Cell-specific characterisation
# of the placental methylome. BMC Genomics. 2021.
# output: cell composition prediction (cytotrophoblasts, syncytiotrophoblasts, nucleated red blood cells, Hofbauer cells,
# endothelial cells, stromal cells)
###########################################################################################################################
# load packages
suppressPackageStartupMessages(library(minfi))
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(data.table))
suppressPackageStartupMessages(library(tibble))
# load the data
annotation = fread(AnnotationFilePath.csv)
betas = fread(BetasFilePath)
ref = fread(referenceData) %>%
column_to_rownames("cpg") %>%
as.matrix()
# filter the beta values to only contain the sites in the reference data
betas.ref = betas %>% filter(rownames(.) %in% rownames(ref)) %>%
as.matrix()
# calculate the cell estimates using the Houseman method from minfi
cells = minfi:::projectCellType(
betas.ref,
ref)
# add the cell compositions to the sample annotation
cells = cells %>% as.data.frame() %>% rownames_to_column("Basename")
full = full_join(annotation, cells, by = "Basename")
# save the updated sample sheet
write.csv(full, outputFileLocation.csv, row.names = F)