Compute window aggregations and alter contents of Amethyst HDF5 files
Project description
Facet is an efficient utility for computing window aggregations on Amethyst HDF5 files produced via the premethyst pipeline.
Create environment
Install facet.py dependencies using mamba:
mamba create -n facet pip && pip install amethyst-facet
Ingest base-pair-resolution .parquet and .cov files
facet calls2h5 will ingest base-pair-resolution methylation observations in the Scale Bio .parquet format as well as the legacy plaintext .cov format to the HDF5 format used by Amethyst. This can then be used to compute window aggregations using facet agg. Context and barcode can be flexibly parsed from the filename.
Example:
facet calls2h5 --parse {barcode1}_{barcode2}_{barcode3}.{context}.cov output.h5 *.cov
This will store any *.cov file with a name in the format to form datasets named /{context}/{barcode1}{barcode2}{barcode3}/1.
To specify how datasets are parsed, you can use the --format option to supply Python code that will format a list of strings barcode and a list of strings context into the group under which the dataset should be stored. Example:
facet calls2h5 --parse {barcode1}_{barcode2}.{context}.cov --format "'/{context[0]}/{barcode[0]}_{barcode[1]}'" output.h5 *.cov
Since the Scale Bio parquet format has a context column, there is no need to parse the context from the filename for these files.
facet calls2h5 --parse {barcode1}_{barcode2}.parquet output.h5 *.parquet
Other options for configuring input parsing and the output datset can be found using facet calls2h5 --help.
The expected schema for .cov files is headerless, tab-delimited files with the following columns:
chr pos pct t c
Only the chr, pos, t, and c columns will be written to the HDF5 file.
Compute Window Aggregations
facet agg will add window aggregations to an existing HDF5 file in version 2.0.0 (see below for information on file format conversion).
Example:
facet agg -u 500 -u step_1000=1000:250 -w special_fancy_windows=windows.tsv -p 55 *.h5
This computes several types of windows.
-u 500computes uniform non-overlapping 500bp windows. These will be stored in/[context]/[barcode]/[window_size]by default. A custom name can be chosen by prepending-u [dataset_name]=500.-u step_1000=1000:250computes 1000bp windows with a 250bp step, so intervals will be computed at $[0, 1000), [250, 1250), ...$. This example uses a custom name ofstep_1000. The default is to use[window_size]_by_[step_size], which in this case would have been1000_by_250.-w special_fancy_windows=windows.tsvcomputes aggregations over custom windows defined in a CSV-like file. The headerschr,startandendare required but the file format is sniffed by DuckDB (csv, tsv etc are allowed). Intervals are left-closed right-open, i.e. $[start, end)$ and may be overlapping and gapped.
The -p 55 option parallelizes the computation using 55 worker cores. All HDF5 files retrieved via *.h5 will have windows computed in this case. Multiple globs can be specified, i.e. -glob path1/*.h5 -glob path2/*.h5.
Other options are described in facet agg --help.
Help
The options for facet.py can be explored at the command line by appending --help.
Example:
$ facet --help
Usage: facet.py [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
agg Compute window sums over methylation observations stored in...
convert Convert an old Amethyst HDF5 file format to v2.0.0 format
delete Delete contexts, barcodes, or datasets from an Amethyst 2.0.0...
version
You can also call --help on subcommands. Example:
facet agg --help
Convert old Amethyst HDF5 file format to version 2.0.0
File format conversion is necessary prior to computing window aggregations using facet.py for Amethyst HDF5 files produced using earlier scripts.
Example:
facet convert old_format.h5 new_format.h5
Explanation and schema comparison:
The old Amethyst HDF5 format stored datasets under a cell barcode under a context group:
/[context]/[barcode]
context values are typically CH and CG. The barcode values are unique identifiers attributed to single cells. Typically each value of barcode is found in both the CH and CG contexts.
The schema of barcode was chr, pos, pct, c, t, with chr the chromosome name, pos the bp position of the observation, pct equal to c/(c+t), and c and t the methylated and unmethylated count at that position.
This gave no clear way to store window aggregations alongside the bp-resolution observations. We therefore altered the schema to:
/[context]/[barcode]/[dataset]
The bp-resolution observations are stored under the dataset 1 by default. Window aggregations are stored under their context and barcode under other names. The schema for window aggregations is chr, start, end, c, t, c_nz, t_nz. The start and end values denote the interval $[start, end)$. The c and t values store the sum of c and t counts for observed positions on that interval. Intervals with no observations are not reported. The c_nz and t_nz fields store the count of positions where c >= 1 or t >= 1 respectively.
Delete datasets
Examples:
facet delete context CH *.h5
facet delete barcode AGCGAGCGAGCAHHCAHH *.h5
facet delete dataset 1 *.h5
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file amethyst-facet-1.1.10.tar.gz.
File metadata
- Download URL: amethyst-facet-1.1.10.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.32.3 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04921929055c14769c0b4ce228f67dba48e9d6f849c2045211277764afac11b2
|
|
| MD5 |
c7ba8b2e612595534fd0427c4a533de1
|
|
| BLAKE2b-256 |
7dcc8fc3bd6f9782a7cbb16b2fba2fd4f33692b50053e66672d9ec797ccfc9e2
|
File details
Details for the file amethyst_facet-1.1.10-py3-none-any.whl.
File metadata
- Download URL: amethyst_facet-1.1.10-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.32.3 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
effb2d31f16fac080fb73f8dffdd6c11d1ed5c7fdc3eae69efc33f2452b2ea68
|
|
| MD5 |
6f7b5ff1d33749464004e03f37a86d37
|
|
| BLAKE2b-256 |
ccab980c0f3ed2cbb72508b58bb8f1ea68b9a0345dd95af44e8731f1f1bc781c
|