Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LabNeuroCogDevel/lncdtools
Browse files Browse the repository at this point in the history
  • Loading branch information
WillForan committed Aug 16, 2024
2 parents f73fbca + a7b9f15 commit 96554fe
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 90 deletions.
123 changes: 107 additions & 16 deletions t/tat2.bats
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ x_cmp_y(){
[[ $output =~ nvoxes=4,4 ]]
}

@test roistats_cmd_log {
run tat2 t.nii.gz -output tat2.nii.gz -mask m.nii.gz
3dNotes tat2.nii.gz
3dNotes tat2.nii.gz| grep 3dROIstats
jq < tat2.log.json
jq .roistats_cmds < tat2.log.json |grep 3dROIstats
}

@test json_log {
run tat2 t.nii.gz -output tat2.nii.gz -mask m.nii.gz
[ -r tat2.log.json ]
# for debugging
cat tat2.log.json; jq < tat2.log.json; jq .nt < tat2.log.json

[ $(jq -r '.nt[0]'< tat2.log.json) -eq 3 ]
}

@test json_log_censor {
run tat2 t.nii.gz -output tat2.nii.gz -mask m.nii.gz -censor_rel c.1D
3dNotes tat2.nii.gz
3dNotes tat2.nii.gz| grep c.1D
cat tat2.log.json
jq .censor_files < tat2.log.json |grep c.1D
}



@test cen_multiple {
# censor applies to each input separately
mkdir -p x y out
Expand All @@ -178,15 +205,22 @@ x_cmp_y(){
echo -e "1\n1\n1" > y/c.1D
tat2 {x,y}/t.nii.gz -output mean.nii.gz -censor_rel c.1D -mask m.nii.gz -mean_time -tmp out -noclean

head -n99 out/*/*_volnorm.1D >&2
head -n99 out/*/*_volnorm*.1D >&2
find out/ -iname '*1D' -or -iname '*nii.gz' >&2
# out/tat2star_MfK2/0_volnorm-nzmedian.1D
# out/tat2star_MfK2/tat2_all.nii.gz
# out/tat2star_MfK2/0_keep-2_volnorm-nzmedian_tat2.nii.gz
# out/tat2star_MfK2/1_keep-3_volnorm-nzmedian_tat2.nii.gz
# out/tat2star_MfK2/1_volnorm-nzmedian.1D
#
# 2 in the first
[ -r out/*/0_keep2_tat2.nii.gz ]
[ $(3dinfo -nt out/*/0_keep2_tat2.nii.gz) -eq 2 ]
[ $(grep -cPv '^\s*#' out/*/0_volnorm.1D) -eq 2 ]
[ -r out/*/0_keep-2_volnorm-nzmedian_tat2.nii.gz ]
[ $(3dinfo -nt out/*/0_keep-2_volnorm-nzmedian_tat2.nii.gz) -eq 2 ]
[ $(grep -cPv '^\s*#' out/*/0_volnorm-nzmedian.1D) -eq 2 ]
# 3 in the second
[ -r out/*/1_keep3_tat2.nii.gz ]
[ $(3dinfo -nt out/*/1_keep3_tat2.nii.gz) -eq 3 ]
[ $(grep -cPv '^\s*#' out/*/1_volnorm.1D) -eq 3 ]
[ -r out/*/1_keep-3_volnorm-nzmedian_tat2.nii.gz ]
[ $(3dinfo -nt out/*/1_keep-3_volnorm-nzmedian_tat2.nii.gz) -eq 3 ]
[ $(grep -cPv '^\s*#' out/*/1_volnorm-nzmedian.1D) -eq 3 ]
# tat2_all has all 5 volumes
[ -r out/*/tat2_all.nii.gz ]
[ $(3dinfo -nt out/*/tat2_all.nii.gz) -eq 5 ]
Expand All @@ -199,7 +233,7 @@ x_cmp_y(){
# censor < mean
tat2 t.nii.gz -output mean.nii.gz -mask m.nii.gz -mean_time
tat2 t.nii.gz -output cen.nii.gz -mask m.nii.gz -mean_time -censor_rel c.1D
3dNotes cen.nii.gz |grep -q keep2
3dNotes cen.nii.gz |grep -q keep-2
x_cmp_y cen.nii.gz '<' mean.nii.gz
}

Expand All @@ -209,7 +243,7 @@ x_cmp_y(){
# censor == mean
tat2 t.nii.gz -output mean.nii.gz -mask m.nii.gz -median_time
tat2 t.nii.gz -output cen.nii.gz -mask m.nii.gz -median_time -censor_rel c.1D
3dNotes cen.nii.gz |grep -q keep2
3dNotes cen.nii.gz |grep -q keep-2
x_cmp_y mean.nii.gz = cen.nii.gz
}

Expand All @@ -220,7 +254,7 @@ x_cmp_y(){
(echo 1; cat c.1D) > d.1D # add another value so we know we actually stopped at 2
tat2 t.nii.gz -output cen.nii.gz -mask m.nii.gz -median_time -censor_rel d.1D -maxvols 2
3dNotes cen.nii.gz >&2
3dNotes cen.nii.gz |grep -q lastidx1
3dNotes cen.nii.gz |grep -q lastidx-1
}

@test maxvolstotal_stop w/enough {
Expand Down Expand Up @@ -330,8 +364,8 @@ x_cmp_y(){
# mean: 356.314 cen: 285.714
tat2 t.nii.gz -output mean.nii.gz -mask m.nii.gz -mean_time -inverse
tat2 t.nii.gz -output cen.nii.gz -mask m.nii.gz -mean_time -censor_rel c.1D -inverse
3dNotes cen.nii.gz |grep -q keep2

3dNotes cen.nii.gz >&2
3dNotes cen.nii.gz |grep -q keep-2
x_cmp_y cen.nii.gz '<' mean.nii.gz
}

Expand All @@ -346,16 +380,23 @@ x_cmp_y(){
}

@test zscore {
# zscore:433.012 mean:400
tat2 t.nii.gz -median_time -mean_vol -output mean.nii.gz -mask m.nii.gz
tat2 t.nii.gz -zscore_vol -output zscore.nii.gz -mask m.nii.gz
# zscore:2.3094 mean:1.6
tat2 t.nii.gz -median_time -mean_vol -no_voxscale -output mean.nii.gz -mask m.nii.gz
tat2 t.nii.gz -calc_zscore -no_voxscale -output zscore.nii.gz -mask m.nii.gz
x_cmp_y zscore.nii.gz '>' mean.nii.gz
}
@test calc_ln {
# ln:173.287 mean:1.6
tat2 t.nii.gz -median_time -no_voxscale -mean_vol -output mean.nii.gz -mask m.nii.gz
tat2 t.nii.gz -no_voxscale -calc_ln -output ln.nii.gz -mask m.nii.gz
3dBrickStat ln.nii.gz >&2
x_cmp_y ln.nii.gz '<' mean.nii.gz
}
@test cen_abspath {
# censor using absolute path (introduced 20210809)
echo -e "1\n1\n1" > $(pwd)/cen1.1D
tat2 t.nii.gz -output cen.nii.gz -mask m.nii.gz -mean_time -censor_rel $(pwd)/cen1.1D
3dNotes cen.nii.gz |grep -q keep3
3dNotes cen.nii.gz |grep -q keep-3
}

@test saneargs_samplemethod {
Expand Down Expand Up @@ -417,3 +458,53 @@ x_cmp_y(){
[[ $status -ne 0 ]]
[[ $output =~ 'must end in nii' ]]
}

@test gen_calc {
source tat2; parse_args
numvox="NVOX"
run args_to_3dcalc_expr
[[ $output == "(x/m)*$SCALE/NVOX" ]]
}
@test gen_calc_novox {
source tat2
parse_args -no_voxscale
run args_to_3dcalc_expr
[[ $output == "(x/m)*1" ]]
}

@test gen_calc_zscore {
# TODO: this should error?
source tat2
parse_args -calc_zscore
numvox="NVOX"
run args_to_3dcalc_expr
[[ $output == "(x-m)/s*$SCALE/NVOX" ]]
}

@test gen_calc_zscore_noscale {
source tat2
parse_args -calc_zscore -no_voxscale
run args_to_3dcalc_expr
[[ $output == "(x-m)/s*1" ]]
}
@test gen_calc_ln_noscale {
source tat2
parse_args -calc_ln -no_voxscale
run args_to_3dcalc_expr
[[ $output == "-1*log(x/m)*1" ]]
}

@test gen_calc_no_vol_noscale {
source tat2
parse_args -no_vol -no_voxscale
run args_to_3dcalc_expr
[[ $output == "(x/m)*m*1" ]]
}
@test gen_calc_no_vol {
source tat2
parse_args -no_vol
numvox="NVOX"
run args_to_3dcalc_expr
[[ $output == "(x/m)*m*$SCALE/NVOX" ]]
}

Loading

0 comments on commit 96554fe

Please sign in to comment.