Skip to main content
added info
Source Link
Relyativist
  • 139
  • 6
  • 16

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could I simplify if statements and parallel this script?

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could I simplify and parallel this script?

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could I simplify if statements and parallel this script?

added 24 characters in body
Source Link
jesse_b
  • 41.6k
  • 14
  • 108
  • 163

for dirname in /input/*; do

for dirname in /input/*; do

    id=${dirname#/input/}    # remove "/input/sub-"
    id=${id%/}             # remove trailing "/"

    printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2
    
    T11=`find /input/${id}/unprocessed/3T -name "*T1*MPR1*" -type f`
    T12=`find /input/${id}/unprocessed/3T -name "*T1*MPR2*" -type f`

    T21=`find /input/${id}/unprocessed/3T -name "*T2*SPC1*" -type f`
    T22=`find /input/${id}/unprocessed/3T -name "*T2*SPC2*" -type f`

    if [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}" -i "${T22}"
    elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}"
    elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T22}"
    elif [ -z "$T11" ] || [ -z "$T21" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T21}"
    elif [ -z "$T11" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T22}"
    else 
        recon-all -s "${id}" -i "${T11}" -i "${T21}" 
    fi

    if [ -e "/output/$subj_id" ]; then
        # no output file corresponding to this ID found,
        # add it to he list
        all_ids+=( "$subj_id" )
    fi
done

done

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could iI simplify and parallel this script?

for dirname in /input/*; do

id=${dirname#/input/}    # remove "/input/sub-"
id=${id%/}             # remove trailing "/"

printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2

T11=`find /input/${id}/unprocessed/3T -name "*T1*MPR1*" -type f`
T12=`find /input/${id}/unprocessed/3T -name "*T1*MPR2*" -type f`

T21=`find /input/${id}/unprocessed/3T -name "*T2*SPC1*" -type f`
T22=`find /input/${id}/unprocessed/3T -name "*T2*SPC2*" -type f`

if [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}" -i "${T22}"
elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}"
elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T22}"
elif [ -z "$T11" ] || [ -z "$T21" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T21}"
elif [ -z "$T11" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T22}"
else 
    recon-all -s "${id}" -i "${T11}" -i "${T21}" 
fi

if [ -e "/output/$subj_id" ]; then
    # no output file corresponding to this ID found,
    # add it to he list
    all_ids+=( "$subj_id" )
fi

done

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could i simplify and parallel this script?

for dirname in /input/*; do

    id=${dirname#/input/}    # remove "/input/sub-"
    id=${id%/}             # remove trailing "/"

    printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2
    
    T11=`find /input/${id}/unprocessed/3T -name "*T1*MPR1*" -type f`
    T12=`find /input/${id}/unprocessed/3T -name "*T1*MPR2*" -type f`

    T21=`find /input/${id}/unprocessed/3T -name "*T2*SPC1*" -type f`
    T22=`find /input/${id}/unprocessed/3T -name "*T2*SPC2*" -type f`

    if [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}" -i "${T22}"
    elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}"
    elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T22}"
    elif [ -z "$T11" ] || [ -z "$T21" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T21}"
    elif [ -z "$T11" ] || [ -z "$T22" ]; then
        recon-all -s "${id}" -i "${T11}" -i "${T22}"
    else 
        recon-all -s "${id}" -i "${T11}" -i "${T21}" 
    fi

    if [ -e "/output/$subj_id" ]; then
        # no output file corresponding to this ID found,
        # add it to he list
        all_ids+=( "$subj_id" )
    fi
done

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could I simplify and parallel this script?

Source Link
Relyativist
  • 139
  • 6
  • 16

Simplify and parallel bash if statement script

I have written a script that finds files in directories, and brings through if statement, here is a code:

for dirname in /input/*; do

id=${dirname#/input/}    # remove "/input/sub-"
id=${id%/}             # remove trailing "/"

printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2

T11=`find /input/${id}/unprocessed/3T -name "*T1*MPR1*" -type f`
T12=`find /input/${id}/unprocessed/3T -name "*T1*MPR2*" -type f`

T21=`find /input/${id}/unprocessed/3T -name "*T2*SPC1*" -type f`
T22=`find /input/${id}/unprocessed/3T -name "*T2*SPC2*" -type f`

if [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}" -i "${T22}"
elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T21" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T21}"
elif [ -z "$T11" ] || [ -z "$T12" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T12}" -i "${T22}"
elif [ -z "$T11" ] || [ -z "$T21" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T21}"
elif [ -z "$T11" ] || [ -z "$T22" ]; then
    recon-all -s "${id}" -i "${T11}" -i "${T22}"
else 
    recon-all -s "${id}" -i "${T11}" -i "${T21}" 
fi

if [ -e "/output/$subj_id" ]; then
    # no output file corresponding to this ID found,
    # add it to he list
    all_ids+=( "$subj_id" )
fi

done

The problem is that there could be different combination inside directories, and T12 and T22 could sometimes be missed, that's why I made a recon-all for every statement. How could i simplify and parallel this script?