-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCausalXtract_Demo.Rmd
121 lines (104 loc) · 5.73 KB
/
CausalXtract_Demo.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
title: "CausalXtract Demo"
output: html_notebook
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook.\
When you execute code within the notebook, the results appear beneath the code.\
Please make sure you were located in the Demo folder when opening this Causal_Xtract_Demo.Rmd file in order to have the correct working directory.
**This demo reproduces the pipeline described in the CausalXtract publication.**
Before executing this demo, please ensure that the following prerequisites are met:
- **Matlab** is installed with the additional toolboxes **"Image Processing Toolbox"** and **"Statistics and Machine Learning Toolbox"** (needed for the CellHunter+ module).\
Note that you can skip the CellHunter+ part if you don't have Matlab.\
- **R** and **C++14** are installed (needed for the causal discovery module).\
- the **CausalXtract github repository** has been replicated locally.\
You can replicate the CausalXtract repository with the command:\
*git clone <https://github.com/miicTeam/CausalXtract.git>*\
- the **MATLAB_DATA.rar** file from [*https://doi.org/10.5281/zenodo.7755699*](https://doi.org/10.5281/zenodo.7755699){.uri} has been downloaded and extracted to obtain the **CausalXtract/MATLAB_DATA** folder. The **ROI MAT.rar** and **ROI_TU MAT.rar** files have to be extracted as well inside the MATLAB_DATA folder, obtaining the folders **CausalXtract/MATLAB_DATA/ROI MAT** and **CausalXtract/MATLAB_DATA/ROI_TU MAT**.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*.
```{r}
cat ("CausalXtract Demo\n")
```
Prerequisites check:
```{r}
if ( ! ( dir.exists ("../CellHunterPlus")
&& dir.exists ("../Demo")
&& dir.exists ("../tMIIC") ) )
stop ("CausalXtract repository not found")
if ( ! dir.exists ("../MATLAB_DATA") )
warning ("MATLAB_data not found (but you can skip this part)\n")
cat ("Prerequisites checked\n")
```
We ensure that the causal discovery module (tMIIC) is installed with the needed R packages:
```{r}
# Check and install if needed the R packages used by tMIIC
if ( ! ("ppcor" %in% installed.packages()) )
install.packages ("ppcor")
if ( ! ("Rcpp" %in% installed.packages()) )
install.packages ("Rcpp")
if ( ! ("scales" %in% installed.packages()) )
install.packages ("scales")
if ( ! ("stats" %in% installed.packages()) )
install.packages ("stats")
# Check and install tMIIC
if ( ( ! ("miic" %in% installed.packages()) )
|| (packageVersion("miic") < "2.0.0") )
install.packages ("../tMIIC", repos=NULL, type="source")
cat ("End of R packages check/installation\n")
```
Here, we execute the CellHunter+ module to perform segmentation & tracking, followed by the feature extraction part.\
(could take some time depending on your hardware !)\
You can skip this part if you don't have Matlab.
```{r}
cat ("CellHunter+ module\n")
system("matlab -r \"run('../CellHunterPlus/main_detection.m');
run('../CellHunterPlus/main_division_detection.m');
run('../CellHunterPlus/main_features.m');
exit\"")
```
Once the features have been extracted, we can run the temporal causal discovery:
```{r}
library (miic)
data <- read.table ("./CausalXtract_Publication_Dataset.csv",
sep=",", header=T)
so <- read.table ("./CausalXtract_Publication_State_Order.csv",
sep=",", header=T)
#
# To get a graph with 50 nodes (3 layers)
#
tmiic_res <- miic (input_data=data, state_order=so, mode="TS")
#
# To get exactly the graph of the CausalXtract publication, uncomment the following
# code as you need to go up to 200 nodes and activate the confidence cuts.
# Be aware that this could take some time depending on your hardware !
#
# tmiic_res <- miic (input_data=data, state_order=so,
# mode="TS", max_nodes=200,
# n_shuffles = 100, conf_threshold=0.01,
# ori_proba_ratio=0.01, n_threads=8)
```
Plotting is available using the usual plot command. Several displays are available (raw, lagged, compact), the default display is compact.
```{r}
if ( ! ("igraph" %in% installed.packages()) )
install.packages ("igraph")
# The specific layout is optional, just for a better visual rendering
specific_layout = matrix(nrow=17, ncol=2)
specific_layout[1,] = c(0,10) # CAF
specific_layout[2,] = c(20,20) # treatment
specific_layout[3,] = c(14,18) # apoptosis
specific_layout[4,] = c(30,10) # division
specific_layout[5,] = c(10,10) # area
specific_layout[6,] = c(30,15) # instantaneous_cancer_velocity
specific_layout[7,] = c(15,0) # instantaneous_shape_change
specific_layout[8,] = c(19,8) # perimeter
specific_layout[9,] = c(26,2) # eccentricity
specific_layout[10,] = c(15,4) # circularity
specific_layout[11,] = c(5,2) # net_displacement
specific_layout[12,] = c(5,16) # directionality
specific_layout[13,] = c(40,17) # number_of_cancer_immune_interactions_r2
specific_layout[14,] = c(40,8) # minimal_cancer_immune_distance_r2
specific_layout[15,] = c(40,0) # mean_immune_velocity_r2
specific_layout[16,] = c(40,4) # mean_immune_velocity_r1
specific_layout[17,] = c(40,12) # number_of_cancer_immune_interactions_r1
plot (tmiic_res, layout=specific_layout)
```
If you are interested in more advanced plotting features, you may consider to execute the causal discovery module on the [online server](https://miic.curie.fr/workbench_timeseries.php), providing the same parameters and inputs: dataset file, state_order file, activate the temporal mode, set the maximum number of nodes to 200, activate the skeleton cut by setting the number of shuffles to 100 and confidence cut to 0.01, then set orientation confidence cut to 0.01.