Skip to content

Commit

Permalink
Update according to feedback comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Isabelle-C committed Oct 7, 2023
1 parent f7f53e3 commit c786f18
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 80 deletions.
2 changes: 2 additions & 0 deletions src/arcade_collection/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from .get_location_voxels import get_location_voxels
from .merge_parsed_results import merge_parsed_results
from .parse_cells_file import parse_cells_file
from .parse_growth_file import parse_growth_file
from .parse_locations_file import parse_locations_file


convert_model_units = task(convert_model_units)
extract_tick_json = task(extract_tick_json)
get_location_voxels = task(get_location_voxels)
Expand Down
50 changes: 17 additions & 33 deletions src/arcade_collection/output/parse_growth_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
from os import path
import tarfile
from typing import List, Union

import numpy as np
import pandas as pd
Expand All @@ -22,6 +20,16 @@
"CYCLE",
]

CELL_STATES = [
"NEUTRAL",
"APOPTOTIC",
"QUIESCENT",
"MIGRATORY",
"PROLIFERATIVE",
"SENESCENT",
"NECROTIC",
]


@task
def parse_growth_file(tar: tarfile.TarFile) -> pd.DataFrame:
Expand Down Expand Up @@ -56,26 +64,6 @@ def parse_growth_file(tar: tarfile.TarFile) -> pd.DataFrame:
return timepoints_df


def convert_state_to_string(state_index: int, state_list: List[str]) -> Union[str, None]:
"""
Convert the numbers that represent cell state into an annotation.
Parameters
----------
state_index :
The index of cell states.
state_list :
The list of cell states.
Returns
-------
:
The cell state annotation.
"""

return state_list[state_index]


def parse_growth_timepoint(timepoint: dict, seed: int) -> list:
"""
Parse one timepoint of the simulation.
Expand All @@ -99,20 +87,16 @@ def parse_growth_timepoint(timepoint: dict, seed: int) -> list:
time = timepoint["time"]

for (location, cells) in timepoint["cells"]:
u = int(location[0])
v = int(location[1])
w = int(location[2])
z = int(location[3])
u, v, w, z = location

for cell in cells:
population = cell[1]
state = cell[2]
position = cell[3]
volume = cell[4]
if len(cell[5]) == 0:
_, population, state, position, volume, cycles = cell

if len(cycles) == 0:
cycle = None
else:
cycle = np.mean(cell[5])
cycle = np.mean(cycles)

data_list = [
time,
seed,
Expand All @@ -122,7 +106,7 @@ def parse_growth_timepoint(timepoint: dict, seed: int) -> list:
z,
position,
population,
convert_state_to_string(state, ["NEU", "APO", "QUI", "MIG", "PRO", "SEN", "NEC"]),
CELL_STATES[state],
volume,
cycle,
]
Expand Down
26 changes: 0 additions & 26 deletions src/arcade_collection/output/parse_params_file.py

This file was deleted.

37 changes: 16 additions & 21 deletions tests/arcade_collection/output/test_parse_growth_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def test_parse_growth_timepoint(self):
"POSITION": [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
"POPULATION": [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0],
"STATE": [
"QUI",
"QUI",
"QUI",
"MIG",
"APO",
"PRO",
"QUI",
"MIG",
"QUI",
"QUI",
"QUI",
"MIG",
"APO",
"PRO",
"QUI",
"NEC",
"QUIESCENT",
"QUIESCENT",
"QUIESCENT",
"MIGRATORY",
"APOPTOTIC",
"PROLIFERATIVE",
"QUIESCENT",
"MIGRATORY",
"QUIESCENT",
"QUIESCENT",
"QUIESCENT",
"MIGRATORY",
"APOPTOTIC",
"PROLIFERATIVE",
"QUIESCENT",
"NECROTIC",
],
"VOLUME": [
2322.26,
Expand Down Expand Up @@ -123,9 +123,4 @@ def test_parse_growth_timepoint(self):
}

expected_df = pd.DataFrame(expected_dict)
print(returned_df)

print("-----")

print(expected_df)
self.assertTrue(expected_df.equals(returned_df))

0 comments on commit c786f18

Please sign in to comment.