Assembly and binning of metagenomes

public public 1yr ago Version: 2.3.2 0 bookmarks
Loading...

Introduction

nf-core/mag is a bioinformatics best-practise analysis pipeline for assembly, binning and annotation of metagenomes.

nf-core/mag workflow overview

The pipeline is built using Nextflow , a workflow tool to run tasks across multiple compute infrastructures in a very portable manner. It uses Docker/Singularity containers making installation trivial and results highly reproducible. The Nextflow DSL2 implementation of this pipeline uses one container per process which makes it much easier to maintain and update software dependencies. Where possible, these processes have been submitted to and installed from nf-core/modules in order to make them available to all nf-core pipelines, and to everyone within the Nextflow community!

On release, automated continuous integration tests run the pipeline on a full-sized dataset on the AWS cloud infrastructure. This ensures that the pipeline runs on AWS, has sensible resource allocation defaults set to run on real-world datasets, and permits the persistent storage of results to benchmark between pipeline releases and other analysis sources.The results obtained from the full-sized test can be viewed on the nf-core website .

Pipeline summary

By default, the pipeline currently performs the following: it supports both short and long reads, quality trims the reads and adapters with fastp and Porechop , and performs basic QC with FastQC . The pipeline then:

Furthermore, the pipeline creates various reports in the results directory specified, including a MultiQC report summarizing some of the findings and software versions.

Quick Start

  1. Install Nextflow ( >=22.10.1 )

  2. Install any of Docker , Singularity (you can follow this tutorial ), Podman , Shifter or Charliecloud for full pipeline reproducibility (you can use Conda both to install Nextflow itself and also to manage software within pipelines. Please only use it within pipelines as a last resort; see docs ) .

  3. Download the pipeline and test it on a minimal dataset with a single command:

    nextflow run nf-core/mag -profile test,YOURPROFILE --outdir <OUTDIR>
    

    Note that some form of configuration will be needed so that Nextflow knows how to fetch the required software. This is usually done in the form of a config profile ( YOURPROFILE in the example command above). You can chain multiple config profiles in a comma-separated string.

    • The pipeline comes with config profiles called docker , singularity , podman , shifter , charliecloud and conda which instruct the pipeline to use the named tool for software management. For example, -profile test,docker .

    • Please check nf-core/configs to see if a custom config file to run nf-core pipelines already exists for your Institute. If so, you can simply use -profile <institute> in your command. This will enable either docker or singularity and set the appropriate execution settings for your local compute environment.

    • If you are using singularity , please use the nf-core download command to download images first, before running the pipeline. Setting the NXF_SINGULARITY_CACHEDIR or singularity.cacheDir Nextflow options enables you to store and re-use the images from a central location for future pipeline runs.

    • If you are using conda , it is highly recommended to use the NXF_CONDA_CACHEDIR or conda.cacheDir settings to store the environments in a central location for future pipeline runs.

  4. Start running your own analysis!

    nextflow run nf-core/mag -profile <docker/singularity/podman/shifter/charliecloud/conda/institute> --input '*_R{1,2}.fastq.gz' --outdir <OUTDIR>
    

    or

nextflow run nf-core/mag -profile <docker/singularity/podman/shifter/charliecloud/conda/institute> --input samplesheet.csv --outdir <OUTDIR>

See usage docs and parameter docs for all of the available options when running the pipeline.

Documentation

The nf-core/mag pipeline comes with documentation about the pipeline usage , parameters and output . Detailed information about how to specify the input can be found under input specifications .

Group-wise co-assembly and co-abundance computation

Each sample has an associated group ID (see input specifications ). This group information can be used for group-wise co-assembly with MEGAHIT or SPAdes and/or to compute co-abundances for the binning step with MetaBAT2 . By default, group-wise co-assembly is disabled, while the computation of group-wise co-abundances is enabled. For more information about how this group information can be used see the documentation for the parameters --coassemble_group and --binning_map_mode .

When group-wise co-assembly is enabled, SPAdes is run on accordingly pooled read files, since metaSPAdes does not yet allow the input of multiple samples or libraries. In contrast, MEGAHIT is run for each group while supplying lists of the individual readfiles.

Credits

nf-core/mag was written by Hadrien Gourlé at SLU , Daniel Straub and Sabrina Krakau at the Quantitative Biology Center (QBiC) . James A. Fellows Yates and Maxime Borry at the Max Planck Institute for Evolutionary Anthropology joined in version 2.2.0.

Long read processing was inspired by caspargross/HybridAssembly written by Caspar Gross @caspargross

We thank the following people for their extensive assistance in the development of this pipeline:

Contributions and Support

If you would like to contribute to this pipeline, please see the contributing guidelines .

For further information or help, don't hesitate to get in touch on the Slack #mag channel (you can join with this invite ).

Citations

If you use nf-core/mag for your analysis, please cite the preprint as follows:

nf-core/mag: a best-practice pipeline for metagenome hybrid assembly and binning

Sabrina Krakau, Daniel Straub, Hadrien Gourlé, Gisela Gabernet, Sven Nahnsen.

NAR Genom Bioinform. 2022 Feb 2;4(1):lqac007. doi: 10.1093/nargab/lqac007 .

additionally you can cite the pipeline directly with the following doi: 10.5281/zenodo.3589527

An extensive list of references for the tools used by the pipeline can be found in the CITATIONS.md file.

You can cite the nf-core publication as follows:

The nf-core framework for community-curated bioinformatics pipelines.

Philip Ewels, Alexander Peltzer, Sven Fillinger, Harshil Patel, Johannes Alneberg, Andreas Wilm, Maxime Ulysse Garcia, Paolo Di Tommaso & Sven Nahnsen.

Nat Biotechnol. 2020 Feb 13. doi: 10.1038/s41587-020-0439-x .

Code Snippets

18
19
20
21
22
23
24
25
26
27
"""
if [ -n "${bins}" ]
then
    for file in ${bins}; do
        [[ \${file} =~ (.*).fasta.gz ]];
        bin="\${BASH_REMATCH[1]}"
        mv \${file} \${bin}.fa.gz
    done
fi
"""
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
combine_tables.py --depths_summary ${bin_depths} \
                $busco_summary \
                $checkm_summary \
                $quast_summary \
                $gtdbtk_summary \
                --out bin_summary.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
INDEX=`find -L ./ -name "*.rev.1.bt2l" -o -name "*.rev.1.bt2" | sed 's/.rev.1.bt2l//' | sed 's/.rev.1.bt2//'`
bowtie2 \\
    -p "${task.cpus}" \\
    -x \$INDEX \\
    $args \\
    $input \\
    2> "${name}.bowtie2.log" | \
    samtools view -@ "${task.cpus}" -bS | \
    samtools sort -@ "${task.cpus}" -o "${name}.bam"
samtools index "${name}.bam"

if [ ${name} = "${assembly_meta.assembler}-${assembly_meta.id}-${assembly_meta.id}" ] ; then
    mv "${name}.bowtie2.log" "${assembly_meta.assembler}-${assembly_meta.id}.bowtie2.log"
fi

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
    samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
    pigz: \$( pigz --version 2>&1 | sed 's/pigz //g' )
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
"""
mkdir bowtie
bowtie2-build --threads $task.cpus $assembly "bt2_index_base"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
END_VERSIONS
"""
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
bowtie2 -p ${task.cpus} \
        -x ${index[0].getSimpleName()} \
        -1 "${reads[0]}" -2 "${reads[1]}" \
        $args \
        --un-conc-gz ${prefix}.unmapped_%.fastq.gz \
        --al-conc-gz ${prefix}.mapped_%.fastq.gz \
        1> /dev/null \
        2> ${prefix}.bowtie2.log
if [ ${save_ids} = "Y" ] ; then
    gunzip -c ${prefix}.mapped_1.fastq.gz | awk '{if(NR%4==1) print substr(\$0, 2)}' | LC_ALL=C sort > ${prefix}.mapped_1.read_ids.txt
    gunzip -c ${prefix}.mapped_2.fastq.gz | awk '{if(NR%4==1) print substr(\$0, 2)}' | LC_ALL=C sort > ${prefix}.mapped_2.read_ids.txt
fi
rm -f ${prefix}.mapped_*.fastq.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
END_VERSIONS
"""
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
bowtie2 -p ${task.cpus} \
        -x ${index[0].getSimpleName()} \
        -U ${reads} \
        $args \
        --un-gz ${prefix}.unmapped.fastq.gz \
        --al-gz ${prefix}.mapped.fastq.gz \
        1> /dev/null \
        2> ${prefix}.bowtie2.log
if [ ${save_ids} = "Y" ] ; then
    gunzip -c ${prefix}.mapped.fastq.gz | awk '{if(NR%4==1) print substr(\$0, 2)}' | LC_ALL=C sort > ${prefix}.mapped.read_ids.txt
fi
rm -f ${prefix}.mapped.fastq.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
"""
mkdir bowtie
bowtie2-build --threads $task.cpus $fasta "bt2_index_base"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
"""
mkdir buscodb
tar -xf ${database} -C buscodb

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    tar: \$(tar --version 2>&1 | sed -n 1p | sed 's/tar (GNU tar) //')
END_VERSIONS
"""
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
"""
# ensure augustus has write access to config directory
if [ ${cp_augustus_config} = "Y" ] ; then
    cp -r /usr/local/config/ augustus_config/
    export AUGUSTUS_CONFIG_PATH=augustus_config
fi

# place db in extra folder to ensure BUSCO recognizes it as path (instead of downloading it)
if [ ${lineage_dataset_provided} = "Y" ] ; then
    mkdir dataset
    mv ${db} dataset/
fi

# set nullgob: if pattern matches no files, expand to a null string rather than to itself
shopt -s nullglob

# only used for saving busco downloads
most_spec_db="NA"

if busco ${p} \
    --mode genome \
    --in ${bin} \
    --cpu "${task.cpus}" \
    --out "BUSCO" > ${bin}_busco.log 2> ${bin}_busco.err; then

    # get name of used specific lineage dataset
    summaries=(BUSCO/short_summary.specific.*.BUSCO.txt)
    if [ \${#summaries[@]} -ne 1 ]; then
        echo "ERROR: none or multiple 'BUSCO/short_summary.specific.*.BUSCO.txt' files found. Expected one."
        exit 1
    fi
    [[ \$summaries =~ BUSCO/short_summary.specific.(.*).BUSCO.txt ]];
    db_name_spec="\${BASH_REMATCH[1]}"
    most_spec_db=\${db_name_spec}
    echo "Used specific lineage dataset: \${db_name_spec}"

    if [ ${lineage_dataset_provided} = "Y" ]; then
        cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.specific_lineage.\${db_name_spec}.${bin}.txt

        # if lineage dataset is provided, BUSCO analysis does not fail in case no genes can be found as when using the auto selection setting
        # report bin as failed to allow consistent warnings within the pipeline for both settings
        if egrep -q \$'WARNING:\tBUSCO did not find any match.' ${bin}_busco.log ; then
            echo "WARNING: BUSCO could not find any genes for the provided lineage dataset! See also ${bin}_busco.log."
            echo -e "${bin}\tNo genes" > "${bin}_busco.failed_bin.txt"
        fi
    else
        # auto lineage selection
        if { egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log \
            && egrep -q \$'INFO:\tLineage \\S+ is selected, supported by ' ${bin}_busco.log ; } || \
            { egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log \
            && egrep -q \$'INFO:\tThe results from the Prodigal gene predictor indicate that your data belongs to the mollicutes clade. Testing subclades...' ${bin}_busco.log \
            && egrep -q \$'INFO:\tUsing local lineages directory ' ${bin}_busco.log ; }; then
            # the second statement is necessary, because certain mollicute clades use a different genetic code, are not part of the BUSCO placement tree, are tested separately
            # and cause different log messages
            echo "Domain and specific lineage could be selected by BUSCO."
            cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.specific_lineage.\${db_name_spec}.${bin}.txt

            db_name_gen=""
            summaries_gen=(BUSCO/short_summary.generic.*.BUSCO.txt)
            if [ \${#summaries_gen[@]} -lt 1 ]; then
                echo "No 'BUSCO/short_summary.generic.*.BUSCO.txt' file found. Assuming selected domain and specific lineages are the same."
                cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.domain.\${db_name_spec}.${bin}.txt
                db_name_gen=\${db_name_spec}
            else
                [[ \$summaries_gen =~ BUSCO/short_summary.generic.(.*).BUSCO.txt ]];
                db_name_gen="\${BASH_REMATCH[1]}"
                echo "Used generic lineage dataset: \${db_name_gen}"
                cp BUSCO/short_summary.generic.\${db_name_gen}.BUSCO.txt short_summary.domain.\${db_name_gen}.${bin}.txt
            fi

            for f in BUSCO/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*faa; do
                cat BUSCO/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*faa | gzip >${bin}_buscos.\${db_name_gen}.faa.gz
                break
            done
            for f in BUSCO/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*fna; do
                cat BUSCO/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*fna | gzip >${bin}_buscos.\${db_name_gen}.fna.gz
                break
            done

        elif egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log && egrep -q \$'INFO:\tNo marker genes were found. Root lineage \\S+ is kept' ${bin}_busco.log ; then
            echo "Domain could be selected by BUSCO, but no more specific lineage."
            cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.domain.\${db_name_spec}.${bin}.txt

        elif egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log && egrep -q \$'INFO:\tNot enough markers were placed on the tree \\([0-9]*\\). Root lineage \\S+ is kept' ${bin}_busco.log ; then
            echo "Domain could be selected by BUSCO, but no more specific lineage."
            cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.domain.\${db_name_spec}.${bin}.txt

        elif egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log && egrep -q \$'INFO:\tRunning virus detection pipeline' ${bin}_busco.log ; then
            # TODO double-check if selected dataset is not one of bacteria_*, archaea_*, eukaryota_*?
            echo "Domain could not be selected by BUSCO, but virus dataset was selected."
            cp BUSCO/short_summary.specific.\${db_name_spec}.BUSCO.txt short_summary.specific_lineage.\${db_name_spec}.${bin}.txt
        else
            echo "ERROR: Some not expected case occurred! See ${bin}_busco.log." >&2
            exit 1
        fi
    fi

    for f in BUSCO/run_\${db_name_spec}/busco_sequences/single_copy_busco_sequences/*faa; do
        cat BUSCO/run_\${db_name_spec}/busco_sequences/single_copy_busco_sequences/*faa | gzip >${bin}_buscos.\${db_name_spec}.faa.gz
        break
    done
    for f in BUSCO/run_\${db_name_spec}/busco_sequences/single_copy_busco_sequences/*fna; do
        cat BUSCO/run_\${db_name_spec}/busco_sequences/single_copy_busco_sequences/*fna | gzip >${bin}_buscos.\${db_name_spec}.fna.gz
        break
    done

elif egrep -q \$'ERROR:\tNo genes were recognized by BUSCO' ${bin}_busco.err ; then
    echo "WARNING: BUSCO analysis failed due to no recognized genes! See also ${bin}_busco.err."
    echo -e "${bin}\tNo genes" > "${bin}_busco.failed_bin.txt"

elif egrep -q \$'INFO:\t\\S+ selected' ${bin}_busco.log && egrep -q \$'ERROR:\tPlacements failed' ${bin}_busco.err ; then
    echo "WARNING: BUSCO analysis failed due to failed placements! See also ${bin}_busco.err. Still using results for selected generic lineage dataset."
    echo -e "${bin}\tPlacements failed" > "${bin}_busco.failed_bin.txt"

    message=\$(egrep \$'INFO:\t\\S+ selected' ${bin}_busco.log)
    [[ \$message =~ INFO:[[:space:]]([_[:alnum:]]+)[[:space:]]selected ]];
    db_name_gen="\${BASH_REMATCH[1]}"
    most_spec_db=\${db_name_gen}
    echo "Used generic lineage dataset: \${db_name_gen}"
    cp BUSCO/auto_lineage/run_\${db_name_gen}/short_summary.txt short_summary.domain.\${db_name_gen}.${bin}.txt

    for f in BUSCO/auto_lineage/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*faa; do
        cat BUSCO/auto_lineage/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*faa | gzip >${bin}_buscos.\${db_name_gen}.faa.gz
        break
    done
    for f in BUSCO/auto_lineage/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*fna; do
        cat BUSCO/auto_lineage/run_\${db_name_gen}/busco_sequences/single_copy_busco_sequences/*fna | gzip >${bin}_buscos.\${db_name_gen}.fna.gz
        break
    done

else
    echo "ERROR: BUSCO analysis failed for some unknown reason! See also ${bin}_busco.err." >&2
    exit 1
fi

# additionally output genes predicted with Prodigal (GFF3)
if [ -f BUSCO/logs/prodigal_out.log ]; then
    mv BUSCO/logs/prodigal_out.log "${bin}_prodigal.gff"
fi

# if needed delete temporary BUSCO files
if [ ${busco_clean} ]; then
    find . -depth -type d -name "augustus_config" -execdir rm -rf "{}" \\;
    find . -depth -type d -name "auto_lineage" -execdir rm -rf "{}" \\;
    find . -depth -type d -name "run_*" -execdir rm -rf "{}" +
fi

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    R: \$(R --version 2>&1 | sed -n 1p | sed 's/R version //' | sed 's/ (.*//')
    busco: \$(busco --version 2>&1 | sed 's/BUSCO //g')
END_VERSIONS
"""
17
18
"""
"""
24
25
26
27
28
29
30
31
32
"""
summary_busco.py $auto $ss $sd $f -o busco_summary.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
CAT prepare --fresh

# get name/date of generated datase
out=(*_taxonomy/)
[[ \$out =~ (.*)_taxonomy/ ]];
DB_NAME="CAT_prepare_\${BASH_REMATCH[1]}"

mv *_taxonomy taxonomy
mv *_database database
rm database/*.nr.gz
if [ ${save_db} = "Y" ] ; then
    tar -cf - taxonomy database | gzip > "\${DB_NAME}".tar.gz
fi

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    CAT: \$(CAT --version | sed "s/CAT v//; s/(.*//")
    diamond: \$(diamond --version 2>&1 | tail -n 1 | sed 's/^diamond version //')
END_VERSIONS
"""
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
if [[ ${database} != *.tar.gz ]]; then
    ln -sr `find ${database}/ -type d -name "*taxonomy*"` taxonomy
    ln -sr `find ${database}/ -type d -name "*database*"` database
else
    mkdir catDB
    tar -xf ${database} -C catDB
    mv `find catDB/ -type d -name "*taxonomy*"` taxonomy/
    mv `find catDB/ -type d -name "*database*"` database/
fi

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    tar: \$(tar --version 2>&1 | sed -n 1p | sed 's/tar (GNU tar) //')
END_VERSIONS
"""
NextFlow From line 17 of local/cat_db.nf
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
CAT bins -b "bins/" -d database/ -t taxonomy/ -n "${task.cpus}" -s .fa --top 6 -o "${meta.assembler}-${meta.binner}-${meta.id}" --I_know_what_Im_doing
CAT add_names -i "${meta.assembler}-${meta.binner}-${meta.id}.ORF2LCA.txt" -o "${meta.assembler}-${meta.binner}-${meta.id}.ORF2LCA.names.txt" -t taxonomy/ ${official_taxonomy}
CAT add_names -i "${meta.assembler}-${meta.binner}-${meta.id}.bin2classification.txt" -o "${meta.assembler}-${meta.binner}-${meta.id}.bin2classification.names.txt" -t taxonomy/ ${official_taxonomy}

mkdir raw
mv *.ORF2LCA.txt *.predicted_proteins.faa *.predicted_proteins.gff *.log *.bin2classification.txt raw/
gzip "raw/${meta.assembler}-${meta.binner}-${meta.id}.ORF2LCA.txt" \
    "raw/${meta.assembler}-${meta.binner}-${meta.id}.concatenated.predicted_proteins.faa" \
    "raw/${meta.assembler}-${meta.binner}-${meta.id}.concatenated.predicted_proteins.gff" \
    "raw/${meta.assembler}-${meta.binner}-${meta.id}.bin2classification.txt" \
    "${meta.assembler}-${meta.binner}-${meta.id}.ORF2LCA.names.txt" \
    "${meta.assembler}-${meta.binner}-${meta.id}.bin2classification.names.txt"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    CAT: \$(CAT --version | sed "s/CAT v//; s/(.*//")
    diamond: \$(diamond --version 2>&1 | tail -n 1 | sed 's/^diamond version //')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
27
28
"""
# use find as sometimes these are empty and need to fail gracefully
find -L -type f -name "*bin2classification.names.txt.gz" -exec sh -c 'for f do gunzip -c \$f > \${f%.*}; done' find-sh {} +

bioawk '(NR == 1) || (FNR > 1)' *.txt > ${prefix}.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bioawk: \$(bioawk --version | cut -f 3 -d ' ' )
END_VERSIONS
"""
16
17
18
19
20
21
22
23
"""
tar -xf "${db}"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    tar: \$(tar --version 2>&1 | sed -n 1p | sed 's/tar (GNU tar) //')
END_VERSIONS
"""
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
centrifuge -x "${db_name}" \
    -p ${task.cpus} \
    --report-file report.txt \
    -S results.txt \
    $input
centrifuge-kreport -x "${db_name}" results.txt > kreport.txt
cat results.txt | cut -f 1,3 > results.krona

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    centrifuge: \$(centrifuge --version | sed -n 1p | sed 's/^.*centrifuge-class version //')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
"""
bioawk '(NR == 1) || (FNR > 1)' ${bin_summaries} > ${prefix}.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bioawk: \$(bioawk --version | cut -f 3 -d ' ' )
END_VERSIONS
"""
19
20
21
22
23
24
25
26
27
"""
gunzip -f $depth
bioawk -t '{ { if (NR > 1) { { print \$1, \$3 } } } }' ${depth.toString() - '.gz'} > ${prefix}_mb2_depth.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bioawk: \$(bioawk --version | cut -f 3 -d ' ' )
END_VERSIONS
"""
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
filtlong \
    -1 ${short_reads_1} \
    -2 ${short_reads_2} \
    --min_length ${params.longreads_min_length} \
    --keep_percent ${params.longreads_keep_percent} \
    --trim \
    --length_weight ${params.longreads_length_weight} \
    ${long_reads} | gzip > ${meta.id}_lr_filtlong.fastq.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    filtlong: \$(filtlong --version | sed -e "s/Filtlong v//g")
END_VERSIONS
"""
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
export GTDBTK_DATA_PATH="\${PWD}/database"
if [ ${pplacer_scratch} != "" ] ; then
    mkdir pplacer_tmp
fi

gtdbtk classify_wf $args \
                --genome_dir bins \
                --prefix "gtdbtk.${meta.assembler}-${meta.binner}-${meta.id}" \
                --out_dir "\${PWD}" \
                --cpus ${task.cpus} \
                --pplacer_cpus ${params.gtdbtk_pplacer_cpus} \
                ${pplacer_scratch} \
                --min_perc_aa ${params.gtdbtk_min_perc_aa} \
                --min_af ${params.gtdbtk_min_af}

gzip "gtdbtk.${meta.assembler}-${meta.binner}-${meta.id}".*.classify.tree "gtdbtk.${meta.assembler}-${meta.binner}-${meta.id}".*.msa.fasta
mv gtdbtk.log "gtdbtk.${meta.assembler}-${meta.binner}-${meta.id}.log"
mv gtdbtk.warnings.log "gtdbtk.${meta.assembler}-${meta.binner}-${meta.id}.warnings.log"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    gtdbtk: \$(gtdbtk --version | sed -n 1p | sed "s/gtdbtk: version //; s/ Copyright.*//")
END_VERSIONS
"""
16
17
18
19
20
21
22
23
24
"""
mkdir database
tar -xzf ${database} -C database --strip 1

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    tar: \$(tar --version 2>&1 | sed -n 1p | sed 's/tar (GNU tar) //')
END_VERSIONS
"""
25
26
27
28
29
30
31
32
33
"""
summary_gtdbtk.py $args $discarded $summaries $filtered $failed --out gtdbtk_summary.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
16
17
18
19
20
21
22
23
24
25
26
"""
mkdir db_tmp
tar -xf "${db}" -C db_tmp
mkdir database
mv `find db_tmp/ -name "*.k2d"` database/

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    tar: \$(tar --version 2>&1 | sed -n 1p | sed 's/tar (GNU tar) //')
END_VERSIONS
"""
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
kraken2 \
    --report-zero-counts \
    --threads ${task.cpus} \
    --db database \
    --report kraken2_report.txt \
    $input \
    > kraken2.kraken
cat kraken2.kraken | cut -f 2,3 > results.krona

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    kraken2: \$(echo \$(kraken2 --version 2>&1) | sed 's/^.*Kraken version //' | sed 's/ Copyright.*//')
END_VERSIONS
"""
13
14
15
16
17
18
19
20
"""
ktUpdateTaxonomy.sh taxonomy

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    ktImportTaxonomy: \$(ktImportTaxonomy 2>&1 | sed -n '/KronaTools /p' | sed 's/^.*KronaTools //; s/ - ktImportTaxonomy.*//')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
"""
ktImportTaxonomy "$report" -tax taxonomy

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    ktImportTaxonomy: \$(ktImportTaxonomy 2>&1 | sed -n '/KronaTools /p' | sed 's/^.*KronaTools //; s/ - ktImportTaxonomy.*//')
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
get_mag_depths.py --bins ${bins} \\
                --depths ${contig_depths} \\
                --assembler ${meta.assembler} \\
                --id ${meta.id} \\
                --binner ${meta.binner}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
27
28
29
"""
plot_mag_depths.py --bin_depths ${depths} \
                --groups ${sample_groups} \
                --out "${meta.assembler}-${meta.binner}-${meta.id}-binDepths.heatmap.png"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
    seaborn: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('seaborn').version)")
END_VERSIONS
"""
17
18
19
20
21
22
23
24
25
26
"""
get_mag_depths_summary.py --depths ${mag_depths} \
                        --out "${prefix}.tsv"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
"""
megahit $args -t "${task.cpus}" -m $mem $input -o MEGAHIT --out-prefix "MEGAHIT-${meta.id}"

gzip -c "MEGAHIT/MEGAHIT-${meta.id}.contigs.fa" > "MEGAHIT/MEGAHIT-${meta.id}.contigs.fa.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    megahit: \$(echo \$(megahit -v 2>&1) | sed 's/MEGAHIT v//')
END_VERSIONS
"""
31
32
33
34
35
36
37
38
39
40
41
42
"""
# get multiqc parsed data for bowtie2
multiqc -f $custom_config_file *.bowtie2.log
multiqc_to_custom_tsv.py ${read_type}
# run multiqc using custom content file instead of original bowtie2 log files
multiqc -f $custom_config_file --ignore "*.bowtie2.log" .

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    multiqc: \$( multiqc --version | sed -e "s/multiqc, version //g" )
END_VERSIONS
"""
44
45
46
47
48
49
50
51
"""
multiqc -f $args .

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    multiqc: \$( multiqc --version | sed -e "s/multiqc, version //g" )
END_VERSIONS
"""
19
20
21
22
23
24
25
26
27
28
29
"""
cat ${reads} | NanoLyse --reference $nanolyse_db | gzip > ${meta.id}_nanolyse.fastq.gz
echo "NanoLyse reference: $params.lambda_reference" >${meta.id}_nanolyse.log
cat ${reads} | echo "total reads before NanoLyse: \$((`wc -l`/4))" >>${meta.id}_nanolyse.log
gunzip -c ${meta.id}_nanolyse.fastq.gz | echo "total reads after NanoLyse: \$((`wc -l`/4))" >> ${meta.id}_nanolyse.log

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    NanoLyse: \$(NanoLyse --version | sed -e "s/NanoLyse //g")
END_VERSIONS
"""
21
22
23
24
25
26
27
28
29
30
31
32
"""
NanoPlot -t ${task.cpus} \
        ${prefix} \
        --title ${title} \
        -c darkblue \
        --fastq ${reads}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    NanoPlot: \$(NanoPlot --version | sed -e "s/NanoPlot //g")
END_VERSIONS
"""
17
18
19
20
21
22
23
24
25
"""
cat ${reads1} > "pooled_${meta.id}_1.fastq.gz"
cat ${reads2} > "pooled_${meta.id}_2.fastq.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    cat: \$(cat --version 2>&1 | sed -n 1p | sed 's/cat (GNU coreutils) //')
END_VERSIONS
"""
17
18
19
20
21
22
23
24
"""
cat ${reads} > "pooled_${meta.id}.fastq.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    cat: \$(cat --version 2>&1 | sed -n 1p | sed 's/cat (GNU coreutils) //')
END_VERSIONS
"""
17
18
19
20
21
22
23
24
"""
porechop -i ${reads} -t ${task.cpus} -o ${meta.id}_porechop.fastq

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    porechop: \$(porechop --version)
END_VERSIONS
"""
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
BINS=\$(echo \"$bins\" | sed 's/[][]//g')
IFS=', ' read -r -a bins <<< \"\$BINS\"
for bin in \"\${bins[@]}\"; do
    metaquast.py --threads "${task.cpus}" --max-ref-number 0 --rna-finding --gene-finding -l "\${bin}" "\${bin}" -o "QUAST/\${bin}"
    if ! [ -f "QUAST/${meta.assembler}-${meta.binner}-${meta.id}-quast_summary.tsv" ]; then
        cp "QUAST/\${bin}/transposed_report.tsv" "QUAST/${meta.assembler}-${meta.binner}-${meta.id}-quast_summary.tsv"
    else
        tail -n +2 "QUAST/\${bin}/transposed_report.tsv" >> "QUAST/${meta.assembler}-${meta.binner}-${meta.id}-quast_summary.tsv"
    fi
done

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    metaquast: \$(metaquast.py --version | sed "s/QUAST v//; s/ (MetaQUAST mode)//")
END_VERSIONS
"""
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
QUAST_BIN=\$(echo \"$summaries\" | sed 's/[][]//g')
IFS=', ' read -r -a quast_bin <<< \"\$QUAST_BIN\"
for quast_file in \"\${quast_bin[@]}\"; do
    if ! [ -f "quast_summary.tsv" ]; then
        cp "\${quast_file}" "quast_summary.tsv"
    else
        tail -n +2 "\${quast_file}" >> "quast_summary.tsv"
    fi
done

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    sed: \$(sed --version 2>&1 | sed -n 1p | sed 's/sed (GNU sed) //')
END_VERSIONS
"""
17
18
19
20
21
22
23
24
25
"""
metaquast.py --threads "${task.cpus}" --rna-finding --max-ref-number 0 -l "${meta.assembler}-${meta.id}" "${assembly}" -o "QUAST"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    metaquast: \$(metaquast.py --version | sed "s/QUAST v//; s/ (MetaQUAST mode)//")
END_VERSIONS
"""
NextFlow From line 17 of local/quast.nf
19
20
21
22
23
"""
if [[ -f unbinned.fa ]]; then
    mv unbinned.fa ${meta.assembler}-DASToolUnbinned-${meta.id}.fa
fi
"""
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
if [ -n "${bins}" ]
then
    for bin in ${bins}; do
        if [[ \${bin} =~ ${meta.assembler}-${meta.binner}-${meta.id}.([_[:alnum:]]+).fa ]]; then
            num=\${BASH_REMATCH[1]}
            mv \${bin} ${meta.assembler}-${meta.binner}Refined-${meta.id}.\${num}.fa
        else
            echo "ERROR: the bin filename \${bin} does not match the expected format '${meta.assembler}-${meta.binner}-${meta.id}.([_[:alnum:]]+).fa'!"
            exit 1
        fi
    done
fi
"""
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
metaspades.py \
    $args \
    --threads "${task.cpus}" \
    --memory $maxmem \
    --pe1-1 ${short_reads[0]} \
    --pe1-2 ${short_reads[1]} \
    --nanopore ${long_reads} \
    -o spades
mv spades/assembly_graph_with_scaffolds.gfa SPAdesHybrid-${meta.id}_graph.gfa
mv spades/scaffolds.fasta SPAdesHybrid-${meta.id}_scaffolds.fasta
mv spades/contigs.fasta SPAdesHybrid-${meta.id}_contigs.fasta
mv spades/spades.log SPAdesHybrid-${meta.id}.log
gzip "SPAdesHybrid-${meta.id}_contigs.fasta"
gzip "SPAdesHybrid-${meta.id}_graph.gfa"
gzip -c "SPAdesHybrid-${meta.id}_scaffolds.fasta" > "SPAdesHybrid-${meta.id}_scaffolds.fasta.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    metaspades: \$(metaspades.py --version | sed "s/SPAdes genome assembler v//; s/ \\[.*//")
END_VERSIONS
"""
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
metaspades.py \
    $args \
    --threads "${task.cpus}" \
    --memory $maxmem \
    --pe1-1 ${reads[0]} \
    --pe1-2 ${reads[1]} \
    -o spades
mv spades/assembly_graph_with_scaffolds.gfa SPAdes-${meta.id}_graph.gfa
mv spades/scaffolds.fasta SPAdes-${meta.id}_scaffolds.fasta
mv spades/contigs.fasta SPAdes-${meta.id}_contigs.fasta
mv spades/spades.log SPAdes-${meta.id}.log
gzip "SPAdes-${meta.id}_contigs.fasta"
gzip "SPAdes-${meta.id}_graph.gfa"
gzip -c "SPAdes-${meta.id}_scaffolds.fasta" > "SPAdes-${meta.id}_scaffolds.fasta.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    metaspades: \$(metaspades.py --version | sed "s/SPAdes genome assembler v//; s/ \\[.*//")
END_VERSIONS
"""
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
# save unbinned contigs above thresholds into individual files, dump others in one file
split_fasta.py $unbinned ${params.min_length_unbinned_contigs} ${params.max_unbinned_contigs} ${params.min_contig_size}

gzip *.fa

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    python: \$(python --version 2>&1 | sed 's/Python //g')
    biopython: 1.7.4
    pandas: \$(python -c "import pkg_resources; print(pkg_resources.get_distribution('pandas').version)")
END_VERSIONS
"""
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
AdapterRemoval  \\
    --file1 $reads \\
    $args \\
    $list \\
    --basename ${prefix} \\
    --threads ${task.cpus} \\
    --seed 42 \\
    --gzip

ensure_fastq() {
    if [ -f "\${1}" ]; then
        mv "\${1}" "\${1::-3}.fastq.gz"
    fi

}

ensure_fastq '${prefix}.truncated.gz'
ensure_fastq '${prefix}.discarded.gz'

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    adapterremoval: \$(AdapterRemoval --version 2>&1 | sed -e "s/AdapterRemoval ver. //g")
END_VERSIONS
"""
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
AdapterRemoval  \\
    --file1 ${reads[0]} \\
    --file2 ${reads[1]} \\
    $args \\
    $list \\
    --basename ${prefix} \\
    --threads $task.cpus \\
    --seed 42 \\
    --gzip

ensure_fastq() {
    if [ -f "\${1}" ]; then
        mv "\${1}" "\${1::-3}.fastq.gz"
    fi

}

ensure_fastq '${prefix}.truncated.gz'
ensure_fastq '${prefix}.discarded.gz'
ensure_fastq '${prefix}.pair1.truncated.gz'
ensure_fastq '${prefix}.pair2.truncated.gz'
ensure_fastq '${prefix}.collapsed.gz'
ensure_fastq '${prefix}.collapsed.truncated.gz'
ensure_fastq '${prefix}.paired.gz'

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    adapterremoval: \$(AdapterRemoval --version 2>&1 | sed -e "s/AdapterRemoval ver. //g")
END_VERSIONS
"""
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
set -e

aria2c \\
    --check-certificate=false \\
    $args \\
    $source_url

mkdir checkm_data_2015_01_16/
tar x -C checkm_data_2015_01_16 -v -z -f *.tar.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    aria2: \$(echo \$(aria2c --version 2>&1) | grep 'aria2 version' | cut -f3 -d ' ')
END_VERSIONS
"""
NextFlow From line 25 of aria2/main.nf
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
cat $fasta \\
    | bcftools \\
        consensus \\
        $vcf \\
        $args \\
        > ${prefix}.fa

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
END_VERSIONS
"""
25
26
27
28
29
30
31
32
33
34
35
36
"""
bcftools \\
    index \\
    $args \\
    --threads $task.cpus \\
    $vcf

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
END_VERSIONS
"""
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
bcftools view \\
    --output ${prefix}.vcf.gz \\
    ${regions_file} \\
    ${targets_file} \\
    ${samples_file} \\
    $args \\
    --threads $task.cpus \\
    ${vcf}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
END_VERSIONS
"""
47
48
49
50
51
52
53
54
"""
touch ${prefix}.vcf.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
END_VERSIONS
"""
NextFlow From line 47 of view/main.nf
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
$checkm_db

checkm \\
    lineage_wf \\
    -t $task.cpus \\
    -f ${prefix}.tsv \\
    --tab_table \\
    --pplacer_threads $task.cpus \\
    -x $fasta_ext \\
    $args \\
    input_bins/ \\
    $prefix

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    checkm: \$( checkm 2>&1 | grep '...:::' | sed 's/.*CheckM v//;s/ .*//' )
END_VERSIONS
"""
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
checkm \\
    qa \\
    --threads ${task.cpus} \\
    --file ${prefix}.${suffix} \\
    $marker_file \\
    $analysis_dir \\
    $coverage \\
    $exclude \\
    $args

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    checkm: \$( checkm 2>&1 | grep '...:::' | sed 's/.*CheckM v//;s/ .*//' )
END_VERSIONS
"""
24
25
26
27
28
29
30
31
32
33
34
35
"""
concoct_coverage_table.py \\
    $args \\
    $bed \\
    $bamfiles \\
    > ${prefix}.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    concoct: \$(echo \$(concoct --version 2>&1) | sed 's/concoct //g' )
END_VERSIONS
"""
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
concoct \\
    $args \\
    --threads ${task.cpus} \\
    --coverage_file ${coverage_file} \\
    --composition_file ${fasta} \\
    -b ${prefix}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    concoct: \$(echo \$(concoct --version 2>&1) | sed 's/concoct //g' )
END_VERSIONS
"""
28
29
30
31
32
33
34
35
36
37
38
39
"""
cut_up_fasta.py \\
    $fasta \\
    $args \\
    $bedfile \\
    > ${prefix}.fasta

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    concoct: \$(echo \$(concoct --version 2>&1) | sed 's/concoct //g' )
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
mkdir ${prefix}

extract_fasta_bins.py \\
    $args \\
    $original_fasta \\
    $csv \\
    --output_path ${prefix}

## Add prefix to each file to disambiguate one sample's 1.fa, 2.fa from sample2
for i in ${prefix}/*.fa; do
    mv \${i} \${i/\\///${prefix}_}
    gzip \${i/\\///${prefix}_}
done

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    concoct: \$(echo \$(concoct --version 2>&1) | sed 's/concoct //g' )
END_VERSIONS
"""
24
25
26
27
28
29
30
31
32
33
34
"""
merge_cutup_clustering.py \\
    $args \\
    $clustering_csv \\
    > ${prefix}.csv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    concoct: \$(echo \$(concoct --version 2>&1) | sed 's/concoct //g' )
END_VERSIONS
"""
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
$decompress_proteins
$decompress_contigs

DAS_Tool \\
    $args \\
    $proteins_pred \\
    $db_dir \\
    -t $task.cpus \\
    -i $bin_list \\
    -c $clean_contigs \\
    -o $prefix

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    dastool: \$( DAS_Tool --version 2>&1 | grep "DAS Tool" | sed 's/DAS Tool //' )
END_VERSIONS
"""
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
$decompress_fasta

Fasta_to_Contig2Bin.sh \\
    $args \\
    -i . \\
    -e $file_extension \\
    > ${prefix}.tsv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    dastool: \$( DAS_Tool --version 2>&1 | grep "DAS Tool" | sed 's/DAS Tool //' )
END_VERSIONS
"""
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
[ ! -f  ${prefix}.fastq.gz ] && ln -sf $reads ${prefix}.fastq.gz

fastp \\
    --stdout \\
    --in1 ${prefix}.fastq.gz \\
    --thread $task.cpus \\
    --json ${prefix}.fastp.json \\
    --html ${prefix}.fastp.html \\
    $adapter_list \\
    $fail_fastq \\
    $args \\
    2> ${prefix}.fastp.log \\
| gzip -c > ${prefix}.fastp.fastq.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    fastp: \$(fastp --version 2>&1 | sed -e "s/fastp //g")
END_VERSIONS
"""
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
[ ! -f  ${prefix}.fastq.gz ] && ln -sf $reads ${prefix}.fastq.gz

fastp \\
    --stdout \\
    --in1 ${prefix}.fastq.gz \\
    --out1  ${prefix}.fastp.fastq.gz \\
    --thread $task.cpus \\
    --json ${prefix}.fastp.json \\
    --html ${prefix}.fastp.html \\
    $adapter_list \\
    $fail_fastq \\
    $args \\
    2> ${prefix}.fastp.log

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    fastp: \$(fastp --version 2>&1 | sed -e "s/fastp //g")
END_VERSIONS
"""
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
"""
[ ! -f  ${prefix}_1.fastq.gz ] && ln -sf ${reads[0]} ${prefix}_1.fastq.gz
[ ! -f  ${prefix}_2.fastq.gz ] && ln -sf ${reads[1]} ${prefix}_2.fastq.gz
fastp \\
    --in1 ${prefix}_1.fastq.gz \\
    --in2 ${prefix}_2.fastq.gz \\
    --out1 ${prefix}_1.fastp.fastq.gz \\
    --out2 ${prefix}_2.fastp.fastq.gz \\
    --json ${prefix}.fastp.json \\
    --html ${prefix}.fastp.html \\
    $adapter_list \\
    $fail_fastq \\
    $merge_fastq \\
    --thread $task.cpus \\
    --detect_adapter_for_pe \\
    $args \\
    2> ${prefix}.fastp.log

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    fastp: \$(fastp --version 2>&1 | sed -e "s/fastp //g")
END_VERSIONS
"""
28
29
30
31
32
33
34
35
36
37
38
"""
printf "%s %s\\n" $rename_to | while read old_name new_name; do
    [ -f "\${new_name}" ] || ln -s \$old_name \$new_name
done
fastqc $args --threads $task.cpus $renamed_files

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    fastqc: \$( fastqc --version | sed -e "s/FastQC v//g" )
END_VERSIONS
"""
42
43
44
45
46
47
48
49
50
"""
touch ${prefix}.html
touch ${prefix}.zip

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    fastqc: \$( fastqc --version | sed -e "s/FastQC v//g" )
END_VERSIONS
"""
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
freebayes \\
    -f $fasta \\
    $targets_file \\
    $samples_file \\
    $populations_file \\
    $cnv_file \\
    $args \\
    $input > ${prefix}.vcf

bgzip ${prefix}.vcf

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    freebayes: \$(echo \$(freebayes --version 2>&1) | sed 's/version:\s*v//g' )
END_VERSIONS
"""
22
23
24
25
26
27
28
29
"""
gunc download_db . -db $db_name $args

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    gunc: \$( gunc --version )
END_VERSIONS
"""
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
gunc \\
    run \\
    --input_fasta $fasta \\
    --db_file $db \\
    --threads $task.cpus \\
    $args

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    gunc: \$( gunc --version )
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
"""
gunzip \\
    -f \\
    $args \\
    $archive

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    gunzip: \$(echo \$(gunzip --version 2>&1) | sed 's/^.*(gzip) //; s/ Copyright.*\$//')
END_VERSIONS
"""
NextFlow From line 23 of gunzip/main.nf
37
38
39
40
41
42
43
"""
touch $gunzip
cat <<-END_VERSIONS > versions.yml
"${task.process}":
    gunzip: \$(echo \$(gunzip --version 2>&1) | sed 's/^.*(gzip) //; s/ Copyright.*\$//')
END_VERSIONS
"""
NextFlow From line 37 of gunzip/main.nf
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
mkdir input/ && mv $contigs input/
run_MaxBin.pl \\
    -contig input/$contigs \\
    $associate_files \\
    -thread $task.cpus \\
    $args \\
    -out $prefix

gzip *.fasta *.noclass *.tooshort *log *.marker

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    maxbin2: \$( run_MaxBin.pl -v | head -n 1 | sed 's/MaxBin //' )
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
export OMP_NUM_THREADS=$task.cpus

jgi_summarize_bam_contig_depths \\
    --outputDepth ${prefix}.txt \\
    $args \\
    $bam

bgzip --threads $task.cpus ${prefix}.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    metabat2: \$( metabat2 --help 2>&1 | head -n 2 | tail -n 1| sed 's/.*\\:\\([0-9]*\\.[0-9]*\\).*/\\1/' )
END_VERSIONS
"""
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
$decompress_depth

metabat2 \\
    $args \\
    -i $fasta \\
    $depth_file \\
    -t $task.cpus \\
    --saveCls \\
    -o metabat2/${prefix}

mv metabat2/${prefix} ${prefix}.tsv
mv metabat2 bins

gzip ${prefix}.tsv
find ./bins/ -name "*.fa" -type f | xargs -t -n 1 bgzip -@ ${task.cpus}
find ./bins/ -name "*[lowDepth,tooShort,unbinned].fa.gz" -type f -exec mv {} . \\;

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    metabat2: \$( metabat2 --help 2>&1 | head -n 2 | tail -n 1| sed 's/.*\\:\\([0-9]*\\.[0-9]*\\).*/\\1/' )
END_VERSIONS
"""
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
pigz -cdf ${genome} | prodigal \\
    $args \\
    -f $output_format \\
    -d "${prefix}.fna" \\
    -o "${prefix}.${output_format}" \\
    -a "${prefix}.faa" \\
    -s "${prefix}_all.txt"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    prodigal: \$(prodigal -v 2>&1 | sed -n 's/Prodigal V\\(.*\\):.*/\\1/p')
    pigz: \$(pigz -V 2>&1 | sed 's/pigz //g')
END_VERSIONS
"""
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
prokka \\
    $args \\
    --cpus $task.cpus \\
    --prefix $prefix \\
    $proteins_opt \\
    $prodigal_tf \\
    $fasta

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    prokka: \$(echo \$(prokka --version 2>&1) | sed 's/^.*prokka //')
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
34
"""
pydamage \\
    analyze \\
    $args \\
    -p $task.cpus \\
    $bam

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    pydamage: \$(echo \$(pydamage --version 2>&1) | sed -e 's/pydamage, version //g')
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
34
"""

pydamage \\
    filter \\
    $args \\
    $csv

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    pydamage: \$(echo \$(pydamage --version 2>&1) | sed -e 's/pydamage, version //g')
END_VERSIONS
"""
23
24
25
26
27
28
29
30
31
32
33
"""
samtools \\
    faidx \\
    $args \\
    $fasta

cat <<-END_VERSIONS > versions.yml
"${task.process}":
    samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
END_VERSIONS
"""
36
37
38
39
40
41
42
43
"""
touch ${fasta}.fai
cat <<-END_VERSIONS > versions.yml

"${task.process}":
    samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
END_VERSIONS
"""
NextFlow From line 36 of faidx/main.nf
ShowHide 50 more snippets with no or duplicated tags.

Login to post a comment if you would like to share your experience with this workflow.

Do you know this workflow well? If so, you can request seller status , and start supporting this workflow.

Related Workflows

cellranger-snakemake-gke
snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...