Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/snippets/process-out-eval.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ process sayHello {
output:
eval('bash --version')

script:
"""
echo Hello world!
"""
Expand Down
1 change: 1 addition & 0 deletions docs/snippets/process-stdout.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ process sayHello {
output:
stdout

script:
"""
echo Hello world!
"""
Expand Down
2 changes: 2 additions & 0 deletions docs/snippets/your-first-script.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ process splitLetters {
output:
path 'chunk_*'

script:
"""
printf '${params.str}' | split -b 6 - chunk_
"""
Expand All @@ -16,6 +17,7 @@ process convertToUpper {
output:
stdout

script:
"""
cat $x | tr '[a-z]' '[A-Z]'
"""
Expand Down
10 changes: 5 additions & 5 deletions tests/ampa-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ process ampaTask {
output:
path 'result'

// The BASH script to be executed - for each - sequence
script:
"""
AMPA.pl -in=${seq} -noplot -rf=result -df=data
"""

}

workflow {
Channel.fromPath(params.in) |
splitFasta(file:true) |
ampaTask |
view { it.text }
Channel.fromPath(params.in)
| splitFasta(file:true)
| ampaTask
| view { file -> file.text }
}

2 changes: 2 additions & 0 deletions tests/basic-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ process splitSequences {
output:
path 'seq_*'

script:
"""
awk '/^>/{f="seq_"++d} {print > f}' < input.fa
"""
Expand All @@ -34,6 +35,7 @@ process reverse {
output:
stdout

script:
"""
cat $x | rev
"""
Expand Down
20 changes: 11 additions & 9 deletions tests/blast-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ params.db = "$baseDir/blast-db/tiny"
params.query = "$baseDir/data/sample.fa"
params.chunkSize = 1

DB = file(params.db)

process blast {
input:
path 'seq.fa'
path db

output:
path 'out'

script:
"""
blastp -db $DB -query seq.fa -outfmt 6 > out
blastp -db $db -query seq.fa -outfmt 6 > out
"""
}

Expand All @@ -25,17 +25,19 @@ process sort {
output:
stdout

script:
"""
sort hits_*
"""
}


workflow {
Channel.fromPath(params.query) |
splitFasta( by: params.chunkSize, file:true ) |
blast |
collect |
sort |
subscribe { println it }
ch_fasta = Channel.fromPath(params.query)
| splitFasta( by: params.chunkSize, file:true )

blast(ch_fasta, file(params.db))
| collect
| sort
| subscribe { hits -> println hits }
}
32 changes: 21 additions & 11 deletions tests/blast-parallel-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ params.db = "$baseDir/blast-db/tiny"
params.query = "$baseDir/data/sample.fa"
params.chunk = 1

db = file(params.db)

/*
* Extends a BLAST query for each entry in the 'chunks' channel
*/
process blast {
input:
path 'query.fa'
path db

output:
path top_hits
path 'top_hits'

script:
"""
blastp -db ${db} -query query.fa -outfmt 6 > blast_result
cat blast_result | head -n 10 | cut -f 2 > top_hits
Expand All @@ -28,11 +28,15 @@ process blast {
process extract {
input:
path top_hits
path db

output:
path 'sequences'

"blastdbcmd -db ${db} -entry_batch top_hits | head -n 10 > sequences"
script:
"""
blastdbcmd -db ${db} -entry_batch top_hits | head -n 10 > sequences
"""
}


Expand All @@ -45,18 +49,24 @@ process align {
input:
path all_seq

"t_coffee $all_seq 2>/dev/null | tee align_result"
script:
"""
t_coffee $all_seq 2>/dev/null | tee align_result
"""
}

/*
* main flow
*/
workflow {
Channel.fromPath(params.query) |
splitFasta(by: params.chunk, file:true) |
blast |
extract |
collectFile(name:'all_seq') | // Collect all hits to a single file called 'all_seq'
align
db = file(params.db)

ch_fasta = Channel.fromPath(params.query)
| splitFasta(by: params.chunk, file:true)

ch_sequences = blast(ch_fasta, db)

extract(ch_sequences, db)
| collectFile(name:'all_seq') // Collect all hits to a single file called 'all_seq'
| align
}
1 change: 1 addition & 0 deletions tests/buffer-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ process blastThemAll {
input:
path x

script:
"""
echo $x
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/cache-bak.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ workflow {

process foo {
debug true

script:
/echo Hello world/
}
3 changes: 2 additions & 1 deletion tests/chunk-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ process foo {
input:
stdin()

script:
"cat -"
}

workflow {
Channel.from(stdin) \
Channel.of(stdin) \
| splitFasta( by: params.chunkSize) \
| foo
}
9 changes: 4 additions & 5 deletions tests/collect-file.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
* limitations under the License.
*/

Channel
.from('alpha', 'beta', 'gamma')
Channel.of('alpha', 'beta', 'gamma')
.collectFile(name: 'sample.txt', newLine: true)
.subscribe {
println "Entries are saved to file: $it"
println "File content is: ${it.text}"
.subscribe { file ->
println "Entries are saved to file: file"
println "File content is: ${file.text}"
}

println 123
46 changes: 25 additions & 21 deletions tests/collect_and_merge.nf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/*
* fake alignment step producing a BAM and BAI files
*/
process algn {
process align {
debug true

input:
Expand All @@ -29,10 +29,10 @@ process algn {
output:
tuple val(barcode), val(seq_id), file('bam'), file('bai')

script:
"""
echo BAM $seq_id - $barcode > bam
echo BAI $seq_id - $barcode > bai

"""
}

Expand All @@ -44,44 +44,48 @@ process merge {
debug true

input:
tuple val(barcode), val(seq_id), file(bam: 'bam?'), file(bai: 'bai?')
tuple val(barcode), val(seq_id), path(bam), path(bai)

script:
"""
echo barcode: $barcode
echo seq_ids: $seq_id
echo bam : $bam
echo bai : $bai
"""

}

workflow {
def ch1 = channel.of('alpha', 'gamma')
def ch2 = channel.of('one', 'two', 'three')

aggregation = algn(ch1, ch2)
aggregation = align(ch1, ch2)

/*
* aggregation is made by using a 'reduce' operator
* followed by 'flatMap'
*/

aggregation = algn.out
.reduce([:]) { map, tuple -> // 'map' is used to collect all values; 'tuple' is the record containing four items: barcode, seqid, bam file and bai file
def barcode = tuple[0] // the first item is the 'barcode'
def group = map[barcode] // get the aggregation for current 'barcode'
if( !group ) group = [ barcode, [], [], [] ] // if new, create a new entry
group[1] << tuple[1] // append 'seq_id' to the aggregation list
group[2] << tuple[2] // append 'bam' file to the aggregation list
group[3] << tuple[3] // append 'bai' file to the aggregation list
map[barcode] = group // set back into the map
return map // return it so that it will be used in the next iteration
}
.flatMap { it.values() } // tricky part: get the list of values of in the map, each value is the
// aggregation build above
// the 'flatMap' emits each of these aggregation list as a single item

.map { it.collect { it instanceof Collection ? it.sort() : it } }
aggregation = align.out
// 'map' is used to collect all values; 'tuple' is the record containing four items: barcode, seqid, bam file and bai file
.reduce([:]) { map, tuple ->
def barcode = tuple[0] // the first item is the 'barcode'
def group = map[barcode] // get the aggregation for current 'barcode'
if( !group ) group = [ barcode, [], [], [] ] // if new, create a new entry
group[1] << tuple[1] // append 'seq_id' to the aggregation list
group[2] << tuple[2] // append 'bam' file to the aggregation list
group[3] << tuple[3] // append 'bai' file to the aggregation list
map[barcode] = group // set back into the map
return map // return it so that it will be used in the next iteration
}

// tricky part: get the list of values of in the map, each value is the
// aggregation build above
// the 'flatMap' emits each of these aggregation list as a single item
.flatMap { map -> map.values() }
.map { group ->
group.collect { v -> v instanceof Collection ? v.sort() : v }
}

merge(aggregation)
}
2 changes: 2 additions & 0 deletions tests/collect_tuple-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ process algn {
output:
tuple val(barcode), val(seq_id), path('bam'), path('bai')

script:
"""
echo BAM $seq_id - $barcode > bam
echo BAI $seq_id - $barcode > bai
Expand All @@ -30,6 +31,7 @@ process merge {
input:
tuple val(barcode), val(seq_id), path(bam, stageAs:'bam?'), path(bai, stageAs:'bai?')

script:
"""
echo barcode: $barcode
echo seq_ids: $seq_id
Expand Down
16 changes: 9 additions & 7 deletions tests/complex-names-dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
process foo {
publishDir 'foo', mode: 'copy'
container 'debian:latest'

output:
path '*.fa'
path 'hello.txt'
Expand All @@ -12,32 +13,33 @@ process foo {
path '.alpha'

script:
$/
'''
echo A > hello.txt
echo B > sample.zip
echo C > sample.html
echo D > 01_A\(R1\).fastq
echo E > 01_A\(R2\).fastq
echo F > sample_\(1\ 2\).vcf
echo D > 01_A\\(R1\\).fastq
echo E > 01_A\\(R2\\).fastq
echo F > sample_\\(1\\ 2\\).vcf
echo 1 > f1.fa
echo 2 > f2.fa
echo 3 > f3.fa
mkdir .alpha
echo "Hello world!" > .alpha/hello.txt
/$
'''
}

process bar {
debug true
container 'debian:latest'

input:
path '*'

script:
$/
'''
cat .alpha/hello.txt
[ `cat * | grep -c ''` == 9 ] || false
/$
'''
}

/*
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/config-labels.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ profiles {
}

test3 {
includeConfig 'config-labels.included'
includeConfig 'config-labels-included.config'
}
}
Loading
Loading