-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotateInteractions.R
41 lines (35 loc) · 1.14 KB
/
annotateInteractions.R
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
# Annotate interactions with an attribute from a Seurat object
# Create function
annotateInteractions <- function(SeuratObj,
Interactions,
Attribute) {
# Retrieve results from Interactions
AnnoInt <- Interactions$Interactions
# Create empty columns for attribute to go in
AnnoInt$Spot1_Anno <- NA
AnnoInt$Spot2_Anno <- NA
# Go through all the spots and annotate
# Report progress
for (x in 1:nrow(AnnoInt)) {
message(paste0(
'Annotating interaction ',
x,
' of ',
nrow(AnnoInt),
'. Progress: ',
round(((
x / nrow(AnnoInt)
) * 100), digits = 1),
'%'
))
AnnoInt$Spot1_Anno[x] <-
as.numeric(as.vector([email protected][, Attribute][colnames(SeuratObj) == AnnoInt$spot1[x]]))
AnnoInt$Spot2_Anno[x] <-
as.numeric(as.vector([email protected][, Attribute][colnames(SeuratObj) == AnnoInt$spot2[x]]))
}
# Ensure annotations are factors
AnnoInt$Spot1_Anno <- as.factor(AnnoInt$Spot1_Anno)
AnnoInt$Spot2_Anno <- as.factor(AnnoInt$Spot2_Anno)
# Return the dataframe
return(AnnoInt)
}