-
Notifications
You must be signed in to change notification settings - Fork 145
Allow relative paths in run_fastsurfer.sh #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -504,6 +504,49 @@ esac | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -- "${POSITIONAL[@]}" # restore positional parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Function to convert path to absolute if it exists and is not empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local var_name="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local var_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval "var_value=\$$var_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$var_value" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -e "$var_value" ] || [ "${var_value#*/}" != "$var_value" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Path exists or contains directory separators - convert to absolute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local abs_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| abs_path=$(realpath "$var_value" 2>/dev/null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ $? -eq 0 ] && [ -n "$abs_path" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval "$var_name=\"$abs_path\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "WARNING: Failed to convert $var_name to absolute path: $var_value" | tee -a "${tmpLF:-/dev/null}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+510
to
+522
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how you can achieve the
Suggested change
Overall, this function should probably be moved to Also, logging can be done more elegantly like indicated. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Convert path variables to absolute paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "sd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer the way this works to be like this
Suggested change
The other version may work, but function that affect variables as a side effect are really ugly and should always be avoided. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "t1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, Also forcing t1 to be an absolute path will probably break longitudinal segmentation, see if [[ -n "$t1" ]] && [[ "$t1" != "from-base" ]]; then
echo "WARNING: --t1 was passed but will be overwritten with T1 from base template." | tee -a "$tmpLF"
fiAlso, the t1 input check checks if the t1 file exists. if [[ "$run_seg_pipeline" == "1" ]] && { [[ -z "$t1" ]] || [[ ! -f "$t1" ]]; }
then
echo "ERROR: T1 image ($t1) could not be found. You must supply an existing T1 input"
echo " (full head) via --t1 <absolute path and name> for generating the segmentation."
echo "NOTE: If running in a container, make sure symlinks are valid!"
exit 1
fiBut this can probably be fixed by moving the conversion block to "after" the input checking and sanitization (search for comment |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "t2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "seg_log" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "conformed_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "norm_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "norm_name_t2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "asegdkt_segfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "mask_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "merged_segfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "cereb_segfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "cereb_statsfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "hypo_segfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "hypo_statsfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "asegdkt_vinn_statsfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "aseg_vinn_statsfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "aseg_segfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+532
to
+545
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these should not be made absolute
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| convert_to_absolute_path "FS_LICENSE" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # make sure FastSurfer is in the PYTHONPATH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export PYTHONPATH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PYTHONPATH="$FASTSURFER_HOME$([[ -n "$PYTHONPATH" ]] && echo ":$PYTHONPATH")" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The condition
[ \"${var_value#*/}\" != \"$var_value\" ]is a complex way to check if a path contains directory separators. Consider using a more readable approach like[[ \"$var_value\" == */* ]]for better maintainability.