Skip to content

Commit

Permalink
fix: correctly assing bud when mother already has one in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Sep 8, 2023
1 parent 3154933 commit 146b1e5
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions cellacdc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8899,11 +8899,14 @@ def warnMotherNotEligible(self, new_mothID, budID, i, why):
Saved data is not changed of course.<br><br>
Apply assignment or cancel process?
""")
msg = QMessageBox()
enforce_assignment = msg.warning(
self, 'Cell not eligible', err_msg, msg.Apply | msg.Cancel
applyButton = widgets.okPushButton(isDefault=False)
applyButton.setText('Apply and remove future annotations')
msg = widgets.myMessageBox()
_, applyButton = msg.warning(
self, 'Cell not eligible', err_msg,
buttonsTexts=('Cancel', applyButton)
)
cancel = enforce_assignment == msg.Cancel
cancel = msg.cancel
elif why == 'not_G1_in_the_past':
err_msg = html_utils.paragraph(f"""
The requested cell in G1
Expand All @@ -8915,11 +8918,11 @@ def warnMotherNotEligible(self, new_mothID, budID, i, why):
One possible solution is to first go to frame {i+1} and
assign the bud of cell {new_mothID} to another cell.
""")
msg = QMessageBox()
msg = widgets.myMessageBox()
msg.warning(
self, 'Cell not eligible', err_msg, msg.Ok
self, 'Cell not eligible', err_msg
)
cancel = None
cancel = msg.cancel
elif why == 'single_frame_G1_duration':
err_msg = html_utils.paragraph(f"""
Assigning bud ID {budID} to cell in G1
Expand All @@ -8936,7 +8939,7 @@ def warnMotherNotEligible(self, new_mothID, budID, i, why):
msg.warning(
self, 'Cell not eligible', err_msg
)
cancel = None
cancel = msg.cancel
return cancel

def warnSettingHistoryKnownCellsFirstFrame(self, ID):
Expand All @@ -8956,6 +8959,7 @@ def checkMothEligibility(self, budID, new_mothID):
Check that the new mother is in G1 for the entire life of the bud
and that the G1 duration is > than 1 frame
"""
last_cca_frame_i = self.navigateScrollBar.maximum()-1
posData = self.data[self.pos_i]
eligible = True

Expand All @@ -8981,7 +8985,7 @@ def checkMothEligibility(self, budID, new_mothID):
cancel = self.warnMotherNotEligible(
new_mothID, budID, i, 'not_G1_in_the_future'
)
if cancel or G1_duration == 1:
if cancel or (G1_duration == 1 and i != last_cca_frame_i):
eligible = False
return eligible
else:
Expand Down Expand Up @@ -9124,6 +9128,7 @@ def blinkPairingItem(self):
def getStatus_RelID_BeforeEmergence(self, budID, curr_mothID):
posData = self.data[self.pos_i]
# Get status of the current mother before it had budID assigned to it
cca_status_before_bud_emerg = None
for i in range(posData.frame_i-1, -1, -1):
# Get cca_df for ith frame from allData_li
cca_df_i = self.get_cca_df(frame_i=i, return_df=True)
Expand All @@ -9132,12 +9137,13 @@ def getStatus_RelID_BeforeEmergence(self, budID, curr_mothID):
if not is_bud_existing:
# Bud was not emerged yet
if curr_mothID in cca_df_i.index:
return cca_df_i.loc[curr_mothID]
cca_status_before_bud_emerg = cca_df_i.loc[curr_mothID]
return cca_status_before_bud_emerg
else:
# The bud emerged together with the mother because
# they appeared together from outside of the fov
# and they were trated as new IDs bud in S0
return pd.Series({
cca_status_before_bud_emerg = pd.Series({
'cell_cycle_stage': 'S',
'generation_num': 0,
'relative_ID': -1,
Expand All @@ -9148,6 +9154,15 @@ def getStatus_RelID_BeforeEmergence(self, budID, curr_mothID):
'corrected_assignment': False,
'will_divide': 0
})
return cca_status_before_bud_emerg

# Mother did not have a status before bud emergence because it was
# already paired with bud at first frame --> reinit to default
cca_status_before_bud_emerg = (
core.getBaseCca_df([curr_mothID]).loc[curr_mothID]
)
return cca_status_before_bud_emerg


def assignBudMoth(self):
"""
Expand Down Expand Up @@ -9241,21 +9256,12 @@ def assignBudMoth(self):
posData.cca_df.at[new_mothID, 'cell_cycle_stage'] = 'S'
posData.cca_df.at[new_mothID, 'relationship'] = 'mother'


if curr_mothID in posData.cca_df.index:
# Cells with UNKNOWN history has relative's ID = -1
# which is not an existing cell
posData.cca_df.loc[curr_mothID] = curr_moth_cca

bud_obj_idx = posData.IDs.index(budID)
new_moth_obj_idx = posData.IDs.index(new_mothID)
if curr_mothID in posData.cca_df.index:
curr_moth_obj_idx = posData.IDs.index(curr_mothID)
rp_budID = posData.rp[bud_obj_idx]
rp_new_mothID = posData.rp[new_moth_obj_idx]

if curr_mothID in posData.cca_df.index:
rp_curr_mothID = posData.rp[curr_moth_obj_idx]

self.updateAllImages()

self.checkMultiBudMoth(draw=True)
Expand Down Expand Up @@ -16586,7 +16592,7 @@ def remove_future_cca_df(self, from_frame_i):
# No cell cycle info present
continue

df.drop(self.cca_df_colnames, axis=1, inplace=True)
df = df.drop(columns=self.cca_df_colnames)
posData.allData_li[i]['acdc_df'] = df

def get_cca_df(self, frame_i=None, return_df=False):
Expand Down

0 comments on commit 146b1e5

Please sign in to comment.