Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add antibody directory to consensus peaks in IGV session #308

Merged
merged 7 commits into from
Oct 2, 2022
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [[2.0.0](https://github.com/nf-core/chipseq/releases/tag/2.0.0)] - 2022-09-30
## [[2.0.0](https://github.com/nf-core/chipseq/releases/tag/2.0.0)] - 2022-10-03

### Enhancements & fixes

Expand Down
40 changes: 34 additions & 6 deletions bin/igv_files_to_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
## REQUIRED PARAMETERS
argParser.add_argument("XML_OUT", help="XML output file.")
argParser.add_argument(
"LIST_FILE", help="Tab-delimited file containing two columns i.e. file_name\tcolour. Header isnt required."
"LIST_FILE",
help="Tab-delimited file containing two columns i.e. file_name\tcolour. Header isnt required.",
)
argParser.add_argument(
"GENOME", help="Full path to genome fasta file or shorthand for genome available in IGV e.g. hg19."
"REPLACE_FILE",
help="Tab-delimited file containing two columns i.e. file_name\treplacement_file_name. Header isnt required.",
)
argParser.add_argument(
"GENOME",
help="Full path to genome fasta file or shorthand for genome available in IGV e.g. hg19.",
)

## OPTIONAL PARAMETERS
Expand Down Expand Up @@ -65,10 +71,20 @@ def makedir(path):
############################################


def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):

makedir(os.path.dirname(XMLOut))

replaceFileDict = {}
fin = open(ReplaceFile, "r")
while True:
line = fin.readline()
if line:
ofile, rfile = line.strip().split("\t")
replaceFileDict[ofile] = rfile
else:
break
fin.close()
fileList = []
fin = open(ListFile, "r")
while True:
Expand All @@ -77,10 +93,17 @@ def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
ifile, colour = line.strip().split("\t")
if len(colour.strip()) == 0:
colour = "0,0,178"
for ofile, rfile in replaceFileDict.items():
if ofile in ifile:
ifile = ifile.replace(ofile, rfile)
fileList.append((PathPrefix.strip() + ifile, colour))
else:
break
fout.close()
fin.close()
fout = open("igv_files.txt", "w")
for ifile, colour in fileList:
fout.write(ifile + "\n")
fout.close()

## ADD RESOURCES SECTION
XMLStr = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
Expand Down Expand Up @@ -138,7 +161,6 @@ def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
'id="%s" name="%s" renderer="BASIC_FEATURE" sortable="false" visible="true" windowFunction="count"/>\n'
% (ifile, os.path.basename(ifile))
)

XMLStr += "\t</Panel>\n"
# XMLStr += '\t<HiddenAttributes>\n\t\t<Attribute name="DATA FILE"/>\n\t\t<Attribute name="DATA TYPE"/>\n\t\t<Attribute name="NAME"/>\n\t</HiddenAttributes>\n'
XMLStr += "</Session>"
Expand All @@ -153,7 +175,13 @@ def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
############################################
############################################

igv_files_to_session(XMLOut=args.XML_OUT, ListFile=args.LIST_FILE, Genome=args.GENOME, PathPrefix=args.PATH_PREFIX)
igv_files_to_session(
XMLOut=args.XML_OUT,
ListFile=args.LIST_FILE,
ReplaceFile=args.REPLACE_FILE,
Genome=args.GENOME,
PathPrefix=args.PATH_PREFIX,
)

############################################
############################################
Expand Down
4 changes: 3 additions & 1 deletion modules/local/deseq2_qc.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ process DESEQ2_QC {
tag "$meta.id"
label 'process_medium'

conda (params.enable_conda ? "conda-forge::r-base=4.0 bioconda::bioconductor-deseq2=1.28.0 bioconda::bioconductor-biocparallel bioconda::bioconductor-tximport bioconda::bioconductor-complexheatmap conda-forge::r-optparse conda-forge::r-ggplot2 conda-forge::r-rcolorbrewer conda-forge::r-pheatmap" : null)
// (Bio)conda packages have intentionally not been pinned to a specific version
// This was to avoid the pipeline failing due to package conflicts whilst creating the environment when using -profile conda
conda (params.enable_conda ? "conda-forge::r-base bioconda::bioconductor-deseq2 bioconda::bioconductor-biocparallel bioconda::bioconductor-tximport bioconda::bioconductor-complexheatmap conda-forge::r-optparse conda-forge::r-ggplot2 conda-forge::r-rcolorbrewer conda-forge::r-pheatmap" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/mulled-v2-8849acf39a43cdd6c839a369a74c0adc823e2f91:ab110436faf952a33575c64dd74615a84011450b-0' :
'quay.io/biocontainers/mulled-v2-8849acf39a43cdd6c839a369a74c0adc823e2f91:ab110436faf952a33575c64dd74615a84011450b-0' }"
Expand Down
24 changes: 15 additions & 9 deletions modules/local/igv.nf
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ process IGV {
'quay.io/biocontainers/python:3.8.3' }"

input:
val aligner_dir
val peak_dir
path fasta
path ("${bigwig_publish_dir}/*")
path ("${peak_publish_dir}/*")
path ("${consensus_publish_dir}/*")
val bigwig_publish_dir
val peak_publish_dir
val consensus_publish_dir
path ("${aligner_dir}/mergedLibrary/bigwig/*")
path ("${aligner_dir}/mergedLibrary/macs2/${peak_dir}/*")
path ("${aligner_dir}/mergedLibrary/macs2/${peak_dir}/consensus/*")
path ("mappings/*")

output:
path "*files.txt" , emit: txt
path "*.xml" , emit: xml
path "versions.yml", emit: versions

script: // scripts are bundled with the pipeline in nf-core/chipseq/bin/
def consensus_dir = "${aligner_dir}/mergedLibrary/macs2/${peak_dir}/consensus/*"
"""
find * -type l -name "*.bigWig" -exec echo -e ""{}"\\t0,0,178" \\; > bigwig.igv.txt
find * -type l -name "*Peak" -exec echo -e ""{}"\\t0,0,178" \\; > peaks.igv.txt
# Avoid error when consensus not produced
find * -type l -name "*.bed" -exec echo -e ""{}"\\t0,0,178" \\; | { grep "^$consensus_publish_dir" || test \$? = 1; } > bed.igv.txt
find * -type l -name "*.bed" -exec echo -e ""{}"\\t0,0,178" \\; | { grep "^$consensus_dir" || test \$? = 1; } > consensus.igv.txt
cat *.txt > igv_files.txt
igv_files_to_session.py igv_session.xml igv_files.txt ../../genome/${fasta.getName()} --path_prefix '../../'
touch replace_paths.txt
if [ -d "mappings" ]; then
cat mappings/* > replace_paths.txt
fi
cat *.igv.txt > igv_files_orig.txt
igv_files_to_session.py igv_session.xml igv_files_orig.txt replace_paths.txt ../../genome/${fasta.getName()} --path_prefix '../../'
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
4 changes: 3 additions & 1 deletion modules/local/macs2_consensus.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ process MACS2_CONSENSUS {
tuple val(meta), path("*.bed") , emit: bed
tuple val(meta), path("*.saf") , emit: saf
tuple val(meta), path("*.pdf") , emit: pdf
tuple val(meta), path("*.antibody.txt") , emit: txt
tuple val(meta), path("*.boolean.txt") , emit: boolean_txt
tuple val(meta), path("*.intersect.txt"), emit: intersect_txt
path "versions.yml" , emit: versions
Expand All @@ -25,7 +26,6 @@ process MACS2_CONSENSUS {
task.ext.when == null || task.ext.when

script: // This script is bundled with the pipeline, in nf-core/chipseq/bin/

def prefix = task.ext.prefix ?: "${meta.id}"
def peak_type = params.narrow_peak ? 'narrowPeak' : 'broadPeak'
def mergecols = params.narrow_peak ? (2..10).join(',') : (2..9).join(',')
Expand All @@ -49,6 +49,8 @@ process MACS2_CONSENSUS {

plot_peak_intersect.r -i ${prefix}.boolean.intersect.txt -o ${prefix}.boolean.intersect.plot.pdf

echo "${prefix}.bed\t${meta.id}/${prefix}.bed" > ${prefix}.antibody.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
python: \$(python --version | sed 's/Python //g')
Expand Down
21 changes: 5 additions & 16 deletions workflows/chipseq.nf
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ workflow CHIPSEQ {
// Consensus peaks analysis
//
ch_macs2_consensus_bed_lib = Channel.empty()
ch_macs2_consensus_txt_lib = Channel.empty()
ch_deseq2_pca_multiqc = Channel.empty()
ch_deseq2_clustering_multiqc = Channel.empty()
if (!params.skip_consensus_peaks) {
Expand Down Expand Up @@ -579,6 +580,7 @@ workflow CHIPSEQ {
ch_antibody_peaks
)
ch_macs2_consensus_bed_lib = MACS2_CONSENSUS.out.bed
ch_macs2_consensus_txt_lib = MACS2_CONSENSUS.out.txt
ch_versions = ch_versions.mix(MACS2_CONSENSUS.out.versions)

if (!params.skip_peak_annotation) {
Expand Down Expand Up @@ -653,26 +655,13 @@ workflow CHIPSEQ {
//
if (!params.skip_igv) {
IGV (
params.aligner,
params.narrow_peak ? 'narrowPeak' : 'broadPeak',
PREPARE_GENOME.out.fasta,
UCSC_BEDGRAPHTOBIGWIG.out.bigwig.collect{it[1]}.ifEmpty([]),
ch_macs2_peaks.collect{it[1]}.ifEmpty([]),
ch_macs2_consensus_bed_lib.collect{it[1]}.ifEmpty([]),
{ "${params.aligner}/mergedLibrary/bigwig" },
{
[
"${params.aligner}/mergedLibrary/macs2",
params.narrow_peak ? '/narrowPeak' : '/broadPeak'
]
.join('')
},
{
[
"${params.aligner}/mergedLibrary/macs2",
params.narrow_peak ? '/narrowPeak' : '/broadPeak',
'/consensus'
]
.join('')
}
ch_macs2_consensus_txt_lib.collect{it[1]}.ifEmpty([])
)
ch_versions = ch_versions.mix(IGV.out.versions)
}
Expand Down