diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 4b8f1f6..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,54 +0,0 @@ -# Simple workflow for deploying static content to GitHub Pages -name: Deploy static content to Pages - -on: - # Runs on pushes targeting the default branch - push: - branches: ["docs"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - # Single deploy job since we're just deploying - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Pages - uses: actions/configure-pages@v3 - - name: build docs - uses: actions/setup-python@v4 - with: - python-version: 3.x - - uses: actions/cache@v2 - with: - key: ${{ github.ref }} - path: .cache - - run: pip install mkdocs-material - - run: mkdir docs/build - - run: mkdocs build -f docs/config/en/mkdocs.yml - - run: mkdocs build -f docs/config/pt/mkdocs.yml - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - with: - # Upload entire repository - path: 'docs/build' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..3f301e2 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,42 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} + steps: + - uses: actions/checkout@v4 + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: 3.8 + mamba-version: "*" + channels: conda-forge,bioconda,defaults + channel-priority: true + + - name: install dependancies + run: | + mamba create -n test tb-profiler -y + + - name: Install dependencies + run: | + conda activate test + pip install --force-reinstall . + - name: Run tests + run: | + cd tests + mamba install pytest -y + pytest -x . + diff --git a/tbprofiler/phylo.py b/tbprofiler/phylo.py index 11da7e3..7fe855f 100644 --- a/tbprofiler/phylo.py +++ b/tbprofiler/phylo.py @@ -60,20 +60,44 @@ def generate_low_dp_mask(bam: str,ref: str,outfile: str,min_dp: int = 10) -> Non for x in missing_positions: O.write(f"{x[0]}\t{x[1]}\t{x[1]+1}\n") +def generate_low_dp_mask_vcf(vcf: str,outfile: str,min_dp: int = 10) -> None: + missing_positions = [] + vcf_obj = pysam.VariantFile(vcf) + for rec in vcf_obj: + # use AD field if available + if 'AD' in rec.samples[0]: + dp = sum(rec.samples[0]['AD']) + else: + dp = rec.samples[0]['DP'] + if dp None: run_cmd(f"usher --tree {treefile} --vcf {vcf_file} --collapse-tree --save-mutation-annotated-tree phylo.pb") def prepare_sample_consensus(sample: str,input_vcf: str,args: argparse.Namespace) -> str: s = sample tmp_vcf = f"{args.files_prefix}.{s}.vcf.gz" - run_cmd(f"bcftools norm -m - {input_vcf} | bcftools view -T ^{args.conf['bedmask']} | bcftools filter --SnpGap 50 | bcftools view -v snps | annotate_maaf.py | bcftools filter -S . -e 'MAAF<0.7' |bcftools filter -S . -e 'FMT/DP<20' | rename_vcf_sample.py --sample-name {s} | bcftools view -v snps -Oz -o {tmp_vcf}") + run_cmd(f"bcftools norm -m - {input_vcf} | bcftools view -T ^{args.conf['bedmask']} | bcftools filter --SnpGap 50 | bcftools view -v snps | annotate_maaf.py | bcftools filter -S . -e 'MAAF<0.7' |bcftools filter -S . -e 'FMT/DP<{args.conf['variant_filters']['depth_soft']}' | rename_vcf_sample.py --sample-name {s} | bcftools view -v snps -Oz -o {tmp_vcf}") run_cmd(f"bcftools index {tmp_vcf}") mask_bed = f"{args.files_prefix}.{s}.mask.bed" if hasattr(args,'supplementary_bam') and args.supplementary_bam: args.bam = args.supplementary_bam - generate_low_dp_mask(f"{args.bam}",args.conf['ref'],mask_bed) - run_cmd(f"bcftools consensus --sample {s} -m {mask_bed} -M N -f {args.conf['ref']} {tmp_vcf} | sed 's/>/>{s} /' > {args.files_prefix}.{s}.consensus.fa") + if args.bam: + generate_low_dp_mask(f"{args.bam}",args.conf['ref'],mask_bed) + mask_cmd = f"-m {mask_bed} -M N" + elif args.vcf: + generate_low_dp_mask_vcf(args.vcf,mask_bed) + mask_cmd = f"-m {mask_bed} -M N" + else: + mask_cmd = "" + run_cmd(f"bcftools consensus --sample {s} {mask_cmd} -f {args.conf['ref']} {tmp_vcf} | sed 's/>/>{s} /' > {args.files_prefix}.{s}.consensus.fa") return f"{args.files_prefix}.{s}.consensus.fa" def get_consensus_vcf(sample: str,input_vcf: str,args: argparse.Namespace) -> str: diff --git a/tests/run_test.py b/tests/run_test.py index 67bccf7..4c341a3 100644 --- a/tests/run_test.py +++ b/tests/run_test.py @@ -31,9 +31,10 @@ ] db = 'testdb' +branch = 'who' def test_db(): - run_cmd(f"tb-profiler update_tbdb --branch test --prefix {db}") + run_cmd(f"tb-profiler update_tbdb --branch {branch} --prefix {db}") def check_assertations(filename):