Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: kymo micron to bp conversion #691

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aafkevandenberg
Copy link
Collaborator

I added a new notebook that uses markers on a kymograph to convert from micrometer to base pair coordinates.

Copy link
Member

@JoepVanlier JoepVanlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see more examples!

I did a quick first pass. My main recommendation would be to add units to the variable names, considering that this is all about positional calibration. Otherwise things can get confusing quickly (especially in a notebook with global state).

Comment on lines +180 to +181
Kymograph with target sites overlaid
------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not calibrate the kymograph as well? We do have Kymo.calibrate_to_kbp(length_kbp).

This does make me wonder whether we need an API for two point calibration for kymographs (taking into account the required offset). What do you think?


We then compare the binding profile, with base pair coordinates, to the expected target sites for the protein.

This Notebook requires the `peakutils` package. Run the following cell to make sure it is installed:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Should probably give instructions for pip vs conda. Ideally, we should offer peakfinding in Pylake itself. The algorithms are already there, just no public API.

I think for now, this is fine, but it'd be great if people wouldn't have to install stuff to use the notebook. What do you think?


indexes = peakutils.indexes(profile_red, thres=0.4, min_dist=30)
print(indexes)
peaks_x = peakutils.interpolate(x, profile_red, ind=indexes, width = 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by default this uses an uncorrected centroid algorithm, which is probably not the best for subpixel optimization since it can be biased with higher backgrounds.


The two highest peaks correspond to the locations of the markers. Use a peak finding algorithm to determined the precise location of these peaks::

indexes = peakutils.indexes(profile_red, thres=0.4, min_dist=30)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this is fine, but maybe we should fast track having peakfinding in Pylake natively. Especially considering that we already have a very similar peakfinder in the codebase (just not public).

Comment on lines +124 to +132
if maxx - peak1 - peak2 < 0:
a = (coord2 - coord1)/(peak2 - peak1)
b = coord1 - a*peak1
c = 0
else: # Flip coordinates if peaks are in the top half of the kymo
a = -(coord2 - coord1)/(peak2 - peak1)
b = coord1 - a*peak1
c = coord2 - coord1
return a*coord + b + c
Copy link
Member

@JoepVanlier JoepVanlier Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it easier to just flip the coordinates? The resulting code seems a lot simpler to me.

Suggested change
if maxx - peak1 - peak2 < 0:
a = (coord2 - coord1)/(peak2 - peak1)
b = coord1 - a*peak1
c = 0
else: # Flip coordinates if peaks are in the top half of the kymo
a = -(coord2 - coord1)/(peak2 - peak1)
b = coord1 - a*peak1
c = coord2 - coord1
return a*coord + b + c
# Flip coordinates if peaks are in the top half of the kymo
if max_coord_um - peak1_um - peak2_um >= 0:
coord2_kbp, coord1_kbp = coord1_kbp, coord2_kbp
kbp_per_um = (coord2_kbp - coord1_kbp) / (peak2_um - peak1_um)
offset_kbp = coord1_kbp - kbp_per_um * peak1_um
return kbp_per_um * coord_um + offset_kbp

Second question, the criterion tests whether the average of the peaks is over half. What if the peaks end up on either side of the middle?

a = -(coord2 - coord1)/(peak2 - peak1)
b = coord1 - a*peak1
c = peak2 - peak1
return (coord_kbp - b)/a + c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (coord_kbp - b)/a + c
return (coord_kbp - offset_kbp) / kbp_per_um

Further quantify target binding [1]_
- Track binding events using the Kymotracker, bin them, and determine which % is on/off target
- Compare the duration of binding on- vs off-target

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the target accuracy? Is chromatic aberration a worry here?

Convert kymograph coordinates to basepairs using markers
--------------------------------------------------------

In this notebook we use two red markers with known coordinates on a kymograph to convert coordinates from micrometers to base pair.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this notebook we use two red markers with known coordinates on a kymograph to convert coordinates from micrometers to base pair.
In this notebook we use two red markers with known coordinates on a kymograph to convert coordinates from micrometers to base pairs.

Comment on lines +52 to +53
marker1 = 33.786 # The location of the markers in kbp
marker2 = 44.826
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
marker1 = 33.786 # The location of the markers in kbp
marker2 = 44.826
marker1_kbp = 33.786 # The location of the markers in kbp
marker2_kbp = 44.826

marker1 = 33.786 # The location of the markers in kbp
marker2 = 44.826
dna_kbp = 48.502 # length of DNA in kbp
target_sites = [18.084, 30.533] # Target binding sites
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why'd you choose to put the sites in an array and the markers in separate floats?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants