1+ % ----------------------------------------------------------------------- %
2+ % OPENEP/batchImport is a template script to automate the import of
3+ % datasets into OpenEP data format. This batchImport script requires a
4+ % number of assumptions to be true in order to function.
5+ %
6+ % 1. Cases should be named using a study number (e.g. 001) and compressed
7+ % into folders named that study number.
8+ % 2. An Excell information spreadsheet should be provided which
9+ % identifies the map to import and should contain two columns where the
10+ % first contains the study number and the second the number of points per
11+ % map.
12+ %
13+ % As currently configured, the script assumes that datasets are stored on
14+ % an external hard drive, but copies dataset zip files to the local machine
15+ % hard drive prior to unzipping, which is usually fastest.
16+ %
17+ % After importing into OpenEP dataformat, intermediate files which can
18+ % number in the 1000s and occupy Gb of space, are removed.
19+ % ----------------------------------------------------------------------- %
20+
21+ % ----------------------------------------------------------------------- %
22+ % Configuration
23+ % testmode copies and unzips files but does not process them
24+ testmode = false ;
25+
26+ % Set up working directories and paths
27+ zip_dir = ' /Volumes/Extreme SSD/openep/openep_carto_export_zips' ;
28+ working_dir = ' /Users/Steven/Desktop/openep_working_dir' ;
29+ info_spreadsheet = ' /Volumes/Extreme SSD/openep/openep_datasheet.xlsx' ;
30+
31+ % Cell array of possible start of names of the study XML file
32+ startStrings = {' CARTO' ' PVI' ' Study' ' 1008' ' PERS' ' AF' ' LA' ' PAF' ' AIAT' };
33+ % ----------------------------------------------------------------------- %
34+
35+ % Load the study dataset Excel file
36+ info = xlsread(info_spreadsheet , ' A:B' );
37+
38+ % Get a list of files in zip_dir
39+ disp(' Getting list of filenames' )
40+ allFiles = nameFiles(zip_dir , ' showhiddenfiles' , false );
41+
42+ % Loop through all the zip files
43+ for i = 1 : numel(allFiles )
44+ disp([' Processing case: ' allFiles{i }]);
45+
46+ % Copy the zip file to the hard drive
47+ sourceFile = [zip_dir filesep() allFiles{i }];
48+ destinationFile = [working_dir filesep() allFiles{i }];
49+ status = copyfile(sourceFile , destinationFile );
50+
51+ % Get the study number
52+ studyNumber = str2double(allFiles{i }(1 : 3 ));
53+
54+ % Unzip the zip file to a folder named studyNumber in working_dir
55+ caseDir = ([working_dir filesep() num2str(studyNumber )]);
56+ unzip(destinationFile , caseDir );
57+
58+ % Locate the carto export xml file
59+ allXmlFiles = nameFiles(caseDir , ' extension' , ' xml' , ' showhiddenfiles' , false );
60+ iF = NaN(size(startStrings ));
61+ for j = 1 : numel(startStrings )
62+ temp = find(strstartcmpi(startStrings{j }, allXmlFiles ));
63+ if ~isempty(temp )
64+ iF(j ) = temp ;
65+ end
66+ end
67+
68+ if nnz(~isnan(iF )) > 1
69+ % Multiple possible files found so the user has to choose which xml file to load
70+ iF(isnan(iF )) = [];
71+ beep()
72+ disp([num2str(numel(iF )) ' possible XML files found:' ])
73+ for j = 1 : numel(iF )
74+ disp([ num2str(j ) ' ' allXmlFiles{iF(j )}]);
75+ end
76+ result = input(' Enter choice: ' );
77+ studyXmlFile = [case_dir filesep() allXmlFiles{iF(result )}];
78+ else % Automatically select the relevant xml file
79+ iF(isnan(iF )) = [];
80+ studyXmlFile = [caseDir filesep() allXmlFiles{iF }];
81+ end
82+
83+ % Check that an XML file has been identified
84+ if ~isfile(studyXmlFile )
85+ error([' RUN_PEPR_EXPERIMENT: Specified XML file - ' studyXmlFile ' - does not exist' ]);
86+ end
87+
88+ % Read the number of points from the spreadsheet
89+ numpts = info(info(: ,1 )==studyNumber ,2 );
90+
91+ % Specify the output directory and filename
92+ outputFile = ([working_dir filesep() [num2str(studyNumber ) ' .mat' ]]);
93+
94+ % Start a timer
95+ tic();
96+
97+ % Run importcarto_mem from the command line
98+ if ~testmode
99+ userdata = importcarto_mem(studyXmlFile ...
100+ , ' maptoread' , numpts ...
101+ , ' refchannel' , ' CS9-CS10' ...
102+ , ' ecgchannel' , ' V1' ...
103+ , ' savefilename' , outputFile ...
104+ );
105+ end
106+
107+ % Stop a timer
108+ elapsedTime = toc();
109+
110+ % Get the size of caseDir and destinationFile
111+ sizeUnZipped = du([' -sh ' caseDir ]);
112+ sizeZipped = du([' -sh ' destinationFile ]);
113+
114+ % Remove the carto files and zip file
115+ deleteFolder(caseDir );
116+ delete(destinationFile );
117+
118+ % Dump the time and filesizes to a text file
119+ fid = fopen([working_dir filesep() [num2str(studyNumber ) ' .data' ]], ' wt' );
120+ fprintf(fid , [num2str(elapsedTime ) ' \n ' ]);
121+ fprintf(fid , [sizeUnZipped ' \n ' ]);
122+ fprintf(fid , [sizeZipped ' \n ' ]);
123+ fclose(fid );
124+
125+ end
0 commit comments