(path: Path)
| 88 | |
| 89 | |
| 90 | def parse_insert_sizes(path: Path) -> dict[str, float | int | None]: |
| 91 | metrics: dict[str, float | int | None] = { |
| 92 | "insert_size_count": None, |
| 93 | "insert_size_median": None, |
| 94 | "insert_size_mean": None, |
| 95 | "nucleosome_free_fraction": None, |
| 96 | } |
| 97 | if not path.exists(): |
| 98 | return metrics |
| 99 | values: list[float] = [] |
| 100 | for line in path.read_text(encoding="utf-8", errors="replace").splitlines(): |
| 101 | try: |
| 102 | value = abs(float(line.strip())) |
| 103 | except ValueError: |
| 104 | continue |
| 105 | if value > 0: |
| 106 | values.append(value) |
| 107 | if not values: |
| 108 | return metrics |
| 109 | metrics["insert_size_count"] = len(values) |
| 110 | metrics["insert_size_median"] = round(float(statistics.median(values)), 3) |
| 111 | metrics["insert_size_mean"] = round(float(sum(values) / len(values)), 3) |
| 112 | metrics["nucleosome_free_fraction"] = round( |
| 113 | sum(1 for value in values if value < 100) / len(values), 4 |
| 114 | ) |
| 115 | return metrics |
| 116 | |
| 117 | |
| 118 | def _rel(path: Path, run_dir: Path) -> str: |
no test coverage detected