Home > SuperSegger > batch > ReadFileName.m

ReadFileName

PURPOSE ^

ReadFileName : extracts the numbers after t,x,y,z in a string *t*c*xy*z*

SYNOPSIS ^

function nameInfo = ReadFileName( str )

DESCRIPTION ^

 ReadFileName : extracts the numbers after t,x,y,z in a string *t*c*xy*z* 

 INPUT :
       str : String that contains any of the the strings in strD
 OUTPUT :
       nameInfo.
           npos: [4x4 double]
           strD: {'t'  'c'  'xy'  'z'}
           basename: before first found strD, eg. 'tsyfp-p-'
           suffix: after last found number of strD, eg. '.tif'
 npos contains the information for each of the strings in strD
 npos (i,1) is the number after strD(i) in the string
 npos (i,2) is the position of strD(i) in the string
 npos (i,3) is the position of the last number after strD(i) in the string
 npos (i,4) is the length of the numbers after strD(i) in the string
 for example for the string file_t5xy1
 str(1,:) would be : 5, 6 , 7, 1

 superSeggerGui : gui for segmenting images with superSegger. 

 Copyright (C) 2016 Wiggins Lab 
 Written by Paul Wiggins & Stella Stylianidou.
 University of Washington, 2016
 This file is part of SuperSegger.
 
 SuperSegger is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SuperSegger is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function nameInfo = ReadFileName( str )
0002 % ReadFileName : extracts the numbers after t,x,y,z in a string *t*c*xy*z*
0003 %
0004 % INPUT :
0005 %       str : String that contains any of the the strings in strD
0006 % OUTPUT :
0007 %       nameInfo.
0008 %           npos: [4x4 double]
0009 %           strD: {'t'  'c'  'xy'  'z'}
0010 %           basename: before first found strD, eg. 'tsyfp-p-'
0011 %           suffix: after last found number of strD, eg. '.tif'
0012 % npos contains the information for each of the strings in strD
0013 % npos (i,1) is the number after strD(i) in the string
0014 % npos (i,2) is the position of strD(i) in the string
0015 % npos (i,3) is the position of the last number after strD(i) in the string
0016 % npos (i,4) is the length of the numbers after strD(i) in the string
0017 % for example for the string file_t5xy1
0018 % str(1,:) would be : 5, 6 , 7, 1
0019 %
0020 % superSeggerGui : gui for segmenting images with superSegger.
0021 %
0022 % Copyright (C) 2016 Wiggins Lab
0023 % Written by Paul Wiggins & Stella Stylianidou.
0024 % University of Washington, 2016
0025 % This file is part of SuperSegger.
0026 %
0027 % SuperSegger is free software: you can redistribute it and/or modify
0028 % it under the terms of the GNU General Public License as published by
0029 % the Free Software Foundation, either version 3 of the License, or
0030 % (at your option) any later version.
0031 %
0032 % SuperSegger is distributed in the hope that it will be useful,
0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0035 % GNU General Public License for more details.
0036 %
0037 % You should have received a copy of the GNU General Public License
0038 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0039 
0040 
0041 nameInfo = [];
0042 strD = {'t',      'c',      'xy',      'z'};
0043 numD = numel(strD);
0044 npos = zeros(numD,4);
0045 
0046 for i = 1:numD
0047     npos(i,:) = intReadIt( strD{i}, str );
0048 end
0049 
0050 basename = str( 1:min(npos(logical(npos(:,2)),2))-1);
0051 suffix_pos = max(npos(:,3))+1;
0052 
0053 if ~isempty( suffix_pos )
0054     suffix = str(suffix_pos:end);
0055 else
0056     suffix = '';
0057 end
0058 
0059 nameInfo.npos = npos;
0060 nameInfo.strD = strD;
0061 nameInfo.basename = basename;
0062 nameInfo.suffix = suffix;
0063 
0064 end
0065 
0066 
0067 
0068 
0069 function nn = intReadIt( str_search, str );
0070 
0071 ns = numel(str_search);
0072 is_num_mask = ismember( str,'01234567890'); % 1 where there are numbers
0073 pos = max(regexpi(str,[str_search,'[0123456789]'])); % finds position of str_search
0074 
0075 if ~isempty(pos)
0076     pad = min(find( ~is_num_mask(pos+ns:end) ))-1; % find length to next not number
0077     pos = [pos, pos+pad+ns-1, pad];
0078     n = str2num(str(pos(1)+ns:pos(2)));
0079 else
0080     pos = [0,0,0];
0081     n = -1;
0082 end
0083 
0084 nn = [n,pos];
0085 
0086 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005