pyLoopSage 0.0.2__tar.gz → 0.0.8__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.
@@ -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) December 2023 Sebastian Korsak - Sevastianos Korsak
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
- LoopSage Copyright (C) December 2023 Sebastian Korsak - Sevastianos Korsak
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.2
3
+ Version: 0.0.8
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
@@ -29,13 +29,20 @@ Requires-Dist: OpenMM
29
29
  Requires-Dist: OpenMM-cuda
30
30
  Requires-Dist: statsmodels
31
31
  Requires-Dist: imageio
32
+ Requires-Dist: imageio[ffmpeg]
32
33
  Requires-Dist: pillow
33
34
 
34
- # LoopSage
35
- An energy-based model for loop extrusion.
35
+ # pyLoopSage
36
+ 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
37
 
37
- **Important!!!** *Now the molecular dynamics can run for larger regions, since the code or `LoopSage_md.py` is fixed and does not allocate so much memory.*
38
+ ## New features
38
39
 
40
+ - More user-friendly environment.
41
+ - Installable with `pip install pyLoopSage`.
42
+ - Parralelization of the stochastic simulation across multiple CPUs.
43
+ - Capability of modelling the whole chromosome.
44
+ - Visualization functions.
45
+ - Capability to run form terminal with a simple command `loopsage -c config.ini`.
39
46
 
40
47
  ## Publication
41
48
  Please cite the method paper in case that you would like to use this model for your work,
@@ -44,33 +51,31 @@ Please cite the method paper in case that you would like to use this model for y
44
51
 
45
52
  ## The model
46
53
 
54
+ 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`.
55
+
47
56
  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
57
 
49
- * Slide right ( $n_{i} -> n_{i+1}$ to the right).
50
- * Slide left ( $m_{i} -> m_{i-1}$ to the left).
58
+ * Slide both locations randomly (as 1D random walk) or
51
59
  * Rebind somewhere else.
52
60
 
61
+ 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
62
 
54
63
  The main idea of the algorithm is to ensemble loop extrusion from a Boltzmann probability distribution, with Hamiltonian,
55
64
 
56
- $$E = \dfrac{f}{N_{fold}}\sum_{i=1}^{N_{coh}}\log(n_i-m_i)+\dfrac{\kappa}{N_{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+\dfrac{b}{N_{bind}}\sum_{i=1}^{N_{coh}}\left(L(m_i)+R(n_i)\right)$$
65
+ $$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
66
 
58
67
  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
68
  $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
69
 
61
70
  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
71
 
63
- $$N_{fold}=N_{coh}\cdot \langle n_i-m_i\rangle,\quad N_{cross}=N_{coh},\quad N_{bind}=\sum_{k}\left(L(k)+R(k)\right).$$
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)$$
72
+ $$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
73
 
69
- where $N_{bw}$ is the number of \texttt{.BigWig} ChIP-Seq experiments that are imported for each one of the proteins of interest. The energy term $W_{i}(\cdot)$ it corresponds to the average values of the ChIP-Seq experiment $i$ for each loci of interest. Finally, $r_{i}$ it is a weight that corresponds each one of these experiments and by default it is set as $r_{i}=b/2$.
74
+ The parameters are defined in such a way that when $$f=b=\kappa=1$$, the three terms of the stochastic energy are balanced.
70
75
 
71
- Thus,
76
+ And the energy difference can be expressed as the energy difference of each term,
72
77
 
73
- $$\Delta E = \Delta E_{fold}+\Delta E_{cross}+\Delta E_{bind} + \Delta E_{bw}.$$
78
+ $$\Delta E = \Delta E_{\text{fold}}+\Delta E_{\text{cross}}+\Delta E_{\text{bind}}.$$
74
79
 
75
80
  In this manner we accept a move in two cases:
76
81
 
@@ -79,35 +84,39 @@ In this manner we accept a move in two cases:
79
84
 
80
85
  And of course, the result - the distribution of loops in equilibrium - depends on temperature of Boltzmann distribution $T$.
81
86
 
82
- ## Packages to install
83
- Install a python 3.10 environment and OpenMM 8.0 and run
84
-
85
- ```
86
- pip install -r requirements.txt
87
- ```
87
+ ## Installation
88
88
 
89
- For faster computations use CUDA toolkit: https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local.
89
+ 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
90
 
91
91
  ## How to use?
92
92
 
93
+ ### Python Implementation
94
+
93
95
  The main script is `LoopSage.py`. The implementation of the code is very easy and it can be described in the following lines,
94
96
 
95
97
  ```python
96
- N_steps, MC_step, burnin, T, T_min = int(1e4), int(2e2), 1000, 5,1
97
- region, chrom = [88271457,88851999], 'chr10'
98
- label=f'Petros_wt1h'
99
- bedpe_file = '/mnt/raid/data/Petros_project/loops/wt1h_pooled_2.bedpe'
100
- coh_track_file = '/mnt/raid/data/Petros_project/bw/RAD21_ChIPseq/mm_BMDM_WT_Rad21_heme_60min.bw'
101
- bw_file1 = '/mnt/raid/data/Petros_project/bw/BACH1_ChIPseq/mm_Bach1_1h_rep1_heme_merged.bw'
102
- bw_file2 = '/mnt/raid/data/Petros_project/bw/RNAPol_ChIPseq/WT-RNAPOLIIS2-1h-heme100-rep1_S5.bw'
103
- bw_files = [bw_file1,bw_file2]
104
-
105
- sim = LoopSage(region,chrom,bedpe_file,label=label,N_lef=50,N_beads=1000,bw_files=bw_files,track_file=coh_track_file)
106
- Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,poisson_choice=True,mode='Annealing',viz=True,save=True)
107
- sim.run_MD()
98
+ # Definition of Monte Carlo parameters
99
+ import Loopsage.stochastic_simulation as lps
100
+
101
+ N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
102
+ mode = 'Metropolis'
103
+
104
+ # Simulation Strengths
105
+ f, b, kappa = 1.0, 1.0, 1.0
106
+
107
+ # Definition of region
108
+ region, chrom = [15550000,16850000], 'chr6'
109
+
110
+ # Definition of data
111
+ output_name='../HiChIP_Annealing_T1_MD_region'
112
+ bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
113
+
114
+ sim = lps.StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
115
+ 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)
116
+ sim.run_MD('CUDA')
108
117
  ```
109
118
 
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. In `coh_track_file` you can optionally define the track file with some cohesin coverage of ChIP-Seq to determine the distribution of LEFs and allow preferencial binding in regions with higher signal. Then the user can optionally define a list of BigWig files which are needed in case that user would like to model other protein factors and their coefficients $r_i$.
119
+ 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
120
 
112
121
  Note that the `.bedpe_file` must be in the following format,
113
122
 
@@ -128,6 +137,35 @@ where the last two columns represent the probabilites for left and right anchor
128
137
 
129
138
  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
139
 
140
+ ### Command-line command
141
+ To run LoopSage from command-line, you only need to type a command
142
+
143
+ ```bash
144
+ loopsage -c config.ini
145
+ ```
146
+
147
+ 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,
148
+
149
+ ```txt
150
+ # Definition of Monte Carlo parameters
151
+ N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
152
+ mode = 'Metropolis'
153
+
154
+ # Simulation Strengths
155
+ f, b, kappa = 1.0, 1.0, 1.0
156
+
157
+ # Definition of region
158
+ region, chrom = [15550000,16850000], 'chr6'
159
+
160
+ # Definition of data
161
+ output_name='../HiChIP_Annealing_T1_MD_region'
162
+ bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
163
+
164
+ sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
165
+ 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)
166
+ sim.run_MD('CUDA')
167
+ ```
168
+
131
169
  ### Output Files
132
170
  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
171
 
@@ -1,8 +1,14 @@
1
- # LoopSage
2
- An energy-based model for loop extrusion.
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
- **Important!!!** *Now the molecular dynamics can run for larger regions, since the code or `LoopSage_md.py` is fixed and does not allocate so much memory.*
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 right ( $n_{i} -> n_{i+1}$ to the right).
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 = \dfrac{f}{N_{fold}}\sum_{i=1}^{N_{coh}}\log(n_i-m_i)+\dfrac{\kappa}{N_{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+\dfrac{b}{N_{bind}}\sum_{i=1}^{N_{coh}}\left(L(m_i)+R(n_i)\right)$$
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
- $$N_{fold}=N_{coh}\cdot \langle n_i-m_i\rangle,\quad N_{cross}=N_{coh},\quad N_{bind}=\sum_{k}\left(L(k)+R(k)\right).$$
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
- where $N_{bw}$ is the number of \texttt{.BigWig} ChIP-Seq experiments that are imported for each one of the proteins of interest. The energy term $W_{i}(\cdot)$ it corresponds to the average values of the ChIP-Seq experiment $i$ for each loci of interest. Finally, $r_{i}$ it is a weight that corresponds each one of these experiments and by default it is set as $r_{i}=b/2$.
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
- Thus,
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_{bind} + \Delta E_{bw}.$$
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
- ## Packages to install
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
- For faster computations use CUDA toolkit: https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local.
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
- N_steps, MC_step, burnin, T, T_min = int(1e4), int(2e2), 1000, 5,1
64
- region, chrom = [88271457,88851999], 'chr10'
65
- label=f'Petros_wt1h'
66
- bedpe_file = '/mnt/raid/data/Petros_project/loops/wt1h_pooled_2.bedpe'
67
- coh_track_file = '/mnt/raid/data/Petros_project/bw/RAD21_ChIPseq/mm_BMDM_WT_Rad21_heme_60min.bw'
68
- bw_file1 = '/mnt/raid/data/Petros_project/bw/BACH1_ChIPseq/mm_Bach1_1h_rep1_heme_merged.bw'
69
- bw_file2 = '/mnt/raid/data/Petros_project/bw/RNAPol_ChIPseq/WT-RNAPOLIIS2-1h-heme100-rep1_S5.bw'
70
- bw_files = [bw_file1,bw_file2]
71
-
72
- sim = LoopSage(region,chrom,bedpe_file,label=label,N_lef=50,N_beads=1000,bw_files=bw_files,track_file=coh_track_file)
73
- Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,poisson_choice=True,mode='Annealing',viz=True,save=True)
74
- sim.run_MD()
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. In `coh_track_file` you can optionally define the track file with some cohesin coverage of ChIP-Seq to determine the distribution of LEFs and allow preferencial binding in regions with higher signal. Then the user can optionally define a list of BigWig files which are needed in case that user would like to model other protein factors and their coefficients $r_i$.
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.2
3
+ Version: 0.0.8
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
@@ -29,13 +29,20 @@ Requires-Dist: OpenMM
29
29
  Requires-Dist: OpenMM-cuda
30
30
  Requires-Dist: statsmodels
31
31
  Requires-Dist: imageio
32
+ Requires-Dist: imageio[ffmpeg]
32
33
  Requires-Dist: pillow
33
34
 
34
- # LoopSage
35
- An energy-based model for loop extrusion.
35
+ # pyLoopSage
36
+ 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
37
 
37
- **Important!!!** *Now the molecular dynamics can run for larger regions, since the code or `LoopSage_md.py` is fixed and does not allocate so much memory.*
38
+ ## New features
38
39
 
40
+ - More user-friendly environment.
41
+ - Installable with `pip install pyLoopSage`.
42
+ - Parralelization of the stochastic simulation across multiple CPUs.
43
+ - Capability of modelling the whole chromosome.
44
+ - Visualization functions.
45
+ - Capability to run form terminal with a simple command `loopsage -c config.ini`.
39
46
 
40
47
  ## Publication
41
48
  Please cite the method paper in case that you would like to use this model for your work,
@@ -44,33 +51,31 @@ Please cite the method paper in case that you would like to use this model for y
44
51
 
45
52
  ## The model
46
53
 
54
+ 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`.
55
+
47
56
  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
57
 
49
- * Slide right ( $n_{i} -> n_{i+1}$ to the right).
50
- * Slide left ( $m_{i} -> m_{i-1}$ to the left).
58
+ * Slide both locations randomly (as 1D random walk) or
51
59
  * Rebind somewhere else.
52
60
 
61
+ 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
62
 
54
63
  The main idea of the algorithm is to ensemble loop extrusion from a Boltzmann probability distribution, with Hamiltonian,
55
64
 
56
- $$E = \dfrac{f}{N_{fold}}\sum_{i=1}^{N_{coh}}\log(n_i-m_i)+\dfrac{\kappa}{N_{cross}}\sum_{i,j}K(m_i,n_i;m_j,n_j)+\dfrac{b}{N_{bind}}\sum_{i=1}^{N_{coh}}\left(L(m_i)+R(n_i)\right)$$
65
+ $$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
66
 
58
67
  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
68
  $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
69
 
61
70
  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
71
 
63
- $$N_{fold}=N_{coh}\cdot \langle n_i-m_i\rangle,\quad N_{cross}=N_{coh},\quad N_{bind}=\sum_{k}\left(L(k)+R(k)\right).$$
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)$$
72
+ $$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
73
 
69
- where $N_{bw}$ is the number of \texttt{.BigWig} ChIP-Seq experiments that are imported for each one of the proteins of interest. The energy term $W_{i}(\cdot)$ it corresponds to the average values of the ChIP-Seq experiment $i$ for each loci of interest. Finally, $r_{i}$ it is a weight that corresponds each one of these experiments and by default it is set as $r_{i}=b/2$.
74
+ The parameters are defined in such a way that when $$f=b=\kappa=1$$, the three terms of the stochastic energy are balanced.
70
75
 
71
- Thus,
76
+ And the energy difference can be expressed as the energy difference of each term,
72
77
 
73
- $$\Delta E = \Delta E_{fold}+\Delta E_{cross}+\Delta E_{bind} + \Delta E_{bw}.$$
78
+ $$\Delta E = \Delta E_{\text{fold}}+\Delta E_{\text{cross}}+\Delta E_{\text{bind}}.$$
74
79
 
75
80
  In this manner we accept a move in two cases:
76
81
 
@@ -79,35 +84,39 @@ In this manner we accept a move in two cases:
79
84
 
80
85
  And of course, the result - the distribution of loops in equilibrium - depends on temperature of Boltzmann distribution $T$.
81
86
 
82
- ## Packages to install
83
- Install a python 3.10 environment and OpenMM 8.0 and run
84
-
85
- ```
86
- pip install -r requirements.txt
87
- ```
87
+ ## Installation
88
88
 
89
- For faster computations use CUDA toolkit: https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local.
89
+ 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
90
 
91
91
  ## How to use?
92
92
 
93
+ ### Python Implementation
94
+
93
95
  The main script is `LoopSage.py`. The implementation of the code is very easy and it can be described in the following lines,
94
96
 
95
97
  ```python
96
- N_steps, MC_step, burnin, T, T_min = int(1e4), int(2e2), 1000, 5,1
97
- region, chrom = [88271457,88851999], 'chr10'
98
- label=f'Petros_wt1h'
99
- bedpe_file = '/mnt/raid/data/Petros_project/loops/wt1h_pooled_2.bedpe'
100
- coh_track_file = '/mnt/raid/data/Petros_project/bw/RAD21_ChIPseq/mm_BMDM_WT_Rad21_heme_60min.bw'
101
- bw_file1 = '/mnt/raid/data/Petros_project/bw/BACH1_ChIPseq/mm_Bach1_1h_rep1_heme_merged.bw'
102
- bw_file2 = '/mnt/raid/data/Petros_project/bw/RNAPol_ChIPseq/WT-RNAPOLIIS2-1h-heme100-rep1_S5.bw'
103
- bw_files = [bw_file1,bw_file2]
104
-
105
- sim = LoopSage(region,chrom,bedpe_file,label=label,N_lef=50,N_beads=1000,bw_files=bw_files,track_file=coh_track_file)
106
- Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,poisson_choice=True,mode='Annealing',viz=True,save=True)
107
- sim.run_MD()
98
+ # Definition of Monte Carlo parameters
99
+ import Loopsage.stochastic_simulation as lps
100
+
101
+ N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
102
+ mode = 'Metropolis'
103
+
104
+ # Simulation Strengths
105
+ f, b, kappa = 1.0, 1.0, 1.0
106
+
107
+ # Definition of region
108
+ region, chrom = [15550000,16850000], 'chr6'
109
+
110
+ # Definition of data
111
+ output_name='../HiChIP_Annealing_T1_MD_region'
112
+ bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
113
+
114
+ sim = lps.StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
115
+ 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)
116
+ sim.run_MD('CUDA')
108
117
  ```
109
118
 
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. In `coh_track_file` you can optionally define the track file with some cohesin coverage of ChIP-Seq to determine the distribution of LEFs and allow preferencial binding in regions with higher signal. Then the user can optionally define a list of BigWig files which are needed in case that user would like to model other protein factors and their coefficients $r_i$.
119
+ 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
120
 
112
121
  Note that the `.bedpe_file` must be in the following format,
113
122
 
@@ -128,6 +137,35 @@ where the last two columns represent the probabilites for left and right anchor
128
137
 
129
138
  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
139
 
140
+ ### Command-line command
141
+ To run LoopSage from command-line, you only need to type a command
142
+
143
+ ```bash
144
+ loopsage -c config.ini
145
+ ```
146
+
147
+ 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,
148
+
149
+ ```txt
150
+ # Definition of Monte Carlo parameters
151
+ N_steps, MC_step, burnin, T, T_min = int(4e4), int(5e2), 1000, 2.5, 1.0
152
+ mode = 'Metropolis'
153
+
154
+ # Simulation Strengths
155
+ f, b, kappa = 1.0, 1.0, 1.0
156
+
157
+ # Definition of region
158
+ region, chrom = [15550000,16850000], 'chr6'
159
+
160
+ # Definition of data
161
+ output_name='../HiChIP_Annealing_T1_MD_region'
162
+ bedpe_file = '/home/skorsak/Data/HiChIP/Maps/hg00731_smc1_maps_2.bedpe'
163
+
164
+ sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000)
165
+ 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)
166
+ sim.run_MD('CUDA')
167
+ ```
168
+
131
169
  ### Output Files
132
170
  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
171
 
@@ -15,4 +15,5 @@ OpenMM
15
15
  OpenMM-cuda
16
16
  statsmodels
17
17
  imageio
18
+ imageio[ffmpeg]
18
19
  pillow
@@ -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.2', # Version of the software
9
+ version='0.0.8', # 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',
@@ -33,11 +33,12 @@ setup(
33
33
  'OpenMM-cuda',
34
34
  'statsmodels',
35
35
  'imageio',
36
+ 'imageio[ffmpeg]',
36
37
  'pillow',
37
38
  ],
38
39
  entry_points={
39
40
  'console_scripts': [
40
- 'loopsage=LoopSage.run:main', # MultiMM command points to run.py's main function
41
+ 'loopsage=LoopSage.run:main', # loopsage command points to run.py's main function
41
42
  ],
42
43
  },
43
44
  classifiers=[
@@ -46,4 +47,4 @@ setup(
46
47
  'Operating System :: POSIX :: Linux', # General OS classifier
47
48
  ],
48
49
  python_requires='>=3.10', # Specify Python version compatibility
49
- )
50
+ )
File without changes