-
Notifications
You must be signed in to change notification settings - Fork 1
/
prep_st_data_for_deconv-CovidLung.Rmd
93 lines (72 loc) · 2.19 KB
/
prep_st_data_for_deconv-CovidLung.Rmd
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: "Prep ST data for deconv (Covid Lungs)"
author: "Yuvarani Masarapu"
output:
html_document:
self_contained: true
highlight: tango
df_print: paged
code_folding: hide
toc: yes
toc_depth: 3
toc_float:
collapsed: false
smooth_scroll: true
---
# Load each of the R objects for st data.
```{r setup, include=FALSE}
knitr::opts_knit$set(progress=TRUE,verbose=TRUE)
knitr::opts_chunk$set(message=FALSE, warning=FALSE, result='hold',fig.width=10, fig.height = 8)
```
```{r packages}
suppressPackageStartupMessages(require(Matrix))
suppressPackageStartupMessages(require(dplyr))
suppressPackageStartupMessages(require(Seurat))
suppressPackageStartupMessages(require(SeuratDisk))
```
```{r load}
data.int <- readRDS(file = paste(indir, "/", "lung.integrated.updated_08_12_2021.rds", sep = ""))
```
```{r}
table(data.int$section_id)
```
```{r}
# keep only RNA assay
data.int@active.assay = "Spatial"
data.int = DietSeurat(data.int, assays = "Spatial")
data.int@tools$Staffli = NULL
# @assays$RNA@data contains counts.
# Garbage collection command
g = gc(verbose = F)
```
# SCP1219, need data in .tsv as sc data is not provided in .h5ad format by authors
```{r}
df <- data.int@assays$Spatial@counts
write.table(df, file= paste(indir,'/stereoscope-covidlung-input/SCP1219/st-data_in_tsv/st-covid-data_for_SCP1219.tsv' ,sep = ""), quote=FALSE, sep='\t', col.names = TRUE, row.names = TRUE)
lung.genes = rownames(data.int)
```
# SCP1052, need data in .h5ad, split by each section
```{r}
indir = getwd()
outdir = paste(indir, "/stereoscope-covidlung-input/SCP1052/st-data_per_sample-CovidLung/", sep = "")
dir.create(outdir, showWarnings = F)
alldata = SplitObject(data.int, split.by = "section_id")
for (sample in names(alldata)){
print(sample)
sfile = file.path(outdir, paste0(sample,".h5Seurat"))
hfile = file.path(outdir, paste0(sample,".h5ad"))
if (!file.exists(hfile)){
SaveH5Seurat(alldata[[sample]], filename = sfile, overwrite = T)
Convert(sfile, dest = "h5ad", overwrite = T)
file.remove(sfile)
}
}
lung.genes = rownames(data.int)
rm(data.int, alldata)
# Garbage collection command
g = gc(verbose = F)
```
### Session info
```{r}
sessionInfo()
```