pyLoopSage 0.0.2__tar.gz → 0.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/LICENSE +2 -2
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/PKG-INFO +72 -35
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/README.md +71 -34
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/PKG-INFO +72 -35
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/setup.py +2 -2
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/SOURCES.txt +0 -0
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/dependency_links.txt +0 -0
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/entry_points.txt +0 -0
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/requires.txt +0 -0
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/pyLoopSage.egg-info/top_level.txt +0 -0
- {pyloopsage-0.0.2 → pyloopsage-0.0.6}/setup.cfg +0 -0
|
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
|
|
|
632
632
|
the "copyright" line and a pointer to where the full notice is found.
|
|
633
633
|
|
|
634
634
|
<one line to give the program's name and a brief idea of what it does.>
|
|
635
|
-
Copyright (C)
|
|
635
|
+
Copyright (C) <year> <name of author>
|
|
636
636
|
|
|
637
637
|
This program is free software: you can redistribute it and/or modify
|
|
638
638
|
it under the terms of the GNU General Public License as published by
|
|
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|
|
652
652
|
If the program does terminal interaction, make it output a short
|
|
653
653
|
notice like this when it starts in an interactive mode:
|
|
654
654
|
|
|
655
|
-
|
|
655
|
+
pyLoopSage Copyright (C) 2024 Sebastian Korsak (Sevastianos Korsak)
|
|
656
656
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
657
657
|
This is free software, and you are welcome to redistribute it
|
|
658
658
|
under certain conditions; type `show c' for details.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyLoopSage
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: An energy-based stochastic model of loop extrusion in chromatin.
|
|
5
5
|
Home-page: https://github.com/SFGLab/pyLoopSage
|
|
6
6
|
Author: Sebastian Korsak
|
|
@@ -31,11 +31,17 @@ Requires-Dist: statsmodels
|
|
|
31
31
|
Requires-Dist: imageio
|
|
32
32
|
Requires-Dist: pillow
|
|
33
33
|
|
|
34
|
-
#
|
|
35
|
-
|
|
34
|
+
# pyLoopSage
|
|
35
|
+
Updated version of the stochastic loop extrusion model: LoopSage with capability to run incredibly fast, parallelized across CPU cores. This package is even more user-friendly and it can be installed via PyPI.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
## New features
|
|
38
38
|
|
|
39
|
+
- More user-friendly environment.
|
|
40
|
+
- Installable with `pip install pyLoopSage`.
|
|
41
|
+
- Parralelization of the stochastic simulation across multiple CPUs.
|
|
42
|
+
- Capability of modelling the whole chromosome.
|
|
43
|
+
- Visualization functions.
|
|
44
|
+
- Capability to run form terminal with a simple command `loopsage -c config.ini`.
|
|
39
45
|
|
|
40
46
|
## Publication
|
|
41
47
|
Please cite the method paper in case that you would like to use this model for your work,
|
|
@@ -44,33 +50,31 @@ Please cite the method paper in case that you would like to use this model for y
|
|
|
44
50
|
|
|
45
51
|
## The model
|
|
46
52
|
|
|
53
|
+
We have a polymer chain with $$N_{\text{beads}}$$ number of monomers. In general we can scale by deault the granularity of the simulation so as to give reasonable results. Therefore if we have a `region` counted in genomic coordinates, we can assume that `N_beads=(region[1]-region[0])//2000`.
|
|
54
|
+
|
|
47
55
|
Let's assume that each cohesin $i$ can be represented of two coordinates $(m_{i},n_{i})$ we allow three moves in our simulation:
|
|
48
56
|
|
|
49
|
-
* Slide
|
|
50
|
-
* Slide left ( $m_{i} -> m_{i-1}$ to the left).
|
|
57
|
+
* Slide both locations randomly (as 1D random walk) or
|
|
51
58
|
* Rebind somewhere else.
|
|
52
59
|
|
|
60
|
+
In general a good working assumption is that the number of cohesins (or loop extrusion factors LEFs) is $$N_{\text{lef}}=2N_{\text{CTCF}}$$.
|
|
53
61
|
|
|
54
62
|
The main idea of the algorithm is to ensemble loop extrusion from a Boltzmann probability distribution, with Hamiltonian,
|
|
55
63
|
|
|
56
|
-
$$E = \
|
|
64
|
+
$$E = c_{\text{fold}}\sum_{i=1}^{N_{\text{coh}}}\log(n_i-m_i)+c_{\text{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+c_{\text{bind}}\sum_{i=1}^{N_{\text{coh}}}\left(L(m_i)+R(n_i)\right)$$
|
|
57
65
|
|
|
58
66
|
The first term corresponds to the folding of chromatin, and the second term is a penalty for the appearance of crosss. Therefore, we have the function,
|
|
59
67
|
$K(m_{i},n_{i};m_{j},n_{j})$ which takes the value 1 when $m_{i} < m_{j} < n_{i} < n_{j}$ or $m_{i}=m_{j}$ or $m_{i}=n_{j}$.
|
|
60
68
|
|
|
61
69
|
These $L(\cdot), R(\cdot)$ functions are two functions that define the binding potential and they are orientation specific - so they are different for left and right position of cohesin (because CTCF motifs are orientation specific), therefore when we have a gap in these functions, it means presence of CTCF. These two functions are derived from data with CTCF binning and by running the script for probabilistic orientation. Moreover, by $N_{(\cdot)}$ we symbolize the normalization constants for each factor,
|
|
62
70
|
|
|
63
|
-
$$
|
|
64
|
-
|
|
65
|
-
An additional term which allows other protein factors that may act as barriers for the motion of LEFs can me optionally added,
|
|
66
|
-
|
|
67
|
-
$$E_{bw}=\sum_{i=1}^{N_{\text{bw}}}\frac{r_{i}}{N_{bw,i}}\sum_{j=1}^{N_{lef}}\left(W_i(m_j)+W_i(n_j)\right),\qquad N_{bw,i} = \sum_{k}W_i(k)$$
|
|
71
|
+
$$c_{\text{fold}}=-\dfrac{N_{\text{beads}}f}{N_{\text{lef}}\log(N_{\text{beads}}/N_{\text{lef}})},\quad c_{\text{bind}}=-\dfrac{N_{\text{beads}}b}{\sum_i \left(L(m_i)+R(n_i)\right)},\quad c_{\text{cross}}=\kappa \times 10^4.$$
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
The parameters are defined in such a way that when $$f=b=\kappa=1$$, the three terms of the stochastic energy are balanced.
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
And the energy difference can be expressed as the energy difference of each term,
|
|
72
76
|
|
|
73
|
-
$$\Delta E = \Delta E_{fold}+\Delta E_{cross}+\Delta E_{
|
|
77
|
+
$$\Delta E = \Delta E_{\text{fold}}+\Delta E_{\text{cross}}+\Delta E_{\text{bind}}.$$
|
|
74
78
|
|
|
75
79
|
In this manner we accept a move in two cases:
|
|
76
80
|
|
|
@@ -79,35 +83,39 @@ In this manner we accept a move in two cases:
|
|
|
79
83
|
|
|
80
84
|
And of course, the result - the distribution of loops in equilibrium - depends on temperature of Boltzmann distribution $T$.
|
|
81
85
|
|
|
82
|
-
##
|
|
83
|
-
Install a python 3.10 environment and OpenMM 8.0 and run
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
pip install -r requirements.txt
|
|
87
|
-
```
|
|
86
|
+
## Installation
|
|
88
87
|
|
|
89
|
-
|
|
88
|
+
Can be easily installed with `pip install pyLoopSage`. To have CUDA acceleration, it is needed to have cuda-toolkit installed in case that you use nvidia drivers (otherwise you can use OpenCL or parallelization across CPU cores).
|
|
90
89
|
|
|
91
90
|
## How to use?
|
|
92
91
|
|
|
92
|
+
### Python Implementation
|
|
93
|
+
|
|
93
94
|
The main script is `LoopSage.py`. The implementation of the code is very easy and it can be described in the following lines,
|
|
94
95
|
|
|
95
96
|
```python
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
# Definition of Monte Carlo parameters
|
|
98
|
+
import Loopsage.stochastic_simulation as lps
|
|
99
|
+
|
|
100
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
101
|
+
mode = 'Metropolis'
|
|
102
|
+
|
|
103
|
+
# Simulation Strengths
|
|
104
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
105
|
+
|
|
106
|
+
# Definition of region
|
|
107
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
108
|
+
|
|
109
|
+
# Definition of data
|
|
110
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
111
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
112
|
+
|
|
113
|
+
sim = lps.StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
114
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
115
|
+
sim.run_MD('CUDA')
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
118
|
+
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
111
119
|
|
|
112
120
|
Note that the `.bedpe_file` must be in the following format,
|
|
113
121
|
|
|
@@ -128,6 +136,35 @@ where the last two columns represent the probabilites for left and right anchor
|
|
|
128
136
|
|
|
129
137
|
Then, we define the main parameters of the simulation `N_beads,N_coh,kappa,f,b` or we can choose the default ones (take care because it might be the case that they are not the appropriate ones and they need to be changed), the parameters of Monte Carlo `N_steps, MC_step, burnin, T`, and we initialize the class `LoopSage()`. The command `sim.run_energy_minimization()` corresponds to the stochastic Monte Carlo simulation, and it produces a set of cohesin constraints as a result (`Ms, Ns`). Note that the stochastic simulation has two modes: `Annealing` and `Metropolis`. We feed cohesin constraints to the molecular simulation part of and we run `MD_LE()` or `MD_EM()` simulation which produces a trajectory of 3d-structures, and the average heatmap. `MD_LE()` function can produce an actual trajectory and a `.dcd` video of how simulation changes over time. However, the implementation needs a high amount of memory since we need to define a bond for each time step, and it may not work for large systems. `EM_LE()` is suggested for large simulations, because it does not require so big amount of memory.
|
|
130
138
|
|
|
139
|
+
### Command-line command
|
|
140
|
+
To run LoopSage from command-line, you only need to type a command
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
loopsage -c config.ini
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
With this command the model will run with parameters specified in `config.ini` file. An example of a `config.ini` file would be the following,
|
|
147
|
+
|
|
148
|
+
```txt
|
|
149
|
+
# Definition of Monte Carlo parameters
|
|
150
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
151
|
+
mode = 'Metropolis'
|
|
152
|
+
|
|
153
|
+
# Simulation Strengths
|
|
154
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
155
|
+
|
|
156
|
+
# Definition of region
|
|
157
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
158
|
+
|
|
159
|
+
# Definition of data
|
|
160
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
161
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
162
|
+
|
|
163
|
+
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
164
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
165
|
+
sim.run_MD('CUDA')
|
|
166
|
+
```
|
|
167
|
+
|
|
131
168
|
### Output Files
|
|
132
169
|
In the output files, simulation produces one folder with 4 subfolders. In subfolder `plots`, you can find plots that are the diagnostics of the algorithm. One of the most basic results you should see is the trajectories of cohesins (LEFs). this diagram should look like that,
|
|
133
170
|
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# pyLoopSage
|
|
2
|
+
Updated version of the stochastic loop extrusion model: LoopSage with capability to run incredibly fast, parallelized across CPU cores. This package is even more user-friendly and it can be installed via PyPI.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## New features
|
|
5
5
|
|
|
6
|
+
- More user-friendly environment.
|
|
7
|
+
- Installable with `pip install pyLoopSage`.
|
|
8
|
+
- Parralelization of the stochastic simulation across multiple CPUs.
|
|
9
|
+
- Capability of modelling the whole chromosome.
|
|
10
|
+
- Visualization functions.
|
|
11
|
+
- Capability to run form terminal with a simple command `loopsage -c config.ini`.
|
|
6
12
|
|
|
7
13
|
## Publication
|
|
8
14
|
Please cite the method paper in case that you would like to use this model for your work,
|
|
@@ -11,33 +17,31 @@ Please cite the method paper in case that you would like to use this model for y
|
|
|
11
17
|
|
|
12
18
|
## The model
|
|
13
19
|
|
|
20
|
+
We have a polymer chain with $$N_{\text{beads}}$$ number of monomers. In general we can scale by deault the granularity of the simulation so as to give reasonable results. Therefore if we have a `region` counted in genomic coordinates, we can assume that `N_beads=(region[1]-region[0])//2000`.
|
|
21
|
+
|
|
14
22
|
Let's assume that each cohesin $i$ can be represented of two coordinates $(m_{i},n_{i})$ we allow three moves in our simulation:
|
|
15
23
|
|
|
16
|
-
* Slide
|
|
17
|
-
* Slide left ( $m_{i} -> m_{i-1}$ to the left).
|
|
24
|
+
* Slide both locations randomly (as 1D random walk) or
|
|
18
25
|
* Rebind somewhere else.
|
|
19
26
|
|
|
27
|
+
In general a good working assumption is that the number of cohesins (or loop extrusion factors LEFs) is $$N_{\text{lef}}=2N_{\text{CTCF}}$$.
|
|
20
28
|
|
|
21
29
|
The main idea of the algorithm is to ensemble loop extrusion from a Boltzmann probability distribution, with Hamiltonian,
|
|
22
30
|
|
|
23
|
-
$$E = \
|
|
31
|
+
$$E = c_{\text{fold}}\sum_{i=1}^{N_{\text{coh}}}\log(n_i-m_i)+c_{\text{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+c_{\text{bind}}\sum_{i=1}^{N_{\text{coh}}}\left(L(m_i)+R(n_i)\right)$$
|
|
24
32
|
|
|
25
33
|
The first term corresponds to the folding of chromatin, and the second term is a penalty for the appearance of crosss. Therefore, we have the function,
|
|
26
34
|
$K(m_{i},n_{i};m_{j},n_{j})$ which takes the value 1 when $m_{i} < m_{j} < n_{i} < n_{j}$ or $m_{i}=m_{j}$ or $m_{i}=n_{j}$.
|
|
27
35
|
|
|
28
36
|
These $L(\cdot), R(\cdot)$ functions are two functions that define the binding potential and they are orientation specific - so they are different for left and right position of cohesin (because CTCF motifs are orientation specific), therefore when we have a gap in these functions, it means presence of CTCF. These two functions are derived from data with CTCF binning and by running the script for probabilistic orientation. Moreover, by $N_{(\cdot)}$ we symbolize the normalization constants for each factor,
|
|
29
37
|
|
|
30
|
-
$$
|
|
31
|
-
|
|
32
|
-
An additional term which allows other protein factors that may act as barriers for the motion of LEFs can me optionally added,
|
|
33
|
-
|
|
34
|
-
$$E_{bw}=\sum_{i=1}^{N_{\text{bw}}}\frac{r_{i}}{N_{bw,i}}\sum_{j=1}^{N_{lef}}\left(W_i(m_j)+W_i(n_j)\right),\qquad N_{bw,i} = \sum_{k}W_i(k)$$
|
|
38
|
+
$$c_{\text{fold}}=-\dfrac{N_{\text{beads}}f}{N_{\text{lef}}\log(N_{\text{beads}}/N_{\text{lef}})},\quad c_{\text{bind}}=-\dfrac{N_{\text{beads}}b}{\sum_i \left(L(m_i)+R(n_i)\right)},\quad c_{\text{cross}}=\kappa \times 10^4.$$
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
The parameters are defined in such a way that when $$f=b=\kappa=1$$, the three terms of the stochastic energy are balanced.
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
And the energy difference can be expressed as the energy difference of each term,
|
|
39
43
|
|
|
40
|
-
$$\Delta E = \Delta E_{fold}+\Delta E_{cross}+\Delta E_{
|
|
44
|
+
$$\Delta E = \Delta E_{\text{fold}}+\Delta E_{\text{cross}}+\Delta E_{\text{bind}}.$$
|
|
41
45
|
|
|
42
46
|
In this manner we accept a move in two cases:
|
|
43
47
|
|
|
@@ -46,35 +50,39 @@ In this manner we accept a move in two cases:
|
|
|
46
50
|
|
|
47
51
|
And of course, the result - the distribution of loops in equilibrium - depends on temperature of Boltzmann distribution $T$.
|
|
48
52
|
|
|
49
|
-
##
|
|
50
|
-
Install a python 3.10 environment and OpenMM 8.0 and run
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
pip install -r requirements.txt
|
|
54
|
-
```
|
|
53
|
+
## Installation
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
Can be easily installed with `pip install pyLoopSage`. To have CUDA acceleration, it is needed to have cuda-toolkit installed in case that you use nvidia drivers (otherwise you can use OpenCL or parallelization across CPU cores).
|
|
57
56
|
|
|
58
57
|
## How to use?
|
|
59
58
|
|
|
59
|
+
### Python Implementation
|
|
60
|
+
|
|
60
61
|
The main script is `LoopSage.py`. The implementation of the code is very easy and it can be described in the following lines,
|
|
61
62
|
|
|
62
63
|
```python
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
# Definition of Monte Carlo parameters
|
|
65
|
+
import Loopsage.stochastic_simulation as lps
|
|
66
|
+
|
|
67
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
68
|
+
mode = 'Metropolis'
|
|
69
|
+
|
|
70
|
+
# Simulation Strengths
|
|
71
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
72
|
+
|
|
73
|
+
# Definition of region
|
|
74
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
75
|
+
|
|
76
|
+
# Definition of data
|
|
77
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
78
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
79
|
+
|
|
80
|
+
sim = lps.StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
81
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
82
|
+
sim.run_MD('CUDA')
|
|
75
83
|
```
|
|
76
84
|
|
|
77
|
-
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
85
|
+
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
78
86
|
|
|
79
87
|
Note that the `.bedpe_file` must be in the following format,
|
|
80
88
|
|
|
@@ -95,6 +103,35 @@ where the last two columns represent the probabilites for left and right anchor
|
|
|
95
103
|
|
|
96
104
|
Then, we define the main parameters of the simulation `N_beads,N_coh,kappa,f,b` or we can choose the default ones (take care because it might be the case that they are not the appropriate ones and they need to be changed), the parameters of Monte Carlo `N_steps, MC_step, burnin, T`, and we initialize the class `LoopSage()`. The command `sim.run_energy_minimization()` corresponds to the stochastic Monte Carlo simulation, and it produces a set of cohesin constraints as a result (`Ms, Ns`). Note that the stochastic simulation has two modes: `Annealing` and `Metropolis`. We feed cohesin constraints to the molecular simulation part of and we run `MD_LE()` or `MD_EM()` simulation which produces a trajectory of 3d-structures, and the average heatmap. `MD_LE()` function can produce an actual trajectory and a `.dcd` video of how simulation changes over time. However, the implementation needs a high amount of memory since we need to define a bond for each time step, and it may not work for large systems. `EM_LE()` is suggested for large simulations, because it does not require so big amount of memory.
|
|
97
105
|
|
|
106
|
+
### Command-line command
|
|
107
|
+
To run LoopSage from command-line, you only need to type a command
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
loopsage -c config.ini
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
With this command the model will run with parameters specified in `config.ini` file. An example of a `config.ini` file would be the following,
|
|
114
|
+
|
|
115
|
+
```txt
|
|
116
|
+
# Definition of Monte Carlo parameters
|
|
117
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
118
|
+
mode = 'Metropolis'
|
|
119
|
+
|
|
120
|
+
# Simulation Strengths
|
|
121
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
122
|
+
|
|
123
|
+
# Definition of region
|
|
124
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
125
|
+
|
|
126
|
+
# Definition of data
|
|
127
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
128
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
129
|
+
|
|
130
|
+
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
131
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
132
|
+
sim.run_MD('CUDA')
|
|
133
|
+
```
|
|
134
|
+
|
|
98
135
|
### Output Files
|
|
99
136
|
In the output files, simulation produces one folder with 4 subfolders. In subfolder `plots`, you can find plots that are the diagnostics of the algorithm. One of the most basic results you should see is the trajectories of cohesins (LEFs). this diagram should look like that,
|
|
100
137
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyLoopSage
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: An energy-based stochastic model of loop extrusion in chromatin.
|
|
5
5
|
Home-page: https://github.com/SFGLab/pyLoopSage
|
|
6
6
|
Author: Sebastian Korsak
|
|
@@ -31,11 +31,17 @@ Requires-Dist: statsmodels
|
|
|
31
31
|
Requires-Dist: imageio
|
|
32
32
|
Requires-Dist: pillow
|
|
33
33
|
|
|
34
|
-
#
|
|
35
|
-
|
|
34
|
+
# pyLoopSage
|
|
35
|
+
Updated version of the stochastic loop extrusion model: LoopSage with capability to run incredibly fast, parallelized across CPU cores. This package is even more user-friendly and it can be installed via PyPI.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
## New features
|
|
38
38
|
|
|
39
|
+
- More user-friendly environment.
|
|
40
|
+
- Installable with `pip install pyLoopSage`.
|
|
41
|
+
- Parralelization of the stochastic simulation across multiple CPUs.
|
|
42
|
+
- Capability of modelling the whole chromosome.
|
|
43
|
+
- Visualization functions.
|
|
44
|
+
- Capability to run form terminal with a simple command `loopsage -c config.ini`.
|
|
39
45
|
|
|
40
46
|
## Publication
|
|
41
47
|
Please cite the method paper in case that you would like to use this model for your work,
|
|
@@ -44,33 +50,31 @@ Please cite the method paper in case that you would like to use this model for y
|
|
|
44
50
|
|
|
45
51
|
## The model
|
|
46
52
|
|
|
53
|
+
We have a polymer chain with $$N_{\text{beads}}$$ number of monomers. In general we can scale by deault the granularity of the simulation so as to give reasonable results. Therefore if we have a `region` counted in genomic coordinates, we can assume that `N_beads=(region[1]-region[0])//2000`.
|
|
54
|
+
|
|
47
55
|
Let's assume that each cohesin $i$ can be represented of two coordinates $(m_{i},n_{i})$ we allow three moves in our simulation:
|
|
48
56
|
|
|
49
|
-
* Slide
|
|
50
|
-
* Slide left ( $m_{i} -> m_{i-1}$ to the left).
|
|
57
|
+
* Slide both locations randomly (as 1D random walk) or
|
|
51
58
|
* Rebind somewhere else.
|
|
52
59
|
|
|
60
|
+
In general a good working assumption is that the number of cohesins (or loop extrusion factors LEFs) is $$N_{\text{lef}}=2N_{\text{CTCF}}$$.
|
|
53
61
|
|
|
54
62
|
The main idea of the algorithm is to ensemble loop extrusion from a Boltzmann probability distribution, with Hamiltonian,
|
|
55
63
|
|
|
56
|
-
$$E = \
|
|
64
|
+
$$E = c_{\text{fold}}\sum_{i=1}^{N_{\text{coh}}}\log(n_i-m_i)+c_{\text{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+c_{\text{bind}}\sum_{i=1}^{N_{\text{coh}}}\left(L(m_i)+R(n_i)\right)$$
|
|
57
65
|
|
|
58
66
|
The first term corresponds to the folding of chromatin, and the second term is a penalty for the appearance of crosss. Therefore, we have the function,
|
|
59
67
|
$K(m_{i},n_{i};m_{j},n_{j})$ which takes the value 1 when $m_{i} < m_{j} < n_{i} < n_{j}$ or $m_{i}=m_{j}$ or $m_{i}=n_{j}$.
|
|
60
68
|
|
|
61
69
|
These $L(\cdot), R(\cdot)$ functions are two functions that define the binding potential and they are orientation specific - so they are different for left and right position of cohesin (because CTCF motifs are orientation specific), therefore when we have a gap in these functions, it means presence of CTCF. These two functions are derived from data with CTCF binning and by running the script for probabilistic orientation. Moreover, by $N_{(\cdot)}$ we symbolize the normalization constants for each factor,
|
|
62
70
|
|
|
63
|
-
$$
|
|
64
|
-
|
|
65
|
-
An additional term which allows other protein factors that may act as barriers for the motion of LEFs can me optionally added,
|
|
66
|
-
|
|
67
|
-
$$E_{bw}=\sum_{i=1}^{N_{\text{bw}}}\frac{r_{i}}{N_{bw,i}}\sum_{j=1}^{N_{lef}}\left(W_i(m_j)+W_i(n_j)\right),\qquad N_{bw,i} = \sum_{k}W_i(k)$$
|
|
71
|
+
$$c_{\text{fold}}=-\dfrac{N_{\text{beads}}f}{N_{\text{lef}}\log(N_{\text{beads}}/N_{\text{lef}})},\quad c_{\text{bind}}=-\dfrac{N_{\text{beads}}b}{\sum_i \left(L(m_i)+R(n_i)\right)},\quad c_{\text{cross}}=\kappa \times 10^4.$$
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
The parameters are defined in such a way that when $$f=b=\kappa=1$$, the three terms of the stochastic energy are balanced.
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
And the energy difference can be expressed as the energy difference of each term,
|
|
72
76
|
|
|
73
|
-
$$\Delta E = \Delta E_{fold}+\Delta E_{cross}+\Delta E_{
|
|
77
|
+
$$\Delta E = \Delta E_{\text{fold}}+\Delta E_{\text{cross}}+\Delta E_{\text{bind}}.$$
|
|
74
78
|
|
|
75
79
|
In this manner we accept a move in two cases:
|
|
76
80
|
|
|
@@ -79,35 +83,39 @@ In this manner we accept a move in two cases:
|
|
|
79
83
|
|
|
80
84
|
And of course, the result - the distribution of loops in equilibrium - depends on temperature of Boltzmann distribution $T$.
|
|
81
85
|
|
|
82
|
-
##
|
|
83
|
-
Install a python 3.10 environment and OpenMM 8.0 and run
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
pip install -r requirements.txt
|
|
87
|
-
```
|
|
86
|
+
## Installation
|
|
88
87
|
|
|
89
|
-
|
|
88
|
+
Can be easily installed with `pip install pyLoopSage`. To have CUDA acceleration, it is needed to have cuda-toolkit installed in case that you use nvidia drivers (otherwise you can use OpenCL or parallelization across CPU cores).
|
|
90
89
|
|
|
91
90
|
## How to use?
|
|
92
91
|
|
|
92
|
+
### Python Implementation
|
|
93
|
+
|
|
93
94
|
The main script is `LoopSage.py`. The implementation of the code is very easy and it can be described in the following lines,
|
|
94
95
|
|
|
95
96
|
```python
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
# Definition of Monte Carlo parameters
|
|
98
|
+
import Loopsage.stochastic_simulation as lps
|
|
99
|
+
|
|
100
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
101
|
+
mode = 'Metropolis'
|
|
102
|
+
|
|
103
|
+
# Simulation Strengths
|
|
104
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
105
|
+
|
|
106
|
+
# Definition of region
|
|
107
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
108
|
+
|
|
109
|
+
# Definition of data
|
|
110
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
111
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
112
|
+
|
|
113
|
+
sim = lps.StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
114
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
115
|
+
sim.run_MD('CUDA')
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
118
|
+
Firstly, we need to define the input files from which LoopSage would take the information to construct the potential. We define also the specific region that we would like to model. Therefore, in the code script above we define a `bedpe_file` from which information about the CTCF loops it is imported.
|
|
111
119
|
|
|
112
120
|
Note that the `.bedpe_file` must be in the following format,
|
|
113
121
|
|
|
@@ -128,6 +136,35 @@ where the last two columns represent the probabilites for left and right anchor
|
|
|
128
136
|
|
|
129
137
|
Then, we define the main parameters of the simulation `N_beads,N_coh,kappa,f,b` or we can choose the default ones (take care because it might be the case that they are not the appropriate ones and they need to be changed), the parameters of Monte Carlo `N_steps, MC_step, burnin, T`, and we initialize the class `LoopSage()`. The command `sim.run_energy_minimization()` corresponds to the stochastic Monte Carlo simulation, and it produces a set of cohesin constraints as a result (`Ms, Ns`). Note that the stochastic simulation has two modes: `Annealing` and `Metropolis`. We feed cohesin constraints to the molecular simulation part of and we run `MD_LE()` or `MD_EM()` simulation which produces a trajectory of 3d-structures, and the average heatmap. `MD_LE()` function can produce an actual trajectory and a `.dcd` video of how simulation changes over time. However, the implementation needs a high amount of memory since we need to define a bond for each time step, and it may not work for large systems. `EM_LE()` is suggested for large simulations, because it does not require so big amount of memory.
|
|
130
138
|
|
|
139
|
+
### Command-line command
|
|
140
|
+
To run LoopSage from command-line, you only need to type a command
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
loopsage -c config.ini
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
With this command the model will run with parameters specified in `config.ini` file. An example of a `config.ini` file would be the following,
|
|
147
|
+
|
|
148
|
+
```txt
|
|
149
|
+
# Definition of Monte Carlo parameters
|
|
150
|
+
N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
|
|
151
|
+
mode = 'Metropolis'
|
|
152
|
+
|
|
153
|
+
# Simulation Strengths
|
|
154
|
+
f, b, kappa = 1.0, 1.0, 1.0
|
|
155
|
+
|
|
156
|
+
# Definition of region
|
|
157
|
+
region, chrom = [15550000,16850000], 'chr6'
|
|
158
|
+
|
|
159
|
+
# Definition of data
|
|
160
|
+
output_name='../HiChIP_Annealing_T1_MD_region'
|
|
161
|
+
bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
|
|
162
|
+
|
|
163
|
+
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
|
|
164
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=True,save=True)
|
|
165
|
+
sim.run_MD('CUDA')
|
|
166
|
+
```
|
|
167
|
+
|
|
131
168
|
### Output Files
|
|
132
169
|
In the output files, simulation produces one folder with 4 subfolders. In subfolder `plots`, you can find plots that are the diagnostics of the algorithm. One of the most basic results you should see is the trajectories of cohesins (LEFs). this diagram should look like that,
|
|
133
170
|
|
|
@@ -6,7 +6,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
|
|
|
6
6
|
|
|
7
7
|
setup(
|
|
8
8
|
name='pyLoopSage', # Package name
|
|
9
|
-
version='0.0.
|
|
9
|
+
version='0.0.6', # Version of the software
|
|
10
10
|
description='An energy-based stochastic model of loop extrusion in chromatin.',
|
|
11
11
|
long_description=long_description,
|
|
12
12
|
long_description_content_type='text/markdown',
|
|
@@ -46,4 +46,4 @@ setup(
|
|
|
46
46
|
'Operating System :: POSIX :: Linux', # General OS classifier
|
|
47
47
|
],
|
|
48
48
|
python_requires='>=3.10', # Specify Python version compatibility
|
|
49
|
-
)
|
|
49
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|