Skip to content

Commit 5d0964c

Browse files
committed
Add function: export summary metric as CSV file.
1 parent f3165b8 commit 5d0964c

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ If you want to use a specified list of valid cell barcodes, you can provide the
9797

9898
To reduce runtime, you may enable the `--skip_umap_tsne` option to bypass dimensionality reduction and visualization steps.
9999

100-
**7- Debug-level message**
100+
**7- Export the summary metrics**
101+
102+
To export the summary metrics, specify the directory where the summary table should be saved as a CSV file.
103+
104+
**8- Debug-level message**
101105

102106
To get debug-level messages and more intermediate computation in cell calling step, you can specify `--verbose`
103107

104-
**8- Re-run QCatch on modified h5ad file**
108+
**9- Re-run QCatch on modified h5ad file**
105109
If you re-run QCatch analysis on a modified `.h5ad` file (i.e., an `.h5ad` file with additional columns added for cell calling results), the existing cell calling-related columns will be removed and then replaced with new results. The new cell calling can be generated either through QCatch's internal method or based on a user-specified list of valid cell barcodes.
106110

107111
**Example directory structures:**
@@ -148,6 +152,7 @@ For more advanced options and usage details, see the sections below.
148152
| `--valid_cell_list` | `-l` | `str` (Optional) |File provides a user-specified list of valid cell barcode. The file must be a TSV containing one column with cell barcodes without a header row. If provided, qcatch will skip the internal cell calling steps and and use the supplied list instead|
149153
| `--n_partitions` | `-n` | `int` (Optional) | Number of partitions (max number of barcodes to consider for ambient estimation). Skip this step if you already specified `--chemistry`. Only use `--n_partitions` when your experiment uses a custom chemistry not listed in the predefined chemistry options.|
150154
| `--skip_umap_tsne` | `-u` | `flag` (Optional) | If provided, skips generation of UMAP and t-SNE plots. |
155+
| `--summary_table_file` | `-t` | `Path` (Optional) | Path to a directory where the summary metrics will be saved as a CSV file. |
151156
| `--verbose` | `-b` | `flag` (Optional) | Enable verbose logging with debug-level messages. |
152157
| `--version` | `-v` | `flag` (Optional) | Display the installed version of qcatch. |
153158

src/qcatch/convert_to_html.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ def create_plotly_plots(
8989
mapping_rate = round(map_json_data["num_mapped"] / num_processed * 100, 2)
9090
seq_saturation_value = generate_seq_saturation(retained_data)
9191

92+
summary_table_file = args.summary_table_file
9293
summary_table_html = generate_summary_table(
93-
data, valid_bcs, total_detected_genes, median_genes_per_cell, mapping_rate, seq_saturation_value
94+
data,
95+
valid_bcs,
96+
total_detected_genes,
97+
median_genes_per_cell,
98+
mapping_rate,
99+
seq_saturation_value,
100+
summary_table_file,
94101
)
95102

96103
# ---------------- Tab2 - Barcode Frequency Plots ---------------

src/qcatch/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def main():
8080
parser.add_argument(
8181
"--skip_umap_tsne", "-u", action="store_true", help="If provided, skips generation of UMAP and t-SNE plots."
8282
)
83+
parser.add_argument(
84+
"--summary_table_file",
85+
"-t",
86+
type=Path,
87+
default=None,
88+
help="Path to a directory where the summary metrics will be saved as a CSV file.",
89+
)
8390
parser.add_argument("--verbose", "-b", action="store_true", help="Enable verbose logging with debug-level messages")
8491

8592
parser.add_argument(

src/qcatch/plots_tables.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import os
45

56
import numpy as np
67
import pandas as pd
@@ -664,17 +665,19 @@ def generate_summary_table(
664665
median_genes_per_cell: int,
665666
mapping_rate: float | None,
666667
seq_saturation_value: float,
668+
summary_table_file: str | None = None,
667669
) -> str:
668670
"""
669671
Generate a summary table with total corrected reads, median UMI, and total number of cells, etc.
670672
671673
Args:
672-
raw_featuredump_data: DataFrame containing featurn dump data.
674+
raw_featuredump_data: DataFrame containing feature dump data.
673675
valid_bcs: List of valid barcode strings.
674676
total_detected_genes: Total number of genes detected in retained cells.
675677
median_genes_per_cell: Median number of genes per retained cell.
676678
mapping_rate: Fraction of reads mapped to reference, or None.
677679
seq_saturation_value: Sequencing saturation percentage.
680+
summary_table_file: Optional path to save the summary table as a CSV file.
678681
679682
Returns
680683
-------
@@ -697,6 +700,13 @@ def generate_summary_table(
697700
"Sequencing saturation": f"{seq_saturation_value}%",
698701
}
699702

703+
# Optionally: Save the summary table to a CSV file
704+
if summary_table_file:
705+
summary_table_file_path = os.path.join(summary_table_file, "summary_table.csv")
706+
logger.info(f"🍡 Saving summary table to CSV at: {summary_table_file_path}")
707+
# Save the summary dictionary as a single-row CSV file with keys as column headers
708+
pd.DataFrame([summary]).to_csv(summary_table_file_path, index=False)
709+
700710
# Convert summary dict to a list of (key, value) pairs
701711
summary_items = list(summary.items())
702712

tests/test_qcatch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def test_simpleaf_with_cb_list(tmp_path):
7878
"--valid_cell_list",
7979
str(valid_cb_list),
8080
"--skip_umap_tsne",
81+
"--summary_table_file",
82+
str(output_path),
8183
"--verbose",
8284
]
8385

0 commit comments

Comments
 (0)