Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
custom
Squadrito_LiverTumor2022
Squadrito_LiverTumor2022_scRNAseqTRC
Commits
185b7a65
Commit
185b7a65
authored
Jul 26, 2023
by
Stefano Beretta
Browse files
Upload New File
parent
387c08bc
Changes
1
Show whitespace changes
Inline
Side-by-side
scripts/1_TCR_analysis.R
0 → 100644
View file @
185b7a65
library
(
scRepertoire
)
library
(
Seurat
)
library
(
openxlsx
)
library
(
gridExtra
)
library
(
data.table
)
library
(
dplyr
)
library
(
reshape2
)
library
(
ggrepel
)
library
(
dittoSeq
)
library
(
RColorBrewer
)
library
(
scales
)
library
(
ggalluvial
)
########################
### General Settings ###
########################
# Working dir
wdir
<-
"squadrito_livertumor2022_scrnaseq"
# Raw data dir (download from GEO)
raw_dir
<-
"GEO_data"
# Results dir
out_dir
<-
paste
(
wdir
,
"results"
,
sep
=
"/"
)
dir.create
(
path
=
out_dir
,
showWarnings
=
F
)
samples
<-
c
(
"GG-11"
,
"GG-18"
,
"GG-22"
,
"GG-23"
,
"GG-25"
)
vdj
<-
list
()
for
(
s
in
samples
)
{
vdj
[[
s
]]
<-
read.csv
(
file
=
paste
(
wdir
,
"counts"
,
paste0
(
s
,
"_counts"
),
"outs"
,
"per_sample_outs"
,
paste0
(
s
,
"_counts"
),
"vdj_t"
,
"filtered_contig_annotations.csv"
,
sep
=
"/"
),
header
=
T
)
vdj
[[
s
]]
$
barcode
<-
gsub
(
pattern
=
"-1"
,
replacement
=
""
,
x
=
vdj
[[
s
]]
$
barcode
)
vdj
[[
s
]][
vdj
[[
s
]]
==
"true"
]
<-
TRUE
vdj
[[
s
]][
vdj
[[
s
]]
==
"false"
]
<-
FALSE
}
# Step 1.
combined_full
<-
combineTCR
(
vdj
,
ID
=
samples
,
samples
=
samples
,
cells
=
"T-AB"
)
combined_full_df
<-
rbind.data.frame
(
combined_full
[[
names
(
combined_full
)[
1
]]],
combined_full
[[
names
(
combined_full
)[
2
]]])
for
(
id
in
names
(
combined_full
)[
3
:
length
(
names
(
combined_full
))]){
combined_full_df
<-
rbind.data.frame
(
combined_full_df
,
combined_full
[[
id
]])
}
Full_obj
<-
readRDS
(
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_final_DBR_labeled.rds"
,
sep
=
"/"
))
combined
<-
list
()
# Creating Cellid same to expression dataset
for
(
id
in
names
(
combined_full
)){
combined_full
[[
id
]]
$
cellID
<-
"ND"
for
(
k
in
1
:
nrow
(
combined_full
[[
id
]]))
{
combined_full
[[
id
]]
$
cellID
[
k
]
<-
paste0
(
combined_full
[[
id
]]
$
sample
[
k
],
"_"
,
strsplit
(
combined_full
[[
id
]]
$
barcode
[
k
],
split
=
"_"
)[[
1
]][
3
],
"-1"
)
}
combined
[[
id
]]
<-
subset
(
combined_full
[[
id
]],
subset
=
cellID
%in%
Cells
(
Full_obj
))
# subsetting with only ids
combined
[[
id
]]
<-
subset
(
combined
[[
id
]],
subset
=
!
is.na
(
TCR2
))
# removing TCR2 == NA
print
(
paste0
(
"Sample "
,
id
,
" final cells: "
,
nrow
(
combined
[[
id
]])
))
}
combined_df
<-
rbind.data.frame
(
combined
[[
names
(
combined
)[
1
]]],
combined
[[
names
(
combined
)[
2
]]])
for
(
id
in
names
(
combined
)[
3
:
length
(
names
(
combined
))]){
combined_df
<-
rbind.data.frame
(
combined_df
,
combined
[[
id
]])
}
##### Aggregated combining the samples ######
A
<-
combined_df
%>%
group_by
(
sample
,
cdr3_aa2
)
%>%
mutate
(
ClonoFreq
=
n
())
%>%
group_by
(
sample
)
%>%
mutate
(
PctClonotype
=
ClonoFreq
/
n
()
*
100
)
%>%
mutate
(
ClonoRel
=
PctClonotype
/
100
)
G
<-
as.data.frame
(
A
)
rownames
(
G
)
<-
G
$
cellID
write.xlsx
(
x
=
list
(
VDJ
=
G
),
file
=
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_freq_by_sample_cdr3_aa2.xlsx"
,
sep
=
"/"
))
saveRDS
(
G
,
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_freq_by_sample_cdr3_aa2.rds"
,
sep
=
"/"
))
Full_obj
<-
AddMetaData
(
object
=
Full_obj
,
metadata
=
G
)
saveRDS
(
object
=
Full_obj
,
file
=
paste
(
out_dir
,
"Full_DBR"
,
"Full_DBR_final_DBR_labeled.rds"
,
sep
=
"/"
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment