Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7c42408
update readdy module to match cytosim as much as possible
Jun 25, 2024
0b17f02
script to copy readdy outputs
Jun 26, 2024
aa344d5
visualize individual trajectories, leverage readdy post processing co…
Jun 27, 2024
de1b0a5
visualize combined
Jun 27, 2024
037f3bf
add readdy baseline individual viz
Jul 1, 2024
fa06164
WIP tomography viz
Jul 1, 2024
9bd0675
tomography visualization
Jul 1, 2024
5cea593
Merge branch 'main' into update-viz
Jul 1, 2024
4bd4c60
calculate compression metrics on tomography data for viz
Jul 2, 2024
27050ce
WIP debugging tomography visualization and analysis
Jul 3, 2024
97b09e3
dim reduction viz, tomography viz in separate files
Jul 8, 2024
1ec3599
WIP adding options to pca viz
Jul 9, 2024
503c5b6
Update name to series_name in workflow docstrings
jessicasyu Jul 1, 2024
1866f55
Move copy readdy outputs into workflow notebooks
jessicasyu Jul 1, 2024
73c4527
Lint readdy processing notebooks
jessicasyu Jul 1, 2024
5164acf
Update docstrings in readdy data structures module
jessicasyu Jul 2, 2024
b599032
Update docstrings in readdy loader module
jessicasyu Jul 2, 2024
1366b98
Update docstrings and type hinting in readdy post processor module
jessicasyu Jul 2, 2024
5190623
Fix readdy no compression simulation series name
jessicasyu Jul 2, 2024
f6e7376
Update readdy simulation workflows
jessicasyu Jul 2, 2024
548f3aa
Fix autodoc for readdy simulation module
jessicasyu Jul 2, 2024
5497614
Fix floating point error when calculating control points
jessicasyu Jul 3, 2024
9ca451b
Fix readdy series name in dim reduction analysis
jessicasyu Jul 3, 2024
36065d0
Add compression metric descriptions and bounds to enum
jessicasyu Jul 3, 2024
6f7b3d5
Update compression workflow to include non compression cases
jessicasyu Jul 3, 2024
e89b6a0
Fix readdy post processor normal calculation to skip start and end
jessicasyu Jul 3, 2024
e9921d2
Remove outdated visualization files
jessicasyu Jul 3, 2024
881125b
Update individual simulator visualization workflows
jessicasyu Jul 3, 2024
b0ff9e6
Adjust number of sampled timepoints for Cytosim to match ReaDDy
jessicasyu Jul 8, 2024
fba0a71
Refactor combined trajectory visualization
jessicasyu Jul 8, 2024
11986b6
Add visualization notebooks to docs
jessicasyu Jul 8, 2024
07ca4eb
Add normalized time to compression metrics workflow
jessicasyu Jul 9, 2024
1d378e2
Update PCA transform points
jessicasyu Jul 9, 2024
a84eb7c
* refactor tomography visualization functions
mogres Jul 9, 2024
cf1ca60
Update tomography visualization
jessicasyu Jul 9, 2024
e4a7597
add column to check if files are ordered
mogres Jul 10, 2024
669374d
Merge branch 'main' into debug-update-viz
jessicasyu Jul 10, 2024
120ad45
Formatting for compression metrics analysis
jessicasyu Jul 10, 2024
6699c55
Update pca analysis workflow to save results to bucket
jessicasyu Jul 10, 2024
18c54a5
Update visualization README
jessicasyu Jul 10, 2024
7e5d06a
Refactor PCA visualization
jessicasyu Jul 10, 2024
0b1001f
merged in changes from testing PCA viz with options
Jul 15, 2024
d81f78c
update colors and camera position for combined viz
Jul 15, 2024
64c8762
PCA viz tested with all options
Jul 16, 2024
d4cf64d
test and tweak individual readdy viz
Jul 17, 2024
723343b
test and tweak individual cytosim viz
Jul 17, 2024
4dd48a3
updated camera views for individual and PCA viz
Jul 17, 2024
dfba623
finish commit
Jul 17, 2024
05bccff
add ipdb to requirements
mogres Jul 17, 2024
83fab65
Methods to calculate twist angle
mogres Jul 17, 2024
d8895fe
Methods to visualize twist angle
mogres Jul 17, 2024
1cb6bff
Remove tangent angle visualization. Fix doc strings.
mogres Jul 18, 2024
5cf8e74
Merge branch 'debug-update-viz' of github.com:simularium/subcell-pipe…
mogres Jul 18, 2024
a3e4740
lint
Jul 19, 2024
e85f117
more lint
Jul 19, 2024
65b4f9d
and more linting
Jul 19, 2024
491173e
fix saving tomography 2D plots
Jul 19, 2024
7c87800
tweaks to dim reduction and tomography viz
Jul 19, 2024
aa34e3b
lint
Jul 19, 2024
9d87bfe
Update subcell_pipeline/analysis/compression_metrics/README.md
Jul 25, 2024
7085345
changes from review
Jul 25, 2024
76b2ced
add h5py with pdm, remove unused imageio dep, remove broken tests
Jul 25, 2024
305b0d0
don't run tests on build since there aren't any
Jul 25, 2024
497bcb5
calculate total steps for readdy
Jul 25, 2024
d0328b5
remove .pdm-python and add to gitignore
Jul 29, 2024
d2c6c0a
Merge remote-tracking branch 'origin/feature/polymer_twist' into debu…
Jul 29, 2024
f2dfd59
more changes from review
Jul 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ jobs:
conda env update --file environment.yml --prune
pdm sync

- name: Test with pytest
shell: bash -l {0}
run: |
pdm run pytest --cov --cov-report html
rm htmlcov/.gitignore

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep the build workflow as is (it'll break the coverage badge otherwise). It just won't find any tests to run, which I think is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it breaks the build otherwise. We can add one test that passes, or maybe the coverage badge should be removed since we know it's zero, unfortunately

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can refactor the existing test so it passes? It doesn't need to be in this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can I leave it like this for this PR and you can pull this back in with the fixed test?

- name: Publish coverage report
if: ${{ github.ref == 'refs/heads/main' && matrix.python-version == '3.10' }}
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
1 change: 1 addition & 0 deletions .pdm-python
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/blairl/Documents/Dev/subcell-pipeline/.venv/bin/python
109 changes: 101 additions & 8 deletions pdm.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"setuptools>=70.0.0",
"io-collection>=0.10.2",
"python-dotenv>=1.0.1",
"imageio",
"h5py>=3.11.0",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion subcell_pipeline/analysis/compression_metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

## Metrics for comparing traces of compressed fibers

Analysis combines compression simulations from Cytosim and Readdy and calculates various compression metrics metrics to compare fibers.
Analysis combines compression simulations from Cytosim and Readdy and calculates various compression metrics to compare fibers.

- **Compare compression metrics between simulators** ([source](https://github.com/simularium/subcell-pipeline/blob/main/subcell_pipeline/analysis/compression_metrics/_compare_compression_metrics.py) | [notebook](https://simularium.github.io/subcell-pipeline/_notebooks/analysis/compression_metrics/_compare_compression_metrics.html))
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def align_fibers(data: pd.DataFrame) -> None:

def align_fiber(coords: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
"""
Align an array of x, y, z coordinates along the positive x axis.
Align an array of x, y, z coordinates along the positive y axis.

The function identifies the furthest point in the yz-plane and computes the
angle needed to rotate this point to lie on the positive y axis. This
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
raise ImportError("This module is a notebook and is not meant to be imported")

# %%
from pathlib import Path

import pandas as pd

from subcell_pipeline.analysis.tomography_data.tomography_data import (
Expand All @@ -37,9 +35,6 @@
sample_tomography_data,
)

# pixels to um
TOMOGRAPHY_SCALE_FACTOR: float = 0.0006

# %% [markdown]
"""
## Load tomography datasets
Expand All @@ -55,13 +50,12 @@
# S3 bucket for input and output files
bucket = "s3://subcell-working-bucket"

# Temporary path to save visualization files
temp_path: Path = Path(__file__).parents[3] / "analysis_outputs"
temp_path.mkdir(parents=True, exist_ok=True)

# Data repository for downloading tomography data
repository = "https://raw.githubusercontent.com/RangamaniLabUCSD/actincme/master/PolarityAnalysis/"

# Conversion factor from pixels to um for this dataset
tomography_scale_factor: float = 0.0006

# Folders and names of branched actin datasets
branched_datasets = [
("2018August_Tomo27", "TomoAugust_27_earlyCME"),
Expand All @@ -87,14 +81,14 @@
name=name,
repository=repository,
datasets=branched_datasets,
scale_factor=TOMOGRAPHY_SCALE_FACTOR,
scale_factor=tomography_scale_factor,
)
unbranched_df = get_unbranched_tomography_data(
bucket=bucket,
name=name,
repository=repository,
datasets=unbranched_datasets,
scale_factor=TOMOGRAPHY_SCALE_FACTOR,
scale_factor=tomography_scale_factor,
)

# %% [markdown]
Expand All @@ -104,7 +98,7 @@

# %%
plot_tomography_data_by_dataset(
branched_df, bucket, f"{name}/{name}_plots_branched.png", str(temp_path)
branched_df, bucket, f"{name}/{name}_plots_branched.png"
)

# %% [markdown]
Expand All @@ -114,7 +108,7 @@

# %%
plot_tomography_data_by_dataset(
unbranched_df, bucket, f"{name}/{name}_plots_unbranched.png", str(temp_path)
unbranched_df, bucket, f"{name}/{name}_plots_unbranched.png"
)

# %% [markdown]
Expand Down Expand Up @@ -162,7 +156,7 @@

# %%
plot_tomography_data_by_dataset(
sampled_data, bucket, f"{name}/{name}_plots_all_sampled.png", str(temp_path)
sampled_data, bucket, f"{name}/{name}_plots_all_sampled.png"
)

# %%
30 changes: 6 additions & 24 deletions subcell_pipeline/analysis/tomography_data/tomography_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import io
import os

import imageio
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from io_collection.keys.check_key import check_key
from io_collection.load.load_dataframe import load_dataframe
from io_collection.save.save_buffer import save_buffer_to_s3
from io_collection.save.save_dataframe import save_dataframe
from PIL import Image
from io_collection.save.save_figure import save_figure

TOMOGRAPHY_SAMPLE_COLUMNS: list[str] = ["xpos", "ypos", "zpos"]


def test_consecutive_segment_angles(polymer_trace: np.ndarray) -> np.bool_:
def test_consecutive_segment_angles(polymer_trace: np.ndarray) -> bool:
"""
Test whether the angles between consecutive segments of a polymer
trace are less than 90 degrees.
Expand All @@ -26,7 +21,7 @@ def test_consecutive_segment_angles(polymer_trace: np.ndarray) -> np.bool_:

Returns
-------
bool
:
True if all consecutive angles are less than 180 degrees.
"""
vectors = polymer_trace[1:] - polymer_trace[:-1]
Expand All @@ -35,7 +30,7 @@ def test_consecutive_segment_angles(polymer_trace: np.ndarray) -> np.bool_:
dot_products = np.dot(vectors[1:], vectors[:-1].T)

# Check if any angle is greater than 90 degrees
return np.all(dot_products > 0)
return np.all(dot_products > 0).item()


def read_tomography_data(file: str, label: str = "fil") -> pd.DataFrame:
Expand Down Expand Up @@ -284,17 +279,10 @@ def sample_tomography_data(
return all_sampled_df


def save_image_to_s3(bucket: str, key: str, image: np.ndarray) -> None:
with io.BytesIO() as buffer:
Image.fromarray(image).save(buffer, format="png")
save_buffer_to_s3(bucket[5:], key, buffer, "image/png")


def plot_tomography_data_by_dataset(
data: pd.DataFrame,
bucket: str,
output_key: str,
temp_path: str,
) -> None:
"""
Plot tomography data for each dataset.
Expand All @@ -307,13 +295,9 @@ def plot_tomography_data_by_dataset(
Where to upload the results.
output_key
File key for results.
temp_path
Local path for saving visualization output files.
"""
local_save_path = os.path.join(temp_path, os.path.basename(output_key))

figure, ax = plt.subplots(1, 3, figsize=(6, 2))
for dataset, group in data.groupby("dataset"):
_, ax = plt.subplots(1, 3, figsize=(6, 2))

ax[1].set_title(dataset)

Expand All @@ -329,6 +313,4 @@ def plot_tomography_data_by_dataset(
ax[1].plot(fiber["xpos"], fiber["zpos"], marker="o", ms=1, lw=1)
ax[2].plot(fiber["ypos"], fiber["zpos"], marker="o", ms=1, lw=1)

plt.savefig(local_save_path)
image: np.ndarray = imageio.imread(local_save_path)
save_image_to_s3(bucket, output_key, image)
save_figure(bucket, output_key, figure)
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@
# Number of monomer points per fiber
n_monomer_points = 200

# Total number of steps for each condition
total_steps: dict[str, int] = {
"0047": int(3.2e8),
"0150": int(1e8),
"0470": int(3.2e7),
"1500": int(1e7),
}

# Temporary path to save downloaded trajectories
temp_path: Path = Path(__file__).parents[3] / "aws_downloads"
temp_path.mkdir(parents=True, exist_ok=True)
Expand All @@ -85,6 +77,6 @@
n_replicates,
n_timepoints,
n_monomer_points,
total_steps,
str(temp_path),
compression=True,
temp_path=str(temp_path),
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
# Number of monomer points per fiber
n_monomer_points = 200

# Total number of steps for each condition
total_steps: dict[str, int] = {"": int(1e7)}

# Temporary path to save downloaded trajectories
temp_path: Path = Path(__file__).parents[3] / "aws_downloads"
temp_path.mkdir(parents=True, exist_ok=True)
Expand All @@ -76,6 +73,6 @@
n_replicates,
n_timepoints,
n_monomer_points,
total_steps,
str(temp_path),
compression=False,
temp_path=str(temp_path),
)
6 changes: 5 additions & 1 deletion subcell_pipeline/simulation/readdy/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from io_collection.save.save_pickle import save_pickle
from tqdm import tqdm

from .data_structures import FrameData, ParticleData, TopologyData
from subcell_pipeline.simulation.readdy.data_structures import (
FrameData,
ParticleData,
TopologyData,
)


class ReaddyLoader:
Expand Down
30 changes: 27 additions & 3 deletions subcell_pipeline/simulation/readdy/parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Methods for parsing ReaDDy simulations."""

import os
from math import floor, log10
from typing import Optional, Union

import boto3
Expand Down Expand Up @@ -47,6 +48,9 @@
BOX_SIZE: np.ndarray = np.array(3 * [600.0])
"""Default simulation volume dimensions (x, y, z)."""

COMPRESSION_DISTANCE: float = 150.0
"""Total distance the fiber end was displaced in nm."""


def _download_s3_file(bucket: str, key: str, dest_path: str) -> Optional[str]:
"""
Expand Down Expand Up @@ -205,14 +209,23 @@ def parse_readdy_simulation_single_fiber_trajectory(
return dataframe


def round_2_sig_figs(x: float) -> int:
return int(round(x, -int(floor(log10(abs(0.1 * x))))))


def velocity_for_cond(condition_key: str) -> float:
"""'NNNN' -> NNN.N."""
return float(condition_key[:3] + "." + condition_key[-1])


def parse_readdy_simulation_data(
bucket: str,
series_name: str,
condition_keys: list[str],
n_replicates: int,
n_timepoints: int,
n_monomer_points: int,
total_steps: dict[str, int],
compression: bool,
temp_path: str,
) -> None:
"""
Expand All @@ -232,11 +245,22 @@ def parse_readdy_simulation_data(
Number of equally spaced timepoints to sample.
n_monomer_points
Number of equally spaced monomer points to sample.
total_steps
Total number of steps for each simulation key.
compression
If True, parse compressed trajectories,
If False, parse baseline uncompressed trajectories.
temp_path
Path for saving temporary h5 files.
"""
total_steps: dict[str, int] = {}
if compression:
total_steps = {
cond: round_2_sig_figs(
(COMPRESSION_DISTANCE * 1e-3 / velocity_for_cond(cond)) * 1e10
)
for cond in condition_keys
}
else:
total_steps = {"": int(1e7)}

for condition_key in condition_keys:
series_key = f"{series_name}_{condition_key}" if condition_key else series_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
fibers using [Simularium](https://simularium.allencell.org/).

- [Define visualization settings](#define-visualization-settings)
- [Visualize tomography data](#visualize-tomography)
- [Visualize tomography data](#visualize-tomography-data)
"""

# %%
Expand Down
25 changes: 0 additions & 25 deletions tests/conftest.py

This file was deleted.

Binary file removed tests/data/readdy/actin_ortho_filament_10_steps.h5
Binary file not shown.
Loading