GCP Variant Transforms

Build Status Coverage


This is a tool for transforming and processing VCF files in a scalable manner based on Apache Beam using Dataflow on Google Cloud Platform.

It can be used to directly load VCF files to BigQuery supporting hundreds of thousands of files, millions of samples, and billions of records. Additionally, it provides a preprocess functionality to validate the VCF files such that the inconsistencies can be easily identified.

Please see this presentation for a high level overview of BigQuery and how to effectively use Variant Transforms and BigQuery. Please also read the blog post about how a GCP customer used Variant Transforms for breakthrough clinical data science with BigQuery.


  1. Follow the getting started instructions on the Google Cloud page.
  2. Enable the Genomics, Compute Engine, Cloud Storage, and Dataflow APIs
  3. Create a new BigQuery dataset by visiting the BigQuery web UI, clicking on the down arrow icon next to your project name in the navigation, and clicking on Create new dataset.

Loading VCF files to BigQuery

Using docker

The easiest way to run the VCF to BigQuery pipeline is to use the docker image, as it has the binaries and all dependencies pre-installed. Please ensure you have the latest gcloud tool by running gcloud components update (more details here).

Use the following command to get the latest version of Variant Transforms.

docker pull gcr.io/cloud-lifesciences/gcp-variant-transforms

Run the script below and replace the following parameters:

# Parameters to replace:

COMMAND="vcf_to_bq \
  --input_pattern ${INPUT_PATTERN} \
  --output_table ${OUTPUT_TABLE} \
  --job_name vcf-to-bigquery \
  --runner DataflowRunner"

docker run -v ~/.config:/root/.config \
  gcr.io/cloud-lifesciences/gcp-variant-transforms \
  --project "${GOOGLE_CLOUD_PROJECT}" \
  --region "${GOOGLE_CLOUD_REGION}" \
  --temp_location "${TEMP_LOCATION}" \

--project, --region, and --temp_location are required inputs. You must set all of them, unless your project and region default values are set in your local gcloud configuration. You may set the default project and region using the following commands:

gcloud config set project GOOGLE_CLOUD_PROJECT
gcloud config set compute/region REGION

The underlying pipeline uses Cloud Dataflow. You can navigate to the Dataflow Console, to see more detailed view of the pipeline (e.g. number of records being processed, number of workers, more detailed error logs).

Running from github

In addition to using the docker image, you may run the pipeline directly from source. First install git, python, pip, and virtualenv:

sudo apt-get install -y git python-pip python-dev build-essential
sudo python -m pip install --upgrade pip
sudo python -m pip install --upgrade virtualenv

Run virtualenv, clone the repo, and install pip packages:

virtualenv venv
source venv/bin/activate
git clone https://github.com/googlegenomics/gcp-variant-transforms.git
cd gcp-variant-transforms
python -m pip install --upgrade .

You may use the DirectRunner (aka local runner) for small (e.g. 10,000 records) files or DataflowRunner for larger files. Files should be stored on Google Cloud Storage if using Dataflow, but may be stored locally for DirectRunner.

Example command for DirectRunner:

python -m gcp_variant_transforms.vcf_to_bq \
  --input_pattern gcp_variant_transforms/testing/data/vcf/valid-4.0.vcf \
  --job_name vcf-to-bigquery-direct-runner \
  --temp_location "${TEMP_LOCATION}"

Example command for DataflowRunner:

python -m gcp_variant_transforms.vcf_to_bq \
  --input_pattern gs://BUCKET/*.vcf \
  --job_name vcf-to-bigquery \
  --setup_file ./setup.py \
  --runner DataflowRunner \
  --project "${GOOGLE_CLOUD_PROJECT}" \
  --region "${GOOGLE_CLOUD_REGION}" \
  --temp_location "${TEMP_LOCATION}"

Running VCF files preprocessor

The VCF files preprocessor is used for validating the datasets such that the inconsistencies can be easily identified. It can be used as a standalone validator to check the validity of the VCF files, or as a helper tool for VCF to BigQuery pipeline. Please refer to VCF files preprocessor for more details.

Running BigQuery to VCF

The BigQuery to VCF pipeline is used to export variants in BigQuery to one VCF file. Please refer to BigQuery to VCF pipeline for more details.

Additional topics