Skip to content

Feature/workflow #18

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
91 changes: 87 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,98 @@
name: Test container build
name: Build, Lint, and Test

on:
push:
branches:
- master
pull_request:
branches_ignore: []
branches-ignore: []

env:
DOCKER_TAG_NAME: snakemake-tutorial

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
no-fail: true

- name: Build Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
tags: ${{ env.DOCKER_TAG_NAME }}
outputs: type=docker, dest=/tmp/${{ env.DOCKER_TAG_NAME }}.tar

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.DOCKER_TAG_NAME }}
path: /tmp/${{ env.DOCKER_TAG_NAME }}.tar

lint:
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Lint Snakefile
uses: github/super-linter@v7
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

VALIDATE_SNAKEMAKE_SNAKEFMT: true

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: snakemake-tutorial
path: /tmp

- name: Load Docker Image
run: docker load -i /tmp/${{ env.DOCKER_TAG_NAME }}.tar

- name: DryRun Snakefile
run: docker run ${{ env.DOCKER_TAG_NAME }} snakemake --cores 1 --dryrun

test:
runs-on: ubuntu-latest
needs: docker-build
steps:
- uses: actions/checkout@master
- run: docker build .
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.DOCKER_TAG_NAME }}
path: /tmp

- name: Load Docker Image
run: docker load -i /tmp/${{env.DOCKER_TAG_NAME}}.tar

- name: Run Tests
run: docker run -v $(pwd):/work -w /work ${{env.DOCKER_TAG_NAME}} \
conda run -n ${{env.DOCKER_TAG_NAME}} -tutorial snakemake --cores 1

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
calls
plots
sorted_reads
mapped_reads
.snakemake
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM snakemake/snakemake:stable
ADD environment.yaml .

Check failure on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

DL3020 error: Use COPY instead of ADD for files and folders
RUN conda create -n snakemake-tutorial --clone snakemake; \
conda env update -n snakemake-tutorial -f environment.yaml;
RUN mkdir -p /tmp/conda
ENV CONDA_PKGS_DIRS /tmp/conda
ENV CONDA_PKGS_DIRS=/tmp/conda
56 changes: 56 additions & 0 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
SAMPLES = ["A", "B"]


rule all:
input:
"plots/quals.svg",


rule bwa_map:
input:
"data/genome.fa",
"data/samples/{sample}.fastq",
output:
"mapped_reads/{sample}.bam",
shell:
"bwa mem {input} | samtools view -Sb - > {output}"


rule samtools_sort:
input:
"mapped_reads/{sample}.bam",
output:
"sorted_reads/{sample}.bam",
shell:
"samtools sort -T sorted_reads/{wildcards.sample} "
"-O bam {input} > {output}"


rule samtools_index:
input:
"sorted_reads/{sample}.bam",
output:
"sorted_reads/{sample}.bam.bai",
shell:
"samtools index {input}"


rule bcftools_call:
input:
fa="data/genome.fa",
bam=expand("sorted_reads/{sample}.bam", sample=SAMPLES),
bai=expand("sorted_reads/{sample}.bam.bai", sample=SAMPLES),
output:
"calls/all.vcf",
shell:
"bcftools mpileup -f {input.fa} {input.bam} | "
"bcftools call -mv - > {output}"


rule plot_quals:
input:
"calls/all.vcf",
output:
"plots/quals.svg",
script:
"scripts/plot-quals.py"
9 changes: 9 additions & 0 deletions workflow/scripts/plot-quals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from pysam import VariantFile

quals = [record.qual for record in VariantFile(snakemake.input[0])]
plt.hist(quals)

plt.savefig(snakemake.output[0])
Loading