Skip to content

Commit 634e830

Browse files
committed
Fix tests and drop donut plot scaffolding
1 parent 687589b commit 634e830

File tree

7 files changed

+18
-137
lines changed

7 files changed

+18
-137
lines changed

docs/cli.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ In brief, this means that every stable version of the MicroHapulator software is
7575
:nodefault:
7676
```
7777

78-
### `mhpl8r mappingqc`
79-
```{argparse}
80-
:module: microhapulator.cli
81-
:func: get_parser
82-
:prog: mhpl8r
83-
:path: mappingqc
84-
:nodefault:
85-
```
86-
87-
8878
### `mhpl8r contrib`
8979

9080
```{argparse}

microhapulator/api.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -815,30 +815,14 @@ def consolidate_read_mapping_qc_tables(samples):
815815
return aggregate_qc_table
816816

817817

818-
def read_mapping_qc(marker_mapped, refr_mapped, repetitive_mapped, figure=None, title=None):
818+
def read_mapping_qc(marker_mapped, refr_mapped, repetitive_mapped):
819819
"""Count on target, off target, repetitive, and contaminant reads
820820
821821
:param str marker_mapped: path of txt file containing number of reads mapped to marker sequences
822822
:param str refr_mapped: path of txt file containing number of reads mapped to the full human reference genome
823823
:param str repetitive_mapped: path of txt file containing number of reads mapped preferentially to non-marker loci in the human reference genome
824-
:param str output: path where the png file of the plot will be saved
825-
:param str sample: name of the sample to be included as the plot title; by default no sample name is shown
826824
"""
827-
data = count_mapped_read_types(marker_mapped, refr_mapped, repetitive_mapped)
828-
if not figure:
829-
return data
830-
backend = matplotlib.get_backend()
831-
plt.switch_backend("Agg")
832-
labels = ["on target", "off target", "contamination", "repetitive"]
833-
plt.pie(data.values[0])
834-
circle = plt.Circle((0, 0), 0.7, color="white")
835-
plt.gca().add_artist(circle)
836-
plt.title(title, fontsize=14)
837-
plt.legend(labels=labels[: len(data.values[0])], bbox_to_anchor=(1.05, 1.0), loc="upper left")
838-
plt.savefig(figure, bbox_inches="tight", dpi=300)
839-
plt.close("all")
840-
plt.switch_backend(backend)
841-
return data
825+
return count_mapped_read_types(marker_mapped, refr_mapped, repetitive_mapped)
842826

843827

844828
def count_mapped_read_types(marker_mapped, refr_mapped, repetitive_mapped):

microhapulator/cli/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from . import getrefr
2323
from . import hetbalance
2424
from . import locbalance
25-
from . import mappingqc
2625
from . import mix
2726
from . import repetitive
2827
from . import pipe
@@ -43,7 +42,6 @@
4342
"getrefr": getrefr.main,
4443
"hetbalance": hetbalance.main,
4544
"locbalance": locbalance.main,
46-
"mappingqc": mappingqc.main,
4745
"mix": mix.main,
4846
"repetitive": repetitive.main,
4947
"pipe": pipe.main,
@@ -64,7 +62,6 @@
6462
"getrefr": getrefr.subparser,
6563
"hetbalance": hetbalance.subparser,
6664
"locbalance": locbalance.subparser,
67-
"mappingqc": mappingqc.subparser,
6865
"mix": mix.subparser,
6966
"repetitive": repetitive.subparser,
7067
"pipe": pipe.subparser,

microhapulator/cli/mappingqc.py

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
# Development Center.
1111
# -------------------------------------------------------------------------------------------------
1212

13+
import microhapulator.api as mhapi
1314
from microhapulator.pipe.mapstats import MappingStats, MappingSummary
1415
from microhapulator.tests import data_file
16+
import pandas as pd
1517
import pytest
1618

1719

@@ -37,3 +39,14 @@ def test_load_mapsummary_from_workdir():
3739
assert repetitive["mh17KK-278.v1"]["SRM8398-1"].repetitive == 0
3840
assert repetitive["mh17KK-278.v1"]["SRM8398-2"].repetitive == 0
3941
assert repetitive["mh17KK-278.v1"]["SRM8398-3"].repetitive == 0
42+
43+
44+
def test_mappingqc(tmp_path):
45+
align_dir = data_file("mapping_workdir/analysis/SRM8398-2/02alignment/")
46+
obs_data = mhapi.read_mapping_qc(
47+
f"{align_dir}/SRM8398-2.bam.stats",
48+
f"{align_dir}/fullrefr/SRM8398-2-fullrefr-mapped-reads.txt",
49+
f"{align_dir}/SRM8398-2-repetitive-reads.csv",
50+
)
51+
exp_data = pd.read_csv(data_file("test-mapping-qc.csv"))
52+
assert obs_data.equals(exp_data)

microhapulator/tests/test_mappingqc.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

microhapulator/workflows/analysis.smk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,9 @@ rule read_mapping_qc:
303303
repetitive=rules.repetitive_mapping.output.counts,
304304
output:
305305
counts="analysis/{sample}/02alignment/{sample}-read-mapping-qc.csv",
306-
shell:
307-
"""
308-
mhpl8r mappingqc {input.marker} {input.full_refr} {input.repetitive} --csv {output.counts}
309-
"""
306+
run:
307+
results = mhapi.read_mapping_qc(input.marker, input.full_refr, input.repetitive)
308+
results.to_csv(output.counts, index=False)
310309

311310

312311
rule aggregate_read_mapping_qc:

0 commit comments

Comments
 (0)