@@ -38,6 +38,7 @@ spe <- WeberDivechaLCdata_Visium()
38
38
39
39
coords <- as.data.frame(spe @ int_colData $ spatialCoords )
40
40
colnames(coords ) <- c(' x' , ' y' )
41
+ coords_rownames <- rownames(spe @ int_colData $ spatialCoords )
41
42
42
43
counts <- spe @ assays @ data $ counts
43
44
@@ -51,16 +52,6 @@ counts_func <- function(x){
51
52
}
52
53
counts_lc <- unlist(lapply(colnames(counts ), counts_func ))
53
54
54
- obs_func <- function (x ){
55
- fields <- unlist(strsplit(x , " _" ))
56
- if ( length(fields ) == 4 ){
57
- return (fields [4 ])
58
- } else {
59
- return (fields [5 ])
60
- }
61
- }
62
- observations_lc <- unlist(lapply(colnames(counts ), obs_func ))
63
-
64
55
LC_samples <- unique(spe @ colData $ sample_id )
65
56
66
57
out_dir <- ' out_dir'
@@ -82,9 +73,10 @@ for (lc in LC_samples){
82
73
83
74
print(lc )
84
75
dir <- paste0(out_dir , " /" , lc )
85
- # TODO Please check this again beause I had to flip the coordinates to get the pictures as seen in:
86
- # https://libd.shinyapps.io/locus-c_Visium/. See ggplot below.
76
+
77
+ # Write coordinates.tsv
87
78
coords_subset <- coords [which(spe @ colData $ sample_id == lc ),]
79
+ rownames(coords_subset ) <- coords_rownames [which(spe @ colData $ sample_id == lc )]
88
80
write.table(coords_subset , file = paste0(dir , " /coordinates.tsv" ), col.names = NA ,
89
81
sep = " \t " , quote = FALSE , row.names = TRUE )
90
82
@@ -95,31 +87,26 @@ for (lc in LC_samples){
95
87
counts_subset <- t(counts_subset )
96
88
writeMM(counts_subset , file = paste0(dir , " /counts.mtx" ))
97
89
98
- observations_subset <- observations_lc [which(counts_lc == lc )]
90
+ observations_subset <- spe @ colData [which(counts_lc == lc ),]
91
+ rownames(observations_subset ) <- lapply(rownames(observations_subset ), function (x ){tail(unlist(strsplit(x ," _" )),1 )})
99
92
write.table(observations_subset , file = paste0(dir , " /observations.tsv" ), col.names = NA , sep = " \t " , quote = FALSE )
100
93
101
94
labels <- spe @ colData $ annot_region [which(spe @ colData $ sample_id == lc )]
102
95
labels [which(labels == TRUE )] <- " LC"
103
96
labels [which(labels == FALSE )] <- " non_LC"
104
- write.table(labels , file = paste0(dir , " /labels.tsv" ), col.names = NA , sep = " \t " , quote = FALSE )
105
-
106
- # TODO #Create the scatter plot
107
- # library(ggplot2)
108
- # plot_df <- coords[which(spe@colData$sample_id == lc),]
109
- # plot_df$label <- labels
110
- # plot_df
111
- # ggplot(plot_df, aes(x = x, y = y, color=label)) +
112
- # geom_point() +
113
- # coord_fixed() + # Keep aspect ratio equal
114
- # scale_y_reverse() # Flip the y-axis
97
+
98
+ labels_df <- data.frame (label = labels )
99
+ rownames(labels_df ) <- rownames(observations_subset )
100
+ write.table(labels_df , file = paste0(dir , " /labels.tsv" ), col.names = NA , sep = " \t " , quote = FALSE )
115
101
116
102
# Fill metadata
117
103
patient_list <- c(patient_list , as.character(unique(spe @ colData [which(spe @ colData $ sample_id == lc ),]$ donor_id )))
118
104
sample_list <- c(sample_list , lc )
119
105
directory_list <- c(directory_list , dir )
120
106
121
107
# Write features.tsv
122
- features <- rownames(spe @ assays @ data $ counts )
108
+ features <- as.data.frame(spe @ rowRanges )
109
+ rownames(features ) <- spe @ rowRanges $ gene_id
123
110
write.table(features , file = paste0(dir ," /features.tsv" ), col.names = NA , sep = " \t " , quote = FALSE )
124
111
}
125
112
0 commit comments