from tiledb.cloud.vcf import ls_samples, split_vcf
Split VCF
You can run this tutorial in two ways:
- Locally on your machine.
- On TileDB Cloud.
However, since TileDB Cloud has a free tier, we strongly recommend that you sign up and run everything there, as that requires no installations or deployment.
TileDB supports the ingestion of single-sample VCF files into TileDB-VCF datasets. Multi-sample or project-level VCF files must be split as a prerequisite for ingestion into TileDB. To accommodate multi-sample VCFs, TileDB offers utilities to split them into individual, single-sample files. The most useful of these utilities is a distributed splitting function to enable simultaneous splitting of numerous samples from a single multi-sample VCF. Once single-sample VCF files are isolated, subsequently ingest them into TileDB datasets or combine the entire process into a broader task graph for standardized processing.
Follow this tutorial to learn how to split multi-sample VCF files stored in public or private S3 buckets.
Setup
First, import the necessary libraries for this tutorial.
Next, set some global variables:
project_vcf
: S3 path of bgzipped VCF to be split. No index file is required for splitting.dest
: S3 directory to write single-sample VCFs.namespace
: Namespace in which to execute task graph in.acn
: TileDB access credential name to authenticate task graph to S3.config
: Parameters for accessing S3, such as region.
More notes concerning these variables:
- Split VCF files are named after the sample name listed in the source multi-sample VCF file. If a VCF file already exists at the S3 URI, it will be overwritten.
- The task graph in
tiledb.cloud.vcf.split.split_vcf
is authenticated by the specified TileDB access credential name (acn
). - For non-task graph access to S3, either pass credentials to
config
or set them as environment variables (recommended).
Split by sample names
To identify all samples within a multi-sample VCF file for splitting, use tiledb.cloud.vcf.split.ls_samples
.
This dataset consists of two samples. To split just one sample, use tiledb.cloud.vcf.split.split_vcf
and pass its name to the samples: Sequence[str]
argument.
This launches a single-node task graph in the indicated namespace
since only one sample is passed to samples
. The resultant single-sample VCF for the indicated sample is saved to the location specified to split_vcf
’s output_uri
argument.
After the task graph completes, the URI of the isolated VCF file is returned. The file is named based on the sample name provided in tiledb.cloud.vcf.split.split_vcf
.
Split all samples
Split all samples in a multi-sample VCF into single-sample VCF files by not specifying a value for samples
.
This starts a two-stage task graph in the specified namespace. The first stage identifies all samples in the VCF. The second stage dynamically creates nodes for each sample identified in the first stage. This results in parallel isolation of each sample from the multi-sample VCF, expediting the splitting process.
Next steps
Now that the multi-sample VCF file has been isolated into single-sample VCF files, proceed with ingestion. To learn how to ingest the newly created single-sample VCF files, visit the ingestion tutorial.