diff --git a/install_SiBoRG.m b/install_SiBoRG.m index 1ab8c92..97c6071 100755 --- a/install_SiBoRG.m +++ b/install_SiBoRG.m @@ -1,180 +1,183 @@ function install_SiBoRG(recompile) % INSTALL_SIBORG adds the package to the work path, creates the required directories, % handles the dependencies and compiles the necessary MEX libraries. % % INSTALL_SIBORG('UNINSTALL') removes this package from the work path. % % INSTALL_SIBORG(RECOMPILE) if RECOMPILE is TRUE, recompiles all MEX files. % % Blanchoud group, University of Fribourg % Simon Blanchoud % 04.11.2019 % By default, do not recompile everything if (nargin == 0) recompile = false; % In that particular case, delete the directories elseif (strcmp(recompile, 'uninstall')) cell_folder = which('install_SiBoRG'); if (~isempty(cell_folder)) [current_dir, junk, junk] = fileparts(cell_folder); folders = strsplit(path(), ':'); % Remove the used directories from the work path for i=1:length(folders) if (strncmp(folders{i}, current_dir, length(current_dir))) rmpath(folders{i}); end end savepath; % Remove the added java libraries if any fname = tilde_expand('~/.octaverc'); fnew = tilde_expand('~/octave.rc'); % We open the file and a new new fid = fopen(fname, 'rt'); if fid >= 0 fnw = fopen(fnew, 'wt'); if fnw >= 0 javastring = ['javaaddpath(''' current_dir]; % And we copy everything that isn't in our directory line = fgetl(fid); while ischar(line) if (~strncmp(line, javastring, length(javastring))) fwrite(fnw, line); end line = fgetl(fid); end fclose(fnw); movefile(fnew, fname); end fclose(fid); end % Move to the root of SiBoRG [root_dir, junk, junk] = fileparts(current_dir); cd(root_dir); % Actually delete this package if required btn = questdlg ("Do you want to delete SiBoRG completely (cannot be undone)?", "DELETE FILES??", "Yes", "No", "No"); if (strcmp (btn, "Yes")) disp('(not really) DELETED') % rmdir(current_dir, 's'); end end return; end % Start by moving inside the containing folder cell_folder = which('install_SiBoRG'); [current_dir, junk, junk] = fileparts(cell_folder); [root_dir, junk, junk] = fileparts(current_dir); cd(current_dir); % Add the proper directories to the work path subdirs = ls(); folders = strsplit(path(), ':'); for i=1:size(subdirs, 1) dir_name = strtrim(subdirs(i,:)); if (isdir(dir_name)) if (dir_name(1) ~= '.' && dir_name(1) ~= '_') full_path = fullfile(current_dir, dir_name); if (~any(strncmp(folders, full_path, length(full_path)))) addpath(full_path); end end end end addpath(current_dir); savepath; % Added the required java libraries if any to octaverc fname = tilde_expand('~/.octaverc'); % We open the file to add our files fid = fopen(fname, 'at'); if fid >= 0 % And we copy everything that is a jar in our libraries libraries = dir(fullfile('libraries', '*.jar')); fdisp(fid, ' '); % We both run the command and store it for the next boot for i=1:length(libraries) library = fullfile(pwd, 'libraries', libraries(i).name); fdisp(fid, ['javaaddpath(''' library ''');']); javaaddpath(library); end fclose(fid); end % Install the required packages if isempty(pkg('list', 'image')) pkg install -forge image end if isempty(pkg('list', 'io')) pkg install -forge io end if isempty(pkg('list', 'statistics')) pkg install -forge statistics end if isempty(pkg('list', 'control')) pkg install -forge control end if isempty(pkg('list', 'signal')) pkg install -forge signal end if isempty(pkg('list', 'tisean')) pkg install -forge tisean end + if isempty(pkg('list', 'matgeom')) + pkg install -forge matgeom + end % Try to compile the necessary MEX files cd('MEX'); files = ls('*_mex.c*'); troubles = false; for i=1:size(files, 1) fname = strtrim(files(i,:)); [junk, no_ext, ext] = fileparts(fname); if (recompile || exist(no_ext) ~= 3) failure = mex(fname); if (failure == 1) troubles = true; wtharning('SiBoRG:MEX', {'Could not compile the required MEX function!' ME.message}); end end end cd(root_dir); % These folders are required as well if (~exist('TmpData', 'dir')) mkdir('TmpData'); end if (~exist('export', 'dir')) mkdir('export'); end % Confirm to the user that everything went fine if (troubles) disp('Installation (almost) successful...'); else disp('Installation successful !'); end % Gnu GPL notice fprintf(1, ['\nSimon''s Botrylloides Regeneration Group plateform, Copyright (C) 2019 Simon Blanchoud\n', ... 'This program comes with ABSOLUTELY NO WARRANTY;\n', ... 'This is free software, and you are welcome to redistribute it\n', ... 'under certain conditions; read licence.txt for details.\n\n']); return; end diff --git a/process_results/parse_regenerating_fragments.m b/process_results/parse_regenerating_fragments.m index 8cb94f4..ce6c809 100644 --- a/process_results/parse_regenerating_fragments.m +++ b/process_results/parse_regenerating_fragments.m @@ -1,638 +1,648 @@ % PARSE_REGENERATING_FRAGMENT studies the properties of the vascular tissue during regeneration % % Blanchoud Group, UNIFR % Simon Blanchoud % 06/12/2021 function parse_regenerating_fragments % load the required packages pkg load matgeom pkg load image % Absolute path to the directory containing the segmentation files fdir = '/home/guest/data/Nathalie/Quantifications/*.roi'; files = glob(fdir); nfiles = length(files); % Structures to store the data all_tunic = cell(nfiles, 2, 1); all_ampullae = cell(nfiles, 2, 4); all_vessels = cell(nfiles, 2, 2); all_evals = cell(nfiles, 2, 4); all_quants = cell(nfiles, 2, 4); % Display? plot_segmentations = true; % Loop through all files for i=1:nfiles % Extract the parts of the filename [dir, name, ext] = fileparts (files{i}); filename = fullfile(dir, name); + % Inform the user on the progress + disp(['Processing: ' name]); + % The actual files imfile = [filename '.tif']; ijfile = [filename '.zip']; umfile = [filename '.txt']; tgfile = [filename '.roi']; % Extract the segmentations ROIs = ReadImageJROI(ijfile); [props, data] = analyze_ROI(ROIs, 'Slice', 'Area', 'Length', 'Centroid'); % Setup the various thresholds scale = csvread(umfile); tdist = (450/scale); rdist = ( 50/scale); pdist = ( 30/scale); vdist = ( 10/scale); % Measure the size of the dataset nframes = max(props(:,1)); ntracks = length(data); % Prepare some temporary variables start = props(:,1) 1); tri = tri(~tiny,:); edges = [tri(:,[1 2]); tri(:,[1 3]); tri(:,[2 3])]; [edges] = unique(edges, 'rows'); bads = ismember(edges, props(tiny,2:3), 'rows'); edges = edges(~bads,:); dist = bsxfun(@minus, pts(:,1), pts(:,1).').^2 + bsxfun(@minus, pts(:,2), pts(:,2).').^2; ind = sub2ind(size(dist), edges(:,1), edges(:,2)); edist = dist(ind); edges = edges(edist <= thresh2,:); periph = outer_edges(pts, edges, thresh); nneigh = histc(edges(:),[1:size(pts,1)]); return end % Identify the periphery of a network function periph = outer_edges(pts, edges) npts = size(pts, 1); sets = zeros(npts, 1); nsets = 0; dist = sqrt((pts(edges(:,1),1) - pts(edges(:,2),1)).^2 + (pts(edges(:,1),2) - pts(edges(:,2),2)).^2); periph = []; for i=1:npts first = find(sets==0, 1); if (isempty(first)) break; end nsets = nsets + 1; sets(first) = nsets; curr_set = first; for j=1:npts conx = ismember(edges, curr_set); conx = edges(any(conx, 2), :); new_set = unique(conx(:)); sets(new_set) = nsets; if numel(curr_set) == numel(new_set) break else curr_set = new_set; end end end pindx = [1:npts].'; for i=1:nsets curr = (sets==i); tmp = pts(curr,:); if (size(tmp,1)<=3) full = pindx(curr); else pcurr = pindx(curr); convs = pcurr(convhull(tmp(:,1), tmp(:,2))); full = []; for j=1:length(convs)-1 if ~any(all(edges==convs(j) | edges==convs(j+1), 2)) [d, p] = distancePointEdge(tmp, [pts(convs(j),:) pts(convs(j+1),:)]); d(d==0) = NaN; [v,dindx] = min(d); midpt = pcurr(dindx); p1 = grShortestPath(pts, edges, convs(j), midpt, dist); p2 = grShortestPath(pts, edges, midpt, convs(j+1), dist); full = [full; p1(1:end-1); p2(1:end-1)]; else full = [full; convs(j)]; end end end periph = [periph; pts(full([1:end 1]),:); NaN(1,2);]; end return end % Fuse close points function merged = merge_points(pts, thresh) merged = pts; if (size(pts, 1) < 2) return; end thresh = thresh*thresh; dist = bsxfun(@minus, pts(:,1), pts(:,1).').^2 + bsxfun(@minus, pts(:,2), pts(:,2).').^2; groups = {}; npts = size(pts,1); candidates = [1:npts]; for i=1:npts if isempty(candidates) break; end ncands = size(candidates, 1); cluster = false(ncands,1); cluster(1) = true; num = 1; for j=1:ncands d = dist(candidates(cluster), candidates); cluster = any(d