pyLoopSage 1.0.23__tar.gz → 1.1.0__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-1.0.23/pyLoopSage.egg-info → pyloopsage-1.1.0}/PKG-INFO +35 -11
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/README.md +33 -10
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/__init__.py +1 -1
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/args_definition.py +34 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/preproc.py +20 -20
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/run.py +5 -3
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/stochastic_simulation.py +80 -39
- {pyloopsage-1.0.23 → pyloopsage-1.1.0/pyLoopSage.egg-info}/PKG-INFO +35 -11
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/pyLoopSage.egg-info/requires.txt +1 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/setup.py +2 -1
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/LICENSE +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/MANIFEST.in +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/em.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/forcefields/classic_sm_ff.xml +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/initial_structures.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/md.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/plots.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/utils.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/loopsage/vizualization_tools.py +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/pyLoopSage.egg-info/SOURCES.txt +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/pyLoopSage.egg-info/dependency_links.txt +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/pyLoopSage.egg-info/entry_points.txt +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/pyLoopSage.egg-info/top_level.txt +0 -0
- {pyloopsage-1.0.23 → pyloopsage-1.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyLoopSage
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
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,6 +31,7 @@ Requires-Dist: statsmodels
|
|
|
31
31
|
Requires-Dist: imageio
|
|
32
32
|
Requires-Dist: imageio[ffmpeg]
|
|
33
33
|
Requires-Dist: pillow
|
|
34
|
+
Requires-Dist: pyBigWig
|
|
34
35
|
Dynamic: author
|
|
35
36
|
Dynamic: author-email
|
|
36
37
|
Dynamic: classifier
|
|
@@ -271,35 +272,54 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
271
272
|
|
|
272
273
|
### Long-table of LoopSage arguments
|
|
273
274
|
|
|
275
|
+
#### General Settings
|
|
274
276
|
| Argument Name | Description | Type | Default Value |
|
|
275
277
|
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
276
278
|
| PLATFORM | Name of the platform. Available choices: CPU, CUDA, OpenCL | str | CPU |
|
|
277
279
|
| DEVICE | Device index for CUDA or OpenCL (count from 0) | str | None |
|
|
278
|
-
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
279
|
-
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
280
280
|
| OUT_PATH | Output folder name. | str | ../results |
|
|
281
|
+
| SAVE_MDT | True to save metadata of the stochastic simulation. | bool | True |
|
|
282
|
+
|
|
283
|
+
#### Input Data
|
|
284
|
+
| Argument Name | Description | Type | Default Value |
|
|
285
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
286
|
+
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
287
|
+
| LEF_TRACK_FILE | Path to a bw file of cohesin or condensin density. If it is provided, then simulation LEFs preferentially bind in enriched regions. | str | None |
|
|
288
|
+
| BW_FILES | List of paths to .bw files containing additional data for simulation. Enriched regions would act as barriers for cohesin. | list | None |
|
|
281
289
|
| REGION_START | Starting region coordinate. | int | None |
|
|
282
290
|
| REGION_END | Ending region coordinate. | int | None |
|
|
283
291
|
| CHROM | Chromosome that corresponds to the modeling region of interest. | str | None |
|
|
284
|
-
|
|
285
|
-
|
|
292
|
+
|
|
293
|
+
#### Stochastic Simulation Parameters
|
|
294
|
+
| Argument Name | Description | Type | Default Value |
|
|
295
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
296
|
+
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
286
297
|
| N_STEPS | Number of Monte Carlo steps. | int | 40000 |
|
|
287
|
-
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
288
|
-
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
289
298
|
| MC_STEP | Monte Carlo frequency to avoid autocorrelated ensembles. | int | 200 |
|
|
290
299
|
| BURNIN | Burn-in period (steps before equilibrium). | int | 1000 |
|
|
291
300
|
| T_INIT | Initial Temperature of the Stochastic Model. | float | 2.0 |
|
|
292
301
|
| T_FINAL | Final Temperature of the Stochastic Model. | float | 1.0 |
|
|
293
302
|
| METHOD | Stochastic modeling method (Metropolis or Simulated Annealing). | str | 'Annealing' |
|
|
303
|
+
| LEF_RW | True if cohesins slide as a random walk instead of one direction. | bool | True |
|
|
304
|
+
| LEF_DRIFT | True if LEFs are pushed back when they encounter other LEFs. | bool | False |
|
|
305
|
+
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
306
|
+
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
307
|
+
|
|
308
|
+
#### Energy Coefficients
|
|
309
|
+
| Argument Name | Description | Type | Default Value |
|
|
310
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
294
311
|
| FOLDING_COEFF | Folding coefficient. | float | 1.0 |
|
|
295
312
|
| FOLDING_COEFF2 | Folding coefficient for the second family of LEFs. | float | 0.0 |
|
|
296
313
|
| CROSS_COEFF | LEF crossing coefficient. | float | 1.0 |
|
|
297
314
|
| CROSS_LOOP | True if the penalty is applied when mi<mj<ni<nj. False if it applies only when mj=ni. When false it is better to enable LEF_DRIFT as well. | bool |True |
|
|
298
315
|
| BIND_COEFF | CTCF binding coefficient. | float | 1.0 |
|
|
299
|
-
|
|
|
300
|
-
|
|
301
|
-
|
|
316
|
+
| BW_STRENGTHS | List of strengths corresponding to each .bw file. | list | None |
|
|
317
|
+
|
|
318
|
+
#### Molecular Dynamics Simulation
|
|
319
|
+
| Argument Name | Description | Type | Default Value |
|
|
320
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
302
321
|
| SIMULATION_TYPE | Either EM (energy minimizations) or MD (molecular dynamics). | str | None |
|
|
322
|
+
| INITIAL_STRUCTURE_TYPE | Choose from: rw, confined_rw, self_avoiding_rw, helix, circle, spiral, sphere. | str | rw |
|
|
303
323
|
| INTEGRATOR_STEP | Step of the integrator. | Quantity | 100 femtosecond |
|
|
304
324
|
| FORCEFIELD_PATH | Path to XML file with forcefield. | str | default_xml_path |
|
|
305
325
|
| ANGLE_FF_STRENGTH | Angle force strength. | float | 200.0 |
|
|
@@ -311,10 +331,14 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
311
331
|
| EV_FF_POWER | Excluded-volume power. | float | 3.0 |
|
|
312
332
|
| FRICTION | Friction coefficient of the Langevin integrator. | float | 0.1 |
|
|
313
333
|
| TOLERANCE | Stopping condition for energy minimization. | float | 0.001 |
|
|
314
|
-
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
315
334
|
| SIM_TEMP | Temperature of the 3D simulation (EM or MD). | Quantity | 310 kelvin |
|
|
316
335
|
| SIM_STEP | Amount of simulation steps for loop force adjustments. | int | 1000 |
|
|
317
336
|
|
|
337
|
+
#### Visualization
|
|
338
|
+
| Argument Name | Description | Type | Default Value |
|
|
339
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
340
|
+
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
341
|
+
| SAVE_PLOTS | True to save diagnostic plots. | bool | True |
|
|
318
342
|
|
|
319
343
|
## Citation
|
|
320
344
|
Please cite the method and biological paper in case that you would like to use this model for your work,
|
|
@@ -226,35 +226,54 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
226
226
|
|
|
227
227
|
### Long-table of LoopSage arguments
|
|
228
228
|
|
|
229
|
+
#### General Settings
|
|
229
230
|
| Argument Name | Description | Type | Default Value |
|
|
230
231
|
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
231
232
|
| PLATFORM | Name of the platform. Available choices: CPU, CUDA, OpenCL | str | CPU |
|
|
232
233
|
| DEVICE | Device index for CUDA or OpenCL (count from 0) | str | None |
|
|
233
|
-
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
234
|
-
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
235
234
|
| OUT_PATH | Output folder name. | str | ../results |
|
|
235
|
+
| SAVE_MDT | True to save metadata of the stochastic simulation. | bool | True |
|
|
236
|
+
|
|
237
|
+
#### Input Data
|
|
238
|
+
| Argument Name | Description | Type | Default Value |
|
|
239
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
240
|
+
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
241
|
+
| LEF_TRACK_FILE | Path to a bw file of cohesin or condensin density. If it is provided, then simulation LEFs preferentially bind in enriched regions. | str | None |
|
|
242
|
+
| BW_FILES | List of paths to .bw files containing additional data for simulation. Enriched regions would act as barriers for cohesin. | list | None |
|
|
236
243
|
| REGION_START | Starting region coordinate. | int | None |
|
|
237
244
|
| REGION_END | Ending region coordinate. | int | None |
|
|
238
245
|
| CHROM | Chromosome that corresponds to the modeling region of interest. | str | None |
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
|
|
247
|
+
#### Stochastic Simulation Parameters
|
|
248
|
+
| Argument Name | Description | Type | Default Value |
|
|
249
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
250
|
+
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
241
251
|
| N_STEPS | Number of Monte Carlo steps. | int | 40000 |
|
|
242
|
-
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
243
|
-
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
244
252
|
| MC_STEP | Monte Carlo frequency to avoid autocorrelated ensembles. | int | 200 |
|
|
245
253
|
| BURNIN | Burn-in period (steps before equilibrium). | int | 1000 |
|
|
246
254
|
| T_INIT | Initial Temperature of the Stochastic Model. | float | 2.0 |
|
|
247
255
|
| T_FINAL | Final Temperature of the Stochastic Model. | float | 1.0 |
|
|
248
256
|
| METHOD | Stochastic modeling method (Metropolis or Simulated Annealing). | str | 'Annealing' |
|
|
257
|
+
| LEF_RW | True if cohesins slide as a random walk instead of one direction. | bool | True |
|
|
258
|
+
| LEF_DRIFT | True if LEFs are pushed back when they encounter other LEFs. | bool | False |
|
|
259
|
+
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
260
|
+
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
261
|
+
|
|
262
|
+
#### Energy Coefficients
|
|
263
|
+
| Argument Name | Description | Type | Default Value |
|
|
264
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
249
265
|
| FOLDING_COEFF | Folding coefficient. | float | 1.0 |
|
|
250
266
|
| FOLDING_COEFF2 | Folding coefficient for the second family of LEFs. | float | 0.0 |
|
|
251
267
|
| CROSS_COEFF | LEF crossing coefficient. | float | 1.0 |
|
|
252
268
|
| CROSS_LOOP | True if the penalty is applied when mi<mj<ni<nj. False if it applies only when mj=ni. When false it is better to enable LEF_DRIFT as well. | bool |True |
|
|
253
269
|
| BIND_COEFF | CTCF binding coefficient. | float | 1.0 |
|
|
254
|
-
|
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
| BW_STRENGTHS | List of strengths corresponding to each .bw file. | list | None |
|
|
271
|
+
|
|
272
|
+
#### Molecular Dynamics Simulation
|
|
273
|
+
| Argument Name | Description | Type | Default Value |
|
|
274
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
257
275
|
| SIMULATION_TYPE | Either EM (energy minimizations) or MD (molecular dynamics). | str | None |
|
|
276
|
+
| INITIAL_STRUCTURE_TYPE | Choose from: rw, confined_rw, self_avoiding_rw, helix, circle, spiral, sphere. | str | rw |
|
|
258
277
|
| INTEGRATOR_STEP | Step of the integrator. | Quantity | 100 femtosecond |
|
|
259
278
|
| FORCEFIELD_PATH | Path to XML file with forcefield. | str | default_xml_path |
|
|
260
279
|
| ANGLE_FF_STRENGTH | Angle force strength. | float | 200.0 |
|
|
@@ -266,10 +285,14 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
266
285
|
| EV_FF_POWER | Excluded-volume power. | float | 3.0 |
|
|
267
286
|
| FRICTION | Friction coefficient of the Langevin integrator. | float | 0.1 |
|
|
268
287
|
| TOLERANCE | Stopping condition for energy minimization. | float | 0.001 |
|
|
269
|
-
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
270
288
|
| SIM_TEMP | Temperature of the 3D simulation (EM or MD). | Quantity | 310 kelvin |
|
|
271
289
|
| SIM_STEP | Amount of simulation steps for loop force adjustments. | int | 1000 |
|
|
272
290
|
|
|
291
|
+
#### Visualization
|
|
292
|
+
| Argument Name | Description | Type | Default Value |
|
|
293
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
294
|
+
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
295
|
+
| SAVE_PLOTS | True to save diagnostic plots. | bool | True |
|
|
273
296
|
|
|
274
297
|
## Citation
|
|
275
298
|
Please cite the method and biological paper in case that you would like to use this model for your work,
|
|
@@ -23,6 +23,7 @@ class Arg(object):
|
|
|
23
23
|
type: type
|
|
24
24
|
default: Union[str, float, int, bool, Quantity, None]
|
|
25
25
|
val: Union[str, float, int, bool, Quantity, None]
|
|
26
|
+
nargs: Union[str, None] = None # Optional attribute for nargs
|
|
26
27
|
|
|
27
28
|
# Define custom type to parse list from string
|
|
28
29
|
def parse_list(s):
|
|
@@ -65,6 +66,18 @@ class ListOfArgs(list):
|
|
|
65
66
|
raise ValueError(f"I Can't recognise unit {unit} in expression {val}. Example of valid quantity: 12.3 femtosecond.")
|
|
66
67
|
return Quantity(value=float(value), unit=unit)
|
|
67
68
|
|
|
69
|
+
def parse_list_of_floats(self, s: str) -> list:
|
|
70
|
+
try:
|
|
71
|
+
return [float(x.strip()) for x in s.strip('[]').split(',')]
|
|
72
|
+
except ValueError:
|
|
73
|
+
raise argparse.ArgumentTypeError("Invalid list format. Must be a comma-separated list of floats.")
|
|
74
|
+
|
|
75
|
+
def parse_list_of_strings(self, s: str) -> list:
|
|
76
|
+
try:
|
|
77
|
+
return [x.strip() for x in s.strip('[]').split(',')]
|
|
78
|
+
except ValueError:
|
|
79
|
+
raise argparse.ArgumentTypeError("Invalid list format. Must be a comma-separated list of strings.")
|
|
80
|
+
|
|
68
81
|
def to_python(self):
|
|
69
82
|
"""Casts string args to ints, floats, bool..."""
|
|
70
83
|
for i in self:
|
|
@@ -78,6 +91,22 @@ class ListOfArgs(list):
|
|
|
78
91
|
i.val = int(i.val)
|
|
79
92
|
elif i.type == float:
|
|
80
93
|
i.val = float(i.val)
|
|
94
|
+
elif i.type == list:
|
|
95
|
+
if i.name == "BW_FILES" or i.name == "STRING_LIST": # Handle lists of strings
|
|
96
|
+
if isinstance(i.val, str):
|
|
97
|
+
i.val = self.parse_list_of_strings(i.val)
|
|
98
|
+
elif not isinstance(i.val, list):
|
|
99
|
+
raise ValueError(f"Can't convert {i.val} into list of strings.")
|
|
100
|
+
elif i.name == "BW_STRENGTHS" or i.name == "FLOAT_LIST": # Handle lists of floats
|
|
101
|
+
if isinstance(i.val, str):
|
|
102
|
+
i.val = self.parse_list_of_floats(i.val)
|
|
103
|
+
elif not isinstance(i.val, list):
|
|
104
|
+
raise ValueError(f"Can't convert {i.val} into list of floats.")
|
|
105
|
+
else: # Handle lists of integers
|
|
106
|
+
if isinstance(i.val, str):
|
|
107
|
+
i.val = parse_list(i.val)
|
|
108
|
+
elif not isinstance(i.val, list):
|
|
109
|
+
raise ValueError(f"Can't convert {i.val} into list of integers.")
|
|
81
110
|
elif i.type == bool:
|
|
82
111
|
if i.val.lower() in ['true', '1', 'y', 'yes']:
|
|
83
112
|
i.val = True
|
|
@@ -138,10 +167,14 @@ args = ListOfArgs([
|
|
|
138
167
|
# Input data
|
|
139
168
|
Arg('N_BEADS', help="Number of Simulation Beads.", type=int, default='', val=''),
|
|
140
169
|
Arg('BEDPE_PATH', help="A .bedpe file path with loops. It is required.", type=str, default='', val=''),
|
|
170
|
+
Arg('LEF_TRACK_FILE', help="An optional track file for cohesin or condensin in bw format. If this file is specified LEF preferentially binds were the signal is enriched.", type=str, default='', val=''),
|
|
171
|
+
Arg('BW_FILES', help="List of bigWig file paths for feature extraction.", type=list, nargs='+', default=[], val=[]),
|
|
141
172
|
Arg('OUT_PATH', help="Output folder name.", type=str, default='../results', val='../results'),
|
|
142
173
|
Arg('REGION_START', help="Starting region coordinate.", type=int, default='', val=''),
|
|
143
174
|
Arg('REGION_END', help="Ending region coordinate.", type=int, default='', val=''),
|
|
144
175
|
Arg('CHROM', help="Chromosome that corresponds the the modelling region of interest (in case that you do not want to model the whole genome).", type=str, default='', val=''),
|
|
176
|
+
Arg('FLOAT_LIST', help="List of floating-point numbers.", type=list, nargs='+', default=[], val=[]),
|
|
177
|
+
Arg('STRING_LIST', help="List of strings.", type=list, nargs='+', default=[], val=[]),
|
|
145
178
|
|
|
146
179
|
# Stochastic Simulation parameters
|
|
147
180
|
Arg('LEF_RW', help="True in case that you would like to make cohesins slide as random walk, instead of sliding only in one direction.", type=bool, default='True', val='True'),
|
|
@@ -157,6 +190,7 @@ args = ListOfArgs([
|
|
|
157
190
|
Arg('FOLDING_COEFF', help="Folding coefficient.", type=float, default='1.0', val='1.0'),
|
|
158
191
|
Arg('FOLDING_COEFF2', help="Folding coefficient for the second family of LEFs.", type=float, default='0.0', val='0.0'),
|
|
159
192
|
Arg('CROSS_COEFF', help="LEF crossing coefficient.", type=float, default='1.0', val='1.0'),
|
|
193
|
+
Arg('BW_STRENGTHS', help="List of strengths of the energy (floats) corresponding to each BW file. This equivalent to the `r` parameter in the LoopSage paper.", type=list, nargs='+', default=[], val=[]),
|
|
160
194
|
Arg('CROSS_LOOP', help="It true if the penalty is applied for situations mi<mj<ni<nj and mi=nj, and false if it is applied only for mi=nj.", type=bool, default='True', val='True'),
|
|
161
195
|
Arg('BIND_COEFF', help="CTCF binding coefficient.", type=float, default='1.0', val='1.0'),
|
|
162
196
|
Arg('SAVE_PLOTS', help="It should be true in case that you would like to save diagnostic plots. In case that you use small MC_STEP or large N_STEPS is better to mark it as False.", type=bool, default='True', val='True'),
|
|
@@ -2,7 +2,7 @@ import numpy as np
|
|
|
2
2
|
import seaborn as sns
|
|
3
3
|
import pandas as pd
|
|
4
4
|
import matplotlib.pyplot as plt
|
|
5
|
-
|
|
5
|
+
import pyBigWig
|
|
6
6
|
from matplotlib.pyplot import figure
|
|
7
7
|
|
|
8
8
|
def binding_vectors_from_bedpe(bedpe_file,N_beads,region,chrom,normalization=False,viz=False):
|
|
@@ -101,24 +101,24 @@ def get_rnap_energy(path,region,chrom,N_beads,normalization):
|
|
|
101
101
|
def distance_point_line(x0,y0,a=1,b=-1,c=0):
|
|
102
102
|
return np.abs(a*x0+b*y0+c)/np.sqrt(a**2+b**2)
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
def load_track(file,region,chrom,N_beads,viz=False,roll=False):
|
|
105
|
+
bw = pyBigWig.open(file)
|
|
106
|
+
weights = bw_to_array(bw, region, chrom, N_beads,viz,roll)
|
|
107
|
+
return weights[:N_beads]
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
def bw_to_array(bw, region, chrom, N_beads, viz=False, roll=False):
|
|
110
|
+
step = (region[1]-region[0])//N_beads
|
|
111
|
+
bw_array = bw.values(chrom, region[0], region[1])
|
|
112
|
+
bw_array = np.nan_to_num(bw_array)
|
|
113
|
+
bw_array_new = list()
|
|
114
|
+
for i in range(step,len(bw_array)+1,step):
|
|
115
|
+
bw_array_new.append(np.average(bw_array[(i-step):i]))
|
|
116
|
+
weights = (np.roll(np.array(bw_array_new),3)+np.roll(np.array(bw_array_new),-3))/2 if roll else bw_array_new
|
|
117
|
+
if viz:
|
|
118
|
+
figure(figsize=(15, 5))
|
|
119
|
+
plt.plot(weights)
|
|
120
|
+
plt.grid()
|
|
121
|
+
plt.title('ChIP-Seq signal',fontsize=20)
|
|
122
|
+
plt.close()
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
return weights
|
|
@@ -69,9 +69,11 @@ def main():
|
|
|
69
69
|
N_beads, N_lef, N_lef2 = args.N_BEADS, args.N_LEF, args.N_LEF2
|
|
70
70
|
N_steps, MC_step, burnin, T, T_min = args.N_STEPS, args.MC_STEP, args.BURNIN, args.T_INIT, args.T_FINAL
|
|
71
71
|
mode = args.METHOD
|
|
72
|
+
bw_paths = args.BW_FILES
|
|
72
73
|
|
|
73
74
|
# Simulation Strengths
|
|
74
75
|
f, f2, b, kappa = args.FOLDING_COEFF, args.FOLDING_COEFF2, args.BIND_COEFF, args.CROSS_COEFF
|
|
76
|
+
r = args.BW_STRENGTHS
|
|
75
77
|
|
|
76
78
|
# Definition of region
|
|
77
79
|
region, chrom = [args.REGION_START,args.REGION_END], args.CHROM
|
|
@@ -81,12 +83,12 @@ def main():
|
|
|
81
83
|
bedpe_file = args.BEDPE_PATH
|
|
82
84
|
|
|
83
85
|
# Run Simulation
|
|
84
|
-
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=N_beads,N_lef=N_lef,N_lef2=N_lef2)
|
|
85
|
-
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=args.SAVE_PLOTS,save=args.SAVE_MDT,lef_rw=args.LEF_RW,f=f,f2=f2,b=b,kappa=kappa,lef_drift=args.LEF_DRIFT,cross_loop=args.CROSS_LOOP)
|
|
86
|
+
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=N_beads,N_lef=N_lef,N_lef2=N_lef2, bw_files=bw_paths, track_file=args.LEF_TRACK_FILE)
|
|
87
|
+
Es, Ms, Ns, Bs, Ks, Fs, ufs = sim.run_energy_minimization(N_steps,MC_step,burnin,T,T_min,mode=mode,viz=args.SAVE_PLOTS,save=args.SAVE_MDT,lef_rw=args.LEF_RW,f=f,f2=f2,b=b,kappa=kappa,lef_drift=args.LEF_DRIFT,cross_loop=args.CROSS_LOOP,r=r)
|
|
86
88
|
if args.SIMULATION_TYPE=='EM':
|
|
87
89
|
sim.run_EM(args.PLATFORM,args.ANGLE_FF_STRENGTH,args.LE_FF_LENGTH,args.LE_FF_STRENGTH,args.EV_FF_STRENGTH,args.EV_FF_POWER,args.TOLERANCE,args.FRICTION,args.INTEGRATOR_STEP,args.SIM_TEMP,args.INITIAL_STRUCTURE_TYPE,args.VIZ_HEATS,args.FORCEFIELD_PATH)
|
|
88
90
|
elif args.SIMULATION_TYPE=='MD':
|
|
89
|
-
sim.run_MD(args.PLATFORM,args.ANGLE_FF_STRENGTH,args.LE_FF_LENGTH,args.LE_FF_STRENGTH,args.EV_FF_STRENGTH,args.EV_FF_POWER,args.TOLERANCE,args.FRICTION,args.INTEGRATOR_STEP,args.SIM_TEMP,args.INITIAL_STRUCTURE_TYPE,args.SIM_STEP,args.VIZ_HEATS,args.FORCEFIELD_PATH,args.EV_P,args.
|
|
91
|
+
sim.run_MD(args.PLATFORM,args.ANGLE_FF_STRENGTH,args.LE_FF_LENGTH,args.LE_FF_STRENGTH,args.EV_FF_STRENGTH,args.EV_FF_POWER,args.TOLERANCE,args.FRICTION,args.INTEGRATOR_STEP,args.SIM_TEMP,args.INITIAL_STRUCTURE_TYPE,args.SIM_STEP,args.VIZ_HEATS,args.FORCEFIELD_PATH,args.EV_P,args.CONTINUOUS_TOP)
|
|
90
92
|
elif args.SIMULATION_TYPE==None:
|
|
91
93
|
print('\n3D simulation did not run because it was not specified. Please specify argument SIMULATION_TYPE as EM or MD.')
|
|
92
94
|
else:
|
|
@@ -66,12 +66,23 @@ def E_fold(ms, ns, fold_norm):
|
|
|
66
66
|
return fold_norm * folding
|
|
67
67
|
|
|
68
68
|
@njit
|
|
69
|
-
def
|
|
69
|
+
def E_bw(N_bws, r, BWs, ms, ns):
|
|
70
|
+
'''
|
|
71
|
+
Calculation of the RNApII binding energy. Needs cohesins positions as input.
|
|
72
|
+
'''
|
|
73
|
+
E_bw = 0
|
|
74
|
+
for i in range(N_bws):
|
|
75
|
+
E_bw += r[i] * np.sum(BWs[i, ms] + BWs[i, ns]) / np.sum(BWs[i])
|
|
76
|
+
return E_bw
|
|
77
|
+
|
|
78
|
+
@njit
|
|
79
|
+
def get_E(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, N_lef, N_lef2, cross_loop, r=None, N_bws=0, BWs=None):
|
|
70
80
|
''''
|
|
71
81
|
The total energy.
|
|
72
82
|
'''
|
|
73
83
|
energy = E_bind(L, R, ms, ns, bind_norm) + E_cross(ms, ns, k_norm, cross_loop) + E_fold(ms, ns, fold_norm)
|
|
74
84
|
if fold_norm2!=0: energy += E_fold(ms[N_lef:N_lef+N_lef2],ns[N_lef:N_lef+N_lef2], fold_norm2)
|
|
85
|
+
if r is not None and BWs is not None: energy += E_bw(N_bws, r, BWs, ms, ns)
|
|
75
86
|
return energy
|
|
76
87
|
|
|
77
88
|
@njit
|
|
@@ -88,6 +99,13 @@ def get_dE_fold(fold_norm,ms,ns,m_new,n_new,idx):
|
|
|
88
99
|
'''
|
|
89
100
|
return fold_norm*(np.log(n_new-m_new)-np.log(ns[idx]-ms[idx]))
|
|
90
101
|
|
|
102
|
+
@njit
|
|
103
|
+
def get_dE_bw(N_bws, r, BWs, ms, ns, m_new, n_new, idx):
|
|
104
|
+
dE_bw = 0
|
|
105
|
+
for i in range(N_bws):
|
|
106
|
+
dE_bw += r[i] * (BWs[i, m_new] + BWs[i, n_new] - BWs[i, ms[idx]] - BWs[i, ns[idx]]) / np.sum(BWs[i])
|
|
107
|
+
return dE_bw
|
|
108
|
+
|
|
91
109
|
@njit
|
|
92
110
|
def get_dE_cross(ms, ns, m_new, n_new, idx, k_norm, cross_loop):
|
|
93
111
|
'''
|
|
@@ -101,7 +119,7 @@ def get_dE_cross(ms, ns, m_new, n_new, idx, k_norm, cross_loop):
|
|
|
101
119
|
return k_norm * (K2 - K1)
|
|
102
120
|
|
|
103
121
|
@njit
|
|
104
|
-
def get_dE(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, m_new, n_new, idx, N_lef, N_lef2, cross_loop):
|
|
122
|
+
def get_dE(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, m_new, n_new, idx, N_lef, N_lef2, cross_loop, r=None, N_bws=0, BWs=None):
|
|
105
123
|
'''
|
|
106
124
|
Total energy difference.
|
|
107
125
|
'''
|
|
@@ -112,14 +130,19 @@ def get_dE(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, m_new, n_new,
|
|
|
112
130
|
dE += get_dE_fold(fold_norm2,ms[N_lef:N_lef+N_lef2],ns[N_lef:N_lef+N_lef2],m_new,n_new,idx-N_lef)
|
|
113
131
|
dE += get_dE_bind(L, R, bind_norm, ms, ns, m_new, n_new, idx)
|
|
114
132
|
dE += get_dE_cross(ms, ns, m_new, n_new, idx, k_norm, cross_loop)
|
|
133
|
+
if r is not None and BWs is not None: dE += get_dE_bw(N_bws, r, BWs, ms, ns, m_new, n_new, idx)
|
|
115
134
|
return dE
|
|
116
135
|
|
|
117
136
|
@njit
|
|
118
|
-
def unbind_bind(N_beads):
|
|
137
|
+
def unbind_bind(N_beads, track=None):
|
|
119
138
|
'''
|
|
120
139
|
Rebinding Monte-Carlo step.
|
|
121
140
|
'''
|
|
122
|
-
|
|
141
|
+
if track is not None:
|
|
142
|
+
weights = track / np.sum(track)
|
|
143
|
+
m_new = np.searchsorted(np.cumsum(weights), np.random.rand())
|
|
144
|
+
else:
|
|
145
|
+
m_new = np.random.randint(0, N_beads - 3)
|
|
123
146
|
n_new = m_new + 2
|
|
124
147
|
return int(m_new), int(n_new)
|
|
125
148
|
|
|
@@ -152,58 +175,58 @@ def unfolding_metric(ms,ns,N_beads):
|
|
|
152
175
|
return unfold
|
|
153
176
|
|
|
154
177
|
@njit
|
|
155
|
-
def initialize(N_beads,N_lef):
|
|
178
|
+
def initialize(N_beads, N_lef, track=None):
|
|
156
179
|
'''
|
|
157
180
|
Random initialization of polymer DNA fiber with some cohesin positions.
|
|
158
181
|
'''
|
|
159
182
|
ms, ns = np.zeros(N_lef,dtype=np.int64), np.zeros(N_lef,dtype=np.int64)
|
|
160
183
|
for i in range(N_lef):
|
|
161
|
-
ms[i], ns[i] = unbind_bind(N_beads)
|
|
184
|
+
ms[i], ns[i] = unbind_bind(N_beads, track)
|
|
162
185
|
return ms, ns
|
|
163
186
|
|
|
164
187
|
@njit
|
|
165
|
-
def run_simulation(N_beads,N_steps,MC_step,burnin,T,T_min,fold_norm,fold_norm2,bind_norm,k_norm,N_lef,N_lef2,L,R,mode,lef_rw=True,lef_drift=True,cross_loop=True):
|
|
188
|
+
def run_simulation(N_beads, N_steps, MC_step, burnin, T, T_min, fold_norm, fold_norm2, bind_norm, k_norm, N_lef, N_lef2, L, R, mode, lef_rw=True, lef_drift=True, cross_loop=True, r=None, N_bws=0, BWs=None, track=None):
|
|
166
189
|
'''
|
|
167
190
|
Runs the Monte Carlo simulation.
|
|
168
191
|
'''
|
|
169
192
|
Ti = T
|
|
170
|
-
bi = burnin//MC_step
|
|
171
|
-
ms, ns = initialize(N_beads,N_lef+N_lef2)
|
|
172
|
-
E = get_E(L, R, bind_norm, fold_norm, fold_norm2, k_norm,
|
|
173
|
-
Es,Ks,Fs,Bs,ufs = np.zeros(N_steps//MC_step, dtype=np.float64),np.zeros(N_steps//MC_step, dtype=np.float64),np.zeros(N_steps//MC_step, dtype=np.float64),np.zeros(N_steps//MC_step, dtype=np.float64),np.zeros(N_steps//MC_step, dtype=np.float64)
|
|
174
|
-
Ms, Ns = np.zeros((N_lef+N_lef2,N_steps//MC_step), dtype=np.int64), np.zeros((N_lef+N_lef2,N_steps//MC_step), dtype=np.int64)
|
|
193
|
+
bi = burnin // MC_step
|
|
194
|
+
ms, ns = initialize(N_beads, N_lef + N_lef2, track)
|
|
195
|
+
E = get_E(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, N_lef, N_lef2, cross_loop, r, N_bws, BWs)
|
|
196
|
+
Es, Ks, Fs, Bs, ufs = np.zeros(N_steps // MC_step, dtype=np.float64), np.zeros(N_steps // MC_step, dtype=np.float64), np.zeros(N_steps // MC_step, dtype=np.float64), np.zeros(N_steps // MC_step, dtype=np.float64), np.zeros(N_steps // MC_step, dtype=np.float64)
|
|
197
|
+
Ms, Ns = np.zeros((N_lef + N_lef2, N_steps // MC_step), dtype=np.int64), np.zeros((N_lef + N_lef2, N_steps // MC_step), dtype=np.int64)
|
|
175
198
|
|
|
176
199
|
for i in range(N_steps):
|
|
177
|
-
Ti = T-(T-T_min)*(i+1)/N_steps if mode=='Annealing' else T
|
|
178
|
-
for j in range(N_lef+N_lef2):
|
|
200
|
+
Ti = T - (T - T_min) * (i + 1) / N_steps if mode == 'Annealing' else T
|
|
201
|
+
for j in range(N_lef + N_lef2):
|
|
179
202
|
# Randomly choose a move (sliding or rebinding)
|
|
180
|
-
|
|
181
|
-
if
|
|
182
|
-
m_new, n_new = unbind_bind(N_beads)
|
|
203
|
+
r_move = np.random.choice(np.array([0, 1]))
|
|
204
|
+
if r_move == 0:
|
|
205
|
+
m_new, n_new = unbind_bind(N_beads, track)
|
|
183
206
|
else:
|
|
184
|
-
m_new, n_new = slide(ms[j],ns[j],ms,ns,N_beads,lef_rw,lef_drift)
|
|
207
|
+
m_new, n_new = slide(ms[j], ns[j], ms, ns, N_beads, lef_rw, lef_drift)
|
|
185
208
|
|
|
186
209
|
# Compute energy difference
|
|
187
|
-
dE = get_dE(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, m_new, n_new, j, N_lef, N_lef2, cross_loop)
|
|
210
|
+
dE = get_dE(L, R, bind_norm, fold_norm, fold_norm2, k_norm, ms, ns, m_new, n_new, j, N_lef, N_lef2, cross_loop, r, N_bws, BWs)
|
|
188
211
|
|
|
189
|
-
if dE <= 0 or np.exp(-dE/Ti) > np.random.rand():
|
|
212
|
+
if dE <= 0 or np.exp(-dE / Ti) > np.random.rand():
|
|
190
213
|
ms[j], ns[j] = m_new, n_new
|
|
191
214
|
E += dE
|
|
192
215
|
# Compute Metrics
|
|
193
|
-
if i%MC_step==0:
|
|
194
|
-
Ms[j,i//MC_step], Ns[j,i//MC_step] = ms[j], ns[j]
|
|
216
|
+
if i % MC_step == 0:
|
|
217
|
+
Ms[j, i // MC_step], Ns[j, i // MC_step] = ms[j], ns[j]
|
|
195
218
|
|
|
196
219
|
# Compute Metrics
|
|
197
|
-
if i%MC_step==0:
|
|
198
|
-
ufs[i//MC_step] = unfolding_metric(ms,ns,N_beads)
|
|
199
|
-
Es[i//MC_step] = E
|
|
200
|
-
Ks[i//MC_step] = E_cross(ms,ns,k_norm,cross_loop)
|
|
201
|
-
Fs[i//MC_step] = E_fold(ms,ns,fold_norm)
|
|
202
|
-
Bs[i//MC_step] = E_bind(L,R,ms,ns,bind_norm)
|
|
220
|
+
if i % MC_step == 0:
|
|
221
|
+
ufs[i // MC_step] = unfolding_metric(ms, ns, N_beads)
|
|
222
|
+
Es[i // MC_step] = E
|
|
223
|
+
Ks[i // MC_step] = E_cross(ms, ns, k_norm, cross_loop)
|
|
224
|
+
Fs[i // MC_step] = E_fold(ms, ns, fold_norm)
|
|
225
|
+
Bs[i // MC_step] = E_bind(L, R, ms, ns, bind_norm)
|
|
203
226
|
return Ms, Ns, Es, Ks, Fs, Bs, ufs
|
|
204
227
|
|
|
205
228
|
class StochasticSimulation:
|
|
206
|
-
def __init__(self,region,chrom,bedpe_file,N_beads=None,N_lef=None,N_lef2=0,out_dir=None):
|
|
229
|
+
def __init__(self,region,chrom,bedpe_file,N_beads=None,N_lef=None,N_lef2=0,out_dir=None, bw_files=None, track_file=None):
|
|
207
230
|
'''
|
|
208
231
|
Definition of simulation parameters and input files.
|
|
209
232
|
|
|
@@ -218,16 +241,17 @@ class StochasticSimulation:
|
|
|
218
241
|
r (list): strength of each ChIP-Seq experinment.
|
|
219
242
|
'''
|
|
220
243
|
self.N_beads = N_beads if N_beads!=None else int(np.round((region[1]-region[0])/2000))
|
|
244
|
+
self.N_bws = len(bw_files) if bw_files else 0
|
|
221
245
|
print('Number of beads:',self.N_beads)
|
|
222
246
|
self.chrom, self.region = chrom, region
|
|
223
|
-
self.bedpe_file = bedpe_file
|
|
247
|
+
self.bedpe_file, self.bw_files, self.track_file = bedpe_file, bw_files, track_file
|
|
224
248
|
self.preprocessing()
|
|
225
249
|
self.N_lef = 2*self.N_CTCF if N_lef==None else N_lef
|
|
226
250
|
self.N_lef2 = N_lef2
|
|
227
251
|
print('Number of LEFs:',self.N_lef+self.N_lef2)
|
|
228
252
|
self.path = make_folder(out_dir)
|
|
229
253
|
|
|
230
|
-
def run_energy_minimization(self,N_steps,MC_step,burnin,T=1,T_min=0,mode='Metropolis',viz=False,save=False, f=1.0, f2=0.0, b=1.0, kappa=1.0, lef_rw=True, lef_drift=True, cross_loop=True):
|
|
254
|
+
def run_energy_minimization(self, N_steps, MC_step, burnin, T=1, T_min=0, mode='Metropolis', viz=False, save=False, f=1.0, f2=0.0, b=1.0, kappa=1.0, lef_rw=True, lef_drift=True, cross_loop=True, r=None):
|
|
231
255
|
'''
|
|
232
256
|
Implementation of the stochastic Monte Carlo simulation.
|
|
233
257
|
|
|
@@ -238,19 +262,23 @@ class StochasticSimulation:
|
|
|
238
262
|
T (float): simulation (initial) temperature.
|
|
239
263
|
mode (str): it can be either 'Metropolis' or 'Annealing'.
|
|
240
264
|
viz (bool): True in case that user wants to see plots.
|
|
265
|
+
r (list): strength of each ChIP-Seq experiment.
|
|
266
|
+
N_bws (int): number of binding weight matrices.
|
|
267
|
+
BWs (np.ndarray): binding weight matrices.
|
|
241
268
|
'''
|
|
242
269
|
# Define normalization constants
|
|
243
270
|
fold_norm, fold_norm2, bind_norm, k_norm = -self.N_beads*f/((self.N_lef+self.N_lef2)*np.log(self.N_beads/(self.N_lef+self.N_lef2))), -self.N_beads*f2/((self.N_lef+self.N_lef2)*np.log(self.N_beads/(self.N_lef+self.N_lef2))), -self.N_beads*b/(np.sum(self.L)+np.sum(self.R)), kappa*1e4
|
|
244
271
|
self.N_steps, self.MC_step = N_steps, MC_step
|
|
272
|
+
r = np.full(self.N_bws, -self.N_beads / 10) if not r and self.N_bws > 0 else (None if not r else r)
|
|
245
273
|
|
|
246
274
|
# Run simulation
|
|
247
275
|
print('\nRunning simulation (with parallelization across CPU cores)...')
|
|
248
276
|
start = time.time()
|
|
249
277
|
self.burnin = burnin
|
|
250
|
-
self.Ms, self.Ns, self.Es, self.Ks, self.Fs, self.Bs, self.ufs = run_simulation(self.N_beads,N_steps,MC_step,burnin,T,T_min,fold_norm,fold_norm2,bind_norm,k_norm,self.N_lef,self.N_lef2,self.L,self.R,mode,lef_rw,lef_drift,cross_loop)
|
|
278
|
+
self.Ms, self.Ns, self.Es, self.Ks, self.Fs, self.Bs, self.ufs = run_simulation(self.N_beads, N_steps, MC_step, burnin, T, T_min, fold_norm, fold_norm2, bind_norm, k_norm, self.N_lef, self.N_lef2, self.L, self.R, mode, lef_rw, lef_drift, cross_loop, r, self.N_bws, self.BWs, self.lef_track)
|
|
251
279
|
end = time.time()
|
|
252
280
|
elapsed = end - start
|
|
253
|
-
print(f'Computation finished
|
|
281
|
+
print(f'Computation finished successfully in {elapsed//3600:.0f} hours, {elapsed%3600//60:.0f} minutes and {elapsed%60:.0f} seconds.')
|
|
254
282
|
|
|
255
283
|
# Save simulation info
|
|
256
284
|
if save:
|
|
@@ -265,7 +293,9 @@ class StochasticSimulation:
|
|
|
265
293
|
file.write(f'Crossing energy in equilibrium is {np.average(self.Ks[burnin//MC_step:]):.2f}. Crossing coefficient kappa={kappa}.\n')
|
|
266
294
|
file.write(f'Folding energy in equilibrium is {np.average(self.Fs[burnin//MC_step:]):.2f}. Folding coefficient f={f}. Folding coefficient for the second family f2={f2}\n')
|
|
267
295
|
file.write(f'Binding energy in equilibrium is {np.average(self.Bs[burnin//MC_step:]):.2f}. Binding coefficient b={b}.\n')
|
|
268
|
-
|
|
296
|
+
if r is not None and self.BWs is not None:
|
|
297
|
+
file.write(f'RNApII binding energy included with {N_bws} binding weight matrices.\n')
|
|
298
|
+
file.write(f'Energy at equilibrium: {np.average(self.Es[self.burnin//MC_step:]):.2f}.\n')
|
|
269
299
|
np.save(save_dir + 'Ms.npy', self.Ms)
|
|
270
300
|
np.save(save_dir + 'Ns.npy', self.Ns)
|
|
271
301
|
np.save(save_dir + 'ufs.npy', self.ufs)
|
|
@@ -274,16 +304,27 @@ class StochasticSimulation:
|
|
|
274
304
|
np.save(save_dir + 'Fs.npy', self.Fs)
|
|
275
305
|
np.save(save_dir + 'Ks.npy', self.Ks)
|
|
276
306
|
|
|
277
|
-
# Some
|
|
278
|
-
if viz: coh_traj_plot(self.Ms,self.Ns,self.N_beads, self.path)
|
|
307
|
+
# Some visualizations
|
|
308
|
+
if viz: coh_traj_plot(self.Ms, self.Ns, self.N_beads, self.path)
|
|
279
309
|
if viz: make_timeplots(self.Es, self.Bs, self.Ks, self.Fs, burnin//MC_step, mode, self.path)
|
|
280
|
-
if viz: coh_probdist_plot(self.Ms,self.Ns,self.N_beads,self.path)
|
|
281
|
-
if viz and self.N_beads<=2000: stochastic_heatmap(self.Ms,self.Ns,MC_step,self.N_beads,self.path)
|
|
310
|
+
if viz: coh_probdist_plot(self.Ms, self.Ns, self.N_beads, self.path)
|
|
311
|
+
if viz and self.N_beads <= 2000: stochastic_heatmap(self.Ms, self.Ns, MC_step, self.N_beads, self.path)
|
|
282
312
|
|
|
283
313
|
return self.Es, self.Ms, self.Ns, self.Bs, self.Ks, self.Fs, self.ufs
|
|
284
314
|
|
|
285
315
|
def preprocessing(self):
|
|
286
316
|
self.L, self.R, self.dists = binding_vectors_from_bedpe(self.bedpe_file,self.N_beads,self.region,self.chrom,False,False)
|
|
317
|
+
if not self.bw_files:
|
|
318
|
+
self.BWs = None
|
|
319
|
+
self.N_bws = 0
|
|
320
|
+
else:
|
|
321
|
+
if isinstance(self.bw_files, str):
|
|
322
|
+
self.bw_files = [self.bw_files]
|
|
323
|
+
self.N_bws = 1
|
|
324
|
+
self.BWs = np.zeros((self.N_bws, self.N_beads))
|
|
325
|
+
for i, f in enumerate(self.bw_files):
|
|
326
|
+
self.BWs[i, :] = load_track(file=f, region=self.region, chrom=self.chrom, N_beads=self.N_beads, viz=False)
|
|
327
|
+
self.lef_track = load_track(self.track_file,self.region,self.chrom,self.N_beads,False,True) if self.track_file else None
|
|
287
328
|
self.N_CTCF = np.max([np.count_nonzero(self.L),np.count_nonzero(self.R)])
|
|
288
329
|
print('Number of CTCF:',self.N_CTCF)
|
|
289
330
|
|
|
@@ -316,7 +357,7 @@ def main():
|
|
|
316
357
|
|
|
317
358
|
sim = StochasticSimulation(region,chrom,bedpe_file,out_dir=output_name,N_beads=1000,N_lef=N_lef,N_lef2=N_lef2)
|
|
318
359
|
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,f=f,f2=f2, b=b, kappa=kappa, lef_rw=lew_rw)
|
|
319
|
-
sim.run_MD('CUDA',continuous_topoisomerase=True, p_ev=0.
|
|
360
|
+
sim.run_MD('CUDA',continuous_topoisomerase=True, p_ev=0.01)
|
|
320
361
|
|
|
321
362
|
if __name__=='__main__':
|
|
322
363
|
main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyLoopSage
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
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,6 +31,7 @@ Requires-Dist: statsmodels
|
|
|
31
31
|
Requires-Dist: imageio
|
|
32
32
|
Requires-Dist: imageio[ffmpeg]
|
|
33
33
|
Requires-Dist: pillow
|
|
34
|
+
Requires-Dist: pyBigWig
|
|
34
35
|
Dynamic: author
|
|
35
36
|
Dynamic: author-email
|
|
36
37
|
Dynamic: classifier
|
|
@@ -271,35 +272,54 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
271
272
|
|
|
272
273
|
### Long-table of LoopSage arguments
|
|
273
274
|
|
|
275
|
+
#### General Settings
|
|
274
276
|
| Argument Name | Description | Type | Default Value |
|
|
275
277
|
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
276
278
|
| PLATFORM | Name of the platform. Available choices: CPU, CUDA, OpenCL | str | CPU |
|
|
277
279
|
| DEVICE | Device index for CUDA or OpenCL (count from 0) | str | None |
|
|
278
|
-
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
279
|
-
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
280
280
|
| OUT_PATH | Output folder name. | str | ../results |
|
|
281
|
+
| SAVE_MDT | True to save metadata of the stochastic simulation. | bool | True |
|
|
282
|
+
|
|
283
|
+
#### Input Data
|
|
284
|
+
| Argument Name | Description | Type | Default Value |
|
|
285
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
286
|
+
| BEDPE_PATH | A .bedpe file path with loops. It is required. | str | None |
|
|
287
|
+
| LEF_TRACK_FILE | Path to a bw file of cohesin or condensin density. If it is provided, then simulation LEFs preferentially bind in enriched regions. | str | None |
|
|
288
|
+
| BW_FILES | List of paths to .bw files containing additional data for simulation. Enriched regions would act as barriers for cohesin. | list | None |
|
|
281
289
|
| REGION_START | Starting region coordinate. | int | None |
|
|
282
290
|
| REGION_END | Ending region coordinate. | int | None |
|
|
283
291
|
| CHROM | Chromosome that corresponds to the modeling region of interest. | str | None |
|
|
284
|
-
|
|
285
|
-
|
|
292
|
+
|
|
293
|
+
#### Stochastic Simulation Parameters
|
|
294
|
+
| Argument Name | Description | Type | Default Value |
|
|
295
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
296
|
+
| N_BEADS | Number of Simulation Beads. | int | None |
|
|
286
297
|
| N_STEPS | Number of Monte Carlo steps. | int | 40000 |
|
|
287
|
-
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
288
|
-
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
289
298
|
| MC_STEP | Monte Carlo frequency to avoid autocorrelated ensembles. | int | 200 |
|
|
290
299
|
| BURNIN | Burn-in period (steps before equilibrium). | int | 1000 |
|
|
291
300
|
| T_INIT | Initial Temperature of the Stochastic Model. | float | 2.0 |
|
|
292
301
|
| T_FINAL | Final Temperature of the Stochastic Model. | float | 1.0 |
|
|
293
302
|
| METHOD | Stochastic modeling method (Metropolis or Simulated Annealing). | str | 'Annealing' |
|
|
303
|
+
| LEF_RW | True if cohesins slide as a random walk instead of one direction. | bool | True |
|
|
304
|
+
| LEF_DRIFT | True if LEFs are pushed back when they encounter other LEFs. | bool | False |
|
|
305
|
+
| N_LEF | Number of loop extrusion factors. | int | None |
|
|
306
|
+
| N_LEF2 | Number of second family loop extrusion factors. | int | 0 |
|
|
307
|
+
|
|
308
|
+
#### Energy Coefficients
|
|
309
|
+
| Argument Name | Description | Type | Default Value |
|
|
310
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
294
311
|
| FOLDING_COEFF | Folding coefficient. | float | 1.0 |
|
|
295
312
|
| FOLDING_COEFF2 | Folding coefficient for the second family of LEFs. | float | 0.0 |
|
|
296
313
|
| CROSS_COEFF | LEF crossing coefficient. | float | 1.0 |
|
|
297
314
|
| CROSS_LOOP | True if the penalty is applied when mi<mj<ni<nj. False if it applies only when mj=ni. When false it is better to enable LEF_DRIFT as well. | bool |True |
|
|
298
315
|
| BIND_COEFF | CTCF binding coefficient. | float | 1.0 |
|
|
299
|
-
|
|
|
300
|
-
|
|
301
|
-
|
|
316
|
+
| BW_STRENGTHS | List of strengths corresponding to each .bw file. | list | None |
|
|
317
|
+
|
|
318
|
+
#### Molecular Dynamics Simulation
|
|
319
|
+
| Argument Name | Description | Type | Default Value |
|
|
320
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
302
321
|
| SIMULATION_TYPE | Either EM (energy minimizations) or MD (molecular dynamics). | str | None |
|
|
322
|
+
| INITIAL_STRUCTURE_TYPE | Choose from: rw, confined_rw, self_avoiding_rw, helix, circle, spiral, sphere. | str | rw |
|
|
303
323
|
| INTEGRATOR_STEP | Step of the integrator. | Quantity | 100 femtosecond |
|
|
304
324
|
| FORCEFIELD_PATH | Path to XML file with forcefield. | str | default_xml_path |
|
|
305
325
|
| ANGLE_FF_STRENGTH | Angle force strength. | float | 200.0 |
|
|
@@ -311,10 +331,14 @@ An example, illustrated with Chimera software, simulated trajectory of structure
|
|
|
311
331
|
| EV_FF_POWER | Excluded-volume power. | float | 3.0 |
|
|
312
332
|
| FRICTION | Friction coefficient of the Langevin integrator. | float | 0.1 |
|
|
313
333
|
| TOLERANCE | Stopping condition for energy minimization. | float | 0.001 |
|
|
314
|
-
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
315
334
|
| SIM_TEMP | Temperature of the 3D simulation (EM or MD). | Quantity | 310 kelvin |
|
|
316
335
|
| SIM_STEP | Amount of simulation steps for loop force adjustments. | int | 1000 |
|
|
317
336
|
|
|
337
|
+
#### Visualization
|
|
338
|
+
| Argument Name | Description | Type | Default Value |
|
|
339
|
+
|------------------------|-----------------------------------------------------------------------------------------------------------------|------------|---------------------|
|
|
340
|
+
| VIZ_HEATS | True to visualize the output average heatmap. | bool | True |
|
|
341
|
+
| SAVE_PLOTS | True to save diagnostic plots. | bool | True |
|
|
318
342
|
|
|
319
343
|
## Citation
|
|
320
344
|
Please cite the method and biological paper in case that you would like to use this model for your work,
|
|
@@ -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='1.0
|
|
9
|
+
version='1.1.0', # 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',
|
|
@@ -39,6 +39,7 @@ setup(
|
|
|
39
39
|
'imageio',
|
|
40
40
|
'imageio[ffmpeg]',
|
|
41
41
|
'pillow',
|
|
42
|
+
'pyBigWig',
|
|
42
43
|
],
|
|
43
44
|
entry_points={
|
|
44
45
|
'console_scripts': [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|