diff --git a/src/MATLAB/ChangeLabel.m b/src/MATLAB/ChangeLabel.m index c5b4a3329baf97c5ecb847a387ed5d42abb9670b..3fa5c434e312dcc12072cb36ea8742b99178293f 100644 --- a/src/MATLAB/ChangeLabel.m +++ b/src/MATLAB/ChangeLabel.m @@ -130,6 +130,18 @@ else %the old track still exists in some fasion RemoveChildren(newTrackID); end end + +%check to see if either of the tracks are dead +familyIDs = []; +if(~isempty(CellTracks(oldTrackID).timeOfDeath)) + familyIDs = StraightenTrack(oldTrackID); +end +if(~isempty(CellTracks(newTrackID).timeOfDeath)) + familyIDs = [familyIDs StraightenTrack(newTrackID)]; +end +if(~isempty(familyIDs)) + ProcessNewborns(familyIDs); +end end function moveChildren(oldTrackID,newTrackID) diff --git a/src/MATLAB/ChangeTrackAndChildrensFamily.m b/src/MATLAB/ChangeTrackAndChildrensFamily.m index c988e5f4aaa569e5be6cd6cf4195e551dc8f1747..f1a7436dc12ba3322d0bbecc7670d9eb38ccaaea 100644 --- a/src/MATLAB/ChangeTrackAndChildrensFamily.m +++ b/src/MATLAB/ChangeTrackAndChildrensFamily.m @@ -21,7 +21,7 @@ if(isempty(CellFamilies(oldFamilyID).tracks)) CellFamilies(oldFamilyID).rootTrackID = []; CellFamilies(oldFamilyID).startTime = []; CellFamilies(oldFamilyID).endTime = []; -else +else %update times CellFamilies(oldFamilyID).startTime = min([CellTracks(CellFamilies(oldFamilyID).tracks).startTime]); CellFamilies(oldFamilyID).endTime = max([CellTracks(CellFamilies(oldFamilyID).tracks).endTime]); diff --git a/src/MATLAB/ChangeTrackParent.m b/src/MATLAB/ChangeTrackParent.m index 11623dda9b857252f40b8812bace48e5abdf946d..0685e1a3186781ded8ab35df49c24e374ded0371 100644 --- a/src/MATLAB/ChangeTrackParent.m +++ b/src/MATLAB/ChangeTrackParent.m @@ -28,26 +28,27 @@ else return end +oldFamilyID = CellTracks(childTrackID).familyID; +newFamilyID = CellTracks(siblingTrackID).familyID; + childIndex = length(CellTracks(parentTrackID).childrenTracks) + 1; CellTracks(parentTrackID).childrenTracks(childIndex) = childTrackID; %clean up old parent if(~isempty(CellTracks(childTrackID).siblingTrack)) CellTracks(CellTracks(childTrackID).siblingTrack).siblingTrack = []; - ChangeLabel(CellTracks(CellTracks(childTrackID).siblingTrack).startTime,... - CellTracks(childTrackID).siblingTrack,CellTracks(childTrackID).parentTrack); - index = CellTracks(CellTracks(childTrackID).parentTrack).childrenTracks == childTrackID; - CellTracks(CellTracks(childTrackID).parentTrack).childrenTracks(index) = []; + CombineTrackWithParent(CellTracks(childTrackID).siblingTrack); +% ChangeLabel(CellTracks(CellTracks(childTrackID).siblingTrack).startTime,... +% CellTracks(childTrackID).siblingTrack,CellTracks(childTrackID).parentTrack); +% index = CellTracks(CellTracks(childTrackID).parentTrack).childrenTracks == childTrackID; +% CellTracks(CellTracks(childTrackID).parentTrack).childrenTracks(index) = []; end CellTracks(childTrackID).parentTrack = parentTrackID; %Detatch childTrack and clean up child's family -oldFamilyID = CellTracks(childTrackID).familyID; -newFamilyID = CellTracks(siblingTrackID).familyID; - -% CellTracks(childTrackID).familyID = newFamilyID; - -ChangeTrackAndChildrensFamily(oldFamilyID,newFamilyID,childTrackID); +if(oldFamilyID~=newFamilyID) + ChangeTrackAndChildrensFamily(oldFamilyID,newFamilyID,childTrackID); +end CellTracks(childTrackID).siblingTrack = siblingTrackID; CellTracks(siblingTrackID).siblingTrack = childTrackID; diff --git a/src/MATLAB/ContextChangeLabel.m b/src/MATLAB/ContextChangeLabel.m index dcec450f790c8713f527b268d6a47bd7b061b7db..42380afded85939b9e5fc8e628ffcd81696cf81f 100644 --- a/src/MATLAB/ContextChangeLabel.m +++ b/src/MATLAB/ContextChangeLabel.m @@ -31,19 +31,38 @@ elseif(newTrackID>length(CellTracks) || isempty(CellTracks(newTrackID).hulls)) switch choice case 'Yes' oldFamily = CellTracks(trackID).familyID; - RemoveFromTree(time,trackID,'yes'); History('Push'); + try + RemoveFromTree(time,trackID,'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(time) ' ' num2str(trackID) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end + LogAction(['Removed ' num2str(trackID) ' From Tree'], oldFamily,CellTracks(trackID).familyID); case 'Cancel' return end elseif(~isempty(find([HashedCells{time}.trackID]==newTrackID,1))) - choice = questdlg(['Label ' num2str(newTrackID) ' exist on this frame. Would you like these labels to swap from here forward or just this frame?'],... - 'Swap Labels?','Forward','This Frame','Cancel','Cancel'); + choice = questdlg(['Label ' num2str(newTrackID) ' exist on this frame. Would you like these labels to swap from here forward or just this frame?'],... + 'Swap Labels?','Forward','This Frame','Cancel','Cancel'); switch choice case 'Forward' - SwapTrackLabels(time,trackID,newTrackID); History('Push'); + try + SwapTrackLabels(time,trackID,newTrackID); + catch errorMessage + try + ErrorHandeling(['SwapTrackLabels(' num2str(time) ' ' num2str(trackID) ' ' num2str(newTrackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Swapped Labels',trackID,newTrackID); case 'This Frame' SwapHulls(time,trackID,newTrackID); @@ -52,20 +71,56 @@ elseif(~isempty(find([HashedCells{time}.trackID]==newTrackID,1))) end elseif(isempty(CellTracks(trackID).parentTrack) && isempty(CellTracks(trackID).childrenTracks) && 1==length(CellTracks(trackID).hulls)) hullID = CellTracks(trackID).hulls(1); - AddSingleHullToTrack(trackID,newTrackID); History('Push'); + try + AddSingleHullToTrack(trackID,newTrackID); + catch errorMessage + try + ErrorHandeling(['AddSingleHullToTrack(' num2str(trackID) ' ' num2str(newTrackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Added hull to track',hullID,newTrackID); elseif(~isempty(CellTracks(trackID).parentTrack) && CellTracks(trackID).parentTrack==newTrackID) - MoveMitosisUp(time,trackID) History('Push'); + try + MoveMitosisUp(time,trackID); + catch errorMessage + try + ErrorHandeling(['MoveMitosisUp(' num2str(time) ' ' num2str(trackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Moved Mitosis Up',trackID,newTrackID); -elseif(~isempty(CellTracks(newTrackID).parentTrack) &&CellTracks(newTrackID).parentTrack==trackID) - MoveMitosisUp(time,newTrackID) +elseif(~isempty(CellTracks(newTrackID).parentTrack) && CellTracks(newTrackID).parentTrack==trackID) History('Push'); + try + MoveMitosisUp(time,newTrackID); + catch errorMessage + try + ErrorHandeling(['MoveMitosisUp(' num2str(time) ' ' num2str(newTrackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Moved Mitosis Up',newTrackID,trackID); else - ChangeLabel(time,trackID,newTrackID); History('Push'); + try + ChangeLabel(time,trackID,newTrackID); + catch errorMessage + try + ErrorHandeling(['ChangeLabel(' num2str(time) ' ' num2str(trackID) ' ' num2str(newTrackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('ChangeLabel',trackID,newTrackID); end diff --git a/src/MATLAB/ContextChangeParent.m b/src/MATLAB/ContextChangeParent.m index 6eaf77b9b08d73067947a1b06fdebdb0a8911855..3648ed93cef73b22f4d2f58aa1387a3008436a2a 100644 --- a/src/MATLAB/ContextChangeParent.m +++ b/src/MATLAB/ContextChangeParent.m @@ -23,9 +23,17 @@ elseif(CellTracks(trackID).endTime < CellTracks(newParentID).startTime) end oldParent = CellTracks(trackID).parentTrack; -ChangeTrackParent(newParentID,time,trackID); - History('Push'); +try + ChangeTrackParent(newParentID,time,trackID); +catch errorMessage + try + ErrorHandeling(['ChangeTrackParent(' num2str(newParentID) ' ' num2str(time) ' ' num2str(trackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end +end LogAction(['Changed parent of ' num2str(trackID)],oldParent,newParentID); DrawTree(CellTracks(newParentID).familyID); diff --git a/src/MATLAB/ContextRemoveFromTree.m b/src/MATLAB/ContextRemoveFromTree.m index fc187c9f0ce5d29a4354405cc813f6743d0fcb84..ce6726cea646da81621b9519c43cf02cc8581e8b 100644 --- a/src/MATLAB/ContextRemoveFromTree.m +++ b/src/MATLAB/ContextRemoveFromTree.m @@ -7,8 +7,16 @@ global CellTracks oldFamilyID = CellTracks(trackID).familyID; -newFamilyID = RemoveFromTree(time, trackID,'yes'); -History('Push'); +try + newFamilyID = RemoveFromTree(time, trackID,'yes'); +catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(time) ' ' num2str(trackID) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end +end LogAction(['Removed part or all of ' num2str(trackID) ' from tree'],oldFamilyID,newFamilyID); DrawTree(oldFamilyID); diff --git a/src/MATLAB/CreateContextMenuCells.m b/src/MATLAB/CreateContextMenuCells.m index 43d7e4649882b5be58eef90e43aff905c5420ba8..1faefc483ce227ef44c1a66eda7f3d4752ad9c19 100644 --- a/src/MATLAB/CreateContextMenuCells.m +++ b/src/MATLAB/CreateContextMenuCells.m @@ -27,9 +27,9 @@ uimenu(Figures.cells.contextMenuHandle,... 'CallBack', @changeLabel,... 'Separator', 'on'); -uimenu(Figures.cells.contextMenuHandle,... - 'Label', 'Change Parent',... - 'CallBack', @changeParent); +% uimenu(Figures.cells.contextMenuHandle,... +% 'Label', 'Change Parent',... +% 'CallBack', @changeParent); addHull = uimenu(Figures.cells.contextMenuHandle,... 'Label', 'Add Hull',... @@ -69,9 +69,9 @@ uimenu(Figures.cells.contextMenuHandle,... 'CallBack', @markDeath,... 'Separator', 'on'); -uimenu(Figures.cells.contextMenuHandle,... - 'Label', 'Remove From Tree',... - 'CallBack', @removeFromTree); +% uimenu(Figures.cells.contextMenuHandle,... +% 'Label', 'Remove From Tree',... +% 'CallBack', @removeFromTree); uimenu(Figures.cells.contextMenuHandle,... 'Label', 'Properties',... @@ -80,17 +80,6 @@ uimenu(Figures.cells.contextMenuHandle,... end %% Callback functions -% function cellSelected(src,evnt) -% %doesn't work, closes context menu -% global Figures -% [hullID trackID] = getClosestCell(); -% -% if(isempty(trackID)) -% set(Figures.cells.contextMenuLabelHandle,'Label','No Cell Selected, Click Closer'); -% else -% set(Figures.cells.contextMenuLabelHandle,'Label',['Cell: ' num2str(trackID)]); -% end -% end function removeMitosis(src,evnt) global CellTracks Figures @@ -106,15 +95,35 @@ choice = questdlg('Which Side to Keep?','Merge With Parent',object.UserData,... switch choice case num2str(object.UserData) remove = CellTracks(object.UserData).siblingTrack; - newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).siblingTrack).startTime,... - CellTracks(object.UserData).siblingTrack,'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).siblingTrack).startTime,... + CellTracks(object.UserData).siblingTrack,'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(CellTracks(CellTracks(object.UserData).siblingTrack).startTime)... + num2str(CellTracks(object.UserData).siblingTrack) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end case num2str(CellTracks(object.UserData).siblingTrack) remove = object.UserData; - newTree = RemoveFromTree(CellTracks(object.UserData).startTime,object.UserData,'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(object.UserData).startTime,object.UserData,'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(CellTracks(' num2str(CellTracks(object.UserData).startTime) ' ' num2str(object.UserData) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end otherwise return end -History('Push'); LogAction(['Removed ' num2str(remove) ' from tree'],Figures.tree.familyID,newTree); DrawTree(Figures.tree.familyID); DrawCells(); @@ -126,13 +135,16 @@ global CellTracks Figures [hullID trackID] = getClosestCell(); if(isempty(trackID)),return,end -answer = inputdlg({'Enter Time of Mitosis',['Enter new sibling of ' num2str(trackID)]},... - 'Add Mitosis',1,{num2str(Figures.time),''}); +% answer = inputdlg({['Enter new sibling of ' num2str(trackID)],'Enter Time of Mitosis'},... +% 'Add Mitosis',1,{'',num2str(Figures.time)}); + +answer = inputdlg({['Enter new sibling of ' num2str(trackID)]},... + 'Add Mitosis',1,{''}); if(isempty(answer)),return,end -time = str2double(answer(1)); -siblingTrack = str2double(answer(2)); +siblingTrack = str2double(answer(1)); +time = Figures.time; if(isempty(CellTracks(siblingTrack).hulls)) msgbox([answer(2) ' is not a valid cell'],'Not a valid cell','error'); @@ -146,12 +158,31 @@ end oldParent = CellTracks(siblingTrack).parentTrack; if(CellTracks(trackID).startTime==time) - ChangeTrackParent(siblingTrack,time,trackID); + History('Push'); + try + ChangeTrackParent(siblingTrack,time,trackID); + catch errorMessage + try + ErrorHandeling(['ChangeTrackParent(' num2str(siblingTrack) ' ' num2str(time) ' ' num2str(trackID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end else - ChangeTrackParent(trackID,time,siblingTrack); + History('Push'); + try + ChangeTrackParent(trackID,time,siblingTrack); + catch errorMessage + try + ErrorHandeling(['ChangeTrackParent(' num2str(trackID) ' ' num2str(time) ' ' num2str(siblingTrack) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end end -History('Push'); LogAction(['Changed parent of ' num2str(siblingTrack)],oldParent,trackID); DrawTree(CellTracks(trackID).familyID); @@ -204,8 +235,18 @@ global Figures CellFamilies [hullID trackID] = getClosestCell(); if(isempty(trackID)),return,end -RemoveHull(hullID); History('Push'); +try + RemoveHull(hullID); +catch errorMessage + try + ErrorHandeling(['RemoveHull(' num2str(hullID) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end +end + LogAction(['Removed hull from track ' num2str(trackID)],hullID,[]); %if the whole family disapears with this change, pick a diffrent family to @@ -237,17 +278,19 @@ CellTracks(trackID).timeOfDeath = Figures.time; %drop children from tree and run ProcessNewborns if(~isempty(CellTracks(trackID).childrenTracks)) - familyIDs = []; - for i=1:length(CellTracks(trackID).childrenTracks) - familyIDs = [familyIDs ... - RemoveFromTree(CellTracks(CellTracks(trackID).childrenTracks(i)).startTime,... - CellTracks(trackID).childrenTracks(i),'yes')]; + History('Push'); + try + ProcessNewborns(StraightenTrack(trackID)); + catch errorMessage + try + ErrorHandeling(['ProcessNewborns(StraightenTrack(' num2str(trackID) ')-- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end end - CellTracks(trackID).childrenTracks = []; - ProcessNewborns(familyIDs); -end +end -History('Push'); LogAction(['Marked time of death for ' num2str(trackID)],[],[]); DrawTree(Figures.tree.familyID); @@ -282,17 +325,33 @@ if ( ~CHullContainsPoint(clickPt(1,1:2), CellHulls(hullID)) ) end if(~isempty(trackID)) - % Try to split the existing hull - newTracks = SplitHull(hullID,num+1);%adding one to the number so that the original hull is accounted for - + % Try to split the existing hull History('Push'); + try + newTracks = SplitHull(hullID,num+1);%adding one to the number so that the original hull is accounted for + catch errorMessage + try + ErrorHandeling(['SplitHull(' num2str(hullID) ' ' num2str(num+1) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Split cell',trackID,[trackID newTracks]); elseif ( num<2 ) % Try to run local segmentation and find a hull we missed or place a % point-hull at least - newTrack = AddNewSegmentHull(clickPt(1,1:2)); - History('Push'); + try + newTrack = AddNewSegmentHull(clickPt(1,1:2)); + catch errorMessage + try + ErrorHandeling(['AddNewSegmentHull(clickPt(1,1:2)) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end LogAction('Added cell',[],newTrack); else return; @@ -302,17 +361,17 @@ DrawTree(Figures.tree.familyID); DrawCells(); end -function [hullID trackID] = getClosestCell(bAllowEmpty) +function [hullID trackID] = getClosestCell(allowEmpty) hullID = FindHull(get(gca,'CurrentPoint')); if(0>=hullID) - if ( bAllowEmpty ) + if (allowEmpty ) hullID = []; else warndlg('Please click closer to the center of the desired cell','Unknown Cell'); end - trackID = []; return end trackID = GetTrackID(hullID); + end diff --git a/src/MATLAB/CreateContextMenuTree.m b/src/MATLAB/CreateContextMenuTree.m index 079861618dd11a0875a8dad4729c8cb58e6a1b12..63019c70106b5a27f564b1529710396f22d0deb2 100644 --- a/src/MATLAB/CreateContextMenuTree.m +++ b/src/MATLAB/CreateContextMenuTree.m @@ -22,13 +22,13 @@ uimenu(Figures.tree.contextMenuHandle,... 'CallBack', @changeLabel,... 'Separator', 'on'); -uimenu(Figures.tree.contextMenuHandle,... - 'Label', 'Change Parent',... - 'CallBack', @changeParent); +% uimenu(Figures.tree.contextMenuHandle,... +% 'Label', 'Change Parent',... +% 'CallBack', @changeParent); -uimenu(Figures.tree.contextMenuHandle,... - 'Label', 'Remove From Tree',... - 'CallBack', @removeFromTree); +% uimenu(Figures.tree.contextMenuHandle,... +% 'Label', 'Remove From Tree',... +% 'CallBack', @removeFromTree); uimenu(Figures.tree.contextMenuHandle,... 'Label', 'Properties',... @@ -61,23 +61,66 @@ end switch choice case num2str(object.UserData) remove = CellTracks(object.UserData).siblingTrack; - newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).siblingTrack).startTime,... - CellTracks(object.UserData).siblingTrack,'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).siblingTrack).startTime,... + CellTracks(object.UserData).siblingTrack,'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(CellTracks(CellTracks(object.UserData).siblingTrack).startTime) ' '... + num2str(CellTracks(object.UserData).siblingTrack) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end case num2str(CellTracks(object.UserData).siblingTrack) remove = object.UserData; - newTree = RemoveFromTree(CellTracks(object.UserData).startTime,object.UserData,'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(object.UserData).startTime,object.UserData,'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(CellTracks(object.UserData).startTime) ' ' num2str(object.UserData) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end case num2str(CellTracks(object.UserData).childrenTracks(1)) remove = CellTracks(object.UserData).childrenTracks(2); - newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).childrenTracks(2)).startTime,... - CellTracks(object.UserData).childrenTracks(2),'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).childrenTracks(2)).startTime,... + CellTracks(object.UserData).childrenTracks(2),'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(CellTracks(CellTracks(object.UserData).childrenTracks(2)).startTime) ' '... + num2str(CellTracks(object.UserData).childrenTracks(2)) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end case num2str(CellTracks(object.UserData).childrenTracks(2)) remove = CellTracks(object.UserData).childrenTracks(1); - newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).childrenTracks(1)).startTime,... - CellTracks(object.UserData).childrenTracks(1),'yes'); + History('Push'); + try + newTree = RemoveFromTree(CellTracks(CellTracks(object.UserData).childrenTracks(1)).startTime,... + CellTracks(object.UserData).childrenTracks(1),'yes'); + catch errorMessage + try + ErrorHandeling(['RemoveFromTree(' num2str(CellTracks(CellTracks(object.UserData).childrenTracks(1)).startTime) ' '... + num2str(CellTracks(object.UserData).childrenTracks(1)) ' yes) -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end + end otherwise return end -History('Push'); + LogAction(['Removed ' num2str(remove) ' from tree'],Figures.tree.familyID,newTree); DrawTree(Figures.tree.familyID); DrawCells(); @@ -108,9 +151,17 @@ end oldParent = CellTracks(siblingTrack).parentTrack; -ChangeTrackParent(trackID,time,siblingTrack); - History('Push'); +try + ChangeTrackParent(trackID,time,siblingTrack); +catch errorMessage + try + ErrorHandeling(['ChangeTrackParent(' num2str(trackID) ' ' num2str(time) ' ' num2str(siblingTrack) ') -- ' errorMessage.message]); + catch errorMessage2 + fprintf(errorMessage2.message); + return + end +end LogAction(['Changed parent of ' num2str(siblingTrack)],oldParent,trackID); DrawTree(CellTracks(trackID).familyID); diff --git a/src/MATLAB/CreateMenuBar.m b/src/MATLAB/CreateMenuBar.m index 3e5af67f05ca8713c02a085ef2f45b4f60ace873..167fe30bbd09c2a945ee4b001e93fb7ec233dc77 100644 --- a/src/MATLAB/CreateMenuBar.m +++ b/src/MATLAB/CreateMenuBar.m @@ -93,6 +93,14 @@ siblingsMenu = uimenu(... 'Checked', 'off',... 'Accelerator', 'b'); +imageMenu = uimenu(... + 'Parent', viewMenu,... + 'Label', 'Show Image',... + 'HandleVisibility', 'callback',... + 'Callback', @toggleImage,... + 'Checked', 'on',... + 'Accelerator', 'i'); + playMenu = uimenu(... 'Parent', viewMenu,... 'Label', 'Play',... @@ -128,6 +136,7 @@ if(strcmp(get(handle,'Tag'),'cells')) Figures.cells.menuHandles.labelsMenu = labelsMenu; Figures.cells.menuHandles.playMenu = playMenu; Figures.cells.menuHandles.siblingsMenu = siblingsMenu; + Figures.cells.menuHandles.imageMenu = imageMenu; else Figures.tree.menuHandles.saveMenu = saveMenu; Figures.tree.menuHandles.undoMenu = undoMenu; @@ -135,6 +144,7 @@ else Figures.tree.menuHandles.labelsMenu = labelsMenu; Figures.tree.menuHandles.playMenu = playMenu; Figures.tree.menuHandles.siblingsMenu = siblingsMenu; + Figures.tree.menuHandles.imageMenu = imageMenu; end end @@ -161,6 +171,7 @@ printdlg; end function undo(src,evnt) +History('Push');%put the current state on the stack then go to the previous History('Pop'); end @@ -194,6 +205,19 @@ else end end +function toggleImage(src,evnt) +global Figures +if(strcmp(get(Figures.cells.menuHandles.imageMenu, 'Checked'), 'on')) + set(Figures.cells.menuHandles.imageMenu, 'Checked', 'off'); + set(Figures.tree.menuHandles.imageMenu, 'Checked', 'off'); + DrawCells(); +else + set(Figures.cells.menuHandles.imageMenu, 'Checked', 'on'); + set(Figures.tree.menuHandles.imageMenu, 'Checked', 'on'); + DrawCells(); +end +end + function timeJump(src,evnt) global Figures HashedCells answer = inputdlg('Enter Frame Number:','Jump to Time...',1,{num2str(Figures.time)}); diff --git a/src/MATLAB/DrawCells.m b/src/MATLAB/DrawCells.m index cf6d15005757822fcb75df6c6ae1368ac1db6d32..ed1401c1f86d065a2e87aaeced6a1b0ecf238725 100644 --- a/src/MATLAB/DrawCells.m +++ b/src/MATLAB/DrawCells.m @@ -14,7 +14,7 @@ if(isempty(CellFamilies(Figures.tree.familyID).tracks)),return,end figure(Figures.cells.handle); set(Figures.cells.timeLabel,'String',['Time: ' num2str(Figures.time)]); %read in image -fileName = [CONSTANTS.rootImageFolder CONSTANTS.datasetName '_t' num2str(Figures.time,'%03d') '.TIF']; +fileName = [CONSTANTS.rootImageFolder CONSTANTS.imageDatasetName '_t' num2str(Figures.time,'%03d') '.TIF']; [img colrMap] = imread(fileName); xl=xlim; yl=ylim; @@ -35,6 +35,11 @@ hold all; siblingsAlreadyDrawn = []; +%draw Image or not +if(strcmp(get(Figures.cells.menuHandles.imageMenu, 'Checked'),'off')) + set(im,'Visible','off'); +end + %draw labels if turned on if(strcmp(get(Figures.cells.menuHandles.labelsMenu, 'Checked'),'on')) for i=1:length(HashedCells{Figures.time}) @@ -150,5 +155,5 @@ plot([CellHulls(hullID).centerOfMass(2) CellHulls(siblingHullID).centerOfMass(2) 'uicontextmenu', Figures.cells.contextMenuHandle,... 'Tag', 'SiblingRelationship'); -set(Figures.cells.removeMenu,'Visible','on'); +% set(Figures.cells.removeMenu,'Visible','on'); end diff --git a/src/MATLAB/ErrorHandeling.m b/src/MATLAB/ErrorHandeling.m new file mode 100644 index 0000000000000000000000000000000000000000..8b665bcad77813aec1278ecd72870ab3c8a9cd2a --- /dev/null +++ b/src/MATLAB/ErrorHandeling.m @@ -0,0 +1,40 @@ +function ErrorHandeling(errorMessage) +%***Possibly Throws Error*** +% ErrorHandeling(errorMessage) will attempt to fix the issue and log the +% error. If unsuccessful, another log entery will be made and will throw +% the new error. + +%--Eric Wait + +global Figures + +History('Pop'); +History('Redo');%this is to get to the state just before the error, it was on the top of the stack + +msgboxHandle = msgbox('Attempting to fix database. Will take some time depending on the size of the database. This window will close when done',... + 'Fixing Database','help','modal'); +LogAction(errorMessage,[],[]); + +%let the user know that this might take a while +set(Figures.tree.handle,'Pointer','watch'); +set(Figures.cells.handle,'Pointer','watch'); + +try + TestDataIntegrity(1); + msgbox('Database corrected. Your last action was undone, please try again. If change errors again, save the data file and then send it and the log to the code distributor.',... + 'Database Correct','help','modal'); +catch errorMessage2 + %let the user know that the drawing is done + set(Figures.tree.handle,'Pointer','arrow'); + set(Figures.cells.handle,'Pointer','arrow'); + LogAction(['Unable to fix database -- ' errorMessage2.message],[],[]); + msgbox('Unable to fix database! Please save the data file and then send it and the log to the code distributor. Your last change did not take place!',... + 'Database ERROR','error'); + rethrow(errorMessage2) +end +close(msgboxHandle); + +%let the user know that the drawing is done +set(Figures.tree.handle,'Pointer','arrow'); +set(Figures.cells.handle,'Pointer','arrow'); +end \ No newline at end of file diff --git a/src/MATLAB/GetTrackID.m b/src/MATLAB/GetTrackID.m index 856b576c98755f2f003c73ec42a1f3abd32aa99a..8da8ff2a52967fd3eba51c05a997a607d27c5924 100644 --- a/src/MATLAB/GetTrackID.m +++ b/src/MATLAB/GetTrackID.m @@ -1,11 +1,18 @@ function trackID = GetTrackID(hullID) -%Given a hull ID a track ID will be returned +%Given a hull ID a track ID will be returned or [] if none found %--Eric Wait global CellHulls HashedCells -hullTime = CellHulls(hullID).time; -hashedCellIndex = [HashedCells{hullTime}.hullID] == hullID; -trackID = HashedCells{hullTime}(hashedCellIndex).trackID; +trackID = []; + +if(hullID>length(CellHulls)) + return +else + hullTime = CellHulls(hullID).time; + hashedCellIndex = [HashedCells{hullTime}.hullID] == hullID; + if(isempty(hashedCellIndex)),return,end + trackID = HashedCells{hullTime}(hashedCellIndex).trackID; +end end diff --git a/src/MATLAB/InitializeFigures.m b/src/MATLAB/InitializeFigures.m index 99b7f554bd08ef55a65b99928187f20e1405352b..64d28f9e90d811eb8b29300623f23d2dcd47573e 100644 --- a/src/MATLAB/InitializeFigures.m +++ b/src/MATLAB/InitializeFigures.m @@ -13,6 +13,9 @@ Figures.time = 1; Figures.cells.handle = figure(); Figures.tree.handle = figure(); +whitebg(Figures.cells.handle,'k'); +whitebg(Figures.tree.handle,'w'); + Figures.advanceTimerHandle = timer(... 'TimerFcn', @play,... 'Period', .1,... diff --git a/src/MATLAB/LEVer.m b/src/MATLAB/LEVer.m index 4752b1f653f68949405739cbacf0aa4842dfd7d4..64cc06cfc088fee13def8d3b9f0f8af219650957 100644 --- a/src/MATLAB/LEVer.m +++ b/src/MATLAB/LEVer.m @@ -14,7 +14,9 @@ end if(OpenData()) InitializeFigures(); History('Init'); -elseif(~isempty(Figures)) +else %if(~isempty(Figures)) History('Pop'); + DrawTree(Figures.tree.familyID); + DrawCells(); end end diff --git a/src/MATLAB/OpenData.m b/src/MATLAB/OpenData.m index f266c322f6528e0ef761db78c7b580d94626425f..7b4f4082cf3ef6071f5b38c2f2e8106514ddceb8 100644 --- a/src/MATLAB/OpenData.m +++ b/src/MATLAB/OpenData.m @@ -7,7 +7,7 @@ function opened = OpenData() global Figures Colors CONSTANTS CellFamilies CellHulls HashedCells Costs CellTracks if(isempty(Figures)) - fprintf('LEVer ver 3.4\n***DO NOT DISTRIBUTE***\n\n'); + fprintf('LEVer ver 3.6\n***DO NOT DISTRIBUTE***\n\n'); end if(exist('ColorScheme.mat','file')) @@ -92,29 +92,29 @@ imageFilter = [settings.imagePath '*' CONSTANTS.datasetName '*.TIF']; while (filterIndexImage==0) fprintf('\nSelect first .TIF image...\n\n'); [imageFile,imagePath,filterIndexImage] = uigetfile(imageFilter,['Open First Image in dataset: ' CONSTANTS.datasetName]); - if (filterIndexImage==0) - return - end + if (filterIndexImage==0),return,end end -opened = 1; - index = strfind(imageFile,'t'); if (~isempty(index) && filterIndexImage~=0) CONSTANTS.rootImageFolder = imagePath; imageDataset = imageFile(1:(index(length(index))-2)); + CONSTANTS.imageDatasetName = imageDataset; fileName=[CONSTANTS.rootImageFolder imageDataset '_t001.TIF']; end while (isempty(index) || ~exist(fileName,'file')) fprintf(['Image file name not in correct format: ' CONSTANTS.datasetName '_t001.TIF\nPlease choose another...\n']); [imageFile,imagePath,filterIndexImage] = uigetfile(settings.imagePath,'Open First Image'); + if(filterIndexImage==0),return,end index = strfind(imageFile,'t'); CONSTANTS.rootImageFolder = [imgPath '\']; imageDataset = imageFile(1:(index(length(index))-2)); fileName=[CONSTANTS.rootImageFolder imageDataSet '_t' num2str(t,'%03d') '.TIF']; end +opened = 1; + %save out settings settings.matFilePath = matPath; settings.imageFile = imageFile; diff --git a/src/MATLAB/ProcessNewborns.m b/src/MATLAB/ProcessNewborns.m index e1eee9cf8549374f5c2fe46d3bc1f0827ac012f7..74c253f737e373eb0de0e86721f338543b69141e 100644 --- a/src/MATLAB/ProcessNewborns.m +++ b/src/MATLAB/ProcessNewborns.m @@ -15,6 +15,7 @@ for i=1:size %Get all the possible hulls that could have been connected childHullID = CellTracks(childTrackID).hulls(1); + if(childHullID>length(Costs)),continue,end parentHullCandidates = find(Costs(:,childHullID)); if(isempty(parentHullCandidates)),continue,end @@ -25,6 +26,7 @@ for i=1:size for j=1:length(parentHullCandidates) %Get the length of time that the parentCandidate exists parentTrackID = GetTrackID(parentHullCandidates(j)); + if(isempty(parentTrackID)),continue,end parentTrackTimeFrame = CellTracks(parentTrackID).endTime - CellTracks(parentTrackID).startTime; %Change the cost of the candidates @@ -49,6 +51,14 @@ for i=1:size %Make the connections parentTrackID = GetTrackID(parentHullID); + if(isempty(parentTrackID)) + try + ErrorHandeling(['GetTrackID(' num2str(parentHullID) ') -- while in ProcessNewborns']); + catch errorMessage2 + fprintf(errorMessage2); + return + end + end connectTime = CellHulls(parentHullID).time; if(CONSTANTS.minParentHistoryTimeFrame < abs(CellTracks(childTrackID).startTime - CellTracks(parentTrackID).startTime)) ChangeTrackParent(parentTrackID,connectTime,childTrackID); diff --git a/src/MATLAB/RemoveHull.m b/src/MATLAB/RemoveHull.m index 78550a63e77e5934694b5654f1530da6018f6f45..b43d109da25bfb82ec22bceca543fcbf9d21607d 100644 --- a/src/MATLAB/RemoveHull.m +++ b/src/MATLAB/RemoveHull.m @@ -9,6 +9,8 @@ global CellTracks HashedCells CellHulls trackID = GetTrackID(hullID); +if(isempty(trackID)),return,end + %remove hull from its track index = find(CellTracks(trackID).hulls==hullID); CellTracks(trackID).hulls(index) = 0; diff --git a/src/MATLAB/StraightenTrack.m b/src/MATLAB/StraightenTrack.m new file mode 100644 index 0000000000000000000000000000000000000000..83f95ce6ca035c08316ae326f5a2057cc0b11cd9 --- /dev/null +++ b/src/MATLAB/StraightenTrack.m @@ -0,0 +1,17 @@ +function familyIDs = StraightenTrack(trackID) +% StraightenTrack(trackID) will drop all right children while traversing +% left. Usefull for cells that should not have mitosis events such as dead +% cells. + +%--Eric Wait + +global CellTracks +familyIDs = []; +if(~isempty(CellTracks(trackID).childrenTracks)) + familyIDs = StraightenTrack(CellTracks(trackID).childrenTracks(1)); + for i=2:length(CellTracks(trackID).childrenTracks) + familyIDs = [familyIDs RemoveFromTree(CellTracks(CellTracks(trackID).childrenTracks(i)).startTime,... + CellTracks(trackID).childrenTracks(i),'yes')]; + end +end +end \ No newline at end of file diff --git a/src/MATLAB/SwapTrackLabels.m b/src/MATLAB/SwapTrackLabels.m index a626f3fdbfb5972b966990b2d16e567bb568eb1c..aca5c799adb1ce4cee6fdf8c4edce3665d277832 100644 --- a/src/MATLAB/SwapTrackLabels.m +++ b/src/MATLAB/SwapTrackLabels.m @@ -66,4 +66,16 @@ if(CellTracks(trackID1).familyID ~= CellTracks(trackID2).familyID) ChangeTrackAndChildrensFamily(CellTracks(trackID1).familyID,CellTracks(trackID2).familyID,CellTracks(trackID2).childrenTracks(i)); end end + +%check to see if either of the tracks are dead +familyIDs = []; +if(~isempty(CellTracks(trackID1).timeOfDeath)) + familyIDs = StraightenTrack(trackID1); +end +if(~isempty(CellTracks(trackID2).timeOfDeath)) + familyIDs = [familyIDs StraightenTrack(trackID2)]; +end +if(~isempty(familyIDs)) + ProcessNewborns(familyIDs); +end end