-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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).
Kymograph with target sites overlaid | ||
------------------------------------ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely makes sense. It is a common workflow. Sometimes markers are used, other times the blue fluorescence from the beads.
|
||
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I was not aware of that. Indeed makes sense to use that. Does that peak finder also fit a Gaussian?
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 |
There was a problem hiding this comment.
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.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a specific use case where the markers are asymmetrically positioned. The script should indeed be able to handle the symmetric case.
a = -(coord2 - coord1)/(peak2 - peak1) | ||
b = coord1 - a*peak1 | ||
c = peak2 - peak1 | ||
return (coord_kbp - b)/a + c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The chromatic aberration has to be determined by the user though. Do we have official specs for the accuracy?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
marker1 = 33.786 # The location of the markers in kbp | ||
marker2 = 44.826 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I had a file with 10 target sites. It does make sense to add the markers to an array too.
I added a new notebook that uses markers on a kymograph to convert from micrometer to base pair coordinates.