This page explains how to run a genomics pipeline that uses the Cloud Life Sciences API to create an index file (BAI file) from a binary file containing DNA sequences (BAM file). BAM files are typically large and can take a long time to read using a genome viewer. You use a BAI file to locate the portions of the BAM file that contain the genome position you are interested in.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. Enable the Cloud Life Sciences, Compute Engine, and Cloud Storage JSON APIs.

    Enable the APIs

  5. Install and initialize the Cloud SDK.
  6. Alternatively, you can use Cloud Shell, which comes with the Cloud SDK already installed.

  7. Install Python 3.8.

    If you are using Windows and you left the relevant checkbox selected when you installed the Cloud SDK, this was done automatically.

Run the pipeline

To run the pipeline, complete the following steps:

  1. Create a bucket where you store the BAI file. Buckets are the basic containers that hold your data in Cloud Storage. To create a bucket named PROJECT_ID-life-sciences, run the gsutil mb command:

    gsutil mb gs://PROJECT_ID-life-sciences

    Replace PROJECT_ID with your Google Cloud project ID. You must use a globally unique bucket name.

    If successful, the command returns the following:

    Creating gs://PROJECT_ID-life-sciences
  2. To start the pipeline, run the gcloud beta lifesciences pipelines run command:

    gcloud beta lifesciences pipelines run \
        --regions us-east1 \
        --command-line 'samtools index ${BAM} ${BAI}' \
        --docker-image "gcr.io/cloud-lifesciences/samtools" \
        --inputs BAM=gs://genomics-public-data/NA12878.chr20.sample.bam \
        --outputs BAI=gs://PROJECT_ID-life-sciences/NA12878.chr20.sample.bam.bai

    If successful, the command returns the following:

    Running [projects/PROJECT_ID/operations/OPERATION_ID]

    Note the OPERATION_ID, which you use in the next step.

  3. To track the pipeline's status, run the gcloud beta lifesciences operations wait command. Replace OPERATION_ID with the value printed in the previous step. The pipeline takes a few minutes to finish.

    gcloud beta lifesciences operations wait OPERATION_ID

    After the operation finishes, it returns the following message:

    Waiting for [projects/PROJECT_ID/operations/OPERATION_ID]...done.
  4. To verify that the BAI file was generated, run the gsutil ls command:

    gsutil ls gs://PROJECT_ID-life-sciences

    If successful, the command returns the following:


You've run a pipeline using the Cloud Life Sciences API to create a BAI file from a BAM file. Use a genome viewer to examine the NA12878.chr20.sample.bam BAM file using the NA12878.chr20.sample.bam.bai index file.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this page, follow these steps.

Delete the BAI file

To delete the generated BAI file but keep the project and bucket you created, run the gsutil rm command:

gsutil rm PROJECT_ID-life-sciences/NA12878.chr20.sample.bam.bai

Delete the bucket

If you created the bucket specifically for this quickstart and no longer need it, but want to keep your project, delete the bucket using the gsutil rb command. Deleting the bucket also deletes the generated BAI file.

gsutil rb gs://PROJECT_ID-life-sciences

Delete the project

If you created the project specifically for this quickstart and no longer need it, you can delete the project. Deleting the project also deletes the BAI file and the Cloud Storage bucket.

  1. In the Cloud Console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

How did it go?

What's next