Skip to content

Commit

Permalink
Change global phaseogram to one-sided only
Browse files Browse the repository at this point in the history
Previously counted nucleosomal frags on both sides of a query fragment,
but this is unnecessary because it will be on average symmetrical. Also
skip counting the query fragment itself.
  • Loading branch information
kbseah committed Apr 7, 2022
1 parent 3c65faf commit 496845c
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions mnutils/Posmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,33 +206,29 @@ def write_wig(self, filename, which="smooth"):


def global_phaseogram(self, window=1000, subsample=1000):
"""Calculate phaseogram of nucleosome positions up and downstream
from other nucleosome.
"""Calculate phaseogram of nucleosome positions downstream from other
nucleosome.
Parameters
----------
window : int
Window (symmetrical, up and downstream) in bp
Window (downstream of target position) in bp
subsample : int
Randomly sample this number of positions per scaffold.
If the number of positions is less, then use all positions.
"""
phaseogram = defaultdict(int)
phaseogram[0] = 0

for scaffold in self._positionmap:
if len(self._positionmap[scaffold]) > subsample:
poss = sample(list(self._positionmap[scaffold]), subsample)
else:
poss = self._positionmap[scaffold]
for pos in poss:
left = int(pos - window)
right = int(pos + window)
width = right - left
for j in range(2 * window):
jumppos = left + j
for j in range(1, window): # Start from 1, do not count self
jumppos = pos + j
if jumppos in self._positionmap[scaffold]:
phaseogram[j - window] += self._positionmap[scaffold][jumppos]
phaseogram[j] += self._positionmap[scaffold][jumppos]
return(phaseogram)


Expand Down

0 comments on commit 496845c

Please sign in to comment.