Skip to content

Commit

Permalink
RM signatures from tomtom
Browse files Browse the repository at this point in the history
  • Loading branch information
jmschrei committed Sep 6, 2024
1 parent 04ca63a commit c712f74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
32 changes: 16 additions & 16 deletions docs/tutorials/Tutorial_D2_TOMTOM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 1,
"id": "29dff7e7-ca13-4967-bf5c-2e9385a73571",
"metadata": {},
"outputs": [
Expand All @@ -36,7 +36,7 @@
"(1, 1646)"
]
},
"execution_count": 10,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -72,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 2,
"id": "2a66616d-457c-4d25-8eb0-f831309aa415",
"metadata": {},
"outputs": [
Expand All @@ -84,7 +84,7 @@
" 'MA1332.1 BEH2', 'MA1333.1 BEH3', 'MA1493.1 HES6'], dtype='<U28')"
]
},
"execution_count": 13,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -105,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"id": "eed69064-ebf5-4786-89fe-c574a224ddc9",
"metadata": {},
"outputs": [
Expand All @@ -115,7 +115,7 @@
"(12, 1646)"
]
},
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -137,7 +137,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 4,
"id": "e26732ac-31c3-411b-a785-611d45cae92e",
"metadata": {},
"outputs": [
Expand All @@ -149,7 +149,7 @@
" -2.18491891e-13, 2.02698924e-09, -1.84918747e-12, 1.90786831e-09])"
]
},
"execution_count": 17,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -174,15 +174,15 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 5,
"id": "80e8d169-bf4f-43ba-9a61-57776bd7ddbe",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.22 s ± 71.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"1.06 s ± 56.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -202,15 +202,15 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 6,
"id": "4228e04b-03ff-4233-b5e0-1c5be2b61397",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.1 s ± 222 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"9.09 s ± 121 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand Down Expand Up @@ -238,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 7,
"id": "398c45b7-6540-48c7-9446-f75ece60d1a7",
"metadata": {},
"outputs": [
Expand All @@ -248,7 +248,7 @@
"(1646, 100)"
]
},
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -268,7 +268,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 8,
"id": "05d713c5-5226-4f1a-924d-756ac0b4ef2f",
"metadata": {},
"outputs": [
Expand All @@ -279,7 +279,7 @@
" 805.])"
]
},
"execution_count": 24,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
20 changes: 7 additions & 13 deletions tangermeme/tools/tomtom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numpy import uint64


@njit("float64(float64[:], float64[:, :], float64, float64, int64[:])")
@njit
def _binned_median(x, bins, x_min, x_max, counts):
"""An internal function for calculating medians quickly.
Expand Down Expand Up @@ -49,9 +49,7 @@ def _binned_median(x, bins, x_min, x_max, counts):
return -99999


@njit('''uint64(float64[:, :], float64[:, :], int32[:, :], float64[:, :],
float64[:, :], float64[:], float64[:, :], float64[:], float64[:], int64[:],
int64, int64, int64)''')
@njit
def _integer_distances_and_histogram(X, Y, gamma, f, Z, medians, median_bins,
X_norm, Y_norm, Y_counts, nq_csum, nq, n_bins):
"""An internal function for integerized scores and the histogram.
Expand Down Expand Up @@ -113,7 +111,7 @@ def _integer_distances_and_histogram(X, Y, gamma, f, Z, medians, median_bins,
return uint64(-i_min * bin_scale)


@njit('void(float64[:], float64[:], float64[:], float64[:], int64)')
@njit
def _pairwise_max(x, y, y_csum, z, n):
"""An internal function for the pdf of the maximum of two pdfs.
Expand All @@ -138,8 +136,7 @@ def _pairwise_max(x, y, y_csum, z, n):
z[i] = x[i] * y_csum[i] + y[i] * x_csum - x[i] * y[i]


@njit('''void(float64[:, :], float64[:, :, :], float64[:, :], float64[:, :, :],
int64, int64, int64, uint64)''')
@njit
def _p_value_backgrounds(f, A, B, A_csum, nq, n_bins, t_max, offset):
"""An internal function that calculates the backgrounds for p-values.
Expand Down Expand Up @@ -213,8 +210,7 @@ def _p_value_backgrounds(f, A, B, A_csum, nq, n_bins, t_max, offset):
B[i, j] = 1 - B[i, j]


@njit('''void(int32[:, :], float64[:, :], uint64[:], int64[:], int64, uint64,
int64, float64[:, :])''')
@njit
def _p_values(gamma, B_cdfs, rr_inv, T_lens, nq, offset, n_bins, results):
"""An internal function for calculating the best match and p-values.
Expand Down Expand Up @@ -261,7 +257,7 @@ def _p_values(gamma, B_cdfs, rr_inv, T_lens, nq, offset, n_bins, results):
total_offset += nt


@njit('void(float64[:, :])')
@njit
def _merge_rc_results(results):
"""An internal method for taking the best across two strands."""

Expand All @@ -282,9 +278,7 @@ def _merge_rc_results(results):
results[i, 4] = 1


@njit('''float64[:, :, :](float64[:, :], float64[:, :], int64[:], int64[:],
float64[:], float64[:], uint64[:], int64[:], int64, int64, int64, int64,
int64)''', parallel=True)
@njit(parallel=True)
def _tomtom(Q, T, Q_lens, T_lens, Q_norm, T_norm, rr_inv, rr_counts, n_nearest,
n_score_bins, n_median_bins, n_cache, reverse_complement):
"""An internal function implementing the TOMTOM algorithm.
Expand Down

0 comments on commit c712f74

Please sign in to comment.