Skip to content

Commit

Permalink
colocalization: add method to classify binding order
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Oct 29, 2024
1 parent 94b5132 commit e1637c9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lumicks/pylake/kymotracker/colocalization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def classify_track(red, blue, timing_window=6):
"""This function classifies the tracks into groups based on the order in which
the proteins bind"""

# 3 blue_start < red_start blue_end < red_end
# 4 blue_start < red_start blue_end = red_end
# 5 blue_start < red_start blue_end > red_end

# 6 blue_start = red_start blue_end < red_end
# 7 blue_start = red_start blue_end = red_end
# 8 blue_start = red_start blue_end > red_end

# 9 red_start < blue_start blue_end < red_end
# 10 red_start < blue_start blue_end = red_end
# 11 red_start < blue_start blue_end > red_end

def classify(time, ref_time):
if ref_time - time > timing_window:
return 0
elif time - ref_time > timing_window:
return 2
else:
return 1

return (
3
+ 3 * classify(blue.time_idx[0], red.time_idx[0])
+ classify(blue.time_idx[-1], red.time_idx[-1])
)
36 changes: 36 additions & 0 deletions lumicks/pylake/kymotracker/tests/test_colocalization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from lumicks.pylake.kymotracker.kymotrack import KymoTrack, KymoTrackGroup
from lumicks.pylake.kymotracker.colocalization import classify_track
from lumicks.pylake.kymotracker.detail.track_proximity import (
BoundingBox,
tracks_close,
Expand Down Expand Up @@ -56,6 +57,41 @@ def test_bbox_construction_test(
assert bbox._valid == is_valid


@pytest.mark.parametrize(
"red_idx, blue_idx, classification",
[
# Blue starts first
([5, 13], [2, 10], 3),
([5, 12], [2, 10], 4),
([5, 10], [2, 10], 4),
([5, 8], [2, 10], 4),
([5, 7], [2, 10], 5),
# Starts at the same time
([0, 13], [2, 10], 6),
([2, 13], [2, 10], 6),
([4, 13], [2, 10], 6),
([5, 13], [2, 10], 3), # Out of the time window for "same time"
([2, 8], [2, 10], 7),
([2, 10], [2, 10], 7),
([2, 12], [2, 12], 7),
([2, 7], [2, 10], 8),
# Red starts first
([2, 13], [5, 10], 9),
([2, 12], [5, 10], 10),
([2, 10], [5, 10], 10),
([2, 8], [5, 10], 10),
([2, 7], [5, 10], 11),
],
)
def test_track_colocalization_classifier(blank_kymo, red_idx, blue_idx, classification):
red = KymoTrack(red_idx, [1, 1], blank_kymo, 0, 0)
blue = KymoTrack(blue_idx, [1, 1], blank_kymo, 0, 0)

assert (
result := classify_track(red, blue, 2)
) == classification, f"expected {classification}, got {result}"


@pytest.mark.parametrize(
"track1, track2, time_window, position_window, result",
[
Expand Down

0 comments on commit e1637c9

Please sign in to comment.