Skip to content

Commit

Permalink
Edits to python imaging README and added processing script to scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmetzcar committed Sep 17, 2024
1 parent 866fb28 commit 6d0578b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python_imaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

`image_processing_for_physicell.py` contains the class `PhysiCellPlotter`. This class enables reproducible visualization with many options - including setting which layers to include (cell, ECM components, diffusing fields), positional tracking of cell movement history, and smoothly generating stills and movies sequentially. It uses a modified version of [`pyMCDS.py`](https://github.com/PhysiCell-Tools/python-loader) - `pyMCDS_ECM.py`. The modifications include loading ECM data .mat outputs and formatting that data for use in visualizations.

See `shell_scripts` for usage examples.
See the folder `scripts` for usage examples of the scripts.

Note that due to continous development and iteration on the plots for the article accompanying this ECM extention, some now out of date figure numbers have crystallized into the the scripts included here. To the best of our ability, we include functional notes that include broadly which images were produced with which scripts. Future work includes smoothing these now historical names to broader/more generic names.

## Random extra scripts

## Scripts
`run_movie_scripts_orthogonal.py` is in the folder `scripts` and is used to invoke the making of the movies for the stochastic replicates by invoking the appropriate video making script multiple times. This specific example is for the invasive cellular front orthgonal scenario, with similar scripts used to make the videos for the other stochastic replicates.

Finally, there is a data vizualization in the paper accompanying this code. The code to produce that (Figure Supplementary Figure 5) is in `scripts`. It is `invasive_front_vizualization_of_variance.py` and uses output from `data_analysis_Painter.py`.

## Simulation visualization scripts

Advanced scripts - using the PhysiCellPlotter class in `image_processing_for_physicell.py`. Place scripts in `output` or other directory at same level or alter path assignment. Examples used to produce stills and movies for [this preprint](https://www.biorxiv.org/content/10.1101/2022.11.21.514608) are given below. Using the various options available in the PhysiCellPlotter class, other visualizations can be created.
* `full_history_movie_script.py`: Generates movie using all available outputs and plots the full cell positional histories as well as current cell positions and ECM fiber element orientations.
Expand Down
62 changes: 62 additions & 0 deletions scripts/run_movie_scripts_orthogonal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import subprocess
import shutil

# assumes that there is a movie making script in each directory - and that the output directory is created
# make sure the movie script points to the python_imaging directory - at the corect level

def run_secondary_scripts(root_dir, output_dir):
for root, dirs, files in os.walk(root_dir):
# print(root)
# print(dirs)
# print(files)
for file in files:
# print(file)
# if file.endswith(".py") and file != "run_movie_scripts_orthogonal.py" || file != "data_analysis_Painter.py" || file != "pyMCDS_ECM.py"):
if file == "simple_test_movies_cells_and_environment_Painter.py":
print(file)
script_path = os.path.join(root, file)
folder_name = os.path.basename(root)
output_mp4 = "orthogonal_" + folder_name + ".mp4"
print(script_path)
print(folder_name)
print(output_mp4)

# # Run the secondary script
os.chdir(folder_name)
# print(os.getcwd())

# run the script
subprocess.call(["python", file])
mp4_path = os.path.join(root, output_mp4)
# print(mp4_path)

# Could confirm is the movie was made - you would start with something like this
# if os.path.exists(mp4_path):
# Rename the .mp4 file to match the folder name
# new_mp4_path = os.path.join(root, folder_name + ".mp4")

# give the movie a new name
os.rename('multi_color_movie.mp4', output_mp4)
print(f"Renamed multi_color_movie.mp4 to {output_mp4}")

# Copy the .mp4 file to the output directory
output_mp4_copy = os.path.join(output_dir, "orthogonal_" + folder_name + ".mp4")
shutil.copy(output_mp4, output_mp4_copy)
print(f"Copied {output_mp4} to {output_mp4_copy}")
# figure this one out next. Ideally copy the file in also ... last step

os.chdir('../')
# print(os.getcwd())

if __name__ == "__main__":
root_directory = "."
output_directory = "../../../1_images_for_paper/stochastic_replicates/invasive_cellular_front_orthogonal/" # remember - the script is actually workign on directory lower
run_secondary_scripts(root_directory, output_directory)

# could make a more general script that handled all the scripts or do something that copied them all (or just one) into the
# directory and then ran them.
# script_names = ["script1.py", "script2.py", "script3.py"]
# subdirectory_prefix = "common_prefix" # Replace with your common prefix
# for script_name in script_names:
# copy_and_run_secondary_scripts(root_directory, script_name, subdirectory_prefix, output_directory)

0 comments on commit 6d0578b

Please sign in to comment.