Skip to content

Commit ad9ad76

Browse files
committedMay 20, 2021
add tad caller
1 parent 9a2338b commit ad9ad76

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
 

‎hictools/tad.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ def __call_oe_neighbor_diff(self, st, ed, left: "TadScore" = None, right: "TadSc
355355
s_sum_back=s_sum_back, c_sum_back=c_sum_back)
356356

357357
def __call_raw_diamond_diff(self, st, ed, left=None, right=None, **kwargs):
358+
"""Technically, it's similar to arrowtad method.
359+
"""
358360
score = 0
359361
if ed - st < 4 or ed - st > 400:
360362
is_tad = False
@@ -434,7 +436,6 @@ def get_outside_mean(self, st, ed, ma: np.ndarray):
434436
w = (ed - st) // 2
435437
# w = (ed - st)
436438

437-
out_left = out_right = -1
438439
try:
439440
out_left = self.mean(max(0, st - w), st, st, ed, ma)
440441
except:
@@ -447,7 +448,20 @@ def get_outside_mean(self, st, ed, ma: np.ndarray):
447448
return out_left, out_right
448449

449450

450-
def solve(borders: List[int], score: Score):
451+
def dp_solve(borders: List[int], score: Score):
452+
"""Find hierarchical TADs by solving a dynamic programming problem, maximize a certain objective score.
453+
454+
Formula:
455+
dp[l][r] = max(dp[l][mid] + dp[mid][r]) for mind in (l: r)
456+
457+
Time complexity:
458+
Only iterate over borders, n = len(border), O(n^3)
459+
460+
Reference:
461+
ONTAD, difference:
462+
1: this method uses iteration instead of recursion
463+
2: with different objective function
464+
"""
451465
assert isinstance(score, Score)
452466
n = len(borders)
453467
dp = [[score.inf for i in range(n)] for i in range(n)]
@@ -469,6 +483,9 @@ def solve(borders: List[int], score: Score):
469483

470484

471485
def call_tads(ob: np.ndarray):
486+
"""
487+
Currently this method will results too much tads.
488+
"""
472489
from scipy import ndimage, signal
473490
ob[~np.isfinite(ob)] = 0
474491

@@ -481,5 +498,5 @@ def call_tads(ob: np.ndarray):
481498
'ob': ob
482499
}
483500
score = TadScore(info=info)
484-
dp = solve(borders, score)
501+
dp = dp_solve(borders, score)
485502
return dp[0][-1].extract_tads()

0 commit comments

Comments
 (0)
Please sign in to comment.