This repository was archived by the owner on Dec 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.R
More file actions
113 lines (87 loc) · 3.56 KB
/
example.R
File metadata and controls
113 lines (87 loc) · 3.56 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
## These packages need to be installed in R (OS-independent):
# install.packages(c('dplyr', 'ggplot2', 'spdep', 'tidyr'))
## package dependencies might require installation of system libraries (OS-dependent):
# brew install pkg-config udunits gdal
# message from 'spdep': "To access larger datasets in this package, install the spDataLarge package with:"
# install.packages('spDataLarge', repos='https://nowosad.github.io/drat/', type='source')
# load custom library with imports
source("./Spatial_Perm_and_Normalization.R")
### Samples are first processed here to generate original and permutated CLQs for each cell to cell pair in a given sample.
### Input file name example: “TAFs1_cell_type_assignment.csv”
files <- (Sys.glob("./input/*cell_type_assignment.csv"))
if (length(files) == 0) {
stop("No files found at path. Check file path and pattern!")
}
for (file in files) {
print(file)
count_file <- write_counts(sample_path = file, out_dir = "./output")
### CLQ_permutated_matrix_gen function is using iteration number, filename and the count_file generated in the previous step.
### This function is dependent on multiple functions [get_CLQ(), KNN_neighbors(), find_cell_type_neighbors()]
### iternum is the iteration number for permutation analysis, which is set to 500.
CLQ_permutated <- CLQ_permutated_matrix_gen1(
iternum = 500,
sample_path = file,
counts_path = count_file,
out_dir = "./output"
)
}
###
### Then, significance of CLQs are calculated based on their percentile.
### The original CLQs and permutated CLQs are retrieved for each sample through the functions [CLQ_matrix_gen(),
### CLQ_permutated_matrix_gen_caller(),get_counts_caller() ]
files <- (Sys.glob("./input/*cell_type_assignment.csv"))
if (length(files) == 0) {
stop("No files found at path. Check file path and pattern!")
}
for (file in files) {
print(file)
CLQ_matrix <- CLQ_matrix_gen(sample_path = file, out_dir = "./output")
CLQ_permutated <- CLQ_permutated_matrix_gen2(sample_path = file, out_dir = "./output")
counts_data <- read_counts(sample_path = file, out_dir = "./output")
### “list_of_matrices” is the 500 different CLQ sets for each iteration.
significance_matrices <- significance_matrix_gen(
iternum = 500,
sample_path = file,
list_of_matrices = CLQ_permutated,
CLQ_matrix_original = CLQ_matrix,
counts_data = counts_data,
out_dir = "./output"
)
### plot_gen generates plot for each CLQ for a pair of cell type A to cell type B. It retrieves the permutated CLQ values
### from CLQ_permutated, and the original CLQ values from CLQ_matrix.
plot_gen(
iternum = 500,
sample_path = file,
list_of_matrices = CLQ_permutated,
CLQ_matrix_original = CLQ_matrix,
out_dir = "./output"
)
}
#
# #calling the function
# #Example 1 : assembloid sample
# filename = "TAFs1_cell_type_assignment.csv"
# righttail = 0.05
# lefttail = 0
# call_normalization_fnc(filename , righttail , lefttail)
# #
#
# calling the function
# Example 2 : clinical specimen
# filename = "lepidic_58.6_cell_type_assignment.csv"
# righttail = 0.05
# lefttail = 0
# call_normalization_fnc(filename , righttail , lefttail)
# filename = "lepidic_58.6_cell_type_assignment.csv"
# righttail = 0.15
# lefttail = 0
# call_normalization_fnc(filename , righttail , lefttail)
#
files <- (Sys.glob("./input/*cell_type_assignment.csv"))
if (length(files) == 0) {
stop("No files found at path. Check file path and pattern!")
}
for (file in files) {
print(file)
call_normalization(sample_path = file, righttail = 0.05, lefttail = 0.00, out_dir = "./output")
}