#! /bin/bash


Folder_A="/home/study/sct_data/t2andt2s/als1/" 
#for folder_aa in ${Folder_A}/*
#do
Folder_B="/test/t2"
for file_a in ${Folder_A}/*
do  
    path_=$file_a
    cd $path_
    #label_discs t22t2s
    sct_deepseg_sc -i t2.nii.gz -c t2 -qc ~/qc_singleSubj
    sct_deepseg_sc -i t2s.nii.gz -c t2s  -qc ~/qc_singleSubj
    
    sct_register_multimodal -i t2.nii.gz -iseg t2_seg.nii.gz -d t2s.nii.gz -dseg t2s_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,algo=syn,slicewise=1,iter=1,metric=CC -owarp t22t2s/warp_t22t2s.nii.gz -owarpinv t22t2s/warp_t2s2t2.nii.gz -ofolder t22t2s/
    #t2s_seg 2 t2
    sct_apply_transfo -i t2s_seg.nii.gz -d t22t2s/t2s_reg.nii.gz -w t22t2s/warp_t2s2t2.nii.gz -o t2s_seg_t2.nii.gz
    #t2andt2s seg -o t2andt2s_seg.nii.gz
    python3 /home/study/sct_data/seg_mask/seg_add.py --dir $path_
    # Register T2 to PAM50
    sct_label_vertebrae -i t2.nii.gz -s t2andt2s_seg.nii.gz -c t2 -qc ~/qc_singleSubj
    #sct_label_utils -i t2andt2s_seg_labeled.nii.gz -vert-body 4,7 -o t2andt2s_labels_vert.nii.gz

    sct_register_multimodal -i t2andt2s_seg_labeled.nii.gz -d t2s.nii.gz -identity 1 -x nn
    
    sct_process_segmentation -i t2s_seg.nii.gz -vertfile t2andt2s_seg_labeled_reg.nii.gz -vert 4:6 -perlevel 1 -o csa_sc_perlevel.csv
    
    sct_deepseg_gm -i t2s.nii.gz 
    sct_process_segmentation -i t2s_gmseg.nii.gz -vertfile t2andt2s_seg_labeled_reg.nii.gz -vert 4:6 -perlevel 1 -o csa_gm_perlevel.csv
done
#done
