diff --git a/src/MATLAB/AddHullToTrack.m b/src/MATLAB/AddHullToTrack.m index 1b72f845bc7ae9f898a26880444a18f356e47297..ed6e5a114bc948940bde81871c713272ac7ce8b9 100644 --- a/src/MATLAB/AddHullToTrack.m +++ b/src/MATLAB/AddHullToTrack.m @@ -1,11 +1,11 @@ function AddHullToTrack(hullID,trackID,previousHullID) -% function AddHullToTrack(time,hullID,trackID,previousTime,previousHullID) -%The hullID will be added to the track and hashed at the given time +% function AddHullToTrack(hullID,trackID,previousHullID) +%The hullID will be added to the track % -%If trackID is given, previousTime & previousHullID are not used. Safe to -%send [] or vice versa. +%If trackID is given, previousHullID is not used. Safe to +%send [] for either trackID or previousHullID. %Prereq to leave trackID empty - Track to be added to exists and the -%previousHullID at previousTime exists in that track. Also, it has been +%previousHullID exists in that track. Also, it has been %removed from any previous track assosiation. %--Eric Wait diff --git a/src/MATLAB/AddSingleHullToTrack.m b/src/MATLAB/AddSingleHullToTrack.m new file mode 100644 index 0000000000000000000000000000000000000000..161ddcbc1152d172581a6823ef594af74b2c397a --- /dev/null +++ b/src/MATLAB/AddSingleHullToTrack.m @@ -0,0 +1,102 @@ +function AddSingleHullToTrack(oldTrackID,newTrackID) +% AddSingleHullToTrack(oldTrackID,newTrackID) +% This function is indended for the oldTrack to be just a single hull, +% typicaly when a hull has been split and now that new hull is being added +% to a track. This function takes the hull and merges it into the +% newTrack. The parent and child relationships of the newTrack will be +% maintained. + +%--Eric Wait + +global CellTracks HashedCells CellFamilies Figures + +if(~isempty(CellTracks(oldTrackID).parentTrack) && ... + ~isempty(CellTracks(oldTrackID).childrenTracks) && ... + 1~=length(CellTracks(oldTrackID).hulls)) + error([num2str(oldTrackID) ' is not a single hull track or has a parent/child']); +end + +if(CellTracks(oldTrackID).startTime<CellTracks(newTrackID).startTime) + %old before new + if(~isempty(CellTracks(newTrackID).parentTrack)) + moveMitosisUp(CellTracks(oldTrackID).startTime,... + CellTracks(newTrackID).siblingTrack); + end + AddHullToTrack(CellTracks(oldTrackID).hulls(1),newTrackID,[]); +elseif(CellTracks(oldTrackID).startTime>CellTracks(newTrackID).endTime) + %new before old + if(~isempty(CellTracks(newTrackID).childrenTracks)) + moveMitosisDown(CellTracks(oldTrackID).startTime,newTrackID); + end + AddHullToTrack(CellTracks(oldTrackID).hulls(1),newTrackID,[]); +else + %old within new + if(~isempty(find([HashedCells{Figures.time}.trackID]==newTrackID,1))) + SwapTrackLabels(CellTracks(oldTrackID).startTime,oldTrackID,newTrackID); + else + AddHullToTrack(CellTracks(oldTrackID).hulls(1),newTrackID,[]); + end +end + +%clean out old track/family +familyID = CellTracks(oldTrackID).familyID; +CellFamilies(familyID).rootTrackID = []; +CellFamilies(familyID).tracks = []; +CellFamilies(familyID).startTime = []; +CellFamilies(familyID).endTime = []; +CellTracks(oldTrackID).familyID = []; +CellTracks(oldTrackID).parentTrack = []; +CellTracks(oldTrackID).siblingTrack = []; +CellTracks(oldTrackID).childrenTracks = []; +CellTracks(oldTrackID).hulls = []; +CellTracks(oldTrackID).startTime = []; +CellTracks(oldTrackID).endTime = []; +CellTracks(oldTrackID).timeOfDeath = []; +CellTracks(oldTrackID).color = []; +end + +function moveMitosisUp(time,siblingTrackID) +global CellTracks + +%remove hulls from parent +hash = time - CellTracks(CellTracks(siblingTrackID).parentTrack).startTime + 1; +hulls = CellTracks(CellTracks(siblingTrackID).parentTrack).hulls(hash:end); +CellTracks(CellTracks(siblingTrackID).parentTrack).hulls(hash:end) = 0; +RehashCellTracks(CellTracks(siblingTrackID).parentTrack,CellTracks(CellTracks(siblingTrackID).parentTrack).startTime); + +%add hulls to sibling +for i=1:length(hulls) + AddHullToTrack(hulls(i),siblingTrackID,[]); +end +end + +function moveMitosisDown(time,trackID) +global CellTracks CellFamilies + +remove = 0; +children = {}; + +for i=1:length(CellTracks(trackID).childrenTracks) + if(CellTracks(CellTracks(trackID).childrenTracks(i)).endTime <= time) + remove = 1; + break + end + hash = time - CellTracks(CellTracks(trackID).childrenTracks(i)).startTime + 1; + if(0<hash) + children(i).startTime = CellTracks(CellTracks(trackID).childrenTracks(i)).startTime; + children(i).hulls = CellTracks(CellTracks(trackID).childrenTracks(i)).hulls(1:hash); + end +end + +if(remove) + RemoveChildren(trackID); +else + for i=1:length(children) + familyID = NewCellFamily(children(i).hulls(1),children(i).startTime); + newTrackID = CellFamilies(familyID).rootTrackID; + for j=2:length(children(i).hulls) + AddHullToTrack(children(i).hulls(j),newTrackID,[]); + end + end +end +end diff --git a/src/MATLAB/ChangeLabel.m b/src/MATLAB/ChangeLabel.m index 4d8109b0142dd6dfb93fa368edccd6bcab58ba56..20f00ee6043df61f363ef905da045958c46fe565 100644 --- a/src/MATLAB/ChangeLabel.m +++ b/src/MATLAB/ChangeLabel.m @@ -17,7 +17,7 @@ function ChangeLabel(time,oldTrackID,newTrackID) %--Eric Wait -global CellTracks CellFamilies CellHulls +global CellTracks CellHulls bothHaveChildren = 0;%flag to deal with conflicting children %flags to deal with position of tracks relitive to one another @@ -58,7 +58,7 @@ if(oldEmptied) if(oldBeforeNew) %deal with any children if(~isempty(CellTracks(oldTrackID).childrenTracks)) - dropChildren(oldTrackID); + RemoveChildren(oldTrackID); end if(~isempty(CellTracks(newTrackID).siblingTrack) && ... isempty(find(CellTracks(oldTrackID).childrenTracks==CellTracks(newTrackID).siblingTrack, 1))) @@ -79,7 +79,7 @@ if(oldEmptied) CellTracks(newTrackID).childrenTracks = []; CellTracks(oldTrackID).siblingTrack = []; else - dropChildren(newTrackID); + RemoveChildren(newTrackID); end moveChildren(oldTrackID,newTrackID); elseif(~isempty(CellTracks(newTrackID).childrenTracks)) @@ -90,7 +90,7 @@ if(oldEmptied) CellTracks(newTrackID).childrenTracks = []; CellTracks(oldTrackID).siblingTrack = []; else - dropChildren(newTrackID); + RemoveChildren(newTrackID); end elseif(~isempty(CellTracks(oldTrackID).childrenTracks)) moveChildren(oldTrackID,newTrackID); @@ -103,8 +103,10 @@ if(oldEmptied) %clean up other fields RemoveTrackFromFamily(oldTrackID); + CellTracks(oldTrackID).familyID = []; CellTracks(oldTrackID).parentTrack = []; CellTracks(oldTrackID).siblingTrack = []; + CellTracks(oldTrackID).hulls = []; CellTracks(oldTrackID).startTime = []; CellTracks(oldTrackID).endTime = []; CellTracks(oldTrackID).color = []; @@ -114,41 +116,31 @@ else %the old track still exists in some fasion %the last hull from the old track has been moved over and had %children if(CellHulls(lastOldHull).time<CellTracks(newTrackID).endTime) - dropChildren(oldTrackID); + RemoveChildren(oldTrackID); elseif(CellHulls(lastOldHull).time>=CellTracks(newTrackID).endTime) if(~isempty(CellTracks(newTrackID).childrenTracks)) - dropChildren(newTrackID); + RemoveChildren(newTrackID); end moveChildren(oldTrackID,newTrackID); end elseif(isempty(find(CellTracks(oldTrackID).hulls==lastOldHull, 1)) &&... CellHulls(lastOldHull).time>CellTracks(newTrackID).endTime &&... ~isempty(CellTracks(newTrackID).childrenTracks)) - dropChildren(newTrackID); + RemoveChildren(newTrackID); end end end -function dropChildren(trackID) -%remove children from tree -global CellTracks - -familyIDs = []; -while ~isempty(CellTracks(trackID).childrenTracks) - familyIDs = [familyIDs RemoveFromTree(CellTracks(CellTracks(trackID).childrenTracks(1)).startTime,CellTracks(trackID).childrenTracks(1),'no')]; -end - -CellTracks(trackID).childrenTracks = []; -%run processNewborns on them -ProcessNewborns(familyIDs); -end - function moveChildren(oldTrackID,newTrackID) global CellTracks if(isempty(CellTracks(oldTrackID).childrenTracks)) %no children elseif(isempty(CellTracks(newTrackID).childrenTracks)) CellTracks(newTrackID).childrenTracks = CellTracks(oldTrackID).childrenTracks; + for i=1:length(CellTracks(newTrackID).childrenTracks) + CellTracks(CellTracks(newTrackID).childrenTracks(i)).parentTrack = newTrackID; + end + if(CellTracks(oldTrackID).familyID ~= CellTracks(newTrackID).familyID) for i=1:length(CellTracks(oldTrackID).childrenTracks) ChangeTrackAndChildrensFamily(CellTracks(oldTrackID).familyID,CellTracks(newTrackID).familyID,CellTracks(oldTrackID).childrenTracks(i)); diff --git a/src/MATLAB/ChangeTrackAndChildrensFamily.m b/src/MATLAB/ChangeTrackAndChildrensFamily.m index 043a07ee89ab7983ee599b696ace05101dacd50d..c988e5f4aaa569e5be6cd6cf4195e551dc8f1747 100644 --- a/src/MATLAB/ChangeTrackAndChildrensFamily.m +++ b/src/MATLAB/ChangeTrackAndChildrensFamily.m @@ -33,6 +33,7 @@ function trackList = traverseTree(newFamilyID,trackID) %will add the tracks to the new family along the way global CellFamilies CellTracks +RemoveTrackFromFamily(trackID); %add track CellFamilies(newFamilyID).tracks(end+1) = trackID; @@ -50,6 +51,4 @@ if(~isempty(CellTracks(trackID).childrenTracks)) trackList = [trackList traverseTree(newFamilyID, CellTracks(trackID).childrenTracks(i))]; end end - -RemoveTrackFromFamily(trackID); end diff --git a/src/MATLAB/ChangeTrackParent.m b/src/MATLAB/ChangeTrackParent.m index fcc5aef54a441e864fc33d52e692112c7a8caf72..11623dda9b857252f40b8812bace48e5abdf946d 100644 --- a/src/MATLAB/ChangeTrackParent.m +++ b/src/MATLAB/ChangeTrackParent.m @@ -45,7 +45,7 @@ CellTracks(childTrackID).parentTrack = parentTrackID; oldFamilyID = CellTracks(childTrackID).familyID; newFamilyID = CellTracks(siblingTrackID).familyID; -CellTracks(childTrackID).familyID = newFamilyID; +% CellTracks(childTrackID).familyID = newFamilyID; ChangeTrackAndChildrensFamily(oldFamilyID,newFamilyID,childTrackID); diff --git a/src/MATLAB/ContextChangeLabel.m b/src/MATLAB/ContextChangeLabel.m index 8af1d7d45dcb0531292e6039aaa22297a2906951..bf4e3f479133034a4b552520517d5471e37afe81 100644 --- a/src/MATLAB/ContextChangeLabel.m +++ b/src/MATLAB/ContextChangeLabel.m @@ -50,6 +50,11 @@ elseif(~isempty(find([HashedCells{time}.trackID]==newTrackID,1))) case 'Cancel' return 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'); + LogAction('Added hull to track',hullID,newTrackID); else ChangeLabel(time,trackID,newTrackID); History('Push'); diff --git a/src/MATLAB/ConvertTrackingData.m b/src/MATLAB/ConvertTrackingData.m index 6ec6b58e3f8161ce8c4b46853be7257f4603511d..f4890427f47646fb2b711282172640216b125d2b 100644 --- a/src/MATLAB/ConvertTrackingData.m +++ b/src/MATLAB/ConvertTrackingData.m @@ -36,48 +36,48 @@ end %loop through the data for i=2:length(objHulls) - if(i<=length(CellHulls)+1 || ~isempty(CellHulls(i).time)) - addHull(i); - end -% CellHulls(i).time = objHulls(i).t; -% CellHulls(i).points = objHulls(i).pts; -% CellHulls(i).centerOfMass = objHulls(i).COM; -% CellHulls(i).indexPixels = objHulls(i).indPixels; -% CellHulls(i).deleted = 0; -% -% if objHulls(i).inID == 0 -% NewCellFamily(i,objHulls(i).t); -% else -% AddHullToTrack(i,[],objHulls(i).inID); +% if(i<=length(CellHulls)+1 || ~isempty(CellHulls(i).time)) +% addHull(i); % end + CellHulls(i).time = objHulls(i).t; + CellHulls(i).points = objHulls(i).pts; + CellHulls(i).centerOfMass = objHulls(i).COM; + CellHulls(i).indexPixels = objHulls(i).indPixels; + CellHulls(i).deleted = 0; + + if objHulls(i).inID == 0 + NewCellFamily(i,objHulls(i).t); + else + AddHullToTrack(i,[],objHulls(i).inID); + end end %create the family trees ProcessNewborns(1:length(CellFamilies)); +end - function addHull(num) - CellHulls(num).time = objHulls(num).t; - CellHulls(num).points = objHulls(num).pts; - CellHulls(num).centerOfMass = objHulls(num).COM; - CellHulls(num).indexPixels = objHulls(num).indPixels; - CellHulls(num).deleted = 0; - - if objHulls(num).inID > length(CellHulls)+1 - if objHulls(objHulls(num).inID).inID == 0 - NewCellFamily(num,objHulls(objHulls(num).inID).t); - else - addHull(objHulls(num).inID); - end - end - - if objHulls(num).inID == 0 - NewCellFamily(num,objHulls(num).t); - else - AddHullToTrack(num,[],objHulls(num).inID); - end - - if objHulls(num).outID > length(CellHulls)+1 - addHull(objHulls(num).outID); - end +function addHull(num) +CellHulls(num).time = objHulls(num).t; +CellHulls(num).points = objHulls(num).pts; +CellHulls(num).centerOfMass = objHulls(num).COM; +CellHulls(num).indexPixels = objHulls(num).indPixels; +CellHulls(num).deleted = 0; + +if(objHulls(num).inID > length(CellHulls)+1) + if(objHulls(objHulls(num).inID).inID == 0) + NewCellFamily(num,objHulls(objHulls(num).inID).t); + else + addHull(objHulls(num).inID); end end + +if(objHulls(num).inID == 0) + NewCellFamily(num,objHulls(num).t); +else + AddHullToTrack(num,[],objHulls(num).inID); +end + +if(objHulls(num).outID > length(CellHulls)+1) + addHull(objHulls(num).outID); +end +end diff --git a/src/MATLAB/CreateContextMenuCells.m b/src/MATLAB/CreateContextMenuCells.m index 2be7ab2dabf4bfeb38c3cd94d937a1dc39c236b5..18f532b42b3e3ded87c4edf820d54a9990580cf8 100644 --- a/src/MATLAB/CreateContextMenuCells.m +++ b/src/MATLAB/CreateContextMenuCells.m @@ -145,7 +145,11 @@ end oldParent = CellTracks(siblingTrack).parentTrack; -ChangeTrackParent(trackID,time,siblingTrack); +if(CellTracks(trackID).startTime==time) + ChangeTrackParent(siblingTrack,time,trackID); +else + ChangeTrackParent(trackID,time,siblingTrack); +end History('Push'); LogAction(['Changed parent of ' num2str(siblingTrack)],oldParent,trackID); diff --git a/src/MATLAB/DrawTree.m b/src/MATLAB/DrawTree.m index a05b13cb4d320bf6002025c8152268c9c160f859..9afd693de35fa164300d2bb552b28683d12af661 100644 --- a/src/MATLAB/DrawTree.m +++ b/src/MATLAB/DrawTree.m @@ -5,7 +5,7 @@ function DrawTree(familyID) global CellFamilies HashedCells Figures -if(isempty(CellFamilies(familyID).tracks) || (isvarname('Figures.tree.familyID') && familyID==Figures.tree.familyID)),return,end +if(isempty(CellFamilies(familyID).tracks)),return,end %let the user know that this might take a while set(Figures.tree.handle,'Pointer','watch'); diff --git a/src/MATLAB/InitializeFigures.m b/src/MATLAB/InitializeFigures.m index 6fbebddfc2e04edcd0e785743023f1f058fa7f56..99b7f554bd08ef55a65b99928187f20e1405352b 100644 --- a/src/MATLAB/InitializeFigures.m +++ b/src/MATLAB/InitializeFigures.m @@ -137,8 +137,10 @@ if(Figures.cells.currentHullID == -1) end trackID = [HashedCells{Figures.time}(:).hullID]==Figures.cells.currentHullID; trackID = HashedCells{Figures.time}(trackID).trackID; -DrawTree(CellTracks(trackID).familyID); -DrawCells(); +if(CellTracks(trackID).familyID~=Figures.tree.familyID) + DrawTree(CellTracks(trackID).familyID); + DrawCells(); +end set(Figures.cells.handle,'WindowButtonUpFcn',''); end diff --git a/src/MATLAB/LogAction.m b/src/MATLAB/LogAction.m index fda88eddadf2dbeb4630af5e994d855664f1adc5..6f87193d3a9e665e97f99657cb227d43f64d146a 100644 --- a/src/MATLAB/LogAction.m +++ b/src/MATLAB/LogAction.m @@ -40,4 +40,5 @@ file = fopen([settings.matFilePath CONSTANTS.datasetName '_log.csv'],'a'); fprintf(file,row); fclose(file); +% TestDataIntegrity(0) end diff --git a/src/MATLAB/OpenData.m b/src/MATLAB/OpenData.m index 6506455d56a214e8a82266b0295dc3fd8c8fec14..f266c322f6528e0ef761db78c7b580d94626425f 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.1\n***DO NOT DISTRIBUTE***\n\n'); + fprintf('LEVer ver 3.4\n***DO NOT DISTRIBUTE***\n\n'); end if(exist('ColorScheme.mat','file')) diff --git a/src/MATLAB/RemoveChildren.m b/src/MATLAB/RemoveChildren.m new file mode 100644 index 0000000000000000000000000000000000000000..43e6be64c13fe2bbdf710a2e18aed48cbad74ab2 --- /dev/null +++ b/src/MATLAB/RemoveChildren.m @@ -0,0 +1,18 @@ +function RemoveChildren(trackID) +% RemoveChildren(trackID) removes the children of the given track and moves +% them to thier own trees. Those new trees are attempted to be added to +% other trees. eg ProcessNewborns + +%--Eric Wait + +global CellTracks + +familyIDs = []; +while ~isempty(CellTracks(trackID).childrenTracks) + familyIDs = [familyIDs RemoveFromTree(CellTracks(CellTracks(trackID).childrenTracks(1)).startTime,CellTracks(trackID).childrenTracks(1),'no')]; +end + +CellTracks(trackID).childrenTracks = []; +%run processNewborns on them +ProcessNewborns(familyIDs); +end diff --git a/src/MATLAB/SplitHull.m b/src/MATLAB/SplitHull.m index 7e8bebccf1edadbe6e8d0946fe410804928445e4..b2586ef4a2bb8ddc00fe54a243fe0679ab232ca5 100644 --- a/src/MATLAB/SplitHull.m +++ b/src/MATLAB/SplitHull.m @@ -4,7 +4,7 @@ function newTrackIDs = SplitHull(hullID, k) %--Mark Winter -global CellHulls +global CellHulls CellFamilies newHulls = ResegmentHull(CellHulls(hullID), k); @@ -15,11 +15,11 @@ end % Just arbitrarily assign clone's hull for now CellHulls(hullID) = newHulls(1); -newTrackIDs = [length(CellHulls)+1 length(CellHulls)+length(newHulls)]; % Other hulls are just added off the clone +newFamilyIDs = []; for i=2:length(newHulls) - CellHulls(end+i-1) = newHulls(i); - NewCellFamily(length(CellHulls), newHulls(i).time); + CellHulls(end+1) = newHulls(i); + newFamilyIDs = [newFamilyIDs NewCellFamily(length(CellHulls), newHulls(i).time)]; end - +newTrackIDs = [CellFamilies(newFamilyIDs).rootTrackID]; end diff --git a/src/MATLAB/SplitTrack.m b/src/MATLAB/SplitTrack.m index 944b5691da57134760b1ae5e8492b6a36a4e25bc..095d2ea4b083465220c3a4b52932aea060ef6cee 100644 --- a/src/MATLAB/SplitTrack.m +++ b/src/MATLAB/SplitTrack.m @@ -38,7 +38,7 @@ CellTracks(newTrackID).color = CellTracks(trackID).color; %attach the parents children to the newTrack CellTracks(newTrackID).childrenTracks = CellTracks(trackID).childrenTracks; for i=1:length(CellTracks(newTrackID).childrenTracks) - CellTracks(CellTracks(newTrackID).childrenTracks(i)).parent = newTrackID; + CellTracks(CellTracks(newTrackID).childrenTracks(i)).parentTrack = newTrackID; end CellTracks(trackID).childrenTracks = newTrackID; diff --git a/src/MATLAB/SwapTrackLabels.m b/src/MATLAB/SwapTrackLabels.m index 74a1c42682a071f68bba6905928f4a17d7bfc7b3..a626f3fdbfb5972b966990b2d16e567bb568eb1c 100644 --- a/src/MATLAB/SwapTrackLabels.m +++ b/src/MATLAB/SwapTrackLabels.m @@ -15,9 +15,15 @@ track2Hulls = CellTracks(trackID2).hulls(track2Hash:end); %clear out the hulls copied CellTracks(trackID1).hulls(track1Hash:end) = []; -CellTracks(trackID2).hulls(track1Hash:end) = []; +CellTracks(trackID2).hulls(track2Hash:end) = []; %copy the hulls to the other track +if(CellTracks(trackID1).startTime + length(CellTracks(trackID1).hulls) - 1 ~= time) + error(''); +end +if(CellTracks(trackID2).startTime + length(CellTracks(trackID2).hulls) - 1 ~= time) + error(''); +end CellTracks(trackID1).hulls = [CellTracks(trackID1).hulls track2Hulls]; CellTracks(trackID2).hulls = [CellTracks(trackID2).hulls track1Hulls]; @@ -54,7 +60,7 @@ end %check to see if the children have moved to a new family if(CellTracks(trackID1).familyID ~= CellTracks(trackID2).familyID) for i=1:length(CellTracks(trackID1).childrenTracks) - ChangeTrackAndChildrensFamily(CellTracks(trackID2).familyID,CellTracks(trackID1).familyID,CellTracks(trackID1).childrenTracks(1)); + ChangeTrackAndChildrensFamily(CellTracks(trackID2).familyID,CellTracks(trackID1).familyID,CellTracks(trackID1).childrenTracks(i)); end for i=1:length(CellTracks(trackID2).childrenTracks) ChangeTrackAndChildrensFamily(CellTracks(trackID1).familyID,CellTracks(trackID2).familyID,CellTracks(trackID2).childrenTracks(i)); diff --git a/src/MATLAB/TestDataIntegrity.m b/src/MATLAB/TestDataIntegrity.m new file mode 100644 index 0000000000000000000000000000000000000000..4d5d189d87737d0ab1f1cd8f2b5be4f3156a096c --- /dev/null +++ b/src/MATLAB/TestDataIntegrity.m @@ -0,0 +1,126 @@ +function TestDataIntegrity(correct) +%TestDataIntegrity(correct) tests to make sure that the database is consistant. +%Takes the CellTracks as the most accurate. If correct=='yes', this +%function will attempt to correct the error using the data from CellTracks +%***USE SPARINGLY, TAKES A LOT OF TIME*** + +%--Eric Wait + +global CellTracks CellHulls CellFamilies HashedCells + +hullsList = []; +fprintf('Checking CellTracks'); +for i=1:length(CellTracks) + fprintf(', %d',i); + %% Check child/parent/sibling relationships + if(~isempty(CellTracks(i).parentTrack)) + if(isempty(find(CellTracks(CellTracks(i).parentTrack).childrenTracks==i, 1))) + error(['Parent ' num2str(CellTracks(i).parentTrack) ' does not recognize track ' num2str(i) ' as a child']); + end + if(CellTracks(CellTracks(i).siblingTrack).siblingTrack~=i) + error(['Track ' num2str(CellTracks(i).siblingTrack) ' does not recognize track ' num2str(i) ' as a sibling']); + end + end + currentFamily = CellTracks(i).familyID; + if(~isempty(CellTracks(i).childrenTracks)) + for j=1:length(CellTracks(i).childrenTracks) + if(CellTracks(CellTracks(i).childrenTracks(j)).parentTrack~=i) + error(['Child ' num2str(CellTracks(i).childrenTracks(j)) ' does not recognize track ' num2str(i) ' as a parent']); + end + if(CellTracks(CellTracks(i).childrenTracks(j)).familyID~=currentFamily) + error(['Track ' num2str(i) ' and child ' num2str(CellTracks(i).childrenTracks(j)) ' do not agree on family ' num2str(currentFamily)]); + end + end + end + + %% check if the current track is in the correct family and not in any + %other + if(~isempty(currentFamily)) + index = find(CellFamilies(currentFamily).tracks==i); + if(isempty(index)) + if(correct) + CellFamilies(currentFamily).tracks(end+1) = i; + fprintf('Track %d added to family %d\n',i,currentFamily); + else + error(['Track ' num2str(i) ' not in family ' num2str(currentFamily)]) + end + elseif(1<length(index)) + if(correct) + for j=2:length(index) + CellFamilies(currentFamily).tracks(index(j)) = 0; + end + CellFamilies(currentFamily).tracks = find(CellFamilies(currentFamily).tracks); + fprintf('Removed additional(s) track %d from family %d\n',i,currentFamily); + else + error(['Too many of track ' num2str(i) ' in family ' num2str(currentFamily)]); + end + end + + %check for parent familyIDs + if(~isempty(CellTracks(i).parentTrack)) + if(CellTracks(CellTracks(i).parentTrack).familyID~=currentFamily) + error(['Track ' num2str(i) ' and its parent ' num2str(CellTracks(i).parentTrack) ' do not agree on a family ' num2str(currentFamily)]); + end + end + + for j=1:length(CellFamilies) +% fprintf('CellFamilies %d ',j); + if(currentFamily==j),continue,end + index = find(CellFamilies(j).tracks==i); + if(~isempty(index)) + if(correct) + CellFamilies(j).tracks(index) = []; + fprintf('Removed track %d from family %d\n',i,j); + else + error(['Track ' num2str(i) ' is in family ' num2str(j) ' as well']); + end + end + end + end + + %% check hulls for a given track + for j=1:length(CellTracks(i).hulls) +% fprintf('Hulls %d ',j); + if(~CellTracks(i).hulls(j)),continue,end + if(any(ismember(hullsList,CellTracks(i).hulls(j)))) + tracks = []; + for q=1:i + if(~isempty(CellTracks(q).hulls) && ~isempty(find(CellTracks(q).hulls==CellTracks(i).hulls(j), 1))) + tracks = [tracks q]; + end + end + error(['Hull ' num2str(CellTracks(i).hulls(j)) ' is in track ' num2str(i) ' as well as other tracks']); + end + hullsList = [hullsList CellTracks(i).hulls(j)]; + time = j + CellTracks(i).startTime - 1; + if(time ~= CellHulls(CellTracks(i).hulls(j)).time) + error(['Hull ' num2str(CellTracks(i).hulls(j)) ' is not hashed correctly in track ' num2str(i)]); + end + index = find([HashedCells{time}.hullID]==CellTracks(i).hulls(j)); + if(isempty(index)) + error(['Hull ' num2str(CellTracks(i).hulls(j)) ' is not found in HashedCells at ' num2str(time)]); + elseif(1<length(index)) + error(['Hull ' num2str(CellTracks(i).hulls(j)) ' is in HashedCells more than once at ' num2str(time)]); + end + if(HashedCells{time}(index).trackID~=i) + error(['Hull ' num2str(CellTracks(i).hulls(j)) ' does not have the correct track ' num2str(i)]); + end + end + +end +fprintf('\n'); + +%% check CellHulls +% if(length(hullsList)~=length(find([CellHulls.deleted]==0))) +missingHulls = find(ismember(find([CellHulls.deleted]==0),hullsList')==0); +if(~isempty(missingHulls)) + if(correct) + for i=1:length(missingHulls) + if(isempty(CellHulls(missingHulls(i)).points)) + CellHulls(missingHulls(i)).deleted = 1; + end + end + end + error('HullsList ~= CellHulls'); +end +end