Skip to content

Commit

Permalink
Merge pull request #18 from frheault/harmonize_json
Browse files Browse the repository at this point in the history
harmonize_json
  • Loading branch information
arnaudbore authored Jun 29, 2023
2 parents 118d804 + 1f33ce6 commit 9b75bcd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
3 changes: 0 additions & 3 deletions USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ OPTIONAL ARGUMENTS (current value)
--use_provided_centroids Use the provided pre-computed centroids rather than using automatic computation ($use_provided_centroids)
--bundle_suffix_to_remove Use to remove the suffix from RBx-Flow ($bundle_suffix_to_remove)

--min_streamline_count Minimum streamline count threshold from trimming of 'edges' in the voxel labels map ($min_streamline_count)
--min_voxel_count Minimum voxel count threshold from trimming of 'edges' in the voxel labels map ($min_voxel_count)

--mean_std_density_weighting Weight the mean/std by the local tract density ($mean_std_density_weighting)
--mean_std_per_point_density_weighting Weight the mean/std per point by the local tract density ($mean_std_per_point_density_weighting)
--endpoints_metric_stats_normalize_weights Normalize the weights to the [0, 1] range ($endpoints_metric_stats_normalize_weights)
Expand Down
70 changes: 44 additions & 26 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ process Bundle_Label_And_Distance_Maps {
centroid=${sid}__\${bname}_centroid_${params.nb_points}.trk
if [[ -f \${centroid} ]]; then
scil_compute_bundle_voxel_label_map.py \$bundle \${centroid} tmp_out\
--min_streamline_count ${params.min_streamline_count} \
--min_voxel_count ${params.min_voxel_count} -f
scil_compute_bundle_voxel_label_map.py \$bundle \${centroid} tmp_out -f
mv tmp_out/labels_map.nii.gz ${sid}__\${bname}_labels.nii.gz
mv tmp_out/distance_map.nii.gz ${sid}__\${bname}_distances.nii.gz
Expand Down Expand Up @@ -445,7 +443,7 @@ process Bundle_Endpoints_Map {
metrics_for_endpoints_roi_stats
.mix(fixel_afd_for_endpoints_roi_stats)
.groupTuple(by: 0)
.map{it -> [it[0], it[1..-1].flatten()]}
.map{it -> [it[0], it[1..-1].flatten()]}
.set{metrics_afd_for_endpoints_roi_stats}

metrics_afd_for_endpoints_roi_stats
Expand Down Expand Up @@ -478,10 +476,13 @@ process Bundle_Metrics_Stats_In_Endpoints {
bname=\${bname/_endpoints_map_head/}
mv \$map \${bname}_head.nii.gz
mv \${map/_head/_tail} \${bname}_tail.nii.gz
if [ -f "\${bname}_afd_metric.nii.gz" ]; then
b_metrics="!(*afd*|*head*|*tail*).nii.gz \${bname}_afd_metric.nii.gz"
else
b_metrics="$metrics"
b_metrics=($metrics)
if [[ -f \${bname}_afd_metric.nii.gz ]];
then
mv \${bname}_afd_metric.nii.gz afd_metric.nii.gz
b_metrics="\${b_metrics[@]//*afd_metric*}"
b_metrics+=" afd_metric.nii.gz"
fi
scil_compute_metrics_stats_in_ROI.py \${bname}_head.nii.gz $normalize_weights\
Expand All @@ -498,7 +499,7 @@ process Bundle_Metrics_Stats_In_Endpoints {
metrics_for_endpoints_metrics
.mix(fixel_afd_for_endpoints_metrics)
.groupTuple(by: 0)
.map{it -> [it[0], it[1..-1].flatten()]}
.map{it -> [it[0], it[1..-1].flatten()]}
.set{metrics_afd_for_endpoints_metrics}

bundles_for_endpoints_metrics
Expand Down Expand Up @@ -529,17 +530,19 @@ process Bundle_Endpoints_Metrics {
fi
bname=\${bname/_uniformized/}
mkdir \${bname}
if [ -f "\${bname}_afd_metric.nii.gz" ]; then
b_metrics="!(*afd*).nii.gz \${bname}_afd_metric.nii.gz"
else
b_metrics="$metrics"
b_metrics=($metrics)
if [[ -f \${bname}_afd_metric.nii.gz ]];
then
mv \${bname}_afd_metric.nii.gz afd_metric.nii.gz
b_metrics="\${b_metrics[@]//*afd_metric*}"
b_metrics+=" afd_metric.nii.gz"
fi
scil_compute_endpoints_metric.py \$bundle \${b_metrics} \${bname}
scil_project_streamlines_to_map.py \$bundle \${bname} --in_metrics \${b_metrics} --from_wm
cd \${bname}
for i in *.nii.gz;
do
mv "\$i" "${sid}__\$i";
do mv "\$i" "${sid}__\$i";
done
rename s/${sid}__${sid}__/${sid}__/ *
Expand All @@ -549,7 +552,7 @@ process Bundle_Endpoints_Metrics {
metrics_for_mean_std
.mix(fixel_afd_for_mean_std)
.groupTuple(by: 0)
.map{it -> [it[0], it[1..-1].flatten()]}
.map{it -> [it[0], it[1..-1].flatten()]}
.set{metrics_afd_for_mean_std}

metrics_afd_for_mean_std
Expand Down Expand Up @@ -579,11 +582,14 @@ process Bundle_Mean_Std {
bname=\${bname/_uniformized/}
mv \$bundle \$bname.trk
if [ -f "\${bname}_afd_metric.nii.gz" ]; then
b_metrics="!(*afd*).nii.gz \${bname}_afd_metric.nii.gz"
else
b_metrics="$metrics"
b_metrics=($metrics)
if [[ -f \${bname}_afd_metric.nii.gz ]];
then
mv \${bname}_afd_metric.nii.gz afd_metric.nii.gz
b_metrics="\${b_metrics[@]//*afd_metric*}"
b_metrics+=" afd_metric.nii.gz"
fi
scil_compute_bundle_mean_std.py $density_weighting \$bname.trk \${b_metrics} >\
\${bname}.json
done
Expand Down Expand Up @@ -676,7 +682,7 @@ process Bundle_Volume_Per_Label {
metrics_for_mean_std_per_point
.mix(fixel_afd_for_mean_std_per_point)
.groupTuple(by: 0)
.map{it -> [it[0], it[1..-1].flatten()]}
.map{it -> [it[0], it[1..-1].flatten()]}
.set{metrics_afd_for_std_per_point}

metrics_afd_for_std_per_point
Expand Down Expand Up @@ -714,10 +720,12 @@ process Bundle_Mean_Std_Per_Point {
label_map=${sid}__\${bname}_labels.nii.gz
distance_map=${sid}__\${bname}_distances.nii.gz
if [ -f "\${bname}_afd_metric.nii.gz" ]; then
b_metrics="!(*afd*).nii.gz \${bname}_afd_metric.nii.gz"
else
b_metrics="$metrics"
b_metrics=($metrics)
if [[ -f \${bname}_afd_metric.nii.gz ]];
then
mv \${bname}_afd_metric.nii.gz afd_metric.nii.gz
b_metrics="\${b_metrics[@]//*afd_metric*}"
b_metrics+=" afd_metric.nii.gz"
fi
scil_compute_bundle_mean_std_per_point.py \$bname.trk \$label_map \
Expand Down Expand Up @@ -782,6 +790,7 @@ process Aggregate_All_Lesion_Load {
script:
"""
scil_merge_json.py $jsons lesion_load.json --average_last_layer --recursive
scil_harmonize_json.py lesion_load.json lesion_load.json -f -v --sort_keys
scil_convert_json_to_xlsx.py lesion_load.json lesion_load.xlsx
"""
}
Expand Down Expand Up @@ -809,6 +818,7 @@ process Aggregate_All_Lesion_Load_Per_Point {
done
scil_merge_json.py *_avg.json lesion_load_per_point.json \
--recursive
scil_harmonize_json.py lesion_load_per_point.json lesion_load_per_point.json -f -v --sort_keys
scil_convert_json_to_xlsx.py lesion_load_per_point.json lesion_load_per_point.xlsx \
--stats_over_population
"""
Expand All @@ -832,6 +842,7 @@ process Aggregate_All_Endpoints_Map {
script:
"""
scil_merge_json.py $jsons endpoints_map.json --no_list
scil_harmonize_json.py endpoints_map.json endpoints_map.json -f -v --sort_keys
scil_convert_json_to_xlsx.py endpoints_map.json endpoints_map.xlsx
"""
}
Expand All @@ -854,6 +865,7 @@ process Aggregate_All_Endpoints_Metric_Stats {
script:
"""
scil_merge_json.py $jsons endpoints_metric_stats.json --no_list
scil_harmonize_json.py endpoints_metric_stats.json endpoints_metric_stats.json -f -v --sort_keys
scil_convert_json_to_xlsx.py endpoints_metric_stats.json endpoints_metric_stats.xlsx
"""
}
Expand All @@ -876,6 +888,7 @@ process Aggregate_All_Bundle_Length_Stats {
script:
"""
scil_merge_json.py $jsons length_stats.json --no_list
scil_harmonize_json.py length_stats.json length_stats.json -f -v --sort_keys
scil_convert_json_to_xlsx.py length_stats.json length_stats.xlsx
"""
}
Expand All @@ -898,6 +911,7 @@ process Aggregate_All_mean_std {
script:
"""
scil_merge_json.py $jsons mean_std.json --no_list
scil_harmonize_json.py mean_std.json mean_std.json -f -v --sort_keys
scil_convert_json_to_xlsx.py mean_std.json mean_std.xlsx
"""
}
Expand All @@ -920,6 +934,7 @@ process Aggregate_All_Volume {
script:
"""
scil_merge_json.py $jsons volumes.json --no_list
scil_harmonize_json.py volumes.json volumes.json -f -v --sort_keys
scil_convert_json_to_xlsx.py volumes.json volumes.xlsx
"""
}
Expand All @@ -942,6 +957,7 @@ process Aggregate_All_Streamline_Count {
script:
"""
scil_merge_json.py $jsons streamline_count.json --no_list
scil_harmonize_json.py streamline_count.json streamline_count.json -f -v --sort_keys
scil_convert_json_to_xlsx.py streamline_count.json streamline_count.xlsx
"""
}
Expand All @@ -964,6 +980,7 @@ process Aggregate_All_Volume_Per_Label {
script:
"""
scil_merge_json.py $jsons volume_per_label.json --no_list
scil_harmonize_json.py volume_per_label.json volume_per_label.json -f -v --sort_keys
scil_convert_json_to_xlsx.py volume_per_label.json volume_per_label.xlsx
"""
}
Expand Down Expand Up @@ -991,6 +1008,7 @@ process Aggregate_All_Mean_Std_Per_Point {
done
scil_merge_json.py *_avg.json mean_std_per_point.json \
--recursive
scil_harmonize_json.py mean_std_per_point.json mean_std_per_point.json -f -v --sort_keys
scil_convert_json_to_xlsx.py mean_std_per_point.json mean_std_per_point.xlsx \
--stats_over_population
"""
Expand Down
3 changes: 0 additions & 3 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ params {
skip_projection_endpoints_metrics=true
bundle_suffix_to_remove='_cleaned'

min_streamline_count=100000
min_voxel_count=1000000

colors=["AC":"0x02d983",
"AF_L":"0xcc0000",
"AF_R":"0xffdf0f",
Expand Down

0 comments on commit 9b75bcd

Please sign in to comment.