Skip to content

Commit

Permalink
0.5.0 (#39)
Browse files Browse the repository at this point in the history
* βž• Use argx instead of pyparam

* πŸ“ Update examples

* πŸ”– 0.5.0
  • Loading branch information
pwwang authored Feb 20, 2023
1 parent fe18edb commit 7a46551
Show file tree
Hide file tree
Showing 31 changed files with 457 additions and 309 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ vcfstats --vcf examples/sample.vcf \
--figtype boxplot
```

![Allele frequency on each chromosome](examples/allele-frequency-on-each-chromosome.boxplot.png)
![Allele frequency on each chromosome](examples/allele-frequency-on-each-chromosome-boxplot.boxplot.png)

#### Using density plot/histogram to investigate the distribution:

Expand All @@ -154,7 +154,7 @@ vcfstats --vcf examples/sample.vcf \
--figtype density
```

![Allele frequency on chromosome 1,2](examples/allele-frequency-on-chromosome-1-2.density.png)
![Allele frequency on chromosome 1,2](examples/allele-frequency-on-chromosome-12.density.png)

### Overall distribution of allele frequency

Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.5.0

- βž• Use argx instead of pyparam

## 0.4.3

- πŸš‘ Fix numpy error raised from plotnine (#35)
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified examples/allele-frequency-on-each-chromosome.violin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/depths-between-sample-1-and-2.scatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/gq-vs-depth-sample-1.scatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/mutant-genotypes-on-each-chromosome-sample-1.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/number-of-substitutions-of-snps-passed.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/number-of-substitutions-of-snps.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/number-of-variants-on-each-chromosome-first-5.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/number-of-variants-on-each-chromosome-modified.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/number-of-variants-on-each-chromosome.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/overall-allele-frequency-distribution.histogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/types-of-variants-on-chromosome-1.pie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/types-of-variants-on-each-chromosome.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/types-of-variants-on-whole-genome.col.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 86 additions & 68 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "vcfstats"
version = "0.4.3"
version = "0.5.0"
description = "Powerful statistics for VCF files"
authors = [ "pwwang <[email protected]>",]
license = "MIT"
Expand All @@ -16,13 +16,14 @@ include = ["vcfstats/args.toml"]
[tool.poetry.dependencies]
python = "^3.8"
cyvcf2 = "^0.30"
pyparam = "^0.5"
lark-parser = "^0.12"
plotnine = "^0.10"
plotnine-prism = "^0.2"
python-slugify = "^8"
datar = { version = "^0.11", extras = ["pandas"] }
py = "^1.10"
argx = "^0.1.0"
rich = "^13"

[tool.poetry.dev-dependencies]
cmdy = "^0.5"
Expand Down
134 changes: 134 additions & 0 deletions run-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1) ~ CONTIG' \
--title 'Number of variants on each chromosome' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1) ~ CONTIG' \
--title 'Number of variants on each chromosome (modified)' \
--config examples/config.toml \
--ggs 'scale_x_discrete(name ="Chromosome", \
limits=["1","2","3","4","5","6","7","8","9","10","X"]); \
ylab("# Variants")'

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1) ~ CONTIG[1,2,3,4,5]' \
--title 'Number of variants on each chromosome (first 5)' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, VARTYPE[snp]) ~ SUBST[A>T,A>G,A>C,T>A,T>G,T>C,G>A,G>T,G>C,C>A,C>T,C>G]' \
--title 'Number of substitutions of SNPs' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, VARTYPE[snp]) ~ SUBST[A>T,A>G,A>C,T>A,T>G,T>C,G>A,G>T,G>C,C>A,C>T,C>G]' \
--title 'Number of substitutions of SNPs (passed)' \
--config examples/config.toml \
--passed

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'AAF ~ CONTIG' \
--title 'Allele frequency on each chromosome' \
--config examples/config.toml --ggs 'theme_dark()'

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'AAF ~ CONTIG' \
--title 'Allele frequency on each chromosome (boxplot)' \
--config examples/config.toml \
--figtype boxplot

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'AAF ~ CONTIG[1,2]' \
--title 'Allele frequency on chromosome 1,2' \
--config examples/config.toml \
--figtype density

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'AAF ~ 1' \
--title 'Overall allele frequency distribution' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'AAF[0.05, 0.95] ~ 1' \
--title 'Overall allele frequency distribution (0.05-0.95)' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, group=VARTYPE) ~ CHROM' \
--title 'Types of variants on each chromosome' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, group=VARTYPE) ~ CHROM[1]' \
--title 'Types of variants on chromosome 1' \
--config examples/config.toml \
--figtype pie

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, group=VARTYPE) ~ 1' \
--title 'Types of variants on whole genome' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'COUNT(1, group=GTTYPEs[HET,HOM_ALT]{0}) ~ CHROM' \
--title 'Mutant genotypes on each chromosome (sample 1)' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'MEAN(GQs{0}) ~ MEAN(DEPTHs{0}, group=CHROM)' \
--title 'GQ vs depth (sample 1)' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi

vcfstats --vcf examples/sample.vcf \
--outdir examples/ \
--formula 'DEPTHs{0} ~ DEPTHs{1}' \
--title 'Depths between sample 1 and 2' \
--config examples/config.toml

if [ $? -ne 0 ]; then exit 1; fi
80 changes: 22 additions & 58 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cmdy
import pytest
from pyparam import Namespace
from argparse import Namespace

from vcfstats.cli import (
MACROS,
Expand All @@ -11,7 +11,6 @@
get_instances,
get_vcf_by_regions,
list_macros,
load_config,
load_macrofile,
main,
)
Expand Down Expand Up @@ -54,18 +53,23 @@ def test_combine_regions(tmp_path):

def test_get_ones(tmp_path):
ones = get_instances(
{
"devpars": {"width": 1000, "height": 1000, "res": 100},
"formula": ["COUNT(1) ~ CHROM", "AAF ~ CHROM"],
"title": ["title1", "title2"],
"ggs": [],
"figtype": [],
"passed": False,
"outdir": tmp_path,
"savedata": False,
"figfmt": [],
},
Namespace(
**{
"devpars": Namespace(
**{"width": [1000], "height": [1000], "res": [100]}
),
"formula": ["COUNT(1) ~ CHROM", "AAF ~ CHROM"],
"title": ["title1", "title2"],
"ggs": [],
"figtype": [],
"passed": False,
"outdir": tmp_path,
"savedata": False,
"figfmt": [],
}
),
["A", "B", "C", "D"],
{},
)
assert len(ones) == 2
assert isinstance(ones[0], Instance)
Expand All @@ -88,66 +92,26 @@ def test_load_macrofile(tmp_path):
from vcfstats.macros import cat
@cat
def DEMO(variant):
return variant.CHROM
return variant.CHROM
"""
)
load_macrofile(macrofile)
assert "DEMO" in MACROS


def test_load_config(tmp_path):
configfile = tmp_path.with_suffix(".config.toml")
with pytest.raises(OSError):
load_config(configfile, {})
configfile.write_text(
'[[instance]]\nformula = "VARTYPE ~ CHROM"\ntitle = "title1"\n'
)
opts = Namespace(
**{
"formula": [],
"figtype": [],
"figfmt": [],
"ggs": [],
"devpars": {},
"title": [],
}
)
load_config(configfile, opts)
assert opts["formula"] == ["VARTYPE ~ CHROM"]
opts = Namespace(
**{
"formula": ["VARTYPE ~ CHROM"],
"figtype": [],
"figfmt": [],
"ggs": [],
"devpars": [{}],
"title": ["title1"],
}
)
load_config(configfile, opts)
assert opts["devpars"] == [{}, {}]

configfile.write_text('[[instance]]\ntitle = "title1"\n')
with pytest.raises(ValueError):
load_config(configfile, opts)
configfile.write_text('[[instance]]\nformula = "VARTYPE ~ CHROM"\n')
with pytest.raises(ValueError):
load_config(configfile, opts)


def test_main(vcffile, tmp_path):
# help
cmd = cmdy.vcfstats(_raise=False)
assert "Print help information for this command" in str(cmd)
cmd = cmdy.vcfstats(_raise=False).stderr
assert "the following arguments are required" in str(cmd)

macrofile = tmp_path.with_suffix(".macromain.py")
macrofile.write_text(
"""
from vcfstats.macros import cat
@cat
def DEMO(variant):
'''Some demo macro'''
return variant.CHROM
'''Some demo macro'''
return variant.CHROM
"""
)
cmd = cmdy.vcfstats(l=True, macro=macrofile, _raise=False)
Expand Down
28 changes: 24 additions & 4 deletions tests/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
import pytest
from cyvcf2 import VCF

from vcfstats.macros import *
from vcfstats.macros import _ONE
from vcfstats.utils import MACROS
from vcfstats.macros import (
_ONE,
TITV,
VARTYPE,
CONTIG,
AAF,
AFs,
COUNT,
DEPTHs,
FILTER,
GTTYPEs,
GQs,
NALT,
QUAL,
SUBST,
SAMPLES,
MEAN,
SUM,
)

HERE = Path(__file__).parent.resolve()

Expand All @@ -29,7 +45,7 @@ def test_titv(variants):
assert TITV(variants[0]) == "transversion"
assert TITV(variants[1]) == "transversion"
assert TITV(variants[5]) == "transition"
assert TITV(variants[3]) == False
assert TITV(variants[3]) is False


def test_contig(variants):
Expand Down Expand Up @@ -83,6 +99,10 @@ def test_one(variants):
assert _ONE(None) == 1


def test_samples(variants):
assert list(SAMPLES(variants[0])) == [0, 1, 2, 3]


@pytest.mark.parametrize("entries", ([], [1, 2], [1, 2, 3]))
def test_count(entries):
assert COUNT(entries) == len(entries)
Expand Down
2 changes: 1 addition & 1 deletion vcfstats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

from . import macros

__version__ = "0.4.3"
__version__ = "0.5.0"
Loading

0 comments on commit 7a46551

Please sign in to comment.