Skip to content
Snippets Groups Projects
Commit 0aa40c0e authored by Mark Winter's avatar Mark Winter
Browse files

Locked add mitosis code which tries to minimally change tree structure on...

Locked add mitosis code which tries to minimally change tree structure on adding a mitosis to a locked tree.
parent f99b71af
Branches
Tags
No related merge requests found
...@@ -26,30 +26,13 @@ if(~isempty(Tracks.GetTimeOfDeath(trackID)) && Tracks.GetTimeOfDeath(trackID)<=t ...@@ -26,30 +26,13 @@ if(~isempty(Tracks.GetTimeOfDeath(trackID)) && Tracks.GetTimeOfDeath(trackID)<=t
return return
end end
bOverrideLock = 0;
bLocked = Helper.CheckTreeLocked([trackID siblingTrack]);
if ( any(bLocked) )
lockedList = [];
if ( bLocked(1) )
lockedList = CellFamilies(CellTracks(trackID).familyID).rootTrackID;
end
if ( bLocked(2) )
lockedList = [lockedList CellFamilies(CellTracks(siblingTrack).familyID).rootTrackID];
end
resp = questdlg(['This edit will affect locked tree(s) ' num2str(lockedList) '. Do you wish to continue?'], 'Warning: Locked Tree', 'Continue', 'Cancel', 'Cancel');
if ( strcmpi(resp,'Cancel') )
return;
end
bOverrideLock = 1;
end
leftChildTrack = []; leftChildTrack = [];
% if both tracks are starting on this frame see who the parent should be % if both tracks are starting on this frame see who the parent should be
% and then merge the track with the parent % and then merge the track with the parent
if(CellTracks(trackID).startTime==time) if(CellTracks(trackID).startTime==time)
valid = 0; bValid = false;
while(~valid) while(~bValid)
answer = inputdlg({'Enter parent of these daughter cells '},'Parent',1,{''}); answer = inputdlg({'Enter parent of these daughter cells '},'Parent',1,{''});
if(isempty(answer)),return,end if(isempty(answer)),return,end
parentTrack = str2double(answer(1)); parentTrack = str2double(answer(1));
...@@ -58,20 +41,11 @@ if(CellTracks(trackID).startTime==time) ...@@ -58,20 +41,11 @@ if(CellTracks(trackID).startTime==time)
(~isempty(Tracks.GetTimeOfDeath(parentTrack)) && Tracks.GetTimeOfDeath(parentTrack)<=time)) (~isempty(Tracks.GetTimeOfDeath(parentTrack)) && Tracks.GetTimeOfDeath(parentTrack)<=time))
choice = questdlg([num2str(parentTrack) ' is an invalid parent for these cells, please choose another'],... choice = questdlg([num2str(parentTrack) ' is an invalid parent for these cells, please choose another'],...
'Not a valid parent','Enter a different parent','Cancel','Cancel'); 'Not a valid parent','Enter a different parent','Cancel','Cancel');
switch choice if ( strcmpi(choice,'Cancel') )
case 'Cancel'
return return
end end
elseif ( ~bOverrideLock && Helper.CheckTreeLocked(parentTrack) )
rootTrack = CellFamilies(CellTracks(parentTrack).familyID).rootTrackID;
resp = questdlg(['This edit will affect locked tree(s) ' num2str(rootTrack) '. Do you wish to continue?'], 'Warning: Locked Tree', 'Continue', 'Cancel', 'Cancel');
if ( strcmpi(resp,'Cancel') )
return;
end
valid = 1;
else else
valid = 1; bValid = true;
end end
end end
...@@ -79,7 +53,36 @@ if(CellTracks(trackID).startTime==time) ...@@ -79,7 +53,36 @@ if(CellTracks(trackID).startTime==time)
trackID = parentTrack; trackID = parentTrack;
end end
bOverrideLock = false;
[bParentLock bChildrenLock bCanAdd] = Families.CheckLockedAddMitosis(trackID, leftChildTrack, siblingTrack, time);
bAffectsLocked = [bParentLock bChildrenLock];
if ( ~bCanAdd )
lockedTracks = [trackID siblingTrack leftChildTrack];
lockedTracks = lockedTracks(bAffectsLocked);
lockedList = unique([CellTracks(lockedTracks).rootTrackID]);
resp = questdlg(['This edit may add or remove multiple unintended mitosis events from the locked tree(s): ' num2str(lockedList) '. Do you wish to continue?'], 'Warning: Breaking Locked Tree', 'Continue', 'Cancel', 'Cancel');
if ( strcmpi(resp,'Cancel') )
return;
end
bOverrideLock = true;
end
% if ( ~bOverrideLock && any([bParentLock bChildrenLock]) )
% resp = questdlg(['This edit will affect locked tree: ' num2str(lockedList) '. Do you wish to continue?'], 'Warning: Editing Locked Tree', 'Continue', 'Cancel', 'Cancel');
% if ( strcmpi(resp,'Cancel') )
% return;
% end
% end
if ( ~bOverrideLock && any(bAffectsLocked) )
bErr = Editor.ReplayableEditAction(@Editor.LockedAddMitosisAction, trackID,leftChildTrack,siblingTrack,time);
else
bErr = Editor.ReplayableEditAction(@Editor.AddMitosisAction, trackID,leftChildTrack,siblingTrack,time); bErr = Editor.ReplayableEditAction(@Editor.AddMitosisAction, trackID,leftChildTrack,siblingTrack,time);
end
if ( bErr ) if ( bErr )
return; return;
end end
......
% historyAction = LockedAddMitosisAction(parentTrack, leftChild, siblingTrack, time)
% Edit Action:
%
% Add siblingTrack as a mitosis event from parentTrack at time. If
% leftChild is non-empty also change its label to the parent track before
% adding the mitosis. Try to minimize locked tree structure changes
function historyAction = LockedAddMitosisAction(parentTrack, leftChildTrack, siblingTrack, time)
global CellTracks
[bParentLock bChildrenLock bCanAdd] = Families.CheckLockedAddMitosis(parentTrack, leftChildTrack, siblingTrack, time);
if ( ~bCanAdd )
error(['Cannot perform a locked add mitosis on ' num2str(parentTrack) '<- ' num2str([leftChildTrack siblingTrack])]);
end
if ( isempty(leftChildTrack) )
if ( bChildrenLock )
% Do a full subtree add if sibling is locked and mitosis is at root of tree
siblingStart = CellTracks(siblingTrack).startTime;
if ( (siblingStart == time) && isempty(CellTracks(siblingTrack).parentTrack) )
Families.AddMitosis(siblingTrack, parentTrack);
historyAction = 'Push';
return;
end
end
else
Tracks.LockedChangeLabel(leftChildTrack, parentTrack, time);
end
% Pull the sibling hull we want out of track
[siblingTrack droppedTracks] = removeSingleHull(siblingTrack, time);
if ( bChildrenLock(1) && ~isempty(droppedTracks) )
error('Locked add mitosis has dropped structure on locked sibling tree');
end
Tracker.GraphEditAddMitosis(parentTrack, siblingTrack, time);
droppedTracks = Families.AddMitosis(siblingTrack, parentTrack);
historyAction = 'Push';
end
function [newTrack droppedTracks] = removeSingleHull(trackID, time)
global CellTracks CellFamilies
droppedTracks = [];
newTrack = trackID;
if ( CellTracks(trackID).startTime == time )
% Leave trackID the same and drop the rest of the track
oldDropped = Families.RemoveFromTreePrune(trackID, time+1);
else
trackHull = Helper.GetNearestTrackHull(trackID, time, 0);
if ( trackHull == 0 )
error('Sibling track must have hull on specified frame');
end
droppedTracks = Tracks.RemoveHullFromTrack(trackHull);
newFam = Families.NewCellFamily(trackHull);
newTrack = CellFamilies(newFam).rootTrackID;
end
end
% [bLocked bCanAdd] = CheckLockedAddMitosis(parentTrack, leftChildTrack, siblingTrack, time)
%
% This function will check to verify if a "tree-preserving" add mitosis is
% possible.
function [bLockedParent bLockedChildren bCanAdd] = CheckLockedAddMitosis(parentTrack, leftChildTrack, siblingTrack, time)
global CellTracks
bCanAdd = false;
bLockedParent = Helper.CheckTreeLocked(parentTrack);
checkChildren = [siblingTrack leftChildTrack];
bLockedChildren = Helper.CheckTreeLocked(checkChildren);
if ( bLockedParent )
% Add mitosis would cause at least a subtree on locked tree to be removed
if ( ~isempty(CellTracks(parentTrack).childrenTracks) )
% Parent is locked and would change mitosis edges
if ( CellTracks(parentTrack).endTime == time-1 )
return;
end
% Parent locked and would replace children
if ( (length(checkChildren) == 2) )
return;
end
end
end
if ( any(bLockedChildren) )
bNonrootTracks = arrayfun(@(x)(~isempty(x.parentTrack)), CellTracks(checkChildren));
lockedStarts = [CellTracks(checkChildren(bLockedChildren & bNonrootTracks)).startTime];
lockedEnds = [CellTracks(checkChildren(bLockedChildren)).endTime];
if ( any(lockedStarts == time) || any(lockedEnds == time) )
return;
end
end
bCanAdd = true;
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment