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

fix: small inconstancy errors in Normal division: lineage tree #571

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cellacdc/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ def _debug_lineage_tree(guiWin):
else:
pgshow(acdc_df)

printl(posData.tracked_lost_centroids)
# printl(posData.tracked_lost_centroids)
2 changes: 1 addition & 1 deletion cellacdc/myutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3325,7 +3325,7 @@ def _download_cellpose_germlineNuclei_model():
def _download_omnipose_models():
urls, file_sizes = _model_url('omnipose')
temp_model_path = tempfile.mkdtemp()
final_model_path = os.path.expanduser('~\.cellpose\models')
final_model_path = os.path.expanduser(r'~\.cellpose\models')
for url, file_size in zip(urls, file_sizes):
filename = url.split('/')[-1]
final_dst = os.path.join(final_model_path, filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def filter_cols(df):
Returns:
- pandas.DataFrame: The filtered DataFrame containing only the specified columns.
"""
lin_tree_cols = {'generation_num_tree', 'root_ID_tree', 'sister_ID_tree', 'parent_ID_tree', 'parent_ID_tree', 'emerg_frame_i', 'division_frame_i'}
lin_tree_cols = {'generation_num_tree', 'root_ID_tree', 'sister_ID_tree', 'parent_ID_tree', 'parent_ID_tree', 'emerg_frame_i', 'division_frame_i', 'is_history_known'}
sis_cols = {col for col in df.columns if col.startswith('sister_ID_tree')}
lin_tree_cols = lin_tree_cols | sis_cols
return df[list(lin_tree_cols)]
Expand Down Expand Up @@ -69,7 +69,7 @@ def reorg_sister_cells_inner_func(row):
return values


def reorg_sister_cells_for_inport(df):
def reorg_sister_cells_for_import(df):
"""
Reorganizes the sister cells for import.

Expand Down Expand Up @@ -174,6 +174,7 @@ def added_lineage_tree_to_cca_df(added_lineage_tree):
- 'parent_ID_tree'
- 'root_ID_tree'
- 'sister_ID_tree'
- 'is_history_known'
"""

cca_df = pd.DataFrame()
Expand All @@ -184,6 +185,9 @@ def added_lineage_tree_to_cca_df(added_lineage_tree):
cca_df['parent_ID_tree'] = [row[2] for row in added_lineage_tree]
cca_df['root_ID_tree'] = [row[4] for row in added_lineage_tree]
cca_df['sister_ID_tree'] = [row[5] for row in added_lineage_tree]
cca_df['is_history_known'] = cca_df['parent_ID_tree'] != -1
cca_df['is_history_known'] = cca_df['is_history_known'].astype(int)

cca_df = cca_df.set_index('Cell_ID')
return cca_df

Expand Down Expand Up @@ -736,11 +740,10 @@ def create_tracked_frame(self, frame_i, mother_daughters, IDs_prev, IDs_curr_unt
for ID in new_unknown_IDs:
# print(f'Frame {frame_i}: New cell ID {ID} suspected of being a cell from the outside.')
self.families.append([(ID, 1)])
added_lineage_tree.append((-1, ID, -1, 1, ID, [-1] * (self.max_daughter-1)))
added_lineage_tree.append((frame_i, ID, -1, 1, ID, [-1] * (self.max_daughter-1)))


for mother, _ in mother_daughters:

mother_ID = IDs_prev[mother]
daughter_IDs = daughter_dict[mother]
found = False # flag to track if a family was associated
Expand Down Expand Up @@ -894,9 +897,11 @@ def update_gen_df_from_df(self, df, frame_i):
Cell_info['generation_num_tree'] = 1
Cell_info['root_ID_tree'] = Cell_info['Cell_ID']
Cell_info['sister_ID_tree'] = [-1]
Cell_info['is_history_known'] = False
corrected_df = pd.concat([corrected_df, Cell_info.to_frame().T])
continue

Cell_info['is_history_known'] = True
parent_cell = unique_Cell_ID_df.loc[Cell_info['parent_ID_tree']]
Cell_info['generation_num_tree'] = parent_cell['generation_num_tree'] + 1
Cell_info['root_ID_tree'] = parent_cell['root_ID_tree']
Expand Down Expand Up @@ -987,7 +992,7 @@ def insert_lineage_df(self, lineage_df, frame_i, propagate_back=False, propagate
elif quick and (propagate_back or propagate_fwd or update_fams or consider_children):
raise ValueError('Quick is True, other options are not supported.')

lineage_df = reorg_sister_cells_for_inport(lineage_df)
lineage_df = reorg_sister_cells_for_import(lineage_df)
lineage_df = filter_cols(lineage_df)
if frame_i == len(self.lineage_list):
if not quick:
Expand Down Expand Up @@ -1056,7 +1061,7 @@ def insert_lineage_df(self, lineage_df, frame_i, propagate_back=False, propagate
def propagate(self, frame_i, Cell_IDs_fixed=None):
"""
Propagates the changes made to self.lineage_list at frame frame_i to the general DataFrame (self.general_df), families (self.families), and lineage list (self.gen_df_to_df_li()). The propagation can be done in both directions, and fixed cell IDs can be provided (in this case only those are propegated and the other Cell_IDs in the specified frame are ignored.)

Also updates is_history_known
Parameters:
- frame_i (int): The index of the frame to be propagated.
- Cell_IDs_fixed (list, optional): List of fixed cell IDs. Defaults to None.
Expand Down Expand Up @@ -1104,7 +1109,7 @@ def load_lineage_df_list(self, df_li):
)

df = filter_cols(df)
df = reorg_sister_cells_for_inport(df)
df = reorg_sister_cells_for_import(df)
self.frames_for_dfs.add(i)
df_li_new.append(df)

Expand Down