Skip to content

Commit b7f3c69

Browse files
committed
contactmaps 3.14 compatible; black/isort
1 parent 320f25e commit b7f3c69

File tree

14 files changed

+58
-71
lines changed

14 files changed

+58
-71
lines changed

examples/customIntegrators/corr_noise.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
>>> python corr_noise.py [gpuid]
2323
2424
"""
25+
2526
import os
2627
import sys
2728
import time

examples/example/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
In this simulation, a simple polymer chain of 10,000 monomers is simulated.
66
"""
77

8-
98
import os
109
import sys
1110

examples/loopExtrusion/directionalModel/flagshipNormLifetime.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33

44
matplotlib.use("Agg")
55

6+
import ctypes
7+
import multiprocessing as mp
68
import os
7-
import numpy as np
9+
810
import matplotlib.pyplot as plt
11+
import numpy as np
912
import pandas as pd
10-
import ctypes
11-
from mirnylib.plotting import nicePlot
12-
import multiprocessing as mp
1313
import pyximport
14-
14+
from mirnylib.plotting import nicePlot
1515
from openmmlib import polymerutils
16-
1716
from openmmlib.polymerutils import scanBlocks
1817

1918
pyximport.install()
19+
import sys
20+
from contextlib import closing
21+
2022
from mirnylib.h5dict import h5dict
23+
from mirnylib.numutils import coarsegrain, completeIC, zoomArray
2124
from mirnylib.systemutils import fmap, setExceptionHook
22-
from mirnylib.numutils import coarsegrain, completeIC
23-
from mirnylib.numutils import zoomArray
24-
from contextlib import closing
25-
import sys
2625
from smcTranslocator import smcTranslocatorDirectional
2726

2827
filename = "/net/levsha/share/nezar/ctcf_sites/GM12878.ctcf_narrowPeak.loj.encodeMotif.rad21.txt"
@@ -70,9 +69,7 @@ def averageContacts(contactFunction, inValues, N, **kwargs):
7069

7170
filenameChunks = [filenames[i::nproc] for i in range(nproc)]
7271

73-
with closing(
74-
mp.Pool(processes=nproc, initializer=init, initargs=sharedARrays_)
75-
) as p:
72+
with closing(mp.Pool(processes=nproc, initializer=init, initargs=sharedARrays_)) as p:
7673
p.map(worker, filenameChunks)
7774

7875

@@ -201,9 +198,7 @@ def doSim(i):
201198
hicdata = np.clip(hicdata, 0, np.percentile(hicdata, 99.99))
202199
hicdata /= np.mean(np.sum(hicdata, axis=1))
203200

204-
fmap(
205-
doSim, range(30), n=20
206-
) # number of threads to use. On a 20-core machine I use 20.
201+
fmap(doSim, range(30), n=20) # number of threads to use. On a 20-core machine I use 20.
207202

208203
arr = coarsegrain(arr, 20)
209204
arr = np.clip(arr, 0, np.percentile(arr, 99.9))
@@ -249,9 +244,10 @@ def calculateAverageLoop():
249244

250245

251246
def doPolymerSimulation(steps, dens, stiff, folder):
247+
import time
248+
252249
from openmmlib.openmmlib import Simulation
253250
from openmmlib.polymerutils import grow_rw
254-
import time
255251

256252
SMCTran = initModel()
257253

@@ -322,7 +318,5 @@ def doPolymerSimulation(steps, dens, stiff, folder):
322318
steps=5000,
323319
stiff=2,
324320
dens=0.2,
325-
folder="flagshipLifetime{1}Mu{2}_try={0}".format(
326-
sys.argv[1], sys.argv[2], sys.argv[3]
327-
),
321+
folder="flagshipLifetime{1}Mu{2}_try={0}".format(sys.argv[1], sys.argv[2], sys.argv[3]),
328322
)

examples/loopExtrusion/directionalModel/showContactmap.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import matplotlib
2-
3-
# matplotlib.use("Agg")
4-
5-
from mirnylib.plotting import nicePlot
61
import os
72
import pickle
8-
from openmmlib import contactmaps
9-
from mirnylib.numutils import zoomArray
10-
from openmmlib import polymerutils
113

4+
import matplotlib
125
import matplotlib.pyplot as plt
136
import numpy as np
14-
from mirnylib.h5dict import h5dict
7+
import pandas as pd
158
from mirnylib.genome import Genome
16-
from mirnylib.numutils import completeIC, coarsegrain
9+
from mirnylib.h5dict import h5dict
10+
from mirnylib.numutils import coarsegrain, completeIC, zoomArray
11+
from mirnylib.plotting import nicePlot
1712
from mirnylib.systemutils import setExceptionHook
13+
from openmmlib import contactmaps, polymerutils
1814
from openmmlib.contactmapManager import averageContacts
19-
import pandas as pd
20-
from mirnylib.numutils import coarsegrain
15+
16+
# matplotlib.use("Agg")
17+
18+
2119

2220
setExceptionHook()
2321

@@ -33,8 +31,8 @@ def __init__(self, i, forw, rev, blocks, steps):
3331
import pyximport
3432

3533
pyximport.install()
36-
from smcTranslocatorDirectional import smcTranslocator
3734
import numpy as np
35+
from smcTranslocatorDirectional import smcTranslocator
3836

3937
N = len(forw)
4038
birthArray = np.zeros(N, dtype=np.double) + 0.1
@@ -365,16 +363,8 @@ def showCmapNew():
365363
if end > 75000:
366364
continue
367365
plt.xlim([st, end])
368-
plt.savefig(
369-
os.path.join(
370-
"heatmaps", "{0}_st={1}_end={2}_r=2.png".format(fname, st, end)
371-
)
372-
)
373-
plt.savefig(
374-
os.path.join(
375-
"heatmaps", "{0}_st={1}_end={2}_r=2.pdf".format(fname, st, end)
376-
)
377-
)
366+
plt.savefig(os.path.join("heatmaps", "{0}_st={1}_end={2}_r=2.png".format(fname, st, end)))
367+
plt.savefig(os.path.join("heatmaps", "{0}_st={1}_end={2}_r=2.pdf".format(fname, st, end)))
378368
plt.clf()
379369

380370
plt.show()

polychrom/contactmaps.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ def worker(x):
281281
return
282282

283283

284+
def identity(x):
285+
return x
286+
287+
284288
def averageContacts(contactIterator, inValues, N, **kwargs):
285289
"""
286290
A main workhorse for averaging contacts on multiple cores into one shared contact
@@ -352,7 +356,7 @@ def next(self): # actual realization of the self.next method
352356
contactBlock = kwargs.get("contactBlock", 5000000)
353357
classInitArgs = kwargs.get("classInitArgs", [])
354358
classInitKwargs = kwargs.get("classInitKwargs", {})
355-
contactProcessing = kwargs.get("contactProcessing", lambda x: x)
359+
contactProcessing = kwargs.get("contactProcessing", identity)
356360
finalSize = N * (N + 1) // 2
357361
boundaries = np.linspace(0, finalSize, bucketNum + 1, dtype=int)
358362
chunks = zip(boundaries[:-1], boundaries[1:])

polychrom/contrib/integrators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
integrators use 0.1 or below).
4545
4646
"""
47+
4748
import numpy as np
4849
import openmm as mm
4950
from openmmtools import utils

polychrom/hdf5_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
`/path/to/the/trajectory/blocks_x-y.h5::42` automatically
9292
9393
"""
94+
9495
import glob
9596
import os
9697
import warnings

polychrom/legacy/forces.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import os
2+
import pickle
3+
14
import numpy as np
25
import simtk.openmm as openmm
3-
import simtk.unit.nanometer as nm
46
import simtk.unit as units
5-
import os
6-
import pickle
7+
import simtk.unit.nanometer as nm
78

89
"""
910
This is a collection of old forces that are likely no longer used
@@ -186,7 +187,6 @@ def lennard_jones_force(
186187
sigmaRep=None,
187188
sigmaAttr=None,
188189
):
189-
190190
"""
191191
Adds a lennard-jones force, that allows for mutual attraction.
192192
This is the slowest force out of all repulsive.
@@ -372,7 +372,6 @@ def exclude_sphere(sim_object, r=5, position=(0, 0, 0)):
372372

373373

374374
def attraction_to_the_core(sim_object, k, r0, coreParticles=[]):
375-
376375
"""Attracts a subset of particles to the core,
377376
repells the rest from the core"""
378377

polychrom/param_units.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
"""
22
Simulation parameters and the Rouse model
33
-----------------------------------------
44
@@ -9,19 +9,19 @@
99
to fit experimental data on chromatin dynamics, it provides some intuition for how
1010
to guess polychrom parameters from first principles.
1111
12-
For example, the mass of a particle is automatically set to 100 amu and
12+
For example, the mass of a particle is automatically set to 100 amu and
1313
the collision rate is set depending on the integrator. For Brownian integrators,
1414
setting the collision rate to 2.0 works well, whereas for Langevin integrators,
1515
it is best to set the collision rate to 0.001-0.01. For loop extrusion simulations,
1616
it is typically set to 0.1. These values have been determined empirically by group
1717
members. For Brownian dynamics, for example, using a smaller collision rate leads
18-
to integration failures. By default the temperature is set to 300K.
18+
to integration failures. By default the temperature is set to 300K.
1919
2020
In any case, the monomer diffusion coefficient naturally follows as
2121
:math:`D=k_B T / m \zeta`, where :math:`\zeta` is the collision rate. So once the
2222
mass and collision rate are set, there is no control over the choice of D unless
2323
you use a custom Brownian integrator (see integrators module) that directly takes
24-
in D as a parameter. However, even then, the units of D are in terms of
24+
in D as a parameter. However, even then, the units of D are in terms of
2525
:math:`k_B T / m \zeta`.
2626
2727
The other arbitrary parameters are the monomer radius, set to sim.conlen = 1 nm
@@ -31,26 +31,26 @@
3131
:math:`k = 2k_B T / x^2`. For a Rouse chain, :math:`k = 3 k_B T / y^2`, where
3232
:math:`y` is the standard deviation of the bond extension. The Rouse model of DNA
3333
is secretely a wormlike chain at shorter length scales; thus, :math:`y` should
34-
be set to the end-to-end distance of the underlying WLC, which is defined as
34+
be set to the end-to-end distance of the underlying WLC, which is defined as
3535
:math:`y = \sqrt{L_0 b}`, where :math:`L_0` is the length of DNA per monomer and
3636
:math:`b` is the Kuhn length. These relations imply that the bondWiggleDistance
37-
should be set to :math:`x = \sqrt{2L_0 b / 3}`.
37+
should be set to :math:`x = \sqrt{2L_0 b / 3}`.
3838
3939
Note that all length scales in
4040
polychrom are in terms of sim.conlen = 1 nm. So :math:`L_0` and :math:`b` should
4141
also be in nanometers. It is not obvious how to convert from nanometers of
4242
chromatin to basepairs. One way of doing it is using the formula
4343
n_basepairs = (n_nm / 0.34 nm/bp) * (1 + 146/<L>), where <L> is the average linker
44-
length in the cell. For example, for human T cells, <L> = 50 bp; so b=40nm of
44+
length in the cell. For example, for human T cells, <L> = 50 bp; so b=40nm of
4545
cumulative linker length would translate to 469 bp of chromatin, where we account
4646
for the buried DNA in nucleosomes. We can also invert this relation to get
4747
n_nm = n_basepairs/(1 + 146/<L>) * 0.34 nm/bp. So if we would like each monomer
4848
to represent 2 kilobases, this would translate to 174 nm of cumulative linker length.
4949
Using these values as an example, the resulting bondWiggleDistance would be
5050
sqrt(2Lb/3) = 68 nm. We then divide by the size of a monomer to understand what the
5151
bondWiggleDistance would be in terms of sim.conlen. So if we posit that the diameter
52-
of a bead is equal to 34 nm, the bondWiggleDistance would be close to 2.0. This is
53-
a much larger number than 0.1, which is what is used as default in polychrom!
52+
of a bead is equal to 34 nm, the bondWiggleDistance would be close to 2.0. This is
53+
a much larger number than 0.1, which is what is used as default in polychrom!
5454
5555
Generally, the more coarse-grained the simulation is, the more flexible the springs
5656
should be and the larger the bondWiggleDistance should be, since there is more DNA
@@ -61,15 +61,14 @@
6161
6262
For a self avoiding polymer there are 2 main dimensionless numbers to keep in mind.
6363
One is Ddt/b^2 and the other is a/b, where a is the radius of a monomer and b is the
64-
Kuhn length. Recall that D and dt (timestep) are set arbitrarily based on
65-
computational convenience, and a is set to 1 nm by default.
64+
Kuhn length. Recall that D and dt (timestep) are set arbitrarily based on
65+
computational convenience, and a is set to 1 nm by default.
6666
Thus, even if length scales and time scales can be
6767
rescaled at the end of the simulation to match experimental data, these ratios should
6868
be decided on beforehand and preserved. Most people set the rest length of the spring
69-
to be the diameter of the monomer = 1 nm.
69+
to be the diameter of the monomer = 1 nm.
7070
"""
7171

72-
7372
import numpy as np
7473
from simtk import unit
7574

polychrom/polymer_analyses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
import numpy as np
3939
import pandas as pd
40-
from scipy.spatial import cKDTree
4140
from scipy.ndimage import gaussian_filter1d
41+
from scipy.spatial import cKDTree
4242

4343
try:
4444
from . import _polymer_math

0 commit comments

Comments
 (0)