Commit ad9d5c6c authored by Chris Cheshire's avatar Chris Cheshire
Browse files

Calc frags now working

parent 8d473267
Loading
Loading
Loading
Loading
+86 −67
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ if(params.run_peak_calling) {

if(params.run_peak_calling && 'seacr' in params.callers) {
    process {
        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:SEACR_.*' {
        withName: '.*:CUTANDRUN:SEACR_.*' {
            ext.args   = "non stringent"
            ext.prefix = { "${meta.id}.seacr.peaks.bed" }
            publishDir = [
@@ -483,7 +483,7 @@ if(params.run_peak_calling && 'seacr' in params.callers) {

if(params.run_peak_calling && 'macs2' in params.callers) {
    process {
        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:MACS2_.*' {
        withName: '.*:CUTANDRUN:MACS2_.*' {
            ext.args   = "-p ${params.macs2_pvalue}"
            ext.prefix = { "${meta.id}.macs2.peaks.bed" }
            publishDir = [
@@ -504,7 +504,7 @@ if(params.run_peak_calling && 'macs2' in params.callers) {

if(params.run_peak_calling) {
    process {
        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:AWK_NAME_PEAK_BED' {
        withName: '.*:AWK_NAME_PEAK_BED' {
            ext.command = "'{OFS = \"\\t\"} {print \$0, FILENAME}'"
            ext.ext     = "bed"
            publishDir = [
@@ -544,7 +544,7 @@ if(params.run_peak_calling) {

if(params.run_peak_calling && !params.run_consensus_all) {
    process {
        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:CONSENSUS_PEAKS:AWK' {
        withName: '.*:CONSENSUS_PEAKS:AWK' {
            ext.command = "' \$10 >= 1 {print \$0}'"
            ext.ext     = "bed"
            publishDir  = [
@@ -559,7 +559,7 @@ if(params.run_peak_calling && !params.run_consensus_all) {

if(params.run_peak_calling && params.run_consensus_all) {
    process {
        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:CONSENSUS_PEAKS_ALL:AWK' {
        withName: '.*:CONSENSUS_PEAKS_ALL:AWK' {
            ext.command = "' \$10 >= " + params.replicate_threshold.toString() + " {print \$0}'"
            ext.ext    = "bed"
            publishDir = [
@@ -572,6 +572,86 @@ if(params.run_peak_calling && params.run_consensus_all) {
    }
}

/*
========================================================================================
    CALCULATE FRAGMENTS
========================================================================================
*/

if(params.run_peak_calling) {
    process {
        withName: '.*:CALCULATE_FRAGMENTS:SAMTOOLS_VIEW' {
            ext.args = "-F 0x04 -b"
            ext.prefix = { "${meta.id}.mapped" }
            publishDir = [
                enabled: false
            ]
        }

        withName: '.*:CALCULATE_FRAGMENTS:SAMTOOLS_SORT' {
            ext.args = "-n"
            ext.prefix = { "${meta.id}.mapped.sorted" }
            publishDir = [
                enabled: false
            ]
        }

        withName: '.*:CALCULATE_FRAGMENTS:BEDTOOLS_BAMTOBED' {
            ext.args = "-bedpe"
            publishDir = [
                enabled: false
            ]
        }

        withName: '.*:CALCULATE_FRAGMENTS:AWK' {
            ext.command = "'\$1==\$4 && \$6-\$2 < 1000 {print \$0}'"
            ext.suffix = ".filt"
            ext.ext    = "bed"
            publishDir = [
                enabled: false
            ]
        }

        withName: '.*:CALCULATE_FRAGMENTS:CUT' {
            ext.args    = "-f 1,2,6"
            ext.command = "| sort -T '.' -k1,1 -k2,2n -k3,3n"
            ext.suffix  = ".frags"
            ext.ext     = "bed"
            publishDir  = [
                path: { "${params.outdir}/03_peak_calling/06_fragments" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                enabled: true
            ]
        }

        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:AWK_FRAG_BIN' {
            ext.args     = "-v w=500"
            ext.command  = "'{print \$1, int((\$2 + \$3)/(2*w))*w + w/2, FILENAME}'"
            ext.command2 = "| sort -T '.' -k1,1V -k2,2n | uniq -c | awk -v OFS=\"\\t\" '{print \$2, \$3, \$1, \$4}' | sort -T '.' -k1,1V -k2,2n"
            ext.suffix   = ".frags.bin500" 
            publishDir   = [
                path: { "${params.outdir}/03_peak_calling/06_fragments" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                enabled: true
            ]
        }

        withName: 'NFCORE_CUTANDRUN:CUTANDRUN:SAMTOOLS_CUSTOMVIEW' {
            ext.args     = "-F 0x04"
            ext.args2    = "awk -F'\\t' 'function abs(x){return ((x < 0.0) ? -x : x)} {print abs(\$9)}' | sort -T '.' | uniq -c | awk -v OFS=\"\\t\" '{print \$2, \$1/2}'"
            ext.suffix   = ".frags.len" 
            publishDir   = [
                path: { "${params.outdir}/03_peak_calling/06_fragments" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                enabled: true
            ]
        }
    }
}

// //TODO: PEAK PLOTTING options - infact all reporting options - how t


@@ -653,64 +733,3 @@ if(params.run_peak_calling && params.run_consensus_all) {
//             args          = "-v"
//             publish_dir   = "04_reporting/multiqc"
//         }
 No newline at end of file

//         /*
//         ========================================================================================
//             CALCULATE FRAGMENTS
//         ========================================================================================
//         */

//         "calc_frag_samtools" {
//             suffix        = ".mapped"
//             publish_files = false
//         }

//         "calc_frag_samtools_view" {
//             args          = "-F 0x04 -b"
//             suffix        = ".mapped"
//             publish_files = false
//         }

//         "calc_frag_samtools_sort" {
//             args          = "-n"
//             suffix        = ".sorted"
//             publish_files = false
//         }

//         "calc_frag_bamtobed" {
//             args          = "-bedpe"
//             publish_files = false
//         }

//         "calc_frag_awk" {
//             suffix        = ".clean"
//             ext           = "bed"
//             command       = "'\$1==\$4 && \$6-\$2 < 1000 {print \$0}'"
//             publish_files = false
//         }

//         "calc_frag_cut" {
//             args          = "-f 1,2,6"
//             suffix        = ".frags"
//             ext           = "bed"
//             command       = "| sort -T '.' -k1,1 -k2,2n -k3,3n"
//             publish_dir   = "03_peak_calling/06_fragments"
//         }

//         "awk_frag_bin" {
//             args         = "-v w=500"
//             suffix        = ".frags.bin500"
//             ext           = "bed"
//             publish_dir   = "03_peak_calling/06_fragments"
//             command       = "'{print \$1, int((\$2 + \$3)/(2*w))*w + w/2, FILENAME}'"
//             command2      = "| sort -T '.' -k1,1V -k2,2n | uniq -c | awk -v OFS=\"\\t\" '{print \$2, \$3, \$1, \$4}' | sort -T '.' -k1,1V -k2,2n"
//         }

//         "samtools_frag_len" {
//             args          = "-F 0x04"
//             args2         = "awk -F'\\t' 'function abs(x){return ((x < 0.0) ? -x : x)} {print abs(\$9)}' | sort -T '.' | uniq -c | awk -v OFS=\"\\t\" '{print \$2, \$1/2}'"
//             suffix        = ".frag_len"
//             publish_dir   = "03_peak_calling/06_fragments"
//         }
//     }
// }
+2 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ process AWK {

    conda (params.enable_conda ? "conda-forge::gawk=5.1.0" : null)
    container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
        'https://depot.galaxyproject.org/singularity/gawk:5.1.0' :
        'quay.io/biocontainers/gawk:5.1.0' }"
        'https://containers.biocontainers.pro/s3/SingImgsRepo/biocontainers/v1.2.0_cv1/biocontainers_v1.2.0_cv1.img' :
        'biocontainers/biocontainers:v1.2.0_cv1' }"

    input:
    tuple val(meta), path(input)
+17 −18
Original line number Diff line number Diff line
@@ -100,10 +100,10 @@ if ((caller_list + callers).unique().size() != caller_list.size()) {
 */
include { INPUT_CHECK                     } from "../subworkflows/local/input_check"
include { AWK as AWK_NAME_PEAK_BED        } from "../modules/local/linux/awk"
include { AWK as AWK_FRAG_BIN             } from "../modules/local/linux/awk"
include { SAMTOOLS_CUSTOMVIEW             } from "../modules/local/samtools_custom_view"
// include { IGV_SESSION                     } from "../modules/local/python/igv_session"                 addParams( options: modules["igv"]                 )
// include { AWK as AWK_EDIT_PEAK_BED        } from "../modules/local/linux/awk"                          addParams( options: modules["awk_edit_peak_bed"]   )
// include { AWK as AWK_FRAG_BIN             } from "../modules/local/linux/awk"                          addParams( options: modules["awk_frag_bin"]        )
// include { SAMTOOLS_CUSTOMVIEW             } from "../modules/local/samtools_custom_view"               addParams( options: modules["samtools_frag_len"]   )
// include { CALCULATE_FRIP                  } from "../modules/local/modules/calculate_frip/main"        addParams( options: modules["calc_frip"]           )
// include { CUT as CUT_CALC_REPROD          } from "../modules/local/linux/cut"                          addParams( options: modules["calc_peak_repro_cut"] )
// include { CALCULATE_PEAK_REPROD           } from "../modules/local/modules/calculate_peak_reprod/main" addParams( options: modules["calc_peak_repro"]     )
@@ -123,7 +123,7 @@ include { ANNOTATE_META_AWK as ANNOTATE_BT2_SPIKEIN_META } from "../subworkflows
include { ANNOTATE_META_AWK as ANNOTATE_DEDUP_META       } from "../subworkflows/local/annotate_meta_awk"
include { CONSENSUS_PEAKS                                } from "../subworkflows/local/consensus_peaks"
include { CONSENSUS_PEAKS as CONSENSUS_PEAKS_ALL         } from "../subworkflows/local/consensus_peaks"
// include { CALCULATE_FRAGMENTS                            } from "../subworkflows/local/calculate_fragments"      addParams( samtools_options: modules["calc_frag_samtools"], samtools_view_options: modules["calc_frag_samtools_view"], samtools_sort_options: modules["calc_frag_samtools_sort"], bamtobed_options: modules["calc_frag_bamtobed"], awk_options: modules["calc_frag_awk"], cut_options: modules["calc_frag_cut"] )
include { CALCULATE_FRAGMENTS                            } from "../subworkflows/local/calculate_fragments"
// include { ANNOTATE_META_CSV as ANNOTATE_FRIP_META        } from "../subworkflows/local/annotate_meta_csv"        addParams( options: modules["meta_csv_frip_options"] )
// include { ANNOTATE_META_CSV as ANNOTATE_PEAK_REPRO_META  } from "../subworkflows/local/annotate_meta_csv"        addParams( options: modules["meta_csv_peak_repro_options"] )

@@ -727,39 +727,38 @@ workflow CUTANDRUN {
        * - Keep the read pairs that are on the same chromosome and fragment length less than 1000bp
        * - Only extract the fragment related columns using cut
        */
        // CALCULATE_FRAGMENTS (
        //     ch_samtools_bam
        // )
        // ch_software_versions = ch_software_versions.mix(CALCULATE_FRAGMENTS.out.versions)
        CALCULATE_FRAGMENTS (
            ch_samtools_bam
        )
        ch_software_versions = ch_software_versions.mix(CALCULATE_FRAGMENTS.out.versions)
        //EXAMPLE CHANNEL STRUCT: NO CHANGE
        //CALCULATE_FRAGMENTS.out.bed | view

        /*
        * MODULE: Bin the fragments into 500bp bins ready for downstream reporting
        */
        // AWK_FRAG_BIN(
        //     CALCULATE_FRAGMENTS.out.bed
        // )
        AWK_FRAG_BIN(
            CALCULATE_FRAGMENTS.out.bed
        )
        //AWK_FRAG_BIN.out.file | view


        /*
        * CHANNEL: Combine bam and bai files on id
        */
        // ch_samtools_bam
        //     .map { row -> [row[0].id, row ].flatten()}
        //     .join ( ch_samtools_bai.map { row -> [row[0].id, row ].flatten()} )
        //     .map { row -> [row[1], row[2], row[4]] }
        //     .set { ch_bam_bai }
        ch_samtools_bam.map { row -> [row[0].id, row ].flatten()}
        .join ( ch_samtools_bai.map { row -> [row[0].id, row ].flatten()} )
        .map { row -> [row[1], row[2], row[4]] }
        .set { ch_bam_bai }
        // EXAMPLE CHANNEL STRUCT: [[META], BAM, BAI]
        //ch_bam_bai | view

        /*
        * MODULE: Calculate fragment lengths
        */
        // SAMTOOLS_CUSTOMVIEW (
        //     ch_bam_bai
        // )
        SAMTOOLS_CUSTOMVIEW (
            ch_bam_bai
        )
        // ch_software_versions = ch_software_versions.mix(SAMTOOLS_CUSTOMVIEW.out.versions)
        //SAMTOOLS_CUSTOMVIEW.out.tsv | view
    }