Skip to content
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

Added a qc reporting file #14

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion primalscheme3/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.0.0"
__version__ = "3.0.1"
8 changes: 8 additions & 0 deletions primalscheme3/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def __str__(self) -> str:

def assign_kwargs(self, **kwargs: Any) -> None:
for key, value in kwargs.items():
# Check if key is valid
if value is None:
continue

if key == "input_bedfile":
setattr(self, key, pathlib.Path(value))
continue

if hasattr(self, key):
# Convert to expected type
if isinstance(getattr(self, key), MappingType):
Expand Down
22 changes: 22 additions & 0 deletions primalscheme3/core/multiplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ def get_coverage_percent(self, msa_index: int) -> float:
self._coverage[msa_index].sum() / len(self._coverage[msa_index]) * 100, 2
)

def get_coverage_gaps(self, msa_index: int) -> list[tuple[int, int]]:
"""
Returns the coverage gaps for the specified MSA index
:param msa_index: int
:return: list[tuple[int, int]]
"""
gaps = []
in_gap = False
gap_start = 0
for i, covered in enumerate(self._coverage[msa_index]):
if not covered:
if not in_gap:
gap_start = i
in_gap = True
else:
if in_gap:
gaps.append((gap_start, i))
in_gap = False
if in_gap:
gaps.append((gap_start, i))
return gaps

def update_coverage(self, primerpair: PrimerPair, add: bool = True) -> None:
"""
Updates the coverage for the specified MSA index
Expand Down
15 changes: 14 additions & 1 deletion primalscheme3/scheme/scheme_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def schemecreate(
for msa_index, msa_obj in msa_dict.items():
# Set up the pm for the MSA
scheme_pt = pm.create_sub_progress(
iter=None, chrom=msa_obj._chrom_name, process="Creating Scheme", leave=False
iter=None, chrom=msa_obj.name, process="Creating Scheme", leave=False
)
scheme_pt.manual_update(n=0, total=msa_obj.array.shape[1])

Expand Down Expand Up @@ -602,6 +602,19 @@ def schemecreate(

upload_pt.manual_update(n=4, update=True)

# Create qc coverage data
qc_data = {}
for msa_index, msa_obj in msa_dict.items():
msa_data = {"coverage": scheme.get_coverage_percent(msa_index)}
msa_data["n_amplicons"] = len(
[x for x in scheme._last_pp_added if x.msa_index == msa_index]
)
msa_data["n_gaps"] = len(scheme.get_coverage_gaps(msa_index))
qc_data[msa_obj.name] = msa_data

with open(OUTPUT_DIR / "work" / "qc.json", "w") as outfile:
outfile.write(json.dumps(qc_data, sort_keys=True))

## DO THIS LAST AS THIS CAN TAKE A LONG TIME
# Writing plot data
plot_data = generate_all_plotdata(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "primalscheme3"
version = "3.0.0"
version = "3.0.1"
description = ""
authors = ["ChrisKent <[email protected]>"]
readme = "README.md"
Expand Down