diff --git a/src/nf_modules/MUSIC/peak_calling_single.config b/src/nf_modules/MUSIC/peak_calling_single.config new file mode 100644 index 0000000000000000000000000000000000000000..7c53891779e89d48608079a71bd20405d75f6a9e --- /dev/null +++ b/src/nf_modules/MUSIC/peak_calling_single.config @@ -0,0 +1,42 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $compute_mappability { + container = "music:6613c53" + } + $music_preprocessing { + container = "music:6613c53" + } + $music_sort { + container = "music:6613c53" + } + $music_dedup { + container = "music:6613c53" + } + $music_computation { + container = "music:6613c53" + } + } + } + sge { + process{ + $compute_mappability { + beforeScript = "module purge; module load MUSIC/6613c53" + } + $music_preprocessing { + beforeScript = "module purge; module load MUSIC/6613c53" + } + $music_sort { + beforeScript = "module purge; module load MUSIC/6613c53" + } + $music_dedup { + beforeScript = "module purge; module load MUSIC/6613c53" + } + $music_computation { + beforeScript = "module purge; module load MUSIC/6613c53" + } + } + } +} diff --git a/src/nf_modules/MUSIC/peak_calling_single.nf b/src/nf_modules/MUSIC/peak_calling_single.nf new file mode 100644 index 0000000000000000000000000000000000000000..3a29726c8d2635a83f9dc80d1e65f18c12f4d9ba --- /dev/null +++ b/src/nf_modules/MUSIC/peak_calling_single.nf @@ -0,0 +1,105 @@ +params.reads_size = 100 +params.frag_size = 200 +params.begin_l = 50 +params.end_l = 500 + +log.info "bam files : ${params.bam}" +log.info "index files : ${params.index}" +log.info "fasta files : ${params.fasta}" + +Channel + .fromPath( params.fasta ) + .ifEmpty { error "Cannot find any bam files matching: ${params.fasta}" } + .set { fasta_files } +Channel + .fromPath( params.bam ) + .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } + .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]} + .set { bam_files } +Channel + .fromPath( params.index ) + .ifEmpty { error "Cannot find any index files matching: ${params.index}" } + .set { index_files } + +process compute_mappability { + tag "${fasta.baseName}" + + input: + file index from index_files.collect() + file fasta from fasta_files + + output: + file "*.bin" into mappability + file "temp/chr_ids.txt" into chr_ids + + script: + +""" +generate_multimappability_signal.csh ${fasta} ${params.reads_size} ./ +bash temp_map_reads.csh +bash temp_process_mapping.csh +""" +} + +process music_preprocessing { + tag "${file_id}" + + input: + set file_id, file(bam) from bam_files + file chr_ids from chr_ids.collect() + + output: + set file_id, "preprocessed/*.tar" into preprocessed_bam_files + + script: + +""" +mkdir preprocessed +samtools view *.bam | \ +MUSIC -preprocess SAM stdin preprocessed/ +mkdir preprocessed/sorted +MUSIC -sort_reads preprocessed/ preprocessed/sorted/ +mkdir preprocessed/dedup +MUSIC -remove_duplicates ./preprocessed/sorted 2 preprocessed/dedup/ +cd preprocessed +tar -c -f ${file_id}.tar * +""" +} + +preprocessed_bam_files_control = Channel.create() +preprocessed_bam_files_chip = Channel.create() +preprocessed_bam_files.choice( + preprocessed_bam_files_control, + preprocessed_bam_files_chip ) { a -> a[0] =~ /.*control.*/ ? 0 : 1 } + +process music_computation { + tag "${file_id}" + publishDir "results/peak_calling/${file_id}", mode: 'copy' + + input: + set file_id, file(control) from preprocessed_bam_files_chip + set file_id_control, file(chip) from preprocessed_bam_files_control.collect() + file mapp from mappability.collect() + + output: + file "*" into music_output_forward + file "*.bed" into peaks_forward + + script: + +""" +mkdir mappability control chip +mv ${mapp} mappability/ +tar -xf ${control} -C control/ +tar -xf ${chip} -C chip/ + +MUSIC -get_per_win_p_vals_vs_FC -chip chip/ -control control/ \ + -l_win_step ${params.end_l} \ + -l_win_min ${params.end_l} -l_win_max ${params.end_l * 10} +MUSIC -get_multiscale_punctate_ERs \ + -chip chip/ -control control/ -mapp mappability/ \ + -begin_l ${params.begin_l} -end_l ${params.end_l} -step 1.1 \ + -l_mapp ${params.reads_size} -l_frag ${params.frag_size} -q_val 1 -l_p 0 +ls -l +""" +}