Skip to content

Commit

Permalink
Merge pull request #6 from cokelaer/master
Browse files Browse the repository at this point in the history
Fixing problem when there is no annotation
  • Loading branch information
cokelaer authored Mar 11, 2022
2 parents 980439d + d9c9cff commit 7d458bb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python: [3.7,3.8]
python: [3.7,3.8,3.9]
fail-fast: false


Expand All @@ -40,7 +40,7 @@ jobs:
- name: conda
run: |
conda install -c conda-forge mamba --quiet
mamba install -c bioconda -c conda-forge --quiet -y freebayes bwa snpeff sambamba picard samtools
mamba install -c bioconda -c conda-forge --quiet -y freebayes bwa snpeff==5.0 sambamba picard samtools bamtools
- name: Install dependencies
run: |
Expand Down
7 changes: 3 additions & 4 deletions sequana_pipelines/variant_calling/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@ def main(args=None):
logger.error("The annotation file must end with .gbk or .gff or .gff3. You provided {}".format(cfg.annotation_file))
sys.exit(1)
cfg['sequana_coverage']['genbank_file'] = cfg.annotation_file
else:
cfg.snpeff.do = False
cfg['sequana_coverage']['genbank_file'] = ""

cfg['sequana_coverage']['do'] = options.do_coverage
cfg['sequana_coverage']["circular"] = options.circular


cfg['joint_freebayes']['do'] = options.do_joint_calling


cfg['bwa_mem']['threads'] = options.threads
cfg['freebayes']['ploidy'] = options.freebayes_ploidy

Expand Down
1 change: 1 addition & 0 deletions sequana_pipelines/variant_calling/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- sambamba
- samtools
- snpEff
- bamtools
21 changes: 11 additions & 10 deletions sequana_pipelines/variant_calling/variant_calling.rules
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ configfile: "config.yaml"

# A convenient manager
manager = PipelineManager("variant_calling", config)
manager.setup(globals(), mode="warning")

config = manager.config

Expand All @@ -48,9 +47,8 @@ if len(manager.samples) == 1:


# ================================================== Define outputs
expected_output = []

__freebayes__output = "{sample}/freebayes/{sample}.raw.vcf"
expected_output += expand(__freebayes__output, sample=manager.samples)

others = []
if config['joint_freebayes']['do']:
Expand Down Expand Up @@ -227,8 +225,7 @@ if config["sequana_coverage"]["do"]:
rule sequana_coverage:
input:
bed="{sample}/samtools_depth/{sample}.bed",
fasta=reference_file,
gbk=annotation_file if config["snpeff"]["do"] else ""
fasta=reference_file
output:
"{sample}/sequana_coverage/sequana_coverage.html"
params:
Expand All @@ -239,11 +236,11 @@ if config["sequana_coverage"]["do"]:
gc_window_size=config["sequana_coverage"]["gc_window_size"],
high_threshold=config["sequana_coverage"]["high_threshold"],
low_threshold=config["sequana_coverage"]["low_threshold"],
mixture_models=config["sequana_coverage"]["mixture_models"]
mixture_models=config["sequana_coverage"]["mixture_models"],
gbk=annotation_file if config["snpeff"]["do"] else None
wrapper:
f"{sequana_wrapper_branch}/wrappers/sequana_coverage"

#__sequana_coverage__report_dir = "{sample}/sequana_coverage"
expected_output += expand("{sample}/sequana_coverage/sequana_coverage.html",
sample=manager.samples)

Expand Down Expand Up @@ -274,7 +271,7 @@ if config["snpeff"]["do"]:

rule snpeff:
input:
vcf = __freebayes__output,
vcf = "{sample}/freebayes/{sample}.raw.vcf",
ann = annotation_file
output:
html="{sample}/snpeff/{sample}.snpeff.html",
Expand All @@ -291,9 +288,13 @@ if config["snpeff"]["do"]:
__freebayes_vcf_filter__input = "{sample}/snpeff/{sample}.ann.vcf"
expected_output += expand("{sample}/snpeff/{sample}.ann.vcf", sample=manager.samples)
else:
__freebayes_vcf_filter__input = __freebayes__output
__freebayes_vcf_filter__input = "{sample}/freebayes/{sample}.raw.vcf"

# Freebayes filter
expected_output += expand("{sample}/freebayes/{sample}.raw.vcf", sample=manager.samples)


# ================================================================== Freebayes filter
#
#
rule freebayes_vcf_filter:
input:
Expand Down
38 changes: 37 additions & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_standalone_subprocess():
subprocess.call(cmd.split())


def test_check_output():
def test_check_output_ref_annot():

with tempfile.TemporaryDirectory() as wk:

Expand Down Expand Up @@ -52,6 +52,42 @@ def test_check_output():
'strand_balance': '0.333'}


def test_version():
cmd = "sequana_variant_calling --version"
subprocess.call(cmd.split())

def test_check_output_no_annotation():

with tempfile.TemporaryDirectory() as wk:

cmd = "sequana_variant_calling --input-directory {} "
cmd += "--working-directory {} --run-mode local --force "
cmd += " --reference-file {}"
cmd = cmd.format(sharedir, wk, reference)
# create the wokring directory and script
subprocess.call(cmd.split())

subprocess.call("sh variant_calling.sh".split(), cwd=wk)

from sequana.freebayes_vcf_filter import VCF_freebayes, Variant
vcf = VCF_freebayes(wk + "/data/freebayes/data.raw.vcf")
vcf.rewind()
vv = [Variant(v)._resume for v in vcf]
# this may change depending on the freebayes version...
assert len(vv) in (67,)
vv = vv[0].copy()
del vv['freebayes_score']
assert vv == {'alternative': 'T',
'chr': 'JB409847',
'depth': 23,
#'freebayes_score': 2.78452e-14,
'type': 'SNV',
'frequency': '0.261',
'position': '2221',
'reference': 'C',
'strand_balance': '0.333'}


def test_version():
cmd = "sequana_variant_calling --version"
subprocess.call(cmd.split())

0 comments on commit 7d458bb

Please sign in to comment.