Skip to content

Instantly share code, notes, and snippets.

@ncweiler
Last active December 31, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncweiler/7953445 to your computer and use it in GitHub Desktop.
Save ncweiler/7953445 to your computer and use it in GitHub Desktop.
%% get multi-channel hdf5 file
% settings
clear_all = 1;
if clear_all
clear all
end
% download hdf5 file to current directory
download_hdf5 = 1;
% for available projects
% view http://openconnecto.me/ocp/ocpca/public_tokens/
% token for desired project
project_token = 'Ex10R55';
% for project-specific channel list and dimensions
% view http://openconnecto.me/ocp/ca/[project_token]/info/
% channels to download:
chan_list = {'Synapsin1-2','PSD95-1','GFP-4','DAPI-1'};
% load contents of hdf5 file into workspace as variable 'data'
hdf5_getvar = 1;
% show single z-section of each channel in 'data'
hdf5_show = 1;
% resolution: (0 - full-scale, 1 - half-scale, 2 - quarter scale)
res = '0';
% data ranges to display: (must be within dataset dimensions @ res)
xbounds = '400,900';
ybounds = '400,900';
zbounds = '15,20';
% output filename
hdf5_file = 'Ex10R55_C-Syn1-M-PSD-G-GFP-B-DAPI_100-400_100-400_15-20.hdf5';
% load data from hdf5 file?
hdf5_getfile = 1;
% show slices (separately) from each downloaded channel
hdf5_show = 1;
show_slices = [3,5];
%%
if download_hdf5
% url arguments
server_base = 'openconnecto.me';
webservice_name = 'ocp/ca';
chan_str = strjoin(chan_list,',');
restful_str = strjoin({res,xbounds,ybounds,zbounds},'/');
% compose url from arguments above:
hdf5_url = sprintf('http://%s/%s/%s/hdf5/%s/%s/',...
server_base, webservice_name, project_token, chan_str,restful_str)
% download cutout
urlwrite(hdf5_url,hdf5_file);
end
%% extract hdf5 file contents to variable 'data' (if file exists)
if hdf5_getvar && exist(hdf5_file,'file')
for i=1:numel(chan_list)
chan_name = chan_list{i};
%chan_base = chan_name(1:strfind(chan_name,'-')-1);
chan_base = regexprep(chan_name,'-','_');
data.(chan_base) = hdf5read ( hdf5_file, chan_name);
end
end
%% show each channel in data variable (if it exists)
if hdf5_show && exist('data','var')
channels = fields(data);
for chan_num = 1:numel(channels)
for slice = show_slices
chan_token = channels{chan_num};
figure
imshow(data.(chan_token)(:,:,slice))
title_str = sprintf('%s %s slice %d',...
project_token, regexprep(chan_token,'_','-'), slice);
title(title_str)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment