clear all
close all

a1 = dir('*-*');    %list all files with '-' in its name

a2 = {a1.name};     %create matrix with name strings



fid=fopen('createFIOvarywCSV.makefile','w') %create makefile

fprintf(fid,['WORKDIR=/workarea/igilab/data/qayyum/tcga_ov\n'])  %set path

fprintf(fid,'\n\n') %leave blank line

fprintf(fid,'all: ') %all jobs

for jj = 1:length(a2)
    fprintf(fid,'job_%s_crFI job_%s_wCSV ', a2{jj}, a2{jj}) %all jobs
end

fprintf(fid,'\n\n') %leave blank line

for ii = 1:length(a2)
fprintf(fid,'job_%s_crFI:\n', a2{ii}) %job create Featrue Image by patient ID
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_grey.nii.gz %s_labels.nii.gz -copy-transform -o %s_labels.nii.gz\n', a2{ii}, a2{ii}, a2{ii}, a2{ii});    %correct headers
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_grey.nii.gz -orient RAI -o %s_grey.nii.gz\n', a2{ii}, a2{ii}, a2{ii});   %reorient grey images to RAI
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_labels.nii.gz -orient RAI -o %s_labels.nii.gz\n', a2{ii}, a2{ii}, a2{ii}); %reorient label maps to RAI
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_labels.nii.gz  -binarize -o  %s_mask.nii.gz\n', a2{ii}, a2{ii}, a2{ii}); %create mask
fprintf(fid,'\tcd $(WORKDIR)/%s;../createFeatureImagesOvary.sh -d 3 -x %s_mask.nii.gz -l3 -n pre -a %s_grey.nii.gz -f 0x2 -o ./%s_ -r 1 -r 3 -s 2 -b 4\n', a2{ii}, a2{ii}, a2{ii}, a2{ii}); %create feature images
fprintf(fid,'\n\n') %leave blank line
fprintf(fid,'job_%s_wCSV:\n', a2{ii}) %job write CSV of FI by patient ID
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_NORMALIZED.nii.gz %s_mask.nii.gz -lstat > %s_pre_NORMALIZED.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_MEAN_RADIUS_1.nii.gz %s_mask.nii.gz -lstat > %s_pre_MEAN_RADIUS_1.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_SIGMA_RADIUS_1.nii.gz %s_mask.nii.gz -lstat > %s_pre_SIGMA_RADIUS_1.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_SKEWNESS_RADIUS_1.nii.gz %s_mask.nii.gz -lstat > %s_pre_SKEWNESS_RADIUS_1.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ENTROPY_RADIUS_1.nii.gz %s_mask.nii.gz -lstat > %s_pre_ENTROPY_RADIUS_1.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_MEAN_RADIUS_3.nii.gz %s_mask.nii.gz -lstat > %s_pre_MEAN_RADIUS_3.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_SIGMA_RADIUS_3.nii.gz %s_mask.nii.gz -lstat > %s_pre_SIGMA_RADIUS_3.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_SKEWNESS_RADIUS_3.nii.gz %s_mask.nii.gz -lstat > %s_pre_SKEWNESS_RADIUS_3.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ENTROPY_RADIUS_3.nii.gz %s_mask.nii.gz -lstat > %s_pre_ENTROPY_RADIUS_3.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_NORMALIZED_DISTANCE.nii.gz %s_mask.nii.gz -lstat > %s_NORMALIZED_DISTANCE.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_POSTERIORS1.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_POSTERIORS1.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_POSTERIORS2.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_POSTERIORS2.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_POSTERIORS3.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_POSTERIORS3.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_POSTERIORS4.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_POSTERIORS4.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_PHYSICAL_VOLUME.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_PHYSICAL_VOLUME.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_VOLUME_TO_SURFACE_AREA_RATIO.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_VOLUME_TO_SURFACE_AREA_RATIO.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_ECCENTRICITY.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_ECCENTRICITY.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_ELONGATION.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_ELONGATION.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_ATROPOS_GMM_LABEL3_DISTANCE.nii.gz %s_mask.nii.gz -lstat > %s_pre_ATROPOS_GMM_LABEL3_DISTANCE.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\tcd $(WORKDIR)/%s;c3d %s_pre_DIFFERENCE.nii.gz %s_mask.nii.gz -lstat > %s_pre_DIFFERENCE.txt\n', a2{ii}, a2{ii}, a2{ii}, a2{ii})
fprintf(fid,'\n\n') %leave blank line
fprintf(fid,'\n\n') %leave blank line
end

fclose(fid) %close makefile