Skip to content

Commit

Permalink
UPDATE: fromnifti uncompress data into aa rather than into the raw di…
Browse files Browse the repository at this point in the history
…rectory
  • Loading branch information
tiborauer committed Nov 6, 2018
1 parent 247d3dd commit 58556f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
18 changes: 9 additions & 9 deletions aa_modules/aamod_diffusionfromnifti.m
Expand Up @@ -38,10 +38,10 @@
end
end
comp = false;
if strcmp(spm_file(niftifile,'Ext'),'gz'),
if strcmp(spm_file(niftifile,'Ext'),'gz')
comp = true;
gunzip(niftifile);
niftifile = niftifile(1:end-3);
gunzip(niftifile,fullfile(sesspth,'temp'));
niftifile = spm_file(niftifile(1:end-3),'path',fullfile(sesspth,'temp'));
end

% BVals/BVecs
Expand All @@ -59,7 +59,7 @@
for ln=1:3
fprintf(fid,'%.14f ',bvecs(:,ln));
fprintf(fid,'\n');
end;
end
fclose(fid);

% Image
Expand All @@ -73,7 +73,7 @@
V(fileind).n=[1 1];
spm_write_vol(V(fileind),Y);
finalepis=[finalepis fn];
end;
end

% Write out the files
% Now move dummy scans to dummy_scans directory
Expand All @@ -84,7 +84,7 @@
for d=1:numdummies
cmd=['mv ' finalepis{d} ' ' dummypath];
dummylist=strvcat(dummylist,spm_file(finalepis{d},'path','dummy_scans'));
[s w]=aas_shell(cmd);
s=aas_shell(cmd);
if (s)
aas_log(aap,1,sprintf('ERROR:Problem moving dummy scan\nERROR: %s to\nERROR: %s\n',finalepis{d},dummypath));
end
Expand All @@ -98,7 +98,7 @@
finalepis = finalepis{1};
ind = find(finalepis=='-');
sfx = '';
if isempty(ind),
if isempty(ind)
ind = find(finalepis=='.');
sfx = '_4D';
end
Expand All @@ -109,7 +109,7 @@
end

%% Describe outputs
if comp, delete(niftifile); end
if comp, rmdir(fullfile(sesspth,'temp'),'s'); end
aap=aas_desc_outputs(aap,domain,indices,'dummyscans',dummylist);
aap=aas_desc_outputs(aap,domain,indices,'diffusion_data',finalepis);
aap=aas_desc_outputs(aap,domain,indices,'bvals',bvals_fn);
Expand All @@ -119,5 +119,5 @@

otherwise
aas_log(aap,1,sprintf('Unknown task %s',task));
end;
end
end
11 changes: 6 additions & 5 deletions aa_modules/aamod_epifromnifti.m
Expand Up @@ -25,6 +25,9 @@
series = series{sess};

%% Process
sesspth=aas_getsesspath(aap,subj,sess);
aas_makedir(aap,sesspth);

% Files
headerFn ='';
imageFn = series;
Expand All @@ -47,8 +50,8 @@
comp = false;
if any(strcmp(spm_file(niftifile,'Ext'),'gz'))
comp = true;
gunzip(niftifile{1});
niftifile{1} = niftifile{1}(1:end-3);
gunzip(niftifile{1},fullfile(sesspth,'temp'));
niftifile{1} = spm_file(niftifile{1}(1:end-3),'path',fullfile(sesspth,'temp'));
end

% Header
Expand All @@ -73,8 +76,6 @@
finalepis={};
V = spm_vol(niftifile);
if iscell(V), V = cell2mat(V); end
sesspth=aas_getsesspath(aap,subj,sess);
aas_makedir(aap,sesspth);
fle = spm_file(niftifile,'basename');
ext = spm_file(niftifile,'Ext');
for fileind=1:numel(V)
Expand Down Expand Up @@ -139,7 +140,7 @@
spm_file_merge(char({V(numdummies+1:end).fname}),finalepis,0,DICOMHEADERS{1}.volumeTR);
end
% And describe outputs
if comp, delete(niftifile{1}); end
if comp, rmdir(fullfile(sesspth,'temp'),'s'); end
aap=aas_desc_outputs(aap,subj,sess,'epi',finalepis);
aap = aas_desc_outputs(aap,subj,sess,'dummyscans',dummylist);
dcmhdrfn = fullfile(sesspth,'dicom_headers.mat');
Expand Down
6 changes: 3 additions & 3 deletions aa_modules/aamod_fieldmapfromnifti.m
Expand Up @@ -37,8 +37,8 @@
for f = 1:numel(niftifile)
comp = strcmp(spm_file(niftifile{f},'Ext'),'gz');
if comp
gunzip(niftifile{f});
niftifile{f} = niftifile{f}(1:end-3);
gunzip(niftifile{f},fullfile(sesspth,'temp'));
niftifile{1} = spm_file(niftifile{f}(1:end-3),'path',fullfile(sesspth,'temp'));
end

aas_makedir(aap,fullfile(sesspth,sprintf('serie%02d',f)));
Expand All @@ -48,7 +48,7 @@
spm_write_vol(V,Y);
fn{f} = V.fname;

if comp, delete(niftifile{f}); end
if comp, rmdir(fullfile(sesspth,'temp'),'s'); end
end
aap=aas_desc_outputs(aap,'session',[subj sess],'fieldmap',char(fn));

Expand Down
12 changes: 6 additions & 6 deletions aa_modules/aamod_structuralfromnifti.m
Expand Up @@ -38,6 +38,8 @@
end
end

sesspth=fullfile(aas_getsubjpath(aap,subj),aap.directory_conventions.structdirname);
aas_makedir(aap,sesspth);
Ys = 0;
for s = 1:numel(series)
niftifile = series(s).fname;
Expand All @@ -51,20 +53,18 @@
end
end
comp = false;
if strcmp(spm_file(niftifile,'Ext'),'gz'),
if strcmp(spm_file(niftifile,'Ext'),'gz')
comp = true;
gunzip(niftifile);
niftifile = niftifile(1:end-3);
gunzip(niftifile,fullfile(sesspth,'temp'));
niftifile = spm_file(niftifile(1:end-3),'path',fullfile(sesspth,'temp'));
end
sesspth=fullfile(aas_getsubjpath(aap,subj),aap.directory_conventions.structdirname);
aas_makedir(aap,sesspth);

fn(s,:)=spm_file(niftifile,'path',sesspth,'suffix','_0001');
V(s)=spm_vol(niftifile);
Y=spm_read_vols(V(s));
V(s).fname=deblank(fn(s,:));
V(s).n=[1 1];
if comp, delete(niftifile); end
if comp, rmdir(fullfile(sesspth,'temp'),'s'); end

if aap.options.(['autoidentify' stream '_average'])
Ys = Ys + Y/numel(series);
Expand Down

0 comments on commit 58556f7

Please sign in to comment.