案例一:
/*
* Default pipeline parameters. They can be overriden on the command line eg.
* given `params.foo` specify on the run command line `--foo some_value`.
*/
params.reads = "$baseDir/data/ggal/*_{1,2}.fq"
params.transcriptome = "$baseDir/data/ggal/ggal_1_48850000_49020000.Ggal71.500bpflank.fa"
params.outdir = "results"
params.multiqc = "$baseDir/multiqc"
log.info """\
R N A S E Q - N F P I P E L I N E
===================================
transcriptome: ${params.transcriptome}
reads : ${params.reads}
outdir : ${params.outdir}
"""
transcriptome_file = file(params.transcriptome) /* 引入文件的方法,file()的括号内是文件的绝对路径,也可以使用 *? 通配符,如 infile = file("/datapath/*fq.gz"),则可以引入多个样本。 */
multiqc_file = file(params.multiqc) /* file()方法可以引入文件和目录*/
Channel /* 设置channel,以fromFilePairs()的方式将文件引入到channel中,则会生成一个list:[samplename,['samplename.R1.fq.gz','samplename.R2.fq.gz']],直接用下标引用。 */
.fromFilePairs( params.reads )
.ifEmpty { error "Cannot find any reads matching: ${params.reads}" }
.into { read_pairs_ch; read_pairs2_ch }
process index {
tag "$transcriptome.simpleName"
input:
file transcriptome from transcriptome_file
output:
file 'index' into index_ch
script:
"""
salmon index --threads $task.cpus -t $transcriptome -i index
"""
}
process quant {
tag "$pair_id" /* 指令声明模块含有cpu/echo/time/tag/penv/label等众多指令,这些指令设置的值将影响当前流程的执行。指令必须在最前面。tag指令允许您将每个流程执行与自定义标签关联起来,以便更容易地在日志文件或跟踪执行报告中标识它们。*/
input:
file index from index_ch
set pair_id, file(reads) from read_pairs_ch /* 引入channel的内容时,可以把内容分为 val/env/file/stdin等几种,使用set可以引入这几种混合的属性内容。 */
/* 这里从read_pairs_ch通道中引入了2种值,分别是pair_id和file(reads) */
output:
file(pair_id) into quant_ch
script:
""" /* reads 明显是一个list,里面分别是R1和R2 */
salmon quant --threads $task.cpus --libType=U -i $index -1 ${reads[0]} -2 ${reads[1]} -o $pair_id
"""
}
process fastqc {
tag "FASTQC on $sample_id"
publishDir params.outdir
input:
set sample_id, file(reads) from read_pairs2_ch
output:
file("fastqc_${sample_id}_logs") into fastqc_ch
script:
"""
mkdir fastqc_${sample_id}_logs
fastqc -o fastqc_${sample_id}_logs -f fastq -q ${reads}
"""
}
process multiqc {
publishDir params.outdir, mode:'copy' /* 把生成的结果输出到指定目录中,而不是在nextflow的work目录中,mode是执行模式,可以是copy/link等 */
input:
file('*') from quant_ch.mix(fastqc_ch).collect() /* collect()收集channel中的所有值,并返回一个list */
file(config) from multiqc_file
output:
file('multiqc_report.html')
script:
"""
cp $config/* . /*可知input中的file()引入的config是一个路径 */
echo "custom_logo: \$PWD/logo.png" >> multiqc_config.yaml
multiqc .
"""
}
workflow.onComplete {
log.info ( workflow.success ? "\nDone! Open the following report in your browser --> $params.outdir/multiqc_report.html\n" : "Oops .. something went wrong" )
}
网友评论