These are chat archives for nextflow-io/nextflow

4th
Nov 2016
Félix C. Morency
@fmorency
Nov 04 2016 15:40
"""
 b0s="\$(ls -v stuff__b0_*.nii.gz)"
 echo "\${#b0s[@]}"
"""
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:40
!
Félix C. Morency
@fmorency
Nov 04 2016 15:40
this code fail with
.command.sh: line 5: b0s: unbound variable
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:40
oh
Félix C. Morency
@fmorency
Nov 04 2016 15:40
however, I can run the .command.sh just fine in bash
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:41
try
'''
 b0s="$(ls -v stuff__b0_*.nii.gz)"
 echo "${#b0s[@]}"
'''
Félix C. Morency
@fmorency
Nov 04 2016 15:42
it fails few lines before because it can't parse the input: correctly
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:42
wat?
how is your process ?
Félix C. Morency
@fmorency
Nov 04 2016 15:43
I have a .command.sh: line 2: dwi: unbound variable where dwi is an input:
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:44
thus it not only that two lines
Félix C. Morency
@fmorency
Nov 04 2016 15:44
no :)
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:44
ah
Félix C. Morency
@fmorency
Nov 04 2016 15:44
process N4_Bias_Field_Correction_DWI {
    cpus params.dwi_n4_num_threads
    echo true

    input:
    val sid from sid_for_dwi_n4
    file dwi from dwi_nlm_for_n4
    file bvals from bvals_for_n4
    file bvecs from bvecs_for_n4

    output:
    file "${sid}__dwi_n4.nii.gz"

    """
    scil_extract_b0.py $dwi $bvals $bvecs ${sid}__b0_all.nii.gz --all

    b0s="\$(ls -v ${sid}__b0_*.nii.gz)"
    echo "\${#b0s[@]}"
    """
}
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:45
try
  shell:
  """
    scil_extract_b0.py !{dwi} !{bvals} !{bvecs} !{sid}__b0_all.nii.gz --all

    b0s="$(ls -v ${sid}__b0_*.nii.gz)"
    echo "${#b0s[@]}"
  """
Félix C. Morency
@fmorency
Nov 04 2016 15:47
still .command.sh: line 5: b0s: unbound variable
    shell:
    '''
    scil_extract_b0.py !{dwi} !{bvals} !{bvecs} !{sid}__b0_all.nii.gz --all

    b0s="$(ls -v !{sid}__b0_*.nii.gz)"
    echo "${#b0s[@]}"
    '''
runs fine from bash
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:51
let me try
no it doesn't
 bash .command.run 
/Users/pditommaso/projects/nextflow/work/9c/ece89df4cb131d4367909760ce3356/.command.sh: line 2: b0s: unbound variable
Félix C. Morency
@fmorency
Nov 04 2016 15:56
mmm what's your bash --version?
Paolo Di Tommaso
@pditommaso
Nov 04 2016 15:56
I don't thins so
put a set +uas the first line of your script
if you look at the script generated by NF you will see
#!/bin/bash -ue
echo "${#b0s[@]}"
the -u means that unbounded vars are not allowed
Félix C. Morency
@fmorency
Nov 04 2016 15:59
let me try
mmm is there a way to force into to output a [] even if there is a single element?
Paolo Di Tommaso
@pditommaso
Nov 04 2016 16:02
which channel are u referring in the code above?
Félix C. Morency
@fmorency
Nov 04 2016 16:02
i could probably use nf mechanism instead of bash to loop on my file list
something like
output:
file "${sid}__b0_all*.nii.gz" into b0s_for_n4
b0s_for_n4 can contain 1 or more elements
i would like to loop on those elements
Paolo Di Tommaso
@pditommaso
Nov 04 2016 16:04
that's fine, you don't any extra syntax to handle that case
the * will capture all existing matching files
Félix C. Morency
@fmorency
Nov 04 2016 16:06
can I loop on b0_for_n4 in the bash script afterward?
Paolo Di Tommaso
@pditommaso
Nov 04 2016 16:07
loop is not a NF friendly concept :)
do you mean in a downstream process ?
Félix C. Morency
@fmorency
Nov 04 2016 16:07
yes
Paolo Di Tommaso
@pditommaso
Nov 04 2016 16:08
ah, yes
..
process afterwards {
  input: 
  file my_files from b0_for_n4
  """
  for x in $my_files; do 
    echo \$x
  done
  """
}
something like the above
Félix C. Morency
@fmorency
Nov 04 2016 16:10
ok. will try that. thanks
Félix C. Morency
@fmorency
Nov 04 2016 17:48
yay it works
Paolo Di Tommaso
@pditommaso
Nov 04 2016 18:07
of course! ;)