Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/rich_codex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
runs-on: ubuntu-latest
env:
FORCE_COLOR: "true"

steps:
- name: Check out the repo
uses: actions/checkout@v3
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Mash sketch files are now validated using MD5 checksum to ensure integrity
- Added `--table-path` option to `search-pangenomes` to save TSV output to a file
- Added `--no-table` flag to disable table output in `search-pangenomes`
- `list-collections` now automatically detects terminal vs redirected output: displays formatted table in interactive terminals, plain TSV when redirected to files or pipes

### Changed

- `search-pangenomes` table output now defaults to stdout instead of a file (previous default was `pangenomes_information.tsv`)

## [0.1.1] - 2025-11-09

Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,23 @@ pangbank search-pangenomes --help
pangbank list-collections
```

Displays all pangenome collections available in PanGBank, along with their description and the number of pangenomes they contain.
Displays the list all pangenome collections available in PanGBank, along with their description and the number of pangenomes they contain.

Output is formatted as a rich table in the terminal, or as plain TSV when redirected (e.g., `pangbank list-collections > collections.tsv`).

<!-- RICH-CODEX hide_command: true -->
![`TERMINAL_WIDTH=110 pangbank list-collections`](docs/img/pangbank-list-collections.svg)

### Search for pangenomes

```bash
pangbank search-pangenomes --taxon "g__Escherichia"
```

Searches PanGBank for pangenomes matching the given taxon.
Results are saved as a **TSV file** named 'pangenomes_information.tsv' by default containing summary metrics for the matching pangenomes.
![`pangbank search-pangenomes --taxon "g__Escherichia" --no-progress --table-path pangenome_information.tsv`](docs/img/pangbank-search-pangenomes_taxon_Escherichia.svg)


This command searches PanGBank for pangenomes matching the given taxon.
Results are printed to **stdout** as plain TSV by default (suitable for piping or redirection). Use `--table-path <file>` to save directly to a file (e.g., `--table-path pangenomes_information.tsv`), or `--no-table` to disable table output.

![`pangbank search-pangenomes --taxon "g__Escherichia" --no-progress`](docs/img/pangbank-search-pangenomes_taxon_Escherichia.svg)

### Download pangenomes

Expand All @@ -132,10 +134,11 @@ pangbank search-pangenomes --taxon "g__Chlamydia" \
--download
```

Searches for **Chlamydia** pangenomes in the `GTDB_refseq` collection, then downloads the corresponding pangenome files into `Chlamydia_pangenomes/`.

![`pangbank search-pangenomes --taxon "g__Chlamydia" --collection GTDB_refseq --outdir Chlamydia_pangenomes/ --download --no-progress`](docs/img/pangbank-search-pangenomes_taxon_Chlamydia_download.svg)

This command searches for **Chlamydia** pangenomes in the `GTDB_refseq` collection, then downloads the corresponding pangenome files into `Chlamydia_pangenomes/`.


### Match a genome to an existing pangenome

```bash
Expand Down
133 changes: 0 additions & 133 deletions docs/img/pangbank-list-collections.svg

This file was deleted.

234 changes: 123 additions & 111 deletions docs/img/pangbank-search-pangenomes_help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 45 additions & 45 deletions docs/img/pangbank-search-pangenomes_taxon_Chlamydia_download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 48 additions & 44 deletions docs/img/pangbank-search-pangenomes_taxon_Escherichia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 30 additions & 13 deletions pangbank_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ def list_collections(
logger.info(f"Found {len(collections)} collections in PanGBank.")

df = format_collections_to_dataframe(collections)
print_dataframe_as_rich_table(df, title="Available collections of PanGBank:")

# Use rich formatting if interactive terminal, plain TSV if redirected
if sys.stdout.isatty():
print_dataframe_as_rich_table(df, title="Available collections of PanGBank:")
else:
df.to_csv(sys.stdout, index=False, sep="\t")

print_yaml = False
if print_yaml:
yaml_collections = format_collections_to_yaml(collections)
Expand Down Expand Up @@ -234,17 +240,24 @@ def search_pangenomes(
rich_help_panel="Output and downloads",
),
] = False,
table: Annotated[
bool,
typer.Option(
help="Output a TSV table summarizing the matching pangenomes to stdout.",
rich_help_panel="Output and downloads",
),
] = True,
table_path: Annotated[
Path,
Optional[Path],
typer.Option(
"--table",
"--table-path",
help=(
"Save a TSV table summarizing the matching pangenomes. "
"Use '-' to print the table to stdout."
"Save TSV table to a file instead of stdout (e.g., pangenomes_information.tsv). "
"Implies --table."
),
rich_help_panel="Output and downloads",
),
] = Path("pangenomes_information.tsv"),
] = None,
# Execution settings
api_url: HttpUrl = ApiUrlOption,
verbose: bool = Verbose,
Expand Down Expand Up @@ -282,14 +295,18 @@ def search_pangenomes(

df = format_pangenomes_to_dataframe(pangenomes)

if str(table_path) == "-":
logger.info("Printing pangenomes information as TSV table to stdout")
output_handle: TextIO | Path = sys.stdout
else:
logger.info(f"Saving pangenomes information as TSV table to file: {table_path}")
output_handle: TextIO | Path = table_path
# Output table if enabled
if table or table_path is not None:
if table_path is not None:
logger.info(
f"Saving pangenomes information as TSV table to file: {table_path}"
)
output_handle: TextIO | Path = table_path
else:
logger.info("Printing pangenomes information as TSV table to stdout")
output_handle: TextIO | Path = sys.stdout

df.to_csv(output_handle, index=False, sep="\t")
df.to_csv(output_handle, index=False, sep="\t")

if details:
display_pangenome_summary_by_collection(pangenomes, True)
Expand Down
2 changes: 1 addition & 1 deletion pangbank_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def print_dataframe_as_rich_table(df: pd.DataFrame, title: Optional[str] = None)
except ValueError:
pass # If not a valid integer, keep None

console = Console(stderr=True, width=terminal_width)
console = Console(width=terminal_width)
table = Table(
title=title,
show_header=True,
Expand Down