Skip to content

Commit

Permalink
give up on snakemake lint for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmeaton committed Sep 23, 2020
1 parent d3a7bcf commit 3745cc8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 75 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,10 @@ jobs:
python-version: '3.7'
- name: install linters
run: pip install black flake8 flake8-bugbear
# Lint snakemake main
- name: lint snakefile
run: |
black $(find . -name "Snakefile")
flake8 $(find . -name "Snakefile")
# Lint snakemake modules
- name: lint snakefile submodules
run: |
black $(find . -name "*.smk")
flake8 $(find . -name "*.smk")
# Lint snakemake files
#- name: lint snakefile
# run: |
# snakemake --lint
- name: lint other python
run: |
black $(find . -name "*.py")
Expand Down
37 changes: 12 additions & 25 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import os # Path manipulation

from snakemake.remote.FTP import RemoteProvider as FTPRemoteProvider
FTP = FTPRemoteProvider()
# Enforce minimum version
from snakemake.utils import min_version
min_version("5.25.0")

# -----------------------------------------------------------------------------#
# Setup #
Expand All @@ -25,23 +28,22 @@ scripts_dir = os.path.join(project_dir, "workflow", "scripts")
envs_dir = os.path.join(project_dir, "workflow", "envs")
logs_dir = os.path.join(project_dir, "workflow", "logs")
report_dir = os.path.join(project_dir, "workflow", "report")
rules_dir = os.path.join(project_dir, "workflow", "rules")


# Include the config file
configfile: os.path.join(project_dir, "config", "snakemake.yaml")

db_path = os.path.join(results_dir, "sqlite_db", config["sqlite_db"])

# Sub snakefiles
include: "rules/sqlite_import.smk"
include: "rules/download.smk"
include: "rules/alignment.smk"
include: "rules/phylogeny.smk"
include: "rules/functions.smk"
include: "rules/targets.smk"
include: rules_dir + "/sqlite_import.smk"
include: rules_dir + "/download.smk"
include: rules_dir + "/alignment.smk"
include: rules_dir + "/phylogeny.smk"
include: rules_dir + "/functions.smk"
include: rules_dir + "/targets.smk"

# Report file
report: "report/workflow.rst"
report: report_dir + "/workflow.rst"

# -----------------------------------------------------------------------------#
# Main Target #
Expand All @@ -52,20 +54,7 @@ rule all:
The default pipeline target.
"""
input:
#---Database Import---#
#results_dir + "/sqlite_import/download_reference.txt",
#results_dir + "/sqlite_import/download_assembly.txt",
#results_dir + "/sqlite_import/eager_sra.tsv",
#---Data Download---#
#download_fna_output,
#download_ref_output,
#download_sra_output,
#---Alignment---#
eager_sra_output2,
#snippy_pairwise_fna_output,
#results_dir + "/snippy_multi/snippy-core.txt"
# IQTREE
iqtree_output
results_dir + "/iqtree/iqtree.core-filter" + str(config['snippy_missing_data']) + ".treefile"

# -----------------------------------------------------------------------------#
# Help and Usage #
Expand All @@ -80,7 +69,6 @@ rule help:
print("-" * 80)
print("rule: ", rule.name )
print(rule.docstring )
# Rule Inputs
if rule._input:
print("\tinput:")
for in_file in rule.input:
Expand All @@ -105,4 +93,3 @@ rule help:
print("\t\tconda: ", rule.conda_env)
if rule._log:
print("\t\tlog: ", rule._log)
#print(rule.conda_env)
4 changes: 2 additions & 2 deletions workflow/rules/download.smk
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ rule download_fna:
"""
message: "Downloading and decompressing fasta file {wildcards.sample}."
input:
results_dir + "/sqlite_import/{download_dir}.txt"
'{{results_dir}}/sqlite_import/{download_dir}.txt'
output:
results_dir + "/{download_dir}/{sample}.fna"
'{{results_dir}}/{download_dir}/{sample}.fna'
run:
for file in input:
with open(file) as temp_file:
Expand Down
31 changes: 0 additions & 31 deletions workflow/rules/functions.smk
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,3 @@ def parse_eager_tsv(eager_tsv, column):
'''Extract a column from the eager TSV file, excluding the header.'''
with open(eager_tsv) as temp_file:
return [line.strip().split("\t")[column] for line in temp_file][1:]


# Custom targets for aggregation rules

# Data Download
download_sra_output = expand(results_dir + "/download_sra/{biosample}/{sra_acc}_1.fastq.gz",
zip,
biosample=identify_sra_sample()["biosample"],
sra_acc=identify_sra_sample()["sra_acc"])

download_fna_output = expand(results_dir +"/download_assembly/{sample}.fna",
sample=identify_assembly_sample(),
)
download_ref_output = expand(results_dir +"/download_reference/{sample}.fna",
sample=identify_reference_sample(),
)
# Alignment
eager_sra_output1 = expand(results_dir + "/eager_sra/final_bams/{biosample}.bam",
biosample=identify_sra_sample()["biosample"])

eager_sra_output2 = expand(results_dir + "/eager_sra/damageprofiler/{sra_acc}_rmdup_{biosample}/DamagePlot.pdf",
zip,
sra_acc=identify_sra_sample()["sra_acc"],
biosample=identify_sra_sample()["biosample"])

snippy_pairwise_fna_output = expand(results_dir + "/snippy_pairwise/{sample}/{sample}_snippy.aligned.fa",
sample=identify_assembly_sample())

# Phylogeny

iqtree_output = expand(results_dir + "/iqtree/iqtree.core-filter{missing_data}.treefile", missing_data = config["snippy_missing_data"])
10 changes: 5 additions & 5 deletions workflow/rules/sqlite_import.smk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rule sqlite_import_reference:
params:
sql_command = config["sqlite_select_command_ref"],
input:
db = results_dir + "/sqlite_db/" + config["sqlite_db"]
db = results_dir + "/sqlite_db/{config[sqlite_db]}"
output:
ref_txt = results_dir + "/sqlite_import/download_reference.txt"
run:
Expand All @@ -25,10 +25,10 @@ rule sqlite_import_assembly:
Import Assembly genome url from database.
"""
input:
db = results_dir + "/sqlite_db/" + config["sqlite_db"]
db = results_dir + "/sqlite_db/{config[sqlite_db]}"
output:
asm_txt = results_dir + "/sqlite_import/download_assembly.txt",
asm_snippy_dir = results_dir + "/snippy_multi/snippy_pairwise_assembly.txt"
asm_snippy_dir = results_dir + "/snippy_multi/snippy_pairwise_assembly.txt",
run:
# Write the assembly FTP url
with open(output.asm_txt, "w") as temp_file:
Expand All @@ -49,9 +49,9 @@ rule sqlite_import_sra:
organism = config["organism"],
max_sra = config["max_datasets_sra"]
input:
db = results_dir + "/sqlite_db/" + config["sqlite_db"]
db = results_dir + "/sqlite_db/{config[sqlite_db]}",
output:
eager_tsv = results_dir + "/sqlite_import/eager_sra.tsv",
eager_tsv = results_dir + "/sqlite_import/eager_sra.tsv".format(results_dir=results_dir),
shell:
"{scripts_dir}/sqlite_EAGER_tsv.py \
--database {input.db} \
Expand Down
4 changes: 2 additions & 2 deletions workflow/rules/targets.smk
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ rule test_download_sra:

rule test_download_fna:
input:
expand(results_dir +"/download_assembly/{sample}.fna",
expand(results_dir + "/download_assembly/{sample}.fna",
sample=identify_assembly_sample(),
)
rule test_download_ref:
input:
expand(results_dir +"/download_reference/{sample}.fna",
expand(results_dir + "/download_reference/{sample}.fna",
sample=identify_reference_sample(),
)
# Alignment
Expand Down

0 comments on commit 3745cc8

Please sign in to comment.