Python

tiledbvcf.dataset

This is the main Python module.

Dataset

Representation of the grouped TileDB arrays that constitute a TileDB-VCF dataset, which includes a sparse 3D array containing the actual variant data and a sparse 1D array containing various sample metadata and the VCF header lines. Read more about the data model here.

Dataset(self, uri, mode='r', cfg=None, stats=False, verbose=False)

Arguments

  • uri: URI of TileDB-VCF dataset

  • mode: (default 'r') Open the array object in read 'r' or write 'w' mode

  • cfg: TileDB-VCF configuration (optional)

  • stats: (bool) Enable of disable TileDB stats

  • verbose: (bool) Enable of disable TileDB-VCF verbose output

ingest_samples()

Ingest samples into an existing TileDB-VCF dataset.

ingest_samples(sample_uris=None, extra_attrs=None, checksum_type=None, allow_duplicates=True, scratch_space_path=None, scratch_space_size=None, sample_batch_size=None)

Arguments:

  • samples: (list of str samples) CSV list of VCF/BCF sample URIs to ingest

  • extra_attrs: (list of str attrs) list of extra attributes to materialize from FMT field

  • checksum_type: (str checksum) Optional override checksum type for creating new dataset (valid values are 'sha256', 'md5' or None)

  • allow_duplicates: (bool) Controls whether records with duplicate end positions can be ingested written to the dataset

  • str scratch_space_path: (str) Directory used for local storage of downloaded remote samples

  • scratch_space_size: (int) Amount of local storage that can be used for downloading remote samples (MB)

  • sample_batch_size: (int) Number of samples per batch for ingestion (default 10)

read()

Reads data from a TileDB-VCF dataset.

read(attrs, samples=None, regions=None, samples_file=None, bed_file=None)

Arguments

  • attrs: (list of str attrs) List of attributes to extract. Can include attributes from the VCF INFO and FORMAT fields (prefixed with info_ and fmt_, respectively) as well as any of the builtin attributes:

    • sample_name

    • id

    • contig

    • alleles

    • filters

    • pos_start

    • pos_end

    • qual

    • query_bed_end

    • query_bed_start

  • samples: (list of str samples) CSV list of sample names to be read

  • regions: (list of str regions) CSV list of genomic regions to be read

  • samples_file: (str filesystem location) URI of file containing sample names to be read, one per line

  • bed_file: (str filesystem location) URI of a BED file of genomic regions to be read

Details

For large datasets, a call to read() may not be able to fit all results in memory. In that case, the returned dataframe will contain as many results as possible, and in order to retrieve the rest of the results, use the continue_read() function.

You can also use the Python generator version, read_iter().

Returns: Pandas DataFrame containing results.

read_completed()

read_completed()

Details

A read is considered complete if the resulting dataframe contained all results.

Returns: (bool) True if the previous read operation was complete

count()

Counts data in a TileDB-VCF dataset.

count(samples=None, regions=None)

Arguments

  • samples: (list of str samples) CSV list of sample names to **include in the count

  • regions: (list of str regions) CSV list of genomic regions to include in the count

Details

Returns: Number of intersecting records in the dataset

attributes()

List queryable attributes available in the VCF dataset

attributes(attr_type = "all")

Arguments

  • attr_type: (list of str attributes) The subset of attributes to retrieve; "info" or "fmt" will only retrieve attributes ingested from the VCF INFO and FORMAT fields, respectively, "builtin" retrieves the static attributes defined in TileDB-VCF's schema, "all" (the default) returns all queryable attributes

Details

Returns: a list of strings representing the attribute names

tiledbvcf.ReadConfig

Set various configuration parameters.

ReadConfig(limit, region_partition, sample_partition, sort_regions, memory_budget_mb, tiledb_config)

Parameters

  • limit: max number of records (rows) to read

  • region_partition: Region partition tuple (idx, num_partitions)

  • sample_partition: Samples partition tuple (idx, num_partitions)

  • sort_regions: Whether or not to sort the regions to be read (default True)

  • memory_budget_mb: Memory budget (MB) for buffer and internal allocations (default 2048)

  • tiledb_config: List of strings in the format "option=value" (see here for full list TileDB configuration parameters)

tiledbvcf.dask

This module is for the TileDB-VCF integration with Dask.

read_dask()

Reads data from a TileDB-VCF dataset into a Dask DataFrame.

read_dask(attrs, region_partitions=1, sample_partitions=1, samples=None, regions=None, samples_file=None, bed_file=None)

Arguments

  • attrs: (list of str attrs) List of attribute names to be read

  • region_partitions (int partitions) Number of partitions over regions

  • sample_partitions (int partitions) Number of partitions over samples

  • samples: (list of str samples) CSV list of sample names to be read

  • regions: (list of str regions) CSV list of genomic regions to be read

  • samples_file: (str filesystem location) URI of file containing sample names to be read, one per line

  • bed_file: (str filesystem location) URI of a BED file of genomic regions to be read

Details

Partitioning proceeds by a straightforward block distribution, parameterized by the total number of partitions and the particular partition index that a particular read operation is responsible for.

Both region and sample partitioning can be used together.

Returns: Dask DataFrame with results

map_dask()

Maps a function on a Dask DataFrame obtained by reading from the dataset.

map_dask(fnc, attrs, region_partitions=1, sample_partitions=1, samples=None, regions=None, samples_file=None, bed_file=None)

Arguments

  • fnc: (function) Function applied to each partition

  • attrs: (list of str attrs) List of attribute names to be read

  • region_partitions (int partitions) Number of partitions over regions

  • sample_partitions (int partitions) Number of partitions over samples

  • samples: (list of str samples) CSV list of sample names to be read

  • regions: (list of str regions) CSV list of genomic regions to be read

  • samples_file: (str filesystem location) URI of file containing sample names to be read, one per line

  • bed_file: (str filesystem location) URI of a BED file of genomic regions to be read

Details

May be more efficient in some cases than read_dask() followed by a regular Dask map operation.

Returns: Dask DataFrame with results