-
Notifications
You must be signed in to change notification settings - Fork 93
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
Aligning two sequences #90
Comments
Hi thanks for trying this package. I'm not aware of an easy or built-in way of doing this. |
I found a hack in the end. After making the graphic records, I located the feature I wanted to line up in each record and its position and orientation. I flipped every sequence record that was the wrong way around and remade the graphic records. Then the longest sequence gave me an anchor position, and I shifted every other graphic record feature by the difference between the anchor and its feature-of-interest position, then changed .first_index to this offset. Then in matplotlib subplots, I use sharex=False, and fix the xlimits to be the same for every plot. It worked.. though I'm not sure how robustly :) |
Thank you for describing this, it will be a good reference for the future. |
You can use Matplotlib's import matplotlib.pyplot as plt
from dna_features_viewer import GraphicFeature, GraphicRecord
fig = plt.figure(figsize=(12, 2)) # Set a large width to allow for shifting
grid = fig.add_gridspec(2, 200) # Two rows, 200 column or as many as necessary
# PLOT 1
features1 = [
GraphicFeature(start=0, end=50, strand=+1, color="#ffcccc", label="Feature 1"),
GraphicFeature(start=100, end=150, strand=-1, color="#ccccff", label="Feature 2"),
]
record1 = GraphicRecord(sequence_length=200, features=features1)
ax1 = fig.add_subplot(grid[0, 0:150])
record1.plot(ax=ax1, with_ruler=True)
# PLOT 2
features2 = [
GraphicFeature(start=10, end=60, strand=+1, color="#ccffcc", label="Feature 3"),
GraphicFeature(start=120, end=180, strand=-1, color="#ffcc99", label="Feature 4"),
]
record2 = GraphicRecord(sequence_length=200, features=features2)
ax2 = fig.add_subplot(grid[1, 50:200])
record2.plot(ax=ax2, with_ruler=True) |
If I am using subplots to plot multiple sequences, is it possible to offset the plot in the x-axis? Then I can align parts of the plot that belong together.
I've tried changing first_index, modifying the xlims of individual axes, but I think I'm missing something obvious.
The text was updated successfully, but these errors were encountered: