Skip to content

Commit

Permalink
TST: Update tests for HF labels
Browse files Browse the repository at this point in the history
  • Loading branch information
robertopreste committed Apr 19, 2020
1 parent c2bf36d commit 97485d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
9 changes: 7 additions & 2 deletions ci/create_suite.py
Expand Up @@ -18,9 +18,10 @@
BASE_MITO_PLOTLY, BASE_MITO_PLOTLY_LEGEND, BASE_MITO_PLOTLY_SPLIT,
BASE_MITO_PLOTLY_LINEAR, BASE_MITO_PLOTLY_LINEAR_LEGEND,
BASE_MITO_PLOTLY_LINEAR_SPLIT,
BASE_IMG, BASE_IMG_LABELS, BASE_IMG_LEGEND, BASE_IMG_SPLIT,
BASE_IMG, BASE_IMG_LABELS, BASE_IMG_LABELS_HF, BASE_IMG_LEGEND,
BASE_IMG_SPLIT,
BASE_IMG_LINEAR, BASE_IMG_LINEAR_LABELS, BASE_IMG_LINEAR_LEGEND,
BASE_IMG_LINEAR_SPLIT,
BASE_IMG_LINEAR_SPLIT, BASE_IMG_LINEAR_LABELS_HF,
BASE_IMG_PLOTLY, BASE_IMG_PLOTLY_LEGEND, BASE_IMG_PLOTLY_SPLIT,
BASE_IMG_PLOTLY_LINEAR, BASE_IMG_PLOTLY_LINEAR_LEGEND,
BASE_IMG_PLOTLY_LINEAR_SPLIT,
Expand Down Expand Up @@ -107,6 +108,8 @@ def create_sample_vcf_polar():
plot_vcf(in_vcf=SAMPLE_VCF, save=True, output=BASE_IMG)
plot_vcf(in_vcf=SAMPLE_VCF, save=True, output=BASE_IMG_LABELS,
labels=True)
plot_vcf(in_vcf=SAMPLE_VCF, save=True, output=BASE_IMG_LABELS_HF,
labels=True, labels_hf=True)
plot_vcf(in_vcf=SAMPLE_VCF, save=True, output=BASE_IMG_LEGEND,
legend=True)
plot_vcf(in_vcf=SAMPLE_VCF, save=True, output=BASE_IMG_SPLIT,
Expand All @@ -118,6 +121,8 @@ def create_sample_vcf_linear():
plot_vcf(in_vcf=SAMPLE_VCF, linear=True, save=True, output=BASE_IMG_LINEAR)
plot_vcf(in_vcf=SAMPLE_VCF, linear=True, save=True,
output=BASE_IMG_LINEAR_LABELS, labels=True)
plot_vcf(in_vcf=SAMPLE_VCF, linear=True, save=True,
output=BASE_IMG_LINEAR_LABELS_HF, labels=True, labels_hf=True)
plot_vcf(in_vcf=SAMPLE_VCF, linear=True, save=True,
output=BASE_IMG_LINEAR_LEGEND, legend=True)
plot_vcf(in_vcf=SAMPLE_VCF, linear=True, save=True,
Expand Down
37 changes: 36 additions & 1 deletion mitoviz/cli/tests/test_mitoviz_plot.py
Expand Up @@ -14,7 +14,7 @@
SAMPLE_HF_TSV_COMM,
BASE_IMG, BASE_IMG_LABELS, BASE_IMG_LEGEND, BASE_IMG_SPLIT,
BASE_IMG_LINEAR, BASE_IMG_LINEAR_LABELS, BASE_IMG_LINEAR_LEGEND,
BASE_IMG_LINEAR_SPLIT,
BASE_IMG_LINEAR_SPLIT, BASE_IMG_LABELS_HF, BASE_IMG_LINEAR_LABELS_HF,
BASE_IMG_PLOTLY, BASE_IMG_PLOTLY_LEGEND, BASE_IMG_PLOTLY_SPLIT,
BASE_IMG_PLOTLY_LINEAR, BASE_IMG_PLOTLY_LINEAR_LEGEND,
BASE_IMG_PLOTLY_LINEAR_SPLIT,
Expand Down Expand Up @@ -136,6 +136,23 @@ def test_cli_plot_polar_labels(self):
# Cleanup
os.remove("MITOVIZ001.png")

def test_cli_plot_polar_labels_hf(self):
# Given
base_img = cv2.imread(BASE_IMG_LABELS_HF)

# When
result = self.runner.invoke(cli.main,
[SAMPLE_VCF, "--labels", "--labels-hf"])
result_img = cv2.imread("MITOVIZ001.png")

# Then
self.assertEqual(0, result.exit_code)
self.assertTrue(os.path.isfile("MITOVIZ001.png"))
diff = cv2.subtract(base_img, result_img)
self.assertFalse(np.any(diff))
# Cleanup
os.remove("MITOVIZ001.png")

def test_cli_plot_linear_labels(self):
# Given
base_img = cv2.imread(BASE_IMG_LINEAR_LABELS)
Expand All @@ -153,6 +170,24 @@ def test_cli_plot_linear_labels(self):
# Cleanup
os.remove("MITOVIZ001.png")

def test_cli_plot_linear_labels_hf(self):
# Given
base_img = cv2.imread(BASE_IMG_LINEAR_LABELS_HF)

# When
result = self.runner.invoke(cli.main,
[SAMPLE_VCF, "--labels", "--labels-hf",
"--linear"])
result_img = cv2.imread("MITOVIZ001.png")

# Then
self.assertEqual(0, result.exit_code)
self.assertTrue(os.path.isfile("MITOVIZ001.png"))
diff = cv2.subtract(base_img, result_img)
self.assertFalse(np.any(diff))
# Cleanup
os.remove("MITOVIZ001.png")

def test_cli_plot_polar_legend(self):
# Given
base_img = cv2.imread(BASE_IMG_LEGEND)
Expand Down
4 changes: 4 additions & 0 deletions mitoviz/plot.py
Expand Up @@ -379,6 +379,7 @@ def _plot_variants_polar(sample: str,
def _plotly_variants_polar(sample: str,
variants: List[_Variant],
labels: bool = False,
labels_hf: bool = False,
legend: bool = False,
split: bool = False) -> go.Figure:
""" Plot variants available in the given list onto a plotly polar plot.
Expand All @@ -387,6 +388,7 @@ def _plotly_variants_polar(sample: str,
sample: sample name, used for the plot title
variants: list of _PolarVariant instances to plot
labels: add a label for each variant shown [default: False]
labels_hf: show HF value in each variant's label [default: False]
legend: add a legend for loci colors in the plot [default: False]
split: plot split H and L strands [default: False]
"""
Expand Down Expand Up @@ -449,6 +451,7 @@ def _plot_variants_linear(sample: str,
def _plotly_variants_linear(sample: str,
variants: List[_Variant],
labels: bool = False,
labels_hf: bool = False,
legend: bool = False,
split: bool = False) -> go.Figure:
""" Plot variant available in a given list onto a plotly linear plot.
Expand All @@ -457,6 +460,7 @@ def _plotly_variants_linear(sample: str,
sample: sample name, used for the plot title
variants: list of _LinearVariant instances to plot
labels: add a label for each variant shown [default: False]
labels_hf: show HF value in each variant's label [default: False]
legend: add a legend for loci colors in the plot [default: False]
split: plot split H and L strands [default: False]
"""
Expand Down
2 changes: 2 additions & 0 deletions mitoviz/tests/constants.py
Expand Up @@ -41,11 +41,13 @@

BASE_IMG = os.path.join(IMGDIR, "sample.png")
BASE_IMG_LABELS = os.path.join(IMGDIR, "sample_labels.png")
BASE_IMG_LABELS_HF = os.path.join(IMGDIR, "sample_labels_hf.png")
BASE_IMG_LEGEND = os.path.join(IMGDIR, "sample_legend.png")
BASE_IMG_SPLIT = os.path.join(IMGDIR, "sample_split.png")

BASE_IMG_LINEAR = os.path.join(IMGDIR, "sample_linear.png")
BASE_IMG_LINEAR_LABELS = os.path.join(IMGDIR, "sample_linear_labels.png")
BASE_IMG_LINEAR_LABELS_HF = os.path.join(IMGDIR, "sample_linear_labels_hf.png")
BASE_IMG_LINEAR_LEGEND = os.path.join(IMGDIR, "sample_linear_legend.png")
BASE_IMG_LINEAR_SPLIT = os.path.join(IMGDIR, "sample_linear_split.png")

Expand Down

0 comments on commit 97485d4

Please sign in to comment.