Skip to content
Snippets Groups Projects
Commit e5f87633 authored by Eric Wait's avatar Eric Wait
Browse files

LEVer 3.4

parent a12cf511
Branches
Tags v3.4
No related merge requests found
Showing
with 334 additions and 79 deletions
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
......
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
......@@ -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));
......
......@@ -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
......@@ -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);
......
......@@ -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');
......
......@@ -36,24 +36,25 @@ 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;
......@@ -62,22 +63,21 @@ ProcessNewborns(1:length(CellFamilies));
CellHulls(num).indexPixels = objHulls(num).indPixels;
CellHulls(num).deleted = 0;
if objHulls(num).inID > length(CellHulls)+1
if objHulls(objHulls(num).inID).inID == 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
if(objHulls(num).inID == 0)
NewCellFamily(num,objHulls(num).t);
else
AddHullToTrack(num,[],objHulls(num).inID);
end
if objHulls(num).outID > length(CellHulls)+1
if(objHulls(num).outID > length(CellHulls)+1)
addHull(objHulls(num).outID);
end
end
end
......@@ -145,7 +145,11 @@ end
oldParent = CellTracks(siblingTrack).parentTrack;
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);
......
......@@ -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');
......
......@@ -137,8 +137,10 @@ if(Figures.cells.currentHullID == -1)
end
trackID = [HashedCells{Figures.time}(:).hullID]==Figures.cells.currentHullID;
trackID = HashedCells{Figures.time}(trackID).trackID;
if(CellTracks(trackID).familyID~=Figures.tree.familyID)
DrawTree(CellTracks(trackID).familyID);
DrawCells();
end
set(Figures.cells.handle,'WindowButtonUpFcn','');
end
......
......@@ -40,4 +40,5 @@ file = fopen([settings.matFilePath CONSTANTS.datasetName '_log.csv'],'a');
fprintf(file,row);
fclose(file);
% TestDataIntegrity(0)
end
......@@ -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'))
......
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
......@@ -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
......@@ -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;
......
......@@ -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));
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment