OSCR

Inhibition of Cxcr4 chemokine receptor signaling improves habituation learning in a zebrafish model of neurofibromatosis.

Code ↔ Paper

4 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 4 matches
  1. [1] § MATERIALS AND METHODS › Immunohistochemistry and confocal imaging ↔ MakeTheMAPMap.m, lines 1–67 · score 0.81 · MakeTheMAPMap, tERK, image stacks, pERK, CMTK, macro
  2. [2] § MATERIALS AND METHODS › Immunohistochemistry and confocal imaging ↔ MakeTheMAPMap.m, lines 1–67 · score 0.67 · tERK, image stacks, pERK, Pairwise, macro, Pixel
  3. [3] § RESULTS › Cxcr4 signaling has limited effects on canonical Ras-Raf-MEK-ERK signaling in the brain ↔ MakeTheMAPMap.m, lines 421–495 · score 0.57 · Mann Whitney, pERK, discovery, bars, stained, FDR
  4. [4] § RESULTS › Cxcr4 signaling has limited effects on canonical Ras-Raf-MEK-ERK signaling in the brain ↔ MakeTheMAPMap.m, lines 68–213 · score 0.57 · tERK, pERK, contraction, indirect, loss, quantified

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 2,413 lines · 76 KB · no license · 4 matches

  1. function MakeTheMAPMap
  2. close all
  3. clear all
  4. ncores = 4;
  5. ERKLabel = '*1_warp*';
  6. pERKLabel = '*3_warp*';
  7. nPermutes = 500;
  8. FDRThresh = 0.00005; %
  9. UsingERK = 1;
  10. % This function will create the MAP-Map whole-brain activity map from
  11. % registered pERK/tERK data by performing differential intensity analysis
  12. % at each voxel.
  13. %
  14. % Morphed pERK data from two groups needs to be in two folders, and we are
  15. % propted for the folders when the program starts. Each parwise comparison
  16. % between all the groups is made. The input images need to be single
  17. % channel 8-bit tiff stacks. Any registered stacks registered to any
  18. % reference brain should work, but to keep consistent with the formatting
  19. % of the Z-Brain and subsequent analysis, images should be registered into
  20. % the reference brain ('Ref20131120pt14pl2.nrrd'), downsampled to
  21. % 300x679x80 (x,y,z), and pre-smoothed with a 2D gaussian filter (sigma =
  22. % 2). I use an Imagej macro script 'PrepareStacksForMAPMapping.ijm' to do
  23. % this, which converts the '.nrrd' files output from CMTK into Tiffs,
  24. % downsample and smooths appropriately.
  25. %
  26. % We look for which files are pERK stains, and which are total ERK stains
  27. % based on the naming, where channel 1 has the string '1_warp' within it,
  28. % while channel 2 is '2_warp', etc. This needs to be set appropriately
  29. % before running the script.
  30. % Pairwise comparisons are made between all of the input folders. the two
  31. % groups analyzed (GroupA and GroupB) are combined and then ranked. A
  32. % Mann-Whitney U statistic Z score is calculated at each pixel. To then set an FDR threshold,
  33. % pseudogroups are assembled by randomization such that they have an equal
  34. % number of fish from GroupA and GroupB, randomly assigned, and a Z score
  35. % is calculated as before. This mixing procedure is repeated 500 times,
  36. % creating a distribution of control Zs at each voxel. From this
  37. % distribution we then set a FDR threshold 0.00005 (0.005% probability of
  38. % finding a value greater than this threshold). This is done assuming a
  39. % normal distribution. The GroupA vs GroupB Z score is then thresholded at
  40. % this value of Z (all pixels with lesser value are set to 0. The image is
  41. % normalized such that 10 = 255 in an 8bit tiff, and the image stacks are
  42. % written. I also set a requirement that there is a minimal pERK staining
  43. % intensity at the pixel to get rid of most non-brain pixels (average
  44. % across all brains must be 5/255), and there also needs to be a mininmum
  45. % of 5 warped fish in each group at the relevant pixel, set based on the
  46. % fact that the only '0' pixels in the stack are those missing after
  47. % warping - ie. not real image values.
  48. % The main file output from this analysis is the
  49. % '*SignificantDeltaMedian.tif' file, which we refer to as the MAP-Map .
  50. % This stack depicts the delta Median value, at each pixel foud to be above
  51. % the FDR threshold.
  52. % Significant pixels are assigned a non-0 value. Green signal indicates
  53. % higher signals in the first Group (for example, GroupX in a
  54. % 'GroupX_over_GroupY' comparison), magneta signals indicate higher signals
  55. % in the second group. These signals are mapped linearly between 0 and
  56. % 65535 in a 16-bit stack, where 65535 represents a delta pERK level of
  57. % 0.5. We also write the thresholded Z-score comparison ('*ZScores.tif'),
  58. % which represents is mapped 0-255 = ZScore 0-10 in an 8bit stack, As a
  59. % control we write the final mixed group analysis from which the FDR
  60. % threshold is calculated in order to give a sense of what false signals
  61. % look like (there should be almost none). Finally we also write stacks
  62. % depicting the median pERK level at each voxel, and the standard deviation
  63. % at each voxel, for each group.
  64. %
  65. %%--------------- Variables that can be tweaked
  66. %
  67. % ncores -- number of cores on your computer (i.e., num workers). over
  68. % which to parallelize parfor loops. Make sure not to set too hight that
  69. % you run out of RAM!
  70. %
  71. %
  72. % ERK and pERK labels -- '*N_warp*' where N = post-warp channel number
  73. %
  74. % nPermutes -- the number of times we make pseudogroup comparisons for the
  75. % FDR calculation
  76. %
  77. % FDRThresh -- The FRD thresholding of the Z-score. A value of 0.00005
  78. % gives very clean control comparisons.
  79. %
  80. % UsingERK -- logical, set to 1 to run the total-ERK based normalization to
  81. % calculate pERK levels (pERK/tERK). If you are not using this normalization (for
  82. % example if you dont have the tERK stain, or want to quantify differences
  83. % in another channel, set to 0).
  84. %
  85. % Written by Owen Randlett ([email hidden])
  86. %
  87. % This function uses two non-standard matlab functions, which I gratefully acknowldege the authors of:
  88. %
  89. % uipickfiles.m by Douglas Schwarz
  90. %
  91. % http://www.mathworks.com/matlabcentral/fileexchange/10867-uipickfiles--uigetfile-on-steroids
  92. % http://www.mathworks.com/matlabcentral/fileexchange/view_license?file_info_id=10867
  93. %
  94. % uipickfiles BSD Licence:
  95. % Copyright (c) 2007, Douglas M. Schwarz
  96. % All rights reserved.
  97. %
  98. % Redistribution and use in source and binary forms, with or without
  99. % modification, are permitted provided that the following conditions are
  100. % met:
  101. %
  102. % * Redistributions of source code must retain the above copyright
  103. % notice, this list of conditions and the following disclaimer.
  104. % * Redistributions in binary form must reproduce the above copyright
  105. % notice, this list of conditions and the following disclaimer in
  106. % the documentation and/or other materials provided with the distribution
  107. %
  108. % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  109. % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  110. % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  111. % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  112. % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  113. % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  114. % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  115. % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  116. % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  117. % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  118. % POSSIBILITY OF SUCH DAMAGE.
  119. %
  120. % parfor_progress.m by Jeremy Scheff
  121. %
  122. % http://www.mathworks.com/matlabcentral/fileexchange/32101-progress-monitor--progress-bar--that-works-with-parfor/content/parfor_progress.m
  123. % http://www.mathworks.com/matlabcentral/fileexchange/view_license?file_info_id=32101
  124. %
  125. % parfor_progress BSD licence
  126. % Copyright (c) 2011, Jeremy Scheff
  127. % All rights reserved.
  128. %
  129. % Redistribution and use in source and binary forms, with or without
  130. % modification, are permitted provided that the following conditions are
  131. % met:
  132. %
  133. % * Redistributions of source code must retain the above copyright
  134. % notice, this list of conditions and the following disclaimer.
  135. % * Redistributions in binary form must reproduce the above copyright
  136. % notice, this list of conditions and the following disclaimer in
  137. % the documentation and/or other materials provided with the distribution
  138. %
  139. % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  140. % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  141. % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  142. % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  143. % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  144. % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  145. % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  146. % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  147. % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  148. % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  149. % POSSIBILITY OF SUCH DAMAGE.
  150. %
  151. %---------------------------------------------
  152. disp(strcat('Running with the following settings: ncores = ', num2str(ncores), ' ERKLabel = ', num2str(ERKLabel), ' pERKLabel = ', num2str(pERKLabel), ' nPermutes = ', num2str(nPermutes), ' FDRThresh = ', num2str(FDRThresh), 'UsingERK = ', num2str(UsingERK)))
  153. prompt = 'Select all the groups';
  154. Groups.dirs = uipickfiles('Prompt', prompt);
  155. NumGroups = length(Groups.dirs);
  156. cd(Groups.dirs{1});
  157. cd('..');
  158. prompt = 'select output directory';
  159. dirOut = cell2mat(uipickfiles('Prompt', prompt));
  160. if length(dirOut) < 1
  161. error('Invalide dirOut')
  162. end
  163. ParObject = parpool(ncores); % open up the parallel workers
  164. for i = 1:NumGroups;
  165. [~, name, ext] = fileparts(Groups.dirs{i}); % automatically get the group nape from the folder name
  166. Groups.names{i} = strcat(name, ext);
  167. disp(['Group ',num2str(i),' was selected as: ', Groups.names{i}]);
  168. end
  169. %setup a progress bar
  170. NumComparisons = NumGroups.*(NumGroups-1)./2;
  171. % now we need to define all the group comparisons
  172. for m = 1:NumGroups
  173. for n = m+1:NumGroups % these loops define all the pariwise comparisons
  174. tic
  175. GrA = Groups.names{m};
  176. dirA = Groups.dirs{m};
  177. GrB = Groups.names{n};
  178. dirB = Groups.dirs{n};
  179. ChurnThroughGroups(GrA, dirA, GrB, dirB, dirOut, UsingERK, ERKLabel, pERKLabel, ncores, nPermutes, FDRThresh) % process each two group comparison
  180. toc
  181. end
  182. end
  183. delete(ParObject); %shut down the paralell pool
  184. clear all
  185. end
  186. function ChurnThroughGroups(GrA, dirA, GrB, dirB, dirOut, UsingERK, ERKLabel, pERKLabel, ncores, nPermutes, FDRThresh)
  187. cd(dirA)
  188. if UsingERK == 1;
  189. fnames = dir(ERKLabel); %Get the file names: this relies on the CMTK program to add a "warp" after the channel numnber to the warped file images
  190. else
  191. fnames = dir('*.tif*');
  192. end
  193. info = imfinfo(fnames(1).name); % get the image paramaters from the info file
  194. height = info(1).Height; % assign the image dimesnsions
  195. width = info(1).Width;
  196. Zs = numel(info);
  197. if info(1).BitsPerSample ~=8
  198. error('Input images not of correct bit depth. Should be 8-bit images') % if not using 8-bit images, the thresholds will be different
  199. end
  200. cd(dirA)
  201. if UsingERK == 1;
  202. if length(dir(ERKLabel)) ~= length(dir(pERKLabel)) % check to make sure that there are the same number of pERK and ERK stacks
  203. warndlg('The number of stacks in group A arent equal');
  204. end
  205. end
  206. if UsingERK == 1;
  207. fnamesERKA = dir(ERKLabel);
  208. fnamespERKA = dir(pERKLabel);
  209. else
  210. fnamespERKA = dir(pERKLabel);
  211. fnamesERKA = [];
  212. end
  213. nGroupA = length(fnamespERKA); % get the number of fish from the number of images found
  214. cd(dirB) % do the same for groupB
  215. if UsingERK == 1;
  216. if length(dir(ERKLabel)) ~= length(dir(pERKLabel)) % check to make sure that there are the same number of pERK and ERK stacks
  217. warndlg('The number of stacks in group B arent equal');
  218. end
  219. end
  220. if UsingERK == 1;
  221. fnamesERKB = dir(ERKLabel);
  222. fnamespERKB = dir(pERKLabel);
  223. else
  224. fnamespERKB = dir(pERKLabel);
  225. fnamesERKB = [];
  226. end
  227. nGroupB = length(fnamespERKB);
  228. % preallocate images
  229. Amedian = zeros(height, width, Zs);
  230. AStd = zeros(height, width, Zs);
  231. Bmedian= zeros(height, width, Zs);
  232. BStd = zeros(height, width, Zs);
  233. mwuZScoresImage = zeros(height, width, Zs);
  234. mwuMixedZScoresImageSingleIteration = zeros(height, width, Zs); % when I finally write the file, I dont want the one that is the mean that has been iterated over many times so I will use this single iteration to write as an example image of the FDR thresholding
  235. %Set up the groups for the mixed group analysis
  236. RandMixedGrA = zeros(floor(nGroupA./2)*2,nPermutes);
  237. RandMixedGrB = zeros(floor(nGroupB./2)*2,nPermutes);
  238. for nperm = 1:nPermutes % pre-assign all of the mixed groups. This is done so that the computation is only done once, and so that we have the same exact mixed group comparisons to write as the control image
  239. RandMixedGrA(:,nperm) = datasample(1:nGroupA, floor(nGroupA./2)*2, 'Replace', false); % pick random indicies for the psuedo group
  240. RandMixedGrB(:,nperm) = datasample(nGroupA+1:nGroupB+nGroupA, floor(nGroupB./2)*2, 'Replace', false);
  241. end
  242. cd(dirOut);
  243. parfor_progress(Zs);
  244. parfor (z = 1:Zs, ncores) % loop through each z plane one at a time to build up the final Z-score image stack
  245. BpERK = zeros(height, width, nGroupB);
  246. ApERK = zeros(height, width, nGroupA);
  247. if UsingERK == 1
  248. BERK = zeros(height, width, nGroupB);
  249. AERK = zeros(height, width, nGroupA);
  250. end
  251. cd(dirA);
  252. for j = 1:nGroupA % we loop through load all images from one group into an image stack
  253. infopERKA = imfinfo(fnamespERKA(j).name);
  254. % now we will calculate the pERK signal over the total signal. This
  255. % will be our matrix.
  256. ApERK(:,:,j) = imread(fnamespERKA(j).name, z, 'Info', infopERKA);
  257. if UsingERK == 1
  258. infoERKA = imfinfo(fnamesERKA(j).name);
  259. AERK(:,:,j) = imread(fnamesERKA(j).name, z, 'Info', infoERKA);
  260. end
  261. end
  262. if UsingERK == 1
  263. A = ApERK./AERK; %calculate pERK signal over total signal
  264. elseif UsingERK == 0
  265. A = ApERK;
  266. end
  267. cd (dirB);
  268. for j = 1:nGroupB % we loop through load all images from one group into an image stack
  269. infopERKB = imfinfo(fnamespERKB(j).name);
  270. % now we will calculate the pERK signal over the total signal. This
  271. % will be our matrix.
  272. BpERK(:,:,j) = imread(fnamespERKB(j).name, z, 'Info', infopERKB);
  273. if UsingERK == 1
  274. infoERKB = imfinfo(fnamesERKB(j).name);
  275. BERK(:,:,j) = imread(fnamesERKB(j).name, z, 'Info', infoERKB);
  276. end
  277. end
  278. if UsingERK == 1
  279. B = BpERK./BERK; %calculate pERK signal over total signal
  280. elseif UsingERK == 0
  281. B = BpERK;
  282. end
  283. Amedian(:,:,z) = nanmedian(A, 3);
  284. Bmedian(:,:,z) = nanmedian(B, 3);
  285. AStd(:,:,z) = nanstd(A, 0, 3);
  286. BStd(:,:,z) = nanstd(B, 0, 3);
  287. meanpERK = mean(cat(3, ApERK, BpERK), 3);
  288. % Now we want to calculate a ranksum like statistic for the groups
  289. % rather than caculating a T-statistic
  290. %
  291. %Combine all into one big matrix to rank.
  292. ABCombined = cat(3,A,B);
  293. %Determine which indices are from which group
  294. FishInGroupA = 1:size(A,3);
  295. FishInGroupB = size(A,3)+1:size(A,3)+size(B,3);
  296. ranks = tiedrank(permute(ABCombined, [3,2,1])); % rank the fish. The permute calls are required because tiedrank only works along the first dimension of a matrix
  297. ranks = permute(ranks, [3,2,1]);
  298. %Fisrt we do a kind of boostrapping we randomly mixed data to find
  299. %the false discovery distribution. By mixing the groups with equal
  300. %numbers of fish from each group, we should destroy any of the
  301. %group by group variablility that we are trying to quantify, and
  302. %thus determine the noise level in our analysis. This is done
  303. %'nPermutes' number of times
  304. ZScoresMixedGrA = zeros(height, width, nPermutes);
  305. ZScoresMixedGrB = zeros(height, width, nPermutes);
  306. for perm = 1:nPermutes
  307. % get the vector for the indiecies of the fish in each mixed group
  308. RandMixedGrAThisPerm = squeeze(RandMixedGrA(:,perm))';
  309. RandMixedGrBThisPerm = squeeze(RandMixedGrB(:,perm))';
  310. FishInMixedGrA = [RandMixedGrAThisPerm(1:end/2),RandMixedGrBThisPerm(1:end/2)];
  311. FishInMixedGrB = [RandMixedGrAThisPerm(end/2+1:end), RandMixedGrBThisPerm(end/2+1:end)];
  312. % sum the ranks from each group
  313. SumRanksMixedGrA = nansum(ranks(:,:,FishInMixedGrA),3);
  314. SumRanksMixedGrB = nansum(ranks(:,:,FishInMixedGrB),3);
  315. % determine the number of fish contributing to each pixel. This is
  316. % not always the same, because if for example part of the forebrain
  317. % was not imaged in one fish, after warping there are 0-pixel
  318. % values at this missing region. These are NaN'd out above, but we
  319. % need to keep track of the Ns for the ranksum and Z-score
  320. % statistics
  321. NsInMixedGrA = length(FishInMixedGrA) - sum(isnan(ranks(:,:,FishInMixedGrA)),3);
  322. NsInMixedGrB = length(FishInMixedGrB) - sum(isnan(ranks(:,:,FishInMixedGrB)),3);
  323. %Calculate the Mann-Whitney U-statistic
  324. %(http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U)
  325. UMixedGrA = SumRanksMixedGrA - (NsInMixedGrA.*(NsInMixedGrA + 1))./2;
  326. UMixedGrB = SumRanksMixedGrB - (NsInMixedGrB.*(NsInMixedGrB + 1))./2;
  327. %Calculate the Z-score. The disribution of Us can be assumed to be
  328. %normal, and from inspection of my data this assumption appears
  329. %valid
  330. %The value of U is the mean between the two groups
  331. MUmixed = (UMixedGrA + UMixedGrB)./2;
  332. SigmaUmixed = sqrt(NsInMixedGrA.*NsInMixedGrB.*(NsInMixedGrA + NsInMixedGrB + 1)./12);
  333. ZScoresMixedGrATemp = (UMixedGrA - MUmixed)./SigmaUmixed;
  334. ZScoresMixedGrBTemp = (UMixedGrB - MUmixed)./SigmaUmixed;
  335. ZScoresMixedGrA(:,:,perm) = ZScoresMixedGrATemp;
  336. ZScoresMixedGrB(:,:,perm) = ZScoresMixedGrBTemp;
  337. end
  338. % now we set the FDR threshold. The distrubition of Zs appears
  339. % normally distributed at each pixel, so I will use norminv to find
  340. % the critical value for Z at each pixel, with an frd rate set
  341. % above (ex 0.00005).
  342. ZScoreThresh = norminv((1-FDRThresh), 0, std(ZScoresMixedGrA, 0, 3));
  343. % now we do the actual comparison between groups. Fist sum the
  344. % ranks;
  345. SumRanksGrA = nansum(ranks(:,:,FishInGroupA),3);
  346. SumRanksGrB = nansum(ranks(:,:,FishInGroupB),3);
  347. %Determine the Ns based on the number of non-NaN values at each
  348. %pixel
  349. NsInGrA = size(A,3) - sum(isnan(ranks(:,:,FishInGroupA)),3);
  350. NsInGrB = size(B,3) - sum(isnan(ranks(:,:,FishInGroupB)),3);
  351. % get the mann-whiteny Us
  352. UGrA = SumRanksGrA - (NsInGrA.*(NsInGrA + 1))./2;
  353. UGrB = SumRanksGrB - (NsInGrB.*(NsInGrB + 1))./2;
  354. %Calculate the Z-score
  355. MU = (UGrA + UGrB)./2;
  356. SigmaU = sqrt(NsInGrA.*NsInGrB.*(NsInGrA + NsInGrB + 1)./12);
  357. ZScoresGrA = (UGrA - MU)./SigmaU;
  358. %throw away any pixel where the mean pERK value is less than 5 (as
  359. %the brain is highly stained, these are mostly non-brain pixels)
  360. ZScoresGrA(meanpERK < 5) = NaN;
  361. %throw away any pixel in which we dont have at least 5 fish
  362. ZScoresGrA(NsInGrA < 5) = NaN;
  363. ZScoresGrA(NsInGrB < 5) = NaN;
  364. %Threshold the ZScores based on the FDR threshold we calculated.
  365. %Note this is done separately at each pixel.
  366. ZScoresGrA(abs(ZScoresGrA)<ZScoreThresh) = NaN;
  367. %Assign these values in the image stack we will wite later
  368. mwuZScoresImage(:,:,z) = ZScoresGrA;
  369. % Do the same thing for the last mixed-group comparison as an
  370. % example of the false discoveries.
  371. ZScoresMixedSigleIterationForWriting = ZScoresMixedGrA(:,:,end); % we will save the last iteration and write to file to show what the control FDR rate images look like.
  372. ZScoresMixedSigleIterationForWriting(meanpERK < 5) = NaN;
  373. ZScoresMixedSigleIterationForWriting(NsInGrA < 5) = NaN;
  374. ZScoresMixedSigleIterationForWriting(NsInGrB < 5) = NaN;
  375. ZScoresMixedSigleIterationForWriting(abs(ZScoresMixedSigleIterationForWriting)<ZScoreThresh) = NaN;
  376. mwuMixedZScoresImageSingleIteration(:,:,z) = ZScoresMixedSigleIterationForWriting;
  377. cd(dirOut);
  378. parfor_progress; %update the lovely parfor progess bar.
  379. end
  380. cd(dirOut);
  381. parfor_progress(0);
  382. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  383. disp(strcat('Completed the comparison of: ', GrA, '-vs-', GrB)) % uodate where we are in the analysis
  384. %now we threshold the images such that a Z-statistic of 10 is saturated. We
  385. %also split into the positive and negative components such that these can
  386. %be written in differnt colours.
  387. mwuZScoresImage = mwuZScoresImage./10;
  388. mwuZScoresImage(mwuZScoresImage > 1) = 1;
  389. mwuZScoresImage(mwuZScoresImage < -1) = -1;
  390. mwuZScoresImagePositive = mwuZScoresImage;
  391. mwuZScoresImagePositive(mwuZScoresImagePositive < 0) = 0;
  392. mwuZScoresImageNegative = mwuZScoresImage.*-1;
  393. mwuZScoresImageNegative(mwuZScoresImageNegative < 0) = 0;
  394. mwuMixedZScoresImageSingleIteration = mwuMixedZScoresImageSingleIteration./10;
  395. mwuMixedZScoresImageSingleIteration(mwuMixedZScoresImageSingleIteration > 1) = 1;
  396. mwuMixedZScoresImageSingleIteration(mwuMixedZScoresImageSingleIteration < -1) = -1;
  397. mwuMixedZScoresImageSingleIterationPositive = mwuMixedZScoresImageSingleIteration;
  398. mwuMixedZScoresImageSingleIterationPositive(mwuMixedZScoresImageSingleIterationPositive < 0) = 0;
  399. mwuMixedZScoresImageSingleIterationNegative = mwuMixedZScoresImageSingleIteration.*-1;
  400. mwuMixedZScoresImageSingleIterationNegative(mwuMixedZScoresImageSingleIterationNegative < 0) = 0;
  401. % Compute the delta Median images thresholded with the ZScores
  402. DeltaMedian = (Amedian - Bmedian)./(Amedian + Bmedian);
  403. DeltaMedianPos = zeros(size(DeltaMedian));
  404. DeltaMedianNeg = zeros(size(DeltaMedian));
  405. DeltaMedianPos(mwuZScoresImagePositive >0) = abs(DeltaMedian(mwuZScoresImagePositive >0));
  406. DeltaMedianNeg(mwuZScoresImageNegative >0) = abs(DeltaMedian(mwuZScoresImageNegative >0));
  407. DeltaMedianPos = uint16(DeltaMedianPos./0.5.*65535);
  408. DeltaMedianNeg = uint16(DeltaMedianNeg./0.5.*65535);
  409. cd(dirOut);
  410. %Write the tiffs. The try/catch loop avoids the bug in windows when maltab
  411. %tries to write to the tiff that windows explorer is accessing.
  412. %Currently I write two files for the comparison of GrA over GrB (where what
  413. %is brighter in GrA is green and brighter in GrB is Magenta), and also
  414. %write GrB over GrA (Where GrB is green). This is redundant, but probably
  415. %useful as I am not defining which is control vs experimental, and I like
  416. %to have experimental as green.
  417. if length(dir(strcat(GrA, '_over_', GrB, '_ZScores.tif'))) < 1 % check to make sure we havent already written this file
  418. tiffFile = strcat(GrA, '_over_', GrB, '_ZScores.tif');
  419. for ind = 1:Zs
  420. while true
  421. try
  422. imwrite(cat(3, mwuZScoresImageNegative(:,:,ind), mwuZScoresImagePositive(:,:,ind), mwuZScoresImageNegative(:,:,ind)), tiffFile,'WriteMode','append', 'Compression', 'none');
  423. break
  424. catch
  425. disp('Encountered a Tiff write error')
  426. end
  427. end
  428. end
  429. else
  430. warning(strcat('Warning! Already written: ', GrA, '_over_', GrB, '_ZScores.tif, Skipping file write'))
  431. end
  432. if length(dir(strcat(GrB, '_over_', GrA, '_ZScores.tif'))) < 1 % check to make sure we havent already written this file
  433. tiffFile = strcat(GrB, '_over_', GrA, '_ZScores.tif');
  434. for ind = 1:Zs
  435. while true
  436. try
  437. imwrite(cat(3, mwuZScoresImagePositive(:,:,ind), mwuZScoresImageNegative(:,:,ind), mwuZScoresImagePositive(:,:,ind)), tiffFile,'WriteMode','append', 'Compression', 'none');
  438. break
  439. catch
  440. disp('Encountered a Tiff write error')
  441. end
  442. end
  443. end
  444. else
  445. warning(strcat('Warning! Already written:', GrB, '_over_', GrA, '_ZScores.tif, Skipping file write'))
  446. end
  447. % write the mixeed control images
  448. if length(dir(strcat('MixedControl', GrA, '_over_', GrB, '_ZScores.tif'))) < 1 % check to make sure we havent already written this file
  449. tiffFile = strcat('MixedControl', GrA, '_over_', GrB, '_ZScores.tif');
  450. for ind = 1:Zs
  451. while true
  452. try
  453. imwrite(cat(3, mwuMixedZScoresImageSingleIterationNegative(:,:,ind), mwuMixedZScoresImageSingleIterationPositive(:,:,ind), mwuMixedZScoresImageSingleIterationNegative(:,:,ind)), tiffFile,'WriteMode','append', 'Compression', 'none');
  454. break
  455. catch
  456. disp('Encountered a Tiff write error')
  457. end
  458. end
  459. end
  460. else
  461. warning(strcat('Warning! Already written:', 'MixedControl', GrA, '_over_', GrB, '_ZScores.tif, Skipping file write'))
  462. end
  463. if length(dir(strcat('MixedControl', GrB, '_over_', GrA, '_ZScores.tif'))) < 1 % check to make sure we havent already written this file
  464. tiffFile = strcat('MixedControl', GrB, '_over_', GrA, '_ZScores.tif');
  465. for ind = 1:Zs
  466. while true
  467. try
  468. imwrite(cat(3, mwuMixedZScoresImageSingleIterationPositive(:,:,ind), mwuMixedZScoresImageSingleIterationNegative(:,:,ind), mwuMixedZScoresImageSingleIterationPositive(:,:,ind)), tiffFile,'WriteMode','append', 'Compression', 'none');
  469. break
  470. catch
  471. disp('Encountered a Tiff write error')
  472. end
  473. end
  474. end
  475. else
  476. warning(strcat('Warning! Already written:', 'MixedControl', GrB, '_over_', GrA, '_ZScores.tif, Skipping file write'))
  477. end
  478. % Write the median stack to file.
  479. if UsingERK == 0; % if raw averages these should be 8 bit, if pERK/ERK analysis, normalize to 10.
  480. Amedian = uint8(Amedian);
  481. Bmedian = uint8(Bmedian);
  482. else
  483. Amedian = uint16(Amedian.*65535/10);
  484. Bmedian = uint16(Bmedian.*65535/10);
  485. end
  486. if length(dir(strcat(GrA, '_medianStack.tif'))) < 1 % check to make sure we havent already written this file
  487. tiffFile = strcat(GrA, '_medianStack.tif');
  488. for ind = 1:Zs
  489. while true
  490. try
  491. imwrite(Amedian(:,:,ind), tiffFile,'WriteMode','append', 'Compression', 'none');
  492. break
  493. catch
  494. disp('Encountered a Tiff write error')
  495. end
  496. end
  497. end
  498. else
  499. %warning(strcat('Warning! Already written:',GrA, '_medianStack.tif,
  500. %Skipping file write'))
  501. end
  502. if length(dir(strcat(GrB, '_medianStack.tif')))<1
  503. tiffFile = strcat(GrB, '_medianStack.tif');
  504. for ind = 1:Zs
  505. while true
  506. try
  507. imwrite(Bmedian(:,:,ind), tiffFile,'WriteMode','append', 'Compression', 'none');
  508. break
  509. catch
  510. disp('Encountered a Tiff write error')
  511. end
  512. end
  513. end
  514. else
  515. %warning(strcat('Warning! Already written:',GrB, '_medianStack.tif,
  516. %Skipping file write'))
  517. end
  518. % Write the std stack to file.
  519. if UsingERK == 0; % if raw averages these should be 8 bit, if pERK/ERK analysis, normalize to 10.
  520. AStd = uint8(AStd);
  521. BStd = uint8(BStd);
  522. elseif UsingERK == 1;
  523. AStd = uint16(AStd.*65535/10);
  524. BStd = uint16(BStd.*65535/10);
  525. end
  526. if length(dir(strcat(GrA, '_StdStack.tif'))) < 1 % check to make sure we havent already written this file
  527. tiffFile = strcat(GrA, '_StdStack.tif');
  528. for ind = 1:Zs
  529. while true
  530. try
  531. imwrite(AStd(:,:,ind), tiffFile,'WriteMode','append', 'Compression', 'none');
  532. break
  533. catch
  534. disp('Encountered a Tiff write error')
  535. end
  536. end
  537. end
  538. else
  539. %warning(strcat('Warning! Already written:',GrA, '_medianStack.tif,
  540. %Skipping file write'))
  541. end
  542. if length(dir(strcat(GrB, '_StdStack.tif')))<1
  543. tiffFile = strcat(GrB, '_StdStack.tif');
  544. for ind = 1:Zs
  545. while true
  546. try
  547. imwrite(BStd(:,:,ind), tiffFile,'WriteMode','append', 'Compression', 'none');
  548. break
  549. catch
  550. disp('Encountered a Tiff write error')
  551. end
  552. end
  553. end
  554. else
  555. %warning(strcat('Warning! Already written:',GrB, '_medianStack.tif,
  556. %Skipping file write'))
  557. end
  558. TiffName = strcat(GrA, '_over_', GrB, '_SignificantDeltaMedians.tif');
  559. if length(dir(TiffName)) < 1 % check to make sure we havent already written this file
  560. for ind = 1:Zs
  561. while true
  562. try
  563. imwrite(cat(3, DeltaMedianNeg(:,:,ind), DeltaMedianPos(:,:,ind), DeltaMedianNeg(:,:,ind)), TiffName,'WriteMode','append', 'Compression', 'none');
  564. break
  565. catch
  566. disp('Encountered a Tiff write error')
  567. end
  568. end
  569. end
  570. else
  571. warning(strcat('Warning! Already written:', TiffName, 'Skipping file write'))
  572. end
  573. TiffName = strcat(GrB, '_over_', GrA, '_SignificantDeltaMedians.tif');
  574. if length(dir(TiffName)) < 1 % check to make sure we havent already written this file
  575. for ind = 1:Zs
  576. while true
  577. try
  578. imwrite(cat(3, DeltaMedianPos(:,:,ind), DeltaMedianNeg(:,:,ind), DeltaMedianPos(:,:,ind)), TiffName,'WriteMode','append', 'Compression', 'none');
  579. break
  580. catch
  581. disp('Encountered a Tiff write error')
  582. end
  583. end
  584. end
  585. else
  586. warning(strcat('Warning! Already written:', TiffName, 'Skipping file write'))
  587. end
  588. end
  589. function out = uipickfiles(varargin)
  590. %uipickfiles: GUI program to select files and/or folders.
  591. %
  592. % Syntax:
  593. % files = uipickfiles('PropertyName',PropertyValue,...)
  594. %
  595. % The current folder can be changed by operating in the file navigator:
  596. % double-clicking on a folder in the list or pressing Enter to move further
  597. % down the tree, using the popup menu, clicking the up arrow button or
  598. % pressing Backspace to move up the tree, typing a path in the box to move
  599. % to any folder or right-clicking (control-click on Mac) on the path box to
  600. % revisit a previously-visited folder. These folders are listed in order
  601. % of when they were last visited (most recent at the top) and the list is
  602. % saved between calls to uipickfiles. The list can be cleared or its
  603. % maximum length changed with the items at the bottom of the menu.
  604. % (Windows only: To go to a UNC-named resource you will have to type the
  605. % UNC name in the path box, but all such visited resources will be
  606. % remembered and listed along with the mapped drives.) The items in the
  607. % file navigator can be sorted by name, modification date or size by
  608. % clicking on the headers, though neither date nor size are displayed. All
  609. % folders have zero size.
  610. %
  611. % Files can be added to the list by double-clicking or selecting files
  612. % (non-contiguous selections are possible with the control key) and
  613. % pressing the Add button. Control-F will select all the files listed in
  614. % the navigator while control-A will select everything (Command instead of
  615. % Control on the Mac). Since double-clicking a folder will open it,
  616. % folders can be added only by selecting them and pressing the Add button.
  617. % Files/folders in the list can be removed or re-ordered. Recall button
  618. % will insert into the Selected Files list whatever files were returned the
  619. % last time uipickfiles was run. When finished, a press of the Done button
  620. % will return the full paths to the selected items in a cell array,
  621. % structure array or character array. If the Cancel button or the escape
  622. % key is pressed then zero is returned.
  623. %
  624. % The figure can be moved and resized in the usual way and this position is
  625. % saved and used for subsequent calls to uipickfiles. The default position
  626. % can be restored by double-clicking in a vacant region of the figure.
  627. %
  628. % The following optional property/value pairs can be specified as arguments
  629. % to control the indicated behavior:
  630. %
  631. % Property Value
  632. % ---------- ----------------------------------------------------------
  633. % FilterSpec String to specify starting folder and/or file filter.
  634. % Ex: 'C:\bin' will start up in that folder. '*.txt'
  635. % will list only files ending in '.txt'. 'c:\bin\*.txt' will
  636. % do both. Default is to start up in the current folder and
  637. % list all files. Can be changed with the GUI.
  638. %
  639. % REFilter String containing a regular expression used to filter the
  640. % file list. Ex: '\.m$|\.mat$' will list files ending in
  641. % '.m' and '.mat'. Default is empty string. Can be used
  642. % with FilterSpec and both filters are applied. Can be
  643. % changed with the GUI.
  644. %
  645. % REDirs Logical flag indicating whether to apply the regular
  646. % expression filter to folder names. Default is false which
  647. % means that all folders are listed. Can be changed with the
  648. % GUI.
  649. %
  650. % Type Two-column cell array where the first column contains file
  651. % filters and the second column contains descriptions. If
  652. % this property is specified an additional popup menu will
  653. % appear below the File Filter and selecting an item will put
  654. % that item into the File Filter. By default, the first item
  655. % will be entered into the File Filter. For example,
  656. % { '*.m', 'M-files' ;
  657. % '*.mat', 'MAT-files' }.
  658. % Can also be a cell vector of file filter strings in which
  659. % case the descriptions will be the same as the file filters
  660. % themselves.
  661. % Must be a cell array even if there is only one entry.
  662. %
  663. % Prompt String containing a prompt appearing in the title bar of
  664. % the figure. Default is 'Select files'.
  665. %
  666. % NumFiles Scalar or vector specifying number of files that must be
  667. % selected. A scalar specifies an exact value; a two-element
  668. % vector can be used to specify a range, [min max]. The
  669. % function will not return unless the specified number of
  670. % files have been chosen. Default is [] which accepts any
  671. % number of files.
  672. %
  673. % Append Cell array of strings, structure array or char array
  674. % containing a previously returned output from uipickfiles.
  675. % Used to start up program with some entries in the Selected
  676. % Files list. Any included files that no longer exist will
  677. % not appear. Default is empty cell array, {}.
  678. %
  679. % Output String specifying the data type of the output: 'cell',
  680. % 'struct' or 'char'. Specifying 'cell' produces a cell
  681. % array of strings, the strings containing the full paths of
  682. % the chosen files. 'Struct' returns a structure array like
  683. % the result of the dir function except that the 'name' field
  684. % contains a full path instead of just the file name. 'Char'
  685. % returns a character array of the full paths. This is most
  686. % useful when you have just one file and want it in a string
  687. % instead of a cell array containing just one string. The
  688. % default is 'cell'.
  689. %
  690. % All properties and values are case-insensitive and need only be
  691. % unambiguous. For example,
  692. %
  693. % files = uipickfiles('num',1,'out','ch')
  694. %
  695. % is valid usage.
  696. % Version: 1.15, 2 March 2012
  697. % Author: Douglas M. Schwarz
  698. % Email: dmschwarz=ieee*org, dmschwarz=urgrad*rochester*edu
  699. % Real_email = regexprep(Email,{'=','*'},{'@','.'})
  700. % Define properties and set default values.
  701. prop.filterspec = '*';
  702. prop.refilter = '';
  703. prop.redirs = false;
  704. prop.type = {};
  705. prop.prompt = 'Select files';
  706. prop.numfiles = [];
  707. prop.append = [];
  708. prop.output = 'cell';
  709. % Process inputs and set prop fields.
  710. prop = parsepropval(prop,varargin{:});
  711. % Validate FilterSpec property.
  712. if isempty(prop.filterspec)
  713. prop.filterspec = '*';
  714. end
  715. if ~ischar(prop.filterspec)
  716. error('FilterSpec property must contain a string.')
  717. end
  718. % Validate REFilter property.
  719. if ~ischar(prop.refilter)
  720. error('REFilter property must contain a string.')
  721. end
  722. % Validate REDirs property.
  723. if ~isscalar(prop.redirs)
  724. error('REDirs property must contain a scalar.')
  725. end
  726. % Validate Type property.
  727. if isempty(prop.type)
  728. elseif iscellstr(prop.type) && isscalar(prop.type)
  729. prop.type = repmat(prop.type(:),1,2);
  730. elseif iscellstr(prop.type) && size(prop.type,2) == 2
  731. else
  732. error(['Type property must be empty or a cellstr vector or ',...
  733. 'a 2-column cellstr matrix.'])
  734. end
  735. % Validate Prompt property.
  736. if ~ischar(prop.prompt)
  737. error('Prompt property must contain a string.')
  738. end
  739. % Validate NumFiles property.
  740. if numel(prop.numfiles) > 2 || any(prop.numfiles < 0)
  741. error('NumFiles must be empty, a scalar or two-element vector.')
  742. end
  743. prop.numfiles = unique(prop.numfiles);
  744. if isequal(prop.numfiles,1)
  745. numstr = 'Select exactly 1 file.';
  746. elseif length(prop.numfiles) == 1
  747. numstr = sprintf('Select exactly %d items.',prop.numfiles);
  748. else
  749. numstr = sprintf('Select %d to %d items.',prop.numfiles);
  750. end
  751. % Validate Append property and initialize pick data.
  752. if isstruct(prop.append) && isfield(prop.append,'name')
  753. prop.append = {prop.append.name};
  754. elseif ischar(prop.append)
  755. prop.append = cellstr(prop.append);
  756. end
  757. if isempty(prop.append)
  758. file_picks = {};
  759. full_file_picks = {};
  760. dir_picks = dir(' '); % Create empty directory structure.
  761. elseif iscellstr(prop.append) && isvector(prop.append)
  762. num_items = length(prop.append);
  763. file_picks = cell(1,num_items);
  764. full_file_picks = cell(1,num_items);
  765. dir_fn = fieldnames(dir(' '));
  766. dir_picks = repmat(cell2struct(cell(length(dir_fn),1),dir_fn(:)),...
  767. num_items,1);
  768. for item = 1:num_items
  769. if exist(prop.append{item},'dir') && ...
  770. ~any(strcmp(full_file_picks,prop.append{item}))
  771. full_file_picks{item} = prop.append{item};
  772. [unused,fn,ext] = fileparts(prop.append{item});
  773. file_picks{item} = [fn,ext];
  774. temp = dir(fullfile(prop.append{item},'..'));
  775. if ispc || ismac
  776. thisdir = strcmpi({temp.name},[fn,ext]);
  777. else
  778. thisdir = strcmp({temp.name},[fn,ext]);
  779. end
  780. dir_picks(item) = temp(thisdir);
  781. dir_picks(item).name = prop.append{item};
  782. elseif exist(prop.append{item},'file') && ...
  783. ~any(strcmp(full_file_picks,prop.append{item}))
  784. full_file_picks{item} = prop.append{item};
  785. [unused,fn,ext] = fileparts(prop.append{item});
  786. file_picks{item} = [fn,ext];
  787. dir_picks(item) = dir(prop.append{item});
  788. dir_picks(item).name = prop.append{item};
  789. else
  790. continue
  791. end
  792. end
  793. % Remove items which no longer exist.
  794. missing = cellfun(@isempty,full_file_picks);
  795. full_file_picks(missing) = [];
  796. file_picks(missing) = [];
  797. dir_picks(missing) = [];
  798. else
  799. error('Append must be a cell, struct or char array.')
  800. end
  801. % Validate Output property.
  802. legal_outputs = {'cell','struct','char'};
  803. out_idx = find(strncmpi(prop.output,legal_outputs,length(prop.output)));
  804. if length(out_idx) == 1
  805. prop.output = legal_outputs{out_idx};
  806. else
  807. error(['Value of ''Output'' property, ''%s'', is illegal or '...
  808. 'ambiguous.'],prop.output)
  809. end
  810. % Set style preference for display of folders.
  811. % 1 => folder icon before and filesep after
  812. % 2 => bullet before and filesep after
  813. % 3 => filesep after only
  814. folder_style_pref = 1;
  815. fsdata = set_folder_style(folder_style_pref);
  816. % Initialize file lists.
  817. if exist(prop.filterspec,'dir')
  818. current_dir = prop.filterspec;
  819. filter = '*';
  820. else
  821. [current_dir,f,e] = fileparts(prop.filterspec);
  822. filter = [f,e];
  823. end
  824. if isempty(current_dir)
  825. current_dir = pwd;
  826. end
  827. if isempty(filter)
  828. filter = '*';
  829. end
  830. re_filter = prop.refilter;
  831. full_filter = fullfile(current_dir,filter);
  832. network_volumes = {};
  833. [path_cell,new_network_vol] = path2cell(current_dir);
  834. if exist(new_network_vol,'dir')
  835. network_volumes = unique([network_volumes,{new_network_vol}]);
  836. end
  837. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  838. @(x)file_sort(x,[1 0 0]));
  839. filenames = {fdir.name}';
  840. filenames = annotate_file_names(filenames,fdir,fsdata);
  841. % Initialize some data.
  842. show_full_path = false;
  843. nodupes = true;
  844. % Get history preferences and set history.
  845. history = getpref('uipickfiles','history',...
  846. struct('name',current_dir,'time',now));
  847. default_history_size = 15;
  848. history_size = getpref('uipickfiles','history_size',default_history_size);
  849. history = update_history(history,current_dir,now,history_size);
  850. % Get figure position preference and create figure.
  851. gray = get(0,'DefaultUIControlBackgroundColor');
  852. if ispref('uipickfiles','figure_position');
  853. fig_pos = getpref('uipickfiles','figure_position');
  854. fig = figure('Position',fig_pos,...
  855. 'Color',gray,...
  856. 'MenuBar','none',...
  857. 'WindowStyle','modal',...
  858. 'Resize','on',...
  859. 'NumberTitle','off',...
  860. 'Name',prop.prompt,...
  861. 'IntegerHandle','off',...
  862. 'CloseRequestFcn',@cancel,...
  863. 'ButtonDownFcn',@reset_figure_size,...
  864. 'KeyPressFcn',@keypressmisc,...
  865. 'Visible','off');
  866. else
  867. fig_pos = [0 0 740 494];
  868. fig = figure('Position',fig_pos,...
  869. 'Color',gray,...
  870. 'MenuBar','none',...
  871. 'WindowStyle','modal',...
  872. 'Resize','on',...
  873. 'NumberTitle','off',...
  874. 'Name',prop.prompt,...
  875. 'IntegerHandle','off',...
  876. 'CloseRequestFcn',@cancel,...
  877. 'CreateFcn',{@movegui,'center'},...
  878. 'ButtonDownFcn',@reset_figure_size,...
  879. 'KeyPressFcn',@keypressmisc,...
  880. 'Visible','off');
  881. end
  882. % Set system-dependent items.
  883. if ismac
  884. set(fig,'DefaultUIControlFontName','Lucida Grande')
  885. set(fig,'DefaultUIControlFontSize',9)
  886. sort_ctrl_size = 8;
  887. mod_key = 'command';
  888. action = 'Control-click';
  889. elseif ispc
  890. set(fig,'DefaultUIControlFontName','Tahoma')
  891. set(fig,'DefaultUIControlFontSize',8)
  892. sort_ctrl_size = 7;
  893. mod_key = 'control';
  894. action = 'Right-click';
  895. else
  896. sort_ctrl_size = get(fig,'DefaultUIControlFontSize') - 1;
  897. mod_key = 'control';
  898. action = 'Right-click';
  899. end
  900. % Create uicontrols.
  901. frame1 = uicontrol('Style','frame',...
  902. 'Position',[255 260 110 70]);
  903. frame2 = uicontrol('Style','frame',...
  904. 'Position',[275 135 110 100]);
  905. navlist = uicontrol('Style','listbox',...
  906. 'Position',[10 10 250 320],...
  907. 'String',filenames,...
  908. 'Value',[],...
  909. 'BackgroundColor','w',...
  910. 'Callback',@clicknav,...
  911. 'KeyPressFcn',@keypressnav,...
  912. 'Max',2);
  913. tri_up = repmat([1 1 1 1 0 1 1 1 1;1 1 1 0 0 0 1 1 1;1 1 0 0 0 0 0 1 1;...
  914. 1 0 0 0 0 0 0 0 1],[1 1 3]);
  915. tri_up(tri_up == 1) = NaN;
  916. tri_down = tri_up(end:-1:1,:,:);
  917. tri_null = NaN(4,9,3);
  918. tri_icon = {tri_down,tri_null,tri_up};
  919. sort_state = [1 0 0];
  920. last_sort_state = [1 1 1];
  921. sort_cb = zeros(1,3);
  922. sort_cb(1) = uicontrol('Style','checkbox',...
  923. 'Position',[15 331 70 15],...
  924. 'String','Name',...
  925. 'FontSize',sort_ctrl_size,...
  926. 'Value',sort_state(1),...
  927. 'CData',tri_icon{sort_state(1)+2},...
  928. 'KeyPressFcn',@keypressmisc,...
  929. 'Callback',{@sort_type,1});
  930. sort_cb(2) = uicontrol('Style','checkbox',...
  931. 'Position',[85 331 70 15],...
  932. 'String','Date',...
  933. 'FontSize',sort_ctrl_size,...
  934. 'Value',sort_state(2),...
  935. 'CData',tri_icon{sort_state(2)+2},...
  936. 'KeyPressFcn',@keypressmisc,...
  937. 'Callback',{@sort_type,2});
  938. sort_cb(3) = uicontrol('Style','checkbox',...
  939. 'Position',[155 331 70 15],...
  940. 'String','Size',...
  941. 'FontSize',sort_ctrl_size,...
  942. 'Value',sort_state(3),...
  943. 'CData',tri_icon{sort_state(3)+2},...
  944. 'KeyPressFcn',@keypressmisc,...
  945. 'Callback',{@sort_type,3});
  946. pickslist = uicontrol('Style','listbox',...
  947. 'Position',[380 10 350 320],...
  948. 'String',file_picks,...
  949. 'BackgroundColor','w',...
  950. 'Callback',@clickpicks,...
  951. 'KeyPressFcn',@keypresslist,...
  952. 'Max',2,...
  953. 'Value',[]);
  954. openbut = uicontrol('Style','pushbutton',...
  955. 'Position',[270 300 80 20],...
  956. 'String','Open',...
  957. 'Enable','off',...
  958. 'KeyPressFcn',@keypressmisc,...
  959. 'Callback',@open);
  960. arrow = [ ...
  961. ' 1 ';
  962. ' 10 ';
  963. ' 10 ';
  964. '000000000000';
  965. ' 10 ';
  966. ' 10 ';
  967. ' 1 '];
  968. cmap = NaN(128,3);
  969. cmap(double('10'),:) = [0.5 0.5 0.5;0 0 0];
  970. arrow_im = NaN(7,76,3);
  971. arrow_im(:,45:56,:) = ind2rgb(double(arrow),cmap);
  972. addbut = uicontrol('Style','pushbutton',...
  973. 'Position',[270 270 80 20],...
  974. 'String','Add ',...
  975. 'Enable','off',...
  976. 'CData',arrow_im,...
  977. 'KeyPressFcn',@keypressmisc,...
  978. 'Callback',@add);
  979. removebut = uicontrol('Style','pushbutton',...
  980. 'Position',[290 205 80 20],...
  981. 'String','Remove',...
  982. 'Enable','off',...
  983. 'KeyPressFcn',@keypressmisc,...
  984. 'Callback',@remove);
  985. moveupbut = uicontrol('Style','pushbutton',...
  986. 'Position',[290 175 80 20],...
  987. 'String','Move Up',...
  988. 'Enable','off',...
  989. 'KeyPressFcn',@keypressmisc,...
  990. 'Callback',@moveup);
  991. movedownbut = uicontrol('Style','pushbutton',...
  992. 'Position',[290 145 80 20],...
  993. 'String','Move Down',...
  994. 'Enable','off',...
  995. 'KeyPressFcn',@keypressmisc,...
  996. 'Callback',@movedown);
  997. dir_popup = uicontrol('Style','popupmenu',...
  998. 'Position',[10 350 225 20],...
  999. 'BackgroundColor','w',...
  1000. 'String',path_cell,...
  1001. 'Value',length(path_cell),...
  1002. 'KeyPressFcn',@keypressmisc,...
  1003. 'Callback',@dirpopup);
  1004. uparrow = [ ...
  1005. ' 0 ';
  1006. ' 000 ';
  1007. '00000 ';
  1008. ' 0 ';
  1009. ' 0 ';
  1010. ' 0 ';
  1011. ' 000000'];
  1012. cmap = NaN(128,3);
  1013. cmap(double('0'),:) = [0 0 0];
  1014. uparrow_im = ind2rgb(double(uparrow),cmap);
  1015. up_dir_but = uicontrol('Style','pushbutton',...
  1016. 'Position',[240 350 20 20],...
  1017. 'CData',uparrow_im,...
  1018. 'KeyPressFcn',@keypressmisc,...
  1019. 'Callback',@dir_up_one,...
  1020. 'ToolTip','Go to parent folder');
  1021. if length(path_cell) > 1
  1022. set(up_dir_but','Enable','on')
  1023. else
  1024. set(up_dir_but','Enable','off')
  1025. end
  1026. hist_cm = uicontextmenu;
  1027. pathbox = uicontrol('Style','edit',...
  1028. 'Position',[10 375 250 26],...
  1029. 'BackgroundColor','w',...
  1030. 'String',current_dir,...
  1031. 'HorizontalAlignment','left',...
  1032. 'TooltipString',[action,' to display folder history'],...
  1033. 'KeyPressFcn',@keypressmisc,...
  1034. 'Callback',@change_path,...
  1035. 'UIContextMenu',hist_cm);
  1036. label1 = uicontrol('Style','text',...
  1037. 'Position',[10 401 250 16],...
  1038. 'String','Current Folder',...
  1039. 'HorizontalAlignment','center',...
  1040. 'TooltipString',[action,' to display folder history'],...
  1041. 'UIContextMenu',hist_cm);
  1042. hist_menus = [];
  1043. make_history_cm()
  1044. label2 = uicontrol('Style','text',...
  1045. 'Position',[10 440+36 80 17],...
  1046. 'String','File Filter',...
  1047. 'HorizontalAlignment','left');
  1048. label3 = uicontrol('Style','text',...
  1049. 'Position',[100 440+36 160 17],...
  1050. 'String','Reg. Exp. Filter',...
  1051. 'HorizontalAlignment','left');
  1052. showallfiles = uicontrol('Style','checkbox',...
  1053. 'Position',[270 420+32 110 20],...
  1054. 'String','Show All Files',...
  1055. 'Value',0,...
  1056. 'HorizontalAlignment','left',...
  1057. 'KeyPressFcn',@keypressmisc,...
  1058. 'Callback',@togglefilter);
  1059. refilterdirs = uicontrol('Style','checkbox',...
  1060. 'Position',[270 420+10 100 20],...
  1061. 'String','RE Filter Dirs',...
  1062. 'Value',prop.redirs,...
  1063. 'HorizontalAlignment','left',...
  1064. 'KeyPressFcn',@keypressmisc,...
  1065. 'Callback',@toggle_refiltdirs);
  1066. filter_ed = uicontrol('Style','edit',...
  1067. 'Position',[10 420+30 80 26],...
  1068. 'BackgroundColor','w',...
  1069. 'String',filter,...
  1070. 'HorizontalAlignment','left',...
  1071. 'KeyPressFcn',@keypressmisc,...
  1072. 'Callback',@setfilspec);
  1073. refilter_ed = uicontrol('Style','edit',...
  1074. 'Position',[100 420+30 160 26],...
  1075. 'BackgroundColor','w',...
  1076. 'String',re_filter,...
  1077. 'HorizontalAlignment','left',...
  1078. 'KeyPressFcn',@keypressmisc,...
  1079. 'Callback',@setrefilter);
  1080. type_value = 1;
  1081. type_popup = uicontrol('Style','popupmenu',...
  1082. 'Position',[10 422 250 20],...
  1083. 'String','',...
  1084. 'BackgroundColor','w',...
  1085. 'Value',type_value,...
  1086. 'KeyPressFcn',@keypressmisc,...
  1087. 'Callback',@filter_type_callback,...
  1088. 'Visible','off');
  1089. if ~isempty(prop.type)
  1090. set(filter_ed,'String',prop.type{type_value,1})
  1091. setfilspec()
  1092. set(type_popup,'String',prop.type(:,2),'Visible','on')
  1093. end
  1094. viewfullpath = uicontrol('Style','checkbox',...
  1095. 'Position',[380 335 230 20],...
  1096. 'String','Show full paths',...
  1097. 'Value',show_full_path,...
  1098. 'HorizontalAlignment','left',...
  1099. 'KeyPressFcn',@keypressmisc,...
  1100. 'Callback',@showfullpath);
  1101. remove_dupes = uicontrol('Style','checkbox',...
  1102. 'Position',[380 360 280 20],...
  1103. 'String','Remove duplicates (as per full path)',...
  1104. 'Value',nodupes,...
  1105. 'HorizontalAlignment','left',...
  1106. 'KeyPressFcn',@keypressmisc,...
  1107. 'Callback',@removedupes);
  1108. recall_button = uicontrol('Style','pushbutton',...
  1109. 'Position',[665 335 65 20],...
  1110. 'String','Recall',...
  1111. 'KeyPressFcn',@keypressmisc,...
  1112. 'Callback',@recall,...
  1113. 'ToolTip','Add previously selected items');
  1114. label4 = uicontrol('Style','text',...
  1115. 'Position',[380 405 350 20],...
  1116. 'String','Selected Items',...
  1117. 'HorizontalAlignment','center');
  1118. done_button = uicontrol('Style','pushbutton',...
  1119. 'Position',[280 80 80 30],...
  1120. 'String','Done',...
  1121. 'KeyPressFcn',@keypressmisc,...
  1122. 'Callback',@done);
  1123. cancel_button = uicontrol('Style','pushbutton',...
  1124. 'Position',[280 30 80 30],...
  1125. 'String','Cancel',...
  1126. 'KeyPressFcn',@keypressmisc,...
  1127. 'Callback',@cancel);
  1128. % If necessary, add warning about number of items to be selected.
  1129. num_files_warn = uicontrol('Style','text',...
  1130. 'Position',[380 385 350 16],...
  1131. 'String',numstr,...
  1132. 'ForegroundColor',[0.8 0 0],...
  1133. 'HorizontalAlignment','center',...
  1134. 'Visible','off');
  1135. if ~isempty(prop.numfiles)
  1136. set(num_files_warn,'Visible','on')
  1137. end
  1138. resize()
  1139. % Make figure visible and hide handle.
  1140. set(fig,'HandleVisibility','off',...
  1141. 'Visible','on',...
  1142. 'ResizeFcn',@resize)
  1143. % Wait until figure is closed.
  1144. uiwait(fig)
  1145. % Compute desired output.
  1146. switch prop.output
  1147. case 'cell'
  1148. out = full_file_picks;
  1149. case 'struct'
  1150. out = dir_picks(:);
  1151. case 'char'
  1152. out = char(full_file_picks);
  1153. case 'cancel'
  1154. out = 0;
  1155. end
  1156. % Update history preference.
  1157. setpref('uipickfiles','history',history)
  1158. if ~isempty(full_file_picks) && ~strcmp(prop.output,'cancel')
  1159. setpref('uipickfiles','full_file_picks',full_file_picks)
  1160. end
  1161. % Update figure position preference.
  1162. setpref('uipickfiles','figure_position',fig_pos)
  1163. % ----------------- Callback nested functions ----------------
  1164. function add(varargin)
  1165. values = get(navlist,'Value');
  1166. for i = 1:length(values)
  1167. dir_pick = fdir(values(i));
  1168. pick = dir_pick.name;
  1169. pick_full = fullfile(current_dir,pick);
  1170. dir_pick.name = pick_full;
  1171. if ~nodupes || ~any(strcmp(full_file_picks,pick_full))
  1172. file_picks{end + 1} = pick; %#ok<AGROW>
  1173. full_file_picks{end + 1} = pick_full; %#ok<AGROW>
  1174. dir_picks(end + 1) = dir_pick; %#ok<AGROW>
  1175. end
  1176. end
  1177. if show_full_path
  1178. set(pickslist,'String',full_file_picks,'Value',[]);
  1179. else
  1180. set(pickslist,'String',file_picks,'Value',[]);
  1181. end
  1182. set([removebut,moveupbut,movedownbut],'Enable','off');
  1183. end
  1184. function remove(varargin)
  1185. values = get(pickslist,'Value');
  1186. file_picks(values) = [];
  1187. full_file_picks(values) = [];
  1188. dir_picks(values) = [];
  1189. top = get(pickslist,'ListboxTop');
  1190. num_above_top = sum(values < top);
  1191. top = top - num_above_top;
  1192. num_picks = length(file_picks);
  1193. new_value = min(min(values) - num_above_top,num_picks);
  1194. if num_picks == 0
  1195. new_value = [];
  1196. set([removebut,moveupbut,movedownbut],'Enable','off')
  1197. end
  1198. if show_full_path
  1199. set(pickslist,'String',full_file_picks,'Value',new_value,...
  1200. 'ListboxTop',top)
  1201. else
  1202. set(pickslist,'String',file_picks,'Value',new_value,...
  1203. 'ListboxTop',top)
  1204. end
  1205. end
  1206. function open(varargin)
  1207. values = get(navlist,'Value');
  1208. if fdir(values).isdir
  1209. set(fig,'pointer','watch')
  1210. drawnow
  1211. % Convert 'My Documents' to 'Documents' when necessary.
  1212. if ispc && strcmp(fdir(values).name,'My Documents')
  1213. if isempty(dir(fullfile(current_dir,fdir(values).name)))
  1214. values = find(strcmp({fdir.name},'Documents'));
  1215. end
  1216. end
  1217. current_dir = fullfile(current_dir,fdir(values).name);
  1218. history = update_history(history,current_dir,now,history_size);
  1219. make_history_cm()
  1220. full_filter = fullfile(current_dir,filter);
  1221. path_cell = path2cell(current_dir);
  1222. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1223. @(x)file_sort(x,sort_state));
  1224. filenames = {fdir.name}';
  1225. filenames = annotate_file_names(filenames,fdir,fsdata);
  1226. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1227. if length(path_cell) > 1
  1228. set(up_dir_but','Enable','on')
  1229. else
  1230. set(up_dir_but','Enable','off')
  1231. end
  1232. set(pathbox,'String',current_dir)
  1233. set(navlist,'ListboxTop',1,'Value',[],'String',filenames)
  1234. set(addbut,'Enable','off')
  1235. set(openbut,'Enable','off')
  1236. set(fig,'pointer','arrow')
  1237. end
  1238. end
  1239. function clicknav(varargin)
  1240. value = get(navlist,'Value');
  1241. nval = length(value);
  1242. dbl_click_fcn = @add;
  1243. switch nval
  1244. case 0
  1245. set([addbut,openbut],'Enable','off')
  1246. case 1
  1247. set(addbut,'Enable','on');
  1248. if fdir(value).isdir
  1249. set(openbut,'Enable','on')
  1250. dbl_click_fcn = @open;
  1251. else
  1252. set(openbut,'Enable','off')
  1253. end
  1254. otherwise
  1255. set(addbut,'Enable','on')
  1256. set(openbut,'Enable','off')
  1257. end
  1258. if strcmp(get(fig,'SelectionType'),'open')
  1259. dbl_click_fcn();
  1260. end
  1261. end
  1262. function keypressmisc(h,evt) %#ok<INUSL>
  1263. if strcmp(evt.Key,'escape') && isequal(evt.Modifier,cell(1,0))
  1264. % Escape key means Cancel.
  1265. cancel()
  1266. end
  1267. end
  1268. function keypressnav(h,evt) %#ok<INUSL>
  1269. if length(path_cell) > 1 && strcmp(evt.Key,'backspace') && ...
  1270. isequal(evt.Modifier,cell(1,0))
  1271. % Backspace means go to parent folder.
  1272. dir_up_one()
  1273. elseif strcmp(evt.Key,'f') && isequal(evt.Modifier,{mod_key})
  1274. % Control-F (Command-F on Mac) means select all files.
  1275. value = find(~[fdir.isdir]);
  1276. set(navlist,'Value',value)
  1277. elseif strcmp(evt.Key,'rightarrow') && ...
  1278. isequal(evt.Modifier,cell(1,0))
  1279. % Right arrow key means select the file.
  1280. add()
  1281. elseif strcmp(evt.Key,'escape') && isequal(evt.Modifier,cell(1,0))
  1282. % Escape key means Cancel.
  1283. cancel()
  1284. end
  1285. end
  1286. function keypresslist(h,evt) %#ok<INUSL>
  1287. if strcmp(evt.Key,'backspace') && isequal(evt.Modifier,cell(1,0))
  1288. % Backspace means remove item from list.
  1289. remove()
  1290. elseif strcmp(evt.Key,'escape') && isequal(evt.Modifier,cell(1,0))
  1291. % Escape key means Cancel.
  1292. cancel()
  1293. end
  1294. end
  1295. function clickpicks(varargin)
  1296. value = get(pickslist,'Value');
  1297. if isempty(value)
  1298. set([removebut,moveupbut,movedownbut],'Enable','off')
  1299. else
  1300. set(removebut,'Enable','on')
  1301. if min(value) == 1
  1302. set(moveupbut,'Enable','off')
  1303. else
  1304. set(moveupbut,'Enable','on')
  1305. end
  1306. if max(value) == length(file_picks)
  1307. set(movedownbut,'Enable','off')
  1308. else
  1309. set(movedownbut,'Enable','on')
  1310. end
  1311. end
  1312. if strcmp(get(fig,'SelectionType'),'open')
  1313. remove();
  1314. end
  1315. end
  1316. function recall(varargin)
  1317. if ispref('uipickfiles','full_file_picks')
  1318. ffp = getpref('uipickfiles','full_file_picks');
  1319. else
  1320. ffp = {};
  1321. end
  1322. for i = 1:length(ffp)
  1323. if exist(ffp{i},'dir') && ...
  1324. (~nodupes || ~any(strcmp(full_file_picks,ffp{i})))
  1325. full_file_picks{end + 1} = ffp{i}; %#ok<AGROW>
  1326. [unused,fn,ext] = fileparts(ffp{i});
  1327. file_picks{end + 1} = [fn,ext]; %#ok<AGROW>
  1328. temp = dir(fullfile(ffp{i},'..'));
  1329. if ispc || ismac
  1330. thisdir = strcmpi({temp.name},[fn,ext]);
  1331. else
  1332. thisdir = strcmp({temp.name},[fn,ext]);
  1333. end
  1334. dir_picks(end + 1) = temp(thisdir); %#ok<AGROW>
  1335. dir_picks(end).name = ffp{i};
  1336. elseif exist(ffp{i},'file') && ...
  1337. (~nodupes || ~any(strcmp(full_file_picks,ffp{i})))
  1338. full_file_picks{end + 1} = ffp{i}; %#ok<AGROW>
  1339. [unused,fn,ext] = fileparts(ffp{i});
  1340. file_picks{end + 1} = [fn,ext]; %#ok<AGROW>
  1341. dir_picks(end + 1) = dir(ffp{i}); %#ok<AGROW>
  1342. dir_picks(end).name = ffp{i};
  1343. end
  1344. end
  1345. if show_full_path
  1346. set(pickslist,'String',full_file_picks,'Value',[]);
  1347. else
  1348. set(pickslist,'String',file_picks,'Value',[]);
  1349. end
  1350. set([removebut,moveupbut,movedownbut],'Enable','off');
  1351. end
  1352. function sort_type(h,evt,cb) %#ok<INUSL>
  1353. if sort_state(cb)
  1354. sort_state(cb) = -sort_state(cb);
  1355. last_sort_state(cb) = sort_state(cb);
  1356. else
  1357. sort_state = zeros(1,3);
  1358. sort_state(cb) = last_sort_state(cb);
  1359. end
  1360. set(sort_cb,{'CData'},tri_icon(sort_state + 2)')
  1361. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1362. @(x)file_sort(x,sort_state));
  1363. filenames = {fdir.name}';
  1364. filenames = annotate_file_names(filenames,fdir,fsdata);
  1365. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1366. if length(path_cell) > 1
  1367. set(up_dir_but','Enable','on')
  1368. else
  1369. set(up_dir_but','Enable','off')
  1370. end
  1371. set(pathbox,'String',current_dir)
  1372. set(navlist,'String',filenames,'Value',[])
  1373. set(addbut,'Enable','off')
  1374. set(openbut,'Enable','off')
  1375. set(fig,'pointer','arrow')
  1376. end
  1377. function dirpopup(varargin)
  1378. value = get(dir_popup,'Value');
  1379. container = path_cell{min(value + 1,length(path_cell))};
  1380. path_cell = path_cell(1:value);
  1381. set(fig,'pointer','watch')
  1382. drawnow
  1383. if ispc && value == 1
  1384. current_dir = '';
  1385. full_filter = filter;
  1386. drives = getdrives(network_volumes);
  1387. num_drives = length(drives);
  1388. temp = tempname;
  1389. mkdir(temp)
  1390. dir_temp = dir(temp);
  1391. rmdir(temp)
  1392. fdir = repmat(dir_temp(1),num_drives,1);
  1393. [fdir.name] = deal(drives{:});
  1394. else
  1395. current_dir = cell2path(path_cell);
  1396. history = update_history(history,current_dir,now,history_size);
  1397. make_history_cm()
  1398. full_filter = fullfile(current_dir,filter);
  1399. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1400. @(x)file_sort(x,sort_state));
  1401. end
  1402. filenames = {fdir.name}';
  1403. selected = find(strcmp(filenames,container));
  1404. filenames = annotate_file_names(filenames,fdir,fsdata);
  1405. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1406. if length(path_cell) > 1
  1407. set(up_dir_but','Enable','on')
  1408. else
  1409. set(up_dir_but','Enable','off')
  1410. end
  1411. set(pathbox,'String',current_dir)
  1412. set(navlist,'String',filenames,'Value',selected)
  1413. set(addbut,'Enable','off')
  1414. set(fig,'pointer','arrow')
  1415. end
  1416. function dir_up_one(varargin)
  1417. value = length(path_cell) - 1;
  1418. container = path_cell{value + 1};
  1419. path_cell = path_cell(1:value);
  1420. set(fig,'pointer','watch')
  1421. drawnow
  1422. if ispc && value == 1
  1423. current_dir = '';
  1424. full_filter = filter;
  1425. drives = getdrives(network_volumes);
  1426. num_drives = length(drives);
  1427. temp = tempname;
  1428. mkdir(temp)
  1429. dir_temp = dir(temp);
  1430. rmdir(temp)
  1431. fdir = repmat(dir_temp(1),num_drives,1);
  1432. [fdir.name] = deal(drives{:});
  1433. else
  1434. current_dir = cell2path(path_cell);
  1435. history = update_history(history,current_dir,now,history_size);
  1436. make_history_cm()
  1437. full_filter = fullfile(current_dir,filter);
  1438. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1439. @(x)file_sort(x,sort_state));
  1440. end
  1441. filenames = {fdir.name}';
  1442. selected = find(strcmp(filenames,container));
  1443. filenames = annotate_file_names(filenames,fdir,fsdata);
  1444. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1445. if length(path_cell) > 1
  1446. set(up_dir_but','Enable','on')
  1447. else
  1448. set(up_dir_but','Enable','off')
  1449. end
  1450. set(pathbox,'String',current_dir)
  1451. set(navlist,'String',filenames,'Value',selected)
  1452. set(addbut,'Enable','off')
  1453. set(fig,'pointer','arrow')
  1454. end
  1455. function change_path(varargin)
  1456. set(fig,'pointer','watch')
  1457. drawnow
  1458. proposed_path = get(pathbox,'String');
  1459. % Process any folders named '..'.
  1460. proposed_path_cell = path2cell(proposed_path);
  1461. ddots = strcmp(proposed_path_cell,'..');
  1462. ddots(find(ddots) - 1) = true;
  1463. proposed_path_cell(ddots) = [];
  1464. proposed_path = cell2path(proposed_path_cell);
  1465. % Check for existance of folder.
  1466. if ~exist(proposed_path,'dir')
  1467. set(fig,'pointer','arrow')
  1468. uiwait(errordlg(['Folder "',proposed_path,...
  1469. '" does not exist.'],'','modal'))
  1470. return
  1471. end
  1472. current_dir = proposed_path;
  1473. history = update_history(history,current_dir,now,history_size);
  1474. make_history_cm()
  1475. full_filter = fullfile(current_dir,filter);
  1476. [path_cell,new_network_vol] = path2cell(current_dir);
  1477. if exist(new_network_vol,'dir')
  1478. network_volumes = unique([network_volumes,{new_network_vol}]);
  1479. end
  1480. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1481. @(x)file_sort(x,sort_state));
  1482. filenames = {fdir.name}';
  1483. filenames = annotate_file_names(filenames,fdir,fsdata);
  1484. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1485. if length(path_cell) > 1
  1486. set(up_dir_but','Enable','on')
  1487. else
  1488. set(up_dir_but','Enable','off')
  1489. end
  1490. set(pathbox,'String',current_dir)
  1491. set(navlist,'String',filenames,'Value',[])
  1492. set(addbut,'Enable','off')
  1493. set(openbut,'Enable','off')
  1494. set(fig,'pointer','arrow')
  1495. end
  1496. function showfullpath(varargin)
  1497. show_full_path = get(viewfullpath,'Value');
  1498. if show_full_path
  1499. set(pickslist,'String',full_file_picks)
  1500. else
  1501. set(pickslist,'String',file_picks)
  1502. end
  1503. end
  1504. function removedupes(varargin)
  1505. nodupes = get(remove_dupes,'Value');
  1506. if nodupes
  1507. num_picks = length(full_file_picks);
  1508. [unused,rev_order] = unique(full_file_picks(end:-1:1)); %#ok<SETNU>
  1509. order = sort(num_picks + 1 - rev_order);
  1510. full_file_picks = full_file_picks(order);
  1511. file_picks = file_picks(order);
  1512. dir_picks = dir_picks(order);
  1513. if show_full_path
  1514. set(pickslist,'String',full_file_picks,'Value',[])
  1515. else
  1516. set(pickslist,'String',file_picks,'Value',[])
  1517. end
  1518. set([removebut,moveupbut,movedownbut],'Enable','off')
  1519. end
  1520. end
  1521. function moveup(varargin)
  1522. value = get(pickslist,'Value');
  1523. set(removebut,'Enable','on')
  1524. n = length(file_picks);
  1525. omega = 1:n;
  1526. index = zeros(1,n);
  1527. index(value - 1) = omega(value);
  1528. index(setdiff(omega,value - 1)) = omega(setdiff(omega,value));
  1529. file_picks = file_picks(index);
  1530. full_file_picks = full_file_picks(index);
  1531. dir_picks = dir_picks(index);
  1532. value = value - 1;
  1533. if show_full_path
  1534. set(pickslist,'String',full_file_picks,'Value',value)
  1535. else
  1536. set(pickslist,'String',file_picks,'Value',value)
  1537. end
  1538. if min(value) == 1
  1539. set(moveupbut,'Enable','off')
  1540. end
  1541. set(movedownbut,'Enable','on')
  1542. end
  1543. function movedown(varargin)
  1544. value = get(pickslist,'Value');
  1545. set(removebut,'Enable','on')
  1546. n = length(file_picks);
  1547. omega = 1:n;
  1548. index = zeros(1,n);
  1549. index(value + 1) = omega(value);
  1550. index(setdiff(omega,value + 1)) = omega(setdiff(omega,value));
  1551. file_picks = file_picks(index);
  1552. full_file_picks = full_file_picks(index);
  1553. dir_picks = dir_picks(index);
  1554. value = value + 1;
  1555. if show_full_path
  1556. set(pickslist,'String',full_file_picks,'Value',value)
  1557. else
  1558. set(pickslist,'String',file_picks,'Value',value)
  1559. end
  1560. if max(value) == n
  1561. set(movedownbut,'Enable','off')
  1562. end
  1563. set(moveupbut,'Enable','on')
  1564. end
  1565. function togglefilter(varargin)
  1566. set(fig,'pointer','watch')
  1567. drawnow
  1568. value = get(showallfiles,'Value');
  1569. if value
  1570. filter = '*';
  1571. re_filter = '';
  1572. set([filter_ed,refilter_ed],'Enable','off')
  1573. else
  1574. filter = get(filter_ed,'String');
  1575. re_filter = get(refilter_ed,'String');
  1576. set([filter_ed,refilter_ed],'Enable','on')
  1577. end
  1578. full_filter = fullfile(current_dir,filter);
  1579. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1580. @(x)file_sort(x,sort_state));
  1581. filenames = {fdir.name}';
  1582. filenames = annotate_file_names(filenames,fdir,fsdata);
  1583. set(navlist,'String',filenames,'Value',[])
  1584. set(addbut,'Enable','off')
  1585. set(fig,'pointer','arrow')
  1586. end
  1587. function toggle_refiltdirs(varargin)
  1588. set(fig,'pointer','watch')
  1589. drawnow
  1590. value = get(refilterdirs,'Value');
  1591. prop.redirs = value;
  1592. full_filter = fullfile(current_dir,filter);
  1593. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1594. @(x)file_sort(x,sort_state));
  1595. filenames = {fdir.name}';
  1596. filenames = annotate_file_names(filenames,fdir,fsdata);
  1597. set(navlist,'String',filenames,'Value',[])
  1598. set(addbut,'Enable','off')
  1599. set(fig,'pointer','arrow')
  1600. end
  1601. function setfilspec(varargin)
  1602. set(fig,'pointer','watch')
  1603. drawnow
  1604. filter = get(filter_ed,'String');
  1605. if isempty(filter)
  1606. filter = '*';
  1607. set(filter_ed,'String',filter)
  1608. end
  1609. % Process file spec if a subdirectory was included.
  1610. [p,f,e] = fileparts(filter);
  1611. if ~isempty(p)
  1612. newpath = fullfile(current_dir,p,'');
  1613. set(pathbox,'String',newpath)
  1614. filter = [f,e];
  1615. if isempty(filter)
  1616. filter = '*';
  1617. end
  1618. set(filter_ed,'String',filter)
  1619. change_path();
  1620. end
  1621. full_filter = fullfile(current_dir,filter);
  1622. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1623. @(x)file_sort(x,sort_state));
  1624. filenames = {fdir.name}';
  1625. filenames = annotate_file_names(filenames,fdir,fsdata);
  1626. set(navlist,'String',filenames,'Value',[])
  1627. set(addbut,'Enable','off')
  1628. set(fig,'pointer','arrow')
  1629. end
  1630. function setrefilter(varargin)
  1631. set(fig,'pointer','watch')
  1632. drawnow
  1633. re_filter = get(refilter_ed,'String');
  1634. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1635. @(x)file_sort(x,sort_state));
  1636. filenames = {fdir.name}';
  1637. filenames = annotate_file_names(filenames,fdir,fsdata);
  1638. set(navlist,'String',filenames,'Value',[])
  1639. set(addbut,'Enable','off')
  1640. set(fig,'pointer','arrow')
  1641. end
  1642. function filter_type_callback(varargin)
  1643. type_value = get(type_popup,'Value');
  1644. set(filter_ed,'String',prop.type{type_value,1})
  1645. setfilspec()
  1646. end
  1647. function done(varargin)
  1648. % Optional shortcut: click on a file and press 'Done'.
  1649. % if isempty(full_file_picks) && strcmp(get(addbut,'Enable'),'on')
  1650. % add();
  1651. % end
  1652. numfiles = length(full_file_picks);
  1653. if ~isempty(prop.numfiles)
  1654. if numfiles < prop.numfiles(1)
  1655. msg = {'Too few items selected.',numstr};
  1656. uiwait(errordlg(msg,'','modal'))
  1657. return
  1658. elseif numfiles > prop.numfiles(end)
  1659. msg = {'Too many items selected.',numstr};
  1660. uiwait(errordlg(msg,'','modal'))
  1661. return
  1662. end
  1663. end
  1664. fig_pos = get(fig,'Position');
  1665. delete(fig)
  1666. end
  1667. function cancel(varargin)
  1668. prop.output = 'cancel';
  1669. fig_pos = get(fig,'Position');
  1670. delete(fig)
  1671. end
  1672. function history_cb(varargin)
  1673. set(fig,'pointer','watch')
  1674. drawnow
  1675. current_dir = history(varargin{3}).name;
  1676. history = update_history(history,current_dir,now,history_size);
  1677. make_history_cm()
  1678. full_filter = fullfile(current_dir,filter);
  1679. path_cell = path2cell(current_dir);
  1680. fdir = filtered_dir(full_filter,re_filter,prop.redirs,...
  1681. @(x)file_sort(x,sort_state));
  1682. filenames = {fdir.name}';
  1683. filenames = annotate_file_names(filenames,fdir,fsdata);
  1684. set(dir_popup,'String',path_cell,'Value',length(path_cell))
  1685. if length(path_cell) > 1
  1686. set(up_dir_but','Enable','on')
  1687. else
  1688. set(up_dir_but','Enable','off')
  1689. end
  1690. set(pathbox,'String',current_dir)
  1691. set(navlist,'ListboxTop',1,'Value',[],'String',filenames)
  1692. set(addbut,'Enable','off')
  1693. set(openbut,'Enable','off')
  1694. set(fig,'pointer','arrow')
  1695. end
  1696. function clear_history(varargin)
  1697. history = update_history(history(1),'',[],history_size);
  1698. make_history_cm()
  1699. end
  1700. function set_history_size(varargin)
  1701. result_cell = inputdlg('Number of Recent Folders:','',1,...
  1702. {sprintf('%g',history_size)});
  1703. if isempty(result_cell)
  1704. return
  1705. end
  1706. result = sscanf(result_cell{1},'%f');
  1707. if isempty(result) || result < 1
  1708. return
  1709. end
  1710. history_size = result;
  1711. history = update_history(history,'',[],history_size);
  1712. make_history_cm()
  1713. setpref('uipickfiles','history_size',history_size)
  1714. end
  1715. function resize(varargin)
  1716. % Get current figure size.
  1717. P = 'Position';
  1718. pos = get(fig,P);
  1719. w = pos(3); % figure width in pixels
  1720. h = pos(4); % figure height in pixels
  1721. % Enforce minimum figure size.
  1722. w = max(w,564);
  1723. h = max(h,443);
  1724. if any(pos(3:4) < [w h])
  1725. pos(3:4) = [w h];
  1726. set(fig,P,pos)
  1727. end
  1728. % Change positions of all uicontrols based on the current figure
  1729. % width and height.
  1730. navw_pckw = round([1 1;-350 250]\[w-140;0]);
  1731. navw = navw_pckw(1);
  1732. pckw = navw_pckw(2);
  1733. navp = [10 10 navw h-174];
  1734. pckp = [w-10-pckw 10 pckw h-174];
  1735. set(navlist,P,navp)
  1736. set(pickslist,P,pckp)
  1737. set(frame1,P,[navw+5 h-234 110 70])
  1738. set(openbut,P,[navw+20 h-194 80 20])
  1739. set(addbut,P,[navw+20 h-224 80 20])
  1740. frame2y = round((h-234 + 110 - 100)/2);
  1741. set(frame2,P,[w-pckw-115 frame2y 110 100])
  1742. set(removebut,P,[w-pckw-100 frame2y+70 80 20])
  1743. set(moveupbut,P,[w-pckw-100 frame2y+40 80 20])
  1744. set(movedownbut,P,[w-pckw-100 frame2y+10 80 20])
  1745. set(done_button,P,[navw+30 80 80 30])
  1746. set(cancel_button,P,[navw+30 30 80 30])
  1747. set(sort_cb(1),P,[15 h-163 70 15])
  1748. set(sort_cb(2),P,[85 h-163 70 15])
  1749. set(sort_cb(3),P,[155 h-163 70 15])
  1750. set(dir_popup,P,[10 h-144 navw-25 20])
  1751. set(up_dir_but,P,[navw-10 h-144 20 20])
  1752. set(pathbox,P,[10 h-119 navw 26])
  1753. set(label1,P,[10 h-93 navw 16])
  1754. set(viewfullpath,P,[pckp(1) h-159 230 20])
  1755. set(remove_dupes,P,[pckp(1) h-134 280 20])
  1756. set(recall_button,P,[w-75 h-159 65 20])
  1757. set(label4,P,[w-10-pckw h-89 pckw 20])
  1758. set(num_files_warn,P,[w-10-pckw h-109 pckw 16])
  1759. set(label2,P,[10 h-18 80 17])
  1760. set(label3,P,[100 h-18 160 17])
  1761. set(showallfiles,P,[270 h-42 110 20])
  1762. set(refilterdirs,P,[270 h-64 100 20])
  1763. set(filter_ed,P,[10 h-44 80 26])
  1764. set(refilter_ed,P,[100 h-44 160 26])
  1765. set(type_popup,P,[10 h-72 250 20])
  1766. end
  1767. function reset_figure_size(varargin)
  1768. if strcmp(get(fig,'SelectionType'),'open')
  1769. root_units = get(0,'units');
  1770. screen_size = get(0,'ScreenSize');
  1771. set(0,'Units',root_units)
  1772. hw = [740 494];
  1773. pos = [round((screen_size(3:4) - hw - [0 26])/2),hw];
  1774. set(fig,'Position',pos)
  1775. resize()
  1776. end
  1777. end
  1778. % ------------------ Other nested functions ------------------
  1779. function make_history_cm
  1780. % Make context menu for history.
  1781. if ~isempty(hist_menus)
  1782. delete(hist_menus)
  1783. end
  1784. num_hist = length(history);
  1785. hist_menus = zeros(1,num_hist+2);
  1786. for i = 1:num_hist
  1787. hist_menus(i) = uimenu(hist_cm,'Label',history(i).name,...
  1788. 'Callback',{@history_cb,i});
  1789. end
  1790. hist_menus(num_hist+1) = uimenu(hist_cm,...
  1791. 'Label','Clear Menu',...
  1792. 'Separator','on',...
  1793. 'Callback',@clear_history);
  1794. hist_menus(num_hist+2) = uimenu(hist_cm,'Label',...
  1795. sprintf('Set Number of Recent Folders (%d) ...',history_size),...
  1796. 'Callback',@set_history_size);
  1797. end
  1798. end
  1799. % -------------------- Subfunctions --------------------
  1800. function [c,network_vol] = path2cell(p)
  1801. % Turns a path string into a cell array of path elements.
  1802. if ispc
  1803. p = strrep(p,'/','\');
  1804. c1 = regexp(p,'(^\\\\[^\\]+\\[^\\]+)|(^[A-Za-z]+:)|[^\\]+','match');
  1805. vol = c1{1};
  1806. c = [{'My Computer'};c1(:)];
  1807. if strncmp(vol,'\\',2)
  1808. network_vol = vol;
  1809. else
  1810. network_vol = '';
  1811. end
  1812. else
  1813. c = textscan(p,'%s','delimiter','/');
  1814. c = [{filesep};c{1}(2:end)];
  1815. network_vol = '';
  1816. end
  1817. end
  1818. % --------------------
  1819. function p = cell2path(c)
  1820. % Turns a cell array of path elements into a path string.
  1821. if ispc
  1822. p = fullfile(c{2:end},'');
  1823. else
  1824. p = fullfile(c{:},'');
  1825. end
  1826. end
  1827. % --------------------
  1828. function d = filtered_dir(full_filter,re_filter,filter_both,sort_fcn)
  1829. % Like dir, but applies filters and sorting.
  1830. p = fileparts(full_filter);
  1831. if isempty(p) && full_filter(1) == '/'
  1832. p = '/';
  1833. end
  1834. if exist(full_filter,'dir')
  1835. dfiles = dir(' ');
  1836. else
  1837. dfiles = dir(full_filter);
  1838. end
  1839. if ~isempty(dfiles)
  1840. dfiles([dfiles.isdir]) = [];
  1841. end
  1842. ddir = dir(p);
  1843. ddir = ddir([ddir.isdir]);
  1844. [unused,index0] = sort(lower({ddir.name})); %#ok<ASGLU>
  1845. ddir = ddir(index0);
  1846. ddir(strcmp({ddir.name},'.') | strcmp({ddir.name},'..')) = [];
  1847. % Additional regular expression filter.
  1848. if nargin > 1 && ~isempty(re_filter)
  1849. if ispc || ismac
  1850. no_match = cellfun('isempty',regexpi({dfiles.name},re_filter));
  1851. else
  1852. no_match = cellfun('isempty',regexp({dfiles.name},re_filter));
  1853. end
  1854. dfiles(no_match) = [];
  1855. end
  1856. if filter_both
  1857. if nargin > 1 && ~isempty(re_filter)
  1858. if ispc || ismac
  1859. no_match = cellfun('isempty',regexpi({ddir.name},re_filter));
  1860. else
  1861. no_match = cellfun('isempty',regexp({ddir.name},re_filter));
  1862. end
  1863. ddir(no_match) = [];
  1864. end
  1865. end
  1866. % Set navigator style:
  1867. % 1 => list all folders before all files, case-insensitive sorting
  1868. % 2 => mix files and folders, case-insensitive sorting
  1869. % 3 => list all folders before all files, case-sensitive sorting
  1870. nav_style = 1;
  1871. switch nav_style
  1872. case 1
  1873. [unused,index1] = sort_fcn(dfiles); %#ok<ASGLU>
  1874. [unused,index2] = sort_fcn(ddir); %#ok<ASGLU>
  1875. d = [ddir(index2);dfiles(index1)];
  1876. case 2
  1877. d = [dfiles;ddir];
  1878. [unused,index] = sort(lower({d.name})); %#ok<ASGLU>
  1879. d = d(index);
  1880. case 3
  1881. [unused,index1] = sort({dfiles.name}); %#ok<ASGLU>
  1882. [unused,index2] = sort({ddir.name}); %#ok<ASGLU>
  1883. d = [ddir(index2);dfiles(index1)];
  1884. end
  1885. end
  1886. % --------------------
  1887. function [files_sorted,index] = file_sort(files,sort_state)
  1888. switch find(sort_state)
  1889. case 1
  1890. [files_sorted,index] = sort(lower({files.name}));
  1891. if sort_state(1) < 0
  1892. files_sorted = files_sorted(end:-1:1);
  1893. index = index(end:-1:1);
  1894. end
  1895. case 2
  1896. if sort_state(2) > 0
  1897. [files_sorted,index] = sort([files.datenum]);
  1898. else
  1899. [files_sorted,index] = sort([files.datenum],'descend');
  1900. end
  1901. case 3
  1902. if sort_state(3) > 0
  1903. [files_sorted,index] = sort([files.bytes]);
  1904. else
  1905. [files_sorted,index] = sort([files.bytes],'descend');
  1906. end
  1907. end
  1908. end
  1909. % --------------------
  1910. function drives = getdrives(other_drives)
  1911. % Returns a cell array of drive names on Windows.
  1912. letters = char('A':'Z');
  1913. num_letters = length(letters);
  1914. drives = cell(1,num_letters);
  1915. for i = 1:num_letters
  1916. if exist([letters(i),':\'],'dir');
  1917. drives{i} = [letters(i),':'];
  1918. end
  1919. end
  1920. drives(cellfun('isempty',drives)) = [];
  1921. if nargin > 0 && iscellstr(other_drives)
  1922. drives = [drives,unique(other_drives)];
  1923. end
  1924. end
  1925. % --------------------
  1926. function filenames = annotate_file_names(filenames,dir_listing,fsdata)
  1927. % Adds a trailing filesep character to folder names and, optionally,
  1928. % prepends a folder icon or bullet symbol.
  1929. for i = 1:length(filenames)
  1930. if dir_listing(i).isdir
  1931. filenames{i} = sprintf('%s%s%s%s',fsdata.pre,filenames{i},...
  1932. fsdata.filesep,fsdata.post);
  1933. end
  1934. end
  1935. end
  1936. % --------------------
  1937. function history = update_history(history,current_dir,time,history_size)
  1938. if ~isempty(current_dir)
  1939. % Insert or move current_dir to the top of the history.
  1940. % If current_dir already appears in the history list, delete it.
  1941. match = strcmp({history.name},current_dir);
  1942. history(match) = [];
  1943. % Prepend history with (current_dir,time).
  1944. history = [struct('name',current_dir,'time',time),history];
  1945. end
  1946. % Trim history to keep at most <history_size> newest entries.
  1947. history = history(1:min(history_size,end));
  1948. end
  1949. % --------------------
  1950. function success = generate_folder_icon(icon_path)
  1951. % Black = 1, manila color = 2, transparent = 3.
  1952. im = [ ...
  1953. 3 3 3 1 1 1 1 3 3 3 3 3;
  1954. 3 3 1 2 2 2 2 1 3 3 3 3;
  1955. 3 1 1 1 1 1 1 1 1 1 1 3;
  1956. 1 2 2 2 2 2 2 2 2 2 2 1;
  1957. 1 2 2 2 2 2 2 2 2 2 2 1;
  1958. 1 2 2 2 2 2 2 2 2 2 2 1;
  1959. 1 2 2 2 2 2 2 2 2 2 2 1;
  1960. 1 2 2 2 2 2 2 2 2 2 2 1;
  1961. 1 2 2 2 2 2 2 2 2 2 2 1;
  1962. 1 1 1 1 1 1 1 1 1 1 1 1];
  1963. cmap = [0 0 0;255 220 130;255 255 255]/255;
  1964. fid = fopen(icon_path,'w');
  1965. if fid > 0
  1966. fclose(fid);
  1967. imwrite(im,cmap,icon_path,'Transparency',[1 1 0])
  1968. end
  1969. success = exist(icon_path,'file');
  1970. end
  1971. % --------------------
  1972. function fsdata = set_folder_style(folder_style_pref)
  1973. % Set style to preference.
  1974. fsdata.style = folder_style_pref;
  1975. % If style = 1, check to make sure icon image file exists. If it doesn't,
  1976. % try to create it. If that fails set style = 2.
  1977. if fsdata.style == 1
  1978. icon_path = fullfile(prefdir,'uipickfiles_folder_icon.png');
  1979. if ~exist(icon_path,'file')
  1980. success = generate_folder_icon(icon_path);
  1981. if ~success
  1982. fsdata.style = 2;
  1983. end
  1984. end
  1985. end
  1986. % Set pre and post fields.
  1987. if fsdata.style == 1
  1988. icon_url = ['file://localhost/',...
  1989. strrep(strrep(icon_path,':','|'),'\','/')];
  1990. fsdata.pre = sprintf('<html><img src="%s">&nbsp;',icon_url);
  1991. fsdata.post = '</html>';
  1992. elseif fsdata.style == 2
  1993. fsdata.pre = '<html><b>&#8226;</b>&nbsp;';
  1994. fsdata.post = '</html>';
  1995. elseif fsdata.style == 3
  1996. fsdata.pre = '';
  1997. fsdata.post = '';
  1998. end
  1999. fsdata.filesep = filesep;
  2000. end
  2001. % --------------------
  2002. function prop = parsepropval(prop,varargin)
  2003. % Parse property/value pairs and return a structure.
  2004. properties = fieldnames(prop);
  2005. arg_index = 1;
  2006. while arg_index <= length(varargin)
  2007. arg = varargin{arg_index};
  2008. if ischar(arg)
  2009. prop_index = match_property(arg,properties);
  2010. prop.(properties{prop_index}) = varargin{arg_index + 1};
  2011. arg_index = arg_index + 2;
  2012. elseif isstruct(arg)
  2013. arg_fn = fieldnames(arg);
  2014. for i = 1:length(arg_fn)
  2015. prop_index = match_property(arg_fn{i},properties);
  2016. prop.(properties{prop_index}) = arg.(arg_fn{i});
  2017. end
  2018. arg_index = arg_index + 1;
  2019. else
  2020. error(['Properties must be specified by property/value pairs',...
  2021. ' or structures.'])
  2022. end
  2023. end
  2024. end
  2025. % --------------------
  2026. function prop_index = match_property(arg,properties)
  2027. % Utility function for parsepropval.
  2028. prop_index = find(strcmpi(arg,properties));
  2029. if isempty(prop_index)
  2030. prop_index = find(strncmpi(arg,properties,length(arg)));
  2031. end
  2032. if length(prop_index) ~= 1
  2033. error('Property ''%s'' does not exist or is ambiguous.',arg)
  2034. end
  2035. end
  2036. function percent = parfor_progress(N)
  2037. %PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor.
  2038. % PARFOR_PROGRESS works by creating a file called parfor_progress.txt in
  2039. % your working directory, and then keeping track of the parfor loop's
  2040. % progress within that file. This workaround is necessary because parfor
  2041. % workers cannot communicate with one another so there is no simple way
  2042. % to know which iterations have finished and which haven't.
  2043. %
  2044. % PARFOR_PROGRESS(N) initializes the progress monitor for a set of N
  2045. % upcoming calculations.
  2046. %
  2047. % PARFOR_PROGRESS updates the progress inside your parfor loop and
  2048. % displays an updated progress bar.
  2049. %
  2050. % PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress
  2051. % bar.
  2052. %
  2053. % To suppress output from any of these functions, just ask for a return
  2054. % variable from the function calls, like PERCENT = PARFOR_PROGRESS which
  2055. % returns the percentage of completion.
  2056. %
  2057. % Example:
  2058. %
  2059. % N = 100;
  2060. % parfor_progress(N);
  2061. % parfor i=1:N
  2062. % pause(rand); % Replace with real code
  2063. % parfor_progress;
  2064. % end
  2065. % parfor_progress(0);
  2066. %
  2067. % See also PARFOR.
  2068. % By Jeremy Scheff - [email hidden] - http://www.jeremyscheff.com/
  2069. narginchk(0, 1);
  2070. if nargin < 1
  2071. N = -1;
  2072. end
  2073. percent = 0;
  2074. w = 50; % Width of progress bar
  2075. if N > 0
  2076. f = fopen('parfor_progress.txt', 'w');
  2077. if f<0
  2078. error('Do you have write permissions for %s?', pwd);
  2079. end
  2080. fprintf(f, '%d\n', N); % Save N at the top of progress.txt
  2081. fclose(f);
  2082. if nargout == 0
  2083. disp([' 0%[>', repmat(' ', 1, w), ']']);
  2084. end
  2085. elseif N == 0
  2086. delete('parfor_progress.txt');
  2087. percent = 100;
  2088. if nargout == 0
  2089. disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']);
  2090. end
  2091. else
  2092. if ~exist('parfor_progress.txt', 'file')
  2093. error('parfor_progress.txt not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize parfor_progress.txt.');
  2094. end
  2095. f = fopen('parfor_progress.txt', 'a');
  2096. fprintf(f, '1\n');
  2097. fclose(f);
  2098. f = fopen('parfor_progress.txt', 'r');
  2099. progress = fscanf(f, '%d');
  2100. fclose(f);
  2101. percent = (length(progress)-1)/progress(1)*100;
  2102. if nargout == 0
  2103. perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentage
  2104. disp([repmat(char(8), 1, (w+9)), char(10), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']);
  2105. end
  2106. end
  2107. end

MakeTheMAPMap.m at commit ee4e50d, no license · at the source

Overview

Authors: Andrew H. Miller1,2,3, Yeng Yang1, Natalie Schmidt1, Jaffna Mathiaparanam1, Mark E. Berres4, Mary C. Halloran1,2
  1. Department of Integrative Biology, University of Wisconsin-Madison, Madison, WI 53706, USA
  2. Department of Neuroscience, University of Wisconsin-Madison, Madison, WI 53706, USA
  3. Neuroscience Training Program, University of Wisconsin-Madison, Madison, WI 53706, USA
  4. Biotechnology Center, University of Wisconsin-Madison, Madison, WI 53706, USA
Institutions: University of Wisconsin–Madison (United States)
Journal: Disease models & mechanisms, volume 19, issue 3, article dmm052509
Dates: received 3 June 2025; accepted 13 January 2026; published online 12 March 2026; in print March 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1242/dmm.052509 · PMID 41582719 · PMCID PMC13035064 · OpenAlex W7125700144
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: zebrafish (organism), cellular / molecular (subfield)
Methods: Connectivity, Statistics, Preprocessing, fMRI & imaging
Keywords: Neurofibromatosis, Habituation, cxcr4, cAMP, Zebrafish
MeSH: Habituation, Psychophysiologic*, Learning*, Neurofibromatosis 1*, Receptors, CXCR4*, Signal Transduction*, Zebrafish*, Zebrafish Proteins*, Animals, Benzylamines, Brain, Cyclams, Cyclic AMP, Cyclic AMP-Dependent Protein Kinases, Disease Models, Animal, Extracellular Signal-Regulated MAP Kinases, Larva, Mutation, Neurofibromin 1, raf Kinases, ras Proteins (* major topic)
Topic: Neurofibromatosis and Schwannoma Cases (Neurology, Medicine), according to OpenAlex
Funding: NIH (T32GM007507, R56NS132890, 1R01NS086934); DOD (W81XWH-16-1-0091); University of Wisconsin
Citations: not cited yet (Europe PMC); 97 references in the paper
Research resources: Gene Expression Center RRID:SCR_017757, DNA Sequencing Facility RRID:SCR_017759, Bioinformatics Resource Center RRID:SCR_017799

Abstract

Neurofibromatosis type 1 (NF1) is a neurogenetic disorder caused by loss-of-function mutations in the gene neurofibromin 1 (NF1). NF1 encodes neurofibromin, a multifunctional tumor-suppressing protein that regulates Ras, cAMP and dopamine signaling. NF1 predisposes patients to a wide range of symptoms, including peripheral nerve tumors, brain tumors and cognitive dysfunction. Despite considerable work using animal models to investigate the role of neurofibromin in behavior, translating research into treatment for NF1-associated cognitive dysfunction has not yet been successful. Here, we provide evidence that Cxcr4 chemokine receptor signaling is a regulator of habituation learning and modulator of cAMP-PKA signaling in nf1 mutant larval zebrafish. Combining a small-molecule drug screen and RNAseq analysis, we show that cxcr4b expression is increased in nf1 mutants and that pharmacological inhibition of Cxcr4 with AMD3100 (plerixafor) improves habituation learning. We further demonstrate that plerixafor activates cAMP-PKA pathway signaling but has limited effects on Ras-Raf-MEK-ERK pathway signaling in the nf1 mutant brain. CXCR4 has previously been identified as a potential therapeutic target for neurofibromin-deficient tumorigenesis. Our results suggest that Cxcr4 signaling also regulates neurofibromin-dependent cognitive function.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 4 matches between paragraphs and lines of code.

zebrafishexplorer.zib.de/home

License: none: the authors keep all their rights
State: unreachable at the last attempt, verified on 30 September 2026
Evidence: found in the paper
Software Heritage: not checked
Found in: the text, “Immunohistochemistry and confocal imaging”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: unreachable at the last attempt
  • 30 September 2026: unreachable at the last attempt

owenrandlett/Z-Brain

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: ee4e50de635daedbc3c5ca0b89ff82d313dc9dce, 11 April 2025
Languages: MATLAB (3), Python (3)
Size: 12 files, 6 scripts
Software Heritage: not archived
Found in: the end of the paper
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Matplotlib (3 files), NumPy (3 files), scikit-image (3 files), SciPy (3 files), Image Processing Toolbox (2 files), Pillow (2 files), Parallel Computing Toolbox (1 file), Statistics and Machine Learning Toolbox (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
7 files

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 6 scripts, each with its path and the digest of its content;
  • 4 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 6 authors, 5 keywords, 20 MeSH terms, 3 funders, 96 references, 3 RRIDs.

Cite

This paper

Miller, A. H., Yang, Y., Schmidt, N., Mathiaparanam, J., Berres, M. E., & Halloran, M. C. (2026). Inhibition of Cxcr4 chemokine receptor signaling improves habituation learning in a zebrafish model of neurofibromatosis. Disease models & mechanisms, 19(3), dmm052509. https://doi.org/10.1242/dmm.052509

BibTeX

@article{miller2026inhibition,
author = {Miller, Andrew H. and Yang, Yeng and Schmidt, Natalie and Mathiaparanam, Jaffna and Berres, Mark E. and Halloran, Mary C.},
title = {{Inhibition of Cxcr4 chemokine receptor signaling improves habituation learning in a zebrafish model of neurofibromatosis}},
journal = {Disease models \& mechanisms},
year = {2026},
month = mar,
volume = {19},
number = {3},
pages = {dmm052509},
publisher = {Company of Biologists},
issn = {1754-8403},
doi = {10.1242/dmm.052509},
url = {https://doi.org/10.1242/dmm.052509},
pmid = {41582719},
pmcid = {PMC13035064}
}

RIS

TY - JOUR
AU - Miller, Andrew H.
AU - Yang, Yeng
AU - Schmidt, Natalie
AU - Mathiaparanam, Jaffna
AU - Berres, Mark E.
AU - Halloran, Mary C.
TI - Inhibition of Cxcr4 chemokine receptor signaling improves habituation learning in a zebrafish model of neurofibromatosis
T2 - Disease models & mechanisms
J2 - Dis Model Mech
PY - 2026
DA - 2026/03/12
VL - 19
IS - 3
SP - dmm052509
SN - 1754-8403
PB - Company of Biologists
DO - 10.1242/dmm.052509
UR - https://doi.org/10.1242/dmm.052509
LA - en
ER -

CSL-JSON

{
"id": "10.1242/dmm.052509",
"type": "article-journal",
"title": "Inhibition of Cxcr4 chemokine receptor signaling improves habituation learning in a zebrafish model of neurofibromatosis",
"container-title": "Disease models & mechanisms",
"author": [
{
"family": "Miller",
"given": "Andrew H."
},
{
"family": "Yang",
"given": "Yeng"
},
{
"family": "Schmidt",
"given": "Natalie"
},
{
"family": "Mathiaparanam",
"given": "Jaffna"
},
{
"family": "Berres",
"given": "Mark E."
},
{
"family": "Halloran",
"given": "Mary C."
}
],
"container-title-short": "Dis Model Mech",
"volume": "19",
"issue": "3",
"page": "dmm052509",
"DOI": "10.1242/dmm.052509",
"PMID": "41582719",
"PMCID": "PMC13035064",
"ISSN": "1754-8403",
"publisher": "Company of Biologists",
"URL": "https://doi.org/10.1242/dmm.052509",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
12
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1093/braincomms/fcag323 [code]
Induced epileptic seizures in larval zebrafish reveal a synaptic modulation associated with the post-ictal state.
Journal: Brain communications
In common: Parallel Computing Toolbox, Image Processing Toolbox, zebrafish, cellular / molecular, 4 references
[2] doi:10.1016/j.isci.2026.116769 [code]
Graph-based modeling of optical system enables adaptive optics on dynamic samples with self-calibration.
Journal: iScience
In common: Parallel Computing Toolbox, scikit-image, Pillow, 4 other tools, 1 reference
[3] doi:10.1126/sciadv.aee9298 [code]
Synaptic zinc plasticity shapes adaptive and maladaptive cortical plasticity following cochlear injury.
Journal: Science advances
In common: Parallel Computing Toolbox, scikit-image, Pillow, 5 other tools, cellular / molecular
[4] doi:10.1038/s41467-026-75347-4 [code]
Sleep reveals dynamics integrating and segregating movement and stimulus representations in V1.
Journal: Nature communications
In common: Parallel Computing Toolbox, scikit-image, Pillow, 5 other tools
[5] doi:10.1162/imag.a.1262 [code]
Frame-wise multi-echo distortion correction for superior functional MRI.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Parallel Computing Toolbox, scikit-image, Pillow, 5 other tools
[6] doi:10.1038/s41467-026-76242-8 [code]
Whole-brain, all-optical interrogation of neuronal dynamics underlying gut and vascular interoception in zebrafish.
Journal: Nature communications
In common: Parallel Computing Toolbox, scikit-image, Image Processing Toolbox, 3 other tools, zebrafish, 1 reference
[7] doi:10.1038/s41380-026-03609-0 [code]
Gut microbiome alterations are sex-dependently associated with brain abnormalities in a mouse model of Neurofibromatosis type I.
Journal: Molecular psychiatry
In common: 5 references
[8] doi:10.1038/s41467-026-71458-0 [code]
Early differential impact of MeCP2 mutations on functional networks in Rett syndrome patient-derived human cortical organoids.
Journal: Nature communications
In common: Parallel Computing Toolbox, scikit-image, Image Processing Toolbox, 4 other tools, cellular / molecular
[9] doi:10.1126/sciadv.adv3770 [code]
Evolution of a central dopamine circuit underlies adaptation of a light-evoked sensorimotor response in the blind cavefish.
Journal: Science advances
In common: scikit-image, Pillow, SciPy, 2 other tools, 2 references
[10] doi:10.1038/s41593-026-02357-2 [code]
Experience reorganizes content-specific memory traces in macaques.
Journal: Nature neuroscience
In common: Parallel Computing Toolbox, scikit-image, Image Processing Toolbox, 4 other tools

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.