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

[DEGA-189] code for calculating spatial gradients and distributions with respect to regions #65

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

huanlity
Copy link
Contributor

  1. move functions from notebooks to a separate .py file, including calculating distance, calculate gradient (bands), and plotting respective results.
  2. to make the code more modular, reusable, and efficient, I organized the functions in the new .py file as a class.

The code can be called like this:

# Specify the polygon
roi_name = 'region_1'

# Initialize the class
distance_calculator = DistanceToPolygon(gdf_micron, gdf_join_micron, roi_name)

# Calculate distances
distance_calculator.calc_distance_to_polygon()

# Plot distances
distance_calculator.plot_distance_to_polygon()

# Calculate gene gradients
band_width = 200
distance_calculator.calc_gene_gradient_to_polygon(band_width=band_width, num_bands=5, gene_list=gene_list)

# Plot gene gradients
distance_calculator.plot_gene_gradient_to_polygon(gene_list=gene_list, markersize=1)

# Save bands to Parquet
distance_calculator.save_bands_to_parquet(f"{path_landscape_files}/gdf_{band_width}_um_bands_from_{roi_name}.parquet")

@huanlity huanlity requested a review from cornhundred February 24, 2025 20:07
@cornhundred
Copy link
Collaborator

Hi @huanlity, I feel like I want to avoid making a class for this and we can instead use SpatialData (https://spatialdata.scverse.org/en/stable/tutorials/notebooks/notebooks/examples/tables.html) to store our state. Can you give that a try and let me know if you want to discuss?

Also, I want to use the Landscape visualization method to interactively visualize these regions and their associated gradients in addition to static plots. I think it is doable to add this to this pull request.

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