2
$\begingroup$

I am trying to create a channel with a CSV file and use it as tuple input. Yet the output I obtain does not contain the entire file but only the first element of the file (1st row).

the csv

dig,val 
1,One
2,Two
3,Three
4,Four
5,Five

output : cat digOne.txt 1 instead of the whole collection digOne, digTwo...


 size_amp_ch = Channel
        .fromPath( params.file)
        .splitCsv(header:true).map{
            row  -> tuple(row.dig,row.val)
        }

process{
    input:

    tuple val(digits), val(values)
    
    output:


    path "dig_${values}.txt"

    script:

    """
    echo $digits >> dig_${values}.txt


}

thank you

$\endgroup$

1 Answer 1

1
$\begingroup$

I think the problem is just that you have extra whitespace at the end of the first line in your CSV file. Either remove the whitespace manually, or use the strip parameter with the splitCsv operator to remove leading and trailing whitespace from values. For example:

params.file = './file.csv'


process test_proc {

    input:
    tuple val(digits), val(values)

    output:
    path "dig_${values}.txt"

    """
    echo "${digits}" > "dig_${values}.txt"
    """
}

workflow { 
 
    Channel.fromPath( params.file ) \
        | splitCsv( header:true, strip:true ) \
        | map { row ->
            tuple( row.dig, row.val )
        } \
        | test_proc \
        | view()

}

Results:

$ nextflow run main.nf 
N E X T F L O W  ~  version 22.10.0
Launching `main.nf` [stupefied_boyd] DSL2 - revision: 2a9d8dc414
executor >  local (5)
[4f/a73196] process > test_proc (2) [100%] 5 of 5 ✔
/path/to/work/9d/4905d0236788c1a3733da5358b7fc4/dig_Four.txt
/path/to/work/f9/d04e8a1c2265d73cde626703317df7/dig_Five.txt
/path/to/work/ff/522238f87a5641fdc7adce3e4d1cea/dig_Three.txt
/path/to/work/e9/9b7ec2a65d45986fd8944da4a2054c/dig_One.txt
/path/to/work/4f/a73196fbd56db3c9647fa7b072edfd/dig_Two.txt

$\endgroup$
2
  • $\begingroup$ Hey thank you so much for the answer, it seems that your answer is not solving my problem, I wonder if my test file is causing this. thank you so much for the help $\endgroup$ Feb 13 at 15:58
  • $\begingroup$ @LoïcBorcard So what is the problem exactly? What are you trying to achieve or what are you expecting? $\endgroup$
    – Steve
    Feb 13 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.