We'll be taking GitLab down for maintenance around 22 in the evening on the 15th of September, so this Sunday. Let us know (tt.mpi-cbg.de) if you experience any issues with it after the maintenance period.

Commit c56a5902 authored by gonciarz's avatar gonciarz

Added new function to read ParticleTracker 2D/3D output

parent 78f9c8b5
......@@ -81,7 +81,7 @@ while 1
lineCnt = 0;
else % if we are still in the same block
% decode line
a = sscanf(line,fmt);
a = sscanf(line,fmt,ncol);
% append line content
lineCnt = lineCnt + 1;
block(lineCnt,1:ncol) = a(1:ncol)';
......
% loadDataFromParticleTrackerPlugin Loads trajectory data from file
% generated by ParticleTracker 2D/3D plugin (part of MosaicSuite)
%
% syntax: [tracksData, operationSucceeded] = loadDataFromParticleTracker('inputFileName', numOfColumns, minTrajectoryLength, maxTrajectoryLength)
%
% inputs: inputFileName name of the text file to be read
% numOfColumns number of columns to be read from file (if file has less columns - nothing will be read)
% NOTICE: output has two first columns
% removed (line number and trajectory
% number) to be compatibile with the other
% data reader from toolbox.
% Default: 5
% minTrajectoryLength minimum length of a trajectory (shorter one, will be skipped)
% Default: 20
% maxTrajectoryLength maximum trajectory length (longer will be shortened to this value)
% Default: 5000
%
% output: tracksData data in the format described below.
% operationSucceeded true if everything went OK
%
% loads the trajectory x,y-data in file 'filename' and returns a list
% of arrays data{} where:
%
% data{i} - is the i-th trajectory of the dat set.
% data{i}(:,1) frame number
% data{i}(:,2) x position
% data{i}(:,3) y position
% data{i}{:,4) z position
% data{i}(:,5) is the 0 order intensity moment
% data{i}(:,6) is the 1 order intensity moment
% data{i}(:,7) is the 2 order intensity moment
% data{i}(:,8) is the 3 order intensity moment
% data{i}(:,9) is the 4 order intensity moment
% data{i}(:,10) the non-particle discrimination score.
%
% Krzysztof Gonciarz, June 15, 2016
function [tracksData, operationSucceeded] = loadDataFromParticleTrackerPlugin(inputFileName, numOfColumns, minTrajectoryLength, maxTrajectoryLength)
% initialize output stuff
tracksData = cell(0);
operationSucceeded = true;
% check parameters and set some default values
if nargin < 1
disp('ERROR: wrong number of input arguments. See "help loadDataFromParticleTracker" !');
operationSucceeded = false;
return;
end;
if nargin < 2
numOfColumns = 5;
end
if nargin < 3
minTrajectoryLength = 20;
end
if nargin < 4
maxTrajectoryLength = 5000;
end
% Check input parameters
if numOfColumns < 5,
disp('loadDataFromParticleTrackerPlugin: numOfColumns must be at least 5. Reset to 5.')
numOfColumns = 5;
end;
fprintf('Parameters: numOfColumns=%d, minTrajectoryLength=%d, maxTrajectoryLength=%d\n', numOfColumns, minTrajectoryLength, maxTrajectoryLength);
% open file
infile = fopen(inputFileName, 'rt');
if infile == -1
fprintf('Cannot open data file [%s]\n', inputFileName);
operationSucceeded = false;
return;
end;
% provide a massive cell array to avoid dynamic creation
maxNumTracksInFile = 100;
tracksData = cell(1, maxNumTracksInFile);
block = zeros(maxTrajectoryLength, numOfColumns);
lineCounter = 0;
trajectoryNum = 0;
currentTrajNum = -1;
while true
line = fgetl(infile);
if ~isHeaderLine(line)
a = sscanf(line, '%f', numOfColumns);
if size(a, 1) == numOfColumns
if (currentTrajNum ~= -1) && (a(2) ~= currentTrajNum)
% if trajectory number changed, save data to output
% structure and reset line counter
updateOutputData();
end
currentTrajNum = a(2);
if lineCounter < maxTrajectoryLength
lineCounter = lineCounter + 1;
block(lineCounter, 1:numOfColumns) = a(1:numOfColumns)';
end
end
end;
% if end of file is reached, store last data and exit loop
if feof(infile),
updateOutputData()
break;
end;
end;
% close file
fclose(infile);
if (trajectoryNum > 0)
tracksData = tracksData(1:trajectoryNum);
else
tracksData = cell(0);
end
fprintf('%d trajectories read from file [%s]\n', length(tracksData), inputFileName);
return;
% sets data in output structure
function updateOutputData()
if (lineCounter > minTrajectoryLength)
trajectoryNum = trajectoryNum + 1;
% store valid data for that track, skip first two columns (line index
% and trajectory number)
tracksData{trajectoryNum} = block(1:lineCounter,3:numOfColumns);
end
lineCounter = 0;
end
function isHeader = isHeaderLine(line)
% Check if we can find one column name from header
if isempty(strfind(line, 'Trajectory'))
isHeader = 0;
else
isHeader = 1;
end
end
end
......@@ -8,6 +8,10 @@
% the trajectory files
% datapathname name of the path where the trajectory files are
% located
% readerType 'legacy' - uses loadData function
% 'plugin' - uses
% loadDataFromParticleTrackerPlugin function
% (check them for specific format information)
% minlen minimum length of trajectories to read.
% varargin{1} optional argument to specify the number of
% columns to be read from the trajectory files.
......@@ -37,7 +41,13 @@
%
% last change: September 13, 2006
function Tracks = loadTracks(inputfilename,datapathname,minlen,varargin)
function Tracks = loadTracks(inputfilename, datapathname, readerType, minlen,varargin)
if ~ischar(readerType) || ~strcmp(readerType, 'legacy') && ~strcmp(readerType, 'plugin')
fprintf('readerType should be one of two: ''legacy'' or ''plugin''\n');
error('Wrong reader type');
end
% check for optinonal arguments
if(length(varargin) == 1)
......@@ -57,6 +67,7 @@ numfiles = 0;
while 1
tempstring = fgetl(fid);
if ~ischar(tempstring) , break, end
if isempty(tempstring), break, end
numfiles = numfiles + 1;
datafilenames{numfiles} = tempstring;
end
......@@ -71,16 +82,23 @@ for i = 1:numfiles
disp(['trying to open',' ',filename]);
% load data from one file
tempData = loadData(filename,columns,minlen,maxTrackLength);
if strcmp(readerType, 'plugin')
[tempData, status] = loadDataFromParticleTrackerPlugin(filename,columns,minlen,maxTrackLength);
if ~status
error('Problem with reading tracks')
end
else
tempData = loadData(filename,columns,minlen,maxTrackLength);
end
% loop over all trajectories in the current file
for j = 1:length(tempData)
% construct struct for each trajectory and store it in Tracks{}
trackData = tempData{j};
trackData = tempData{j};
newTrack = struct( ...
'filename',filename,'trackNo',j,'x',trackData(:,2), ...
'y',trackData(:,3),'frameNos',trackData(:,1),'labels',[], ...
'unnamedData',trackData(:,4:columns),'validity','isValid');
'unnamedData',trackData(:,4:end),'validity','isValid');
trackCnt = trackCnt + 1;
Tracks{trackCnt} = newTrack;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment