SeqShop: Variant Calling and Filtering for SNPs Practical, May 2015

From Genome Analysis Wiki
Jump to: navigation, search


Main Workshop wiki page: SeqShop: May 2015

See the introductory slides for an intro to this tutorial.

Goals of This Session

  • What we want to learn
    •  How to generate filtered variant calls for SNPs from BAMs
    • Basic variant call file format (VCF)
    •  How to examine the variants at particular genomic positions
    •  How to evaluate the quality of SNP calls


This section is specifically for the SeqShop Workshop computers.

If you are not running during the SeqShop Workshop, please skip this section.

Login to the seqshop-server Linux Machine

This section will appear redundantly in each session. If you are already logged in or know how to log in to the server, please skip this section

  1. Login to the windows machine
    • The username/password for the Windows machine should be written on the right-hand monitor
  2. Start xming so you can open external windows on our Linux machine
    • Start->Enter "Xming" in the search and select "Xming" from the program list
    • Nothing will happen, but Xming was started.
    • View Screenshot
    • Xming.png

  3. Open putty
    • Start->Enter "putty" in the search and select "PuTTY" from the program list
    • View Screenshot
    • PuttyS.png

  4. Configure PuTTY in the PuTTY Configuration window
    • Host Name:
    • View Screenshot
    • Seqshop.png

    • Setup to allow you to open external windows:
      • In the left pannel: Connection->SSH->X11
        • Add a check mark in the box next to Enable X11 forwarding
        • View Screenshot
        • SeqshopX11.png

    • Click Open
    • If it prompts about a key, click OK
  5. Enter your provided username & password as provided

You should now be logged into a terminal on the seqshop-server and be able to access the test files.

  • If you need another terminal, repeat from step 3.

Login to the seqshop Machine

So you can each run multiple jobs at once, we will have you run on 4 different machines within our seqshop setup.

  • You can only access these machines after logging onto seqshop-server

3 users logon to:

ssh -X seqshop1

3 users logon to:

ssh -X seqshop2

2 users logon to:

ssh -X seqshop3

2 users logon to:

ssh -X seqshop4

Prerequisite Tutorials

This tutorial builds on the alignment tutorial, if you have not already, please first run that tutorial: Alignment Tutorial

Setup your run environment

Environment variables will be used throughout the tutorial.

We recommend that you setup these variables so you won't have to modify every command in the tutorial.

  1. Point to where you installed GotCloud
  2. Point to where you installed the seqshop files
  3. Point to where you want the output to go
Using bash (replace the paths below with the appropriate paths):
export GC=~/seqshop/gotcloud
export SS=~/seqshop/example
export OUT=~/seqshop/output
Using tcsh (replace the paths below with the appropriate paths):
setenv GC ~/seqshop/gotcloud
setenv SS ~/seqshop/example
setenv OUT ~/seqshop/output

Examining GotCloud SnpCall Input files

Sequence Alignment Files: BAM Files

Per sample BAM files contain sequence reads that are mapped to positions in the genome.

For a reminder on how to look at/read BAM files, see: SeqShop Aligment: BAM Files

For this tutorial, we will use the 4 BAMs produced in the SeqShop: Sequence Mapping and Assembly Practical as well as with 58 BAMs that were pre-aligned to that 1MB region of chromosome 22.

Reference Files

Reference files can be downloaded with GotCloud or from other sources.

For GotCloud snpcall, you need:

  1. Reference genome FASTA file
    • Contains the reference base for each position of each chromosome
      • Used to compare bases in sequence reads to the reference positions they mapped to
      • Used to identify SNPs/variations in the sequence reads
    • Additional information on the FASTA format:
  2. VCF (variant call format) files with chromosomes/positions
    • indel - contains known insertions & deletions to help with filtering
    • omni - used as likely true positives for SVM filtering
    • hapmap - used as likely true positives for SVM filtering and for generating summary statistics
    • dbsnp - used for generating summary statistics

We looked at them yesterday, but you can take another look at the chromosome 22 reference files included for this tutorial:

ls ${SS}/ref22
  • View Screenshot
  • RefDir.png

GotCloud BAM List File

The BAM list file points GotCloud to the BAM files

  • generated by the alignment pipeline

Look at the BAM list file the alignment pipeline generated

cat ${OUT}/bam.list
What is the path to the BAM file for sample HG00640?
  • Answer:
    • /net/seqshop-server/home/YourUserName/out/bams/HG00640.recal.bam
    • BamindexNew.png

The alignment pipeline only processed 4 samples, but for snpcall, we want to run on 62 samples.

  • The other 58 samples were already aligned:
ls ${SS}/bams

Look at the BAM list file for those BAMs:

less ${SS}/bams/bam.list

Remember, use 'q' to exit out of less

Do you notice a difference between this list and yours?
  • Answer:
    • It doesn't have a full path to the BAM file, while your list has /home/...
    • BamList1.png

    • That's ok, we will use the --base_prefix ${SS} command-line option to prefix the BAM paths
    • Alternatively, we could have set BAM_PREFIX in gotcloud.conf to the path to the BAMs
      BAM_PREFIX = /net/seqshop-server/home/mktrost/seqshop/example
      • NOTE: the conf file can't interpret ${SS} environment variables or '~', so you would have to specify the full path
      • We just used the command-line option for this tutorial since this path will vary by user when running outside the workshop.

We need to add these BAMs to our list

  • Append the bam.list from the pre-aligned BAMs to the one you generated from the alignment pipeline
    • Be sure to do this command just once
cat ${SS}/bams/bam.list >> ${OUT}/bam.list
  • ">>" will append to the file that follows it
    • Check that your BAM list is the correct size
      wc -l ${OUT}/bam.list
      • wc -l counts the number of lines in the file
      • Should be 62

Verify your BAM list contains the additional BAMs

 less ${OUT}/bam.list

Remember, use 'q' to exit out of less

Do you see both sets of BAMs?
  • Annotated Screenshot:
    • If not, let me know
    • BamList2.png

GotCloud Configuration File

We will use the same configuration file as we used yesterday in GotCloud Align.

See SeqShop: Alignment: GotCloud Configuration File for more details

  • Note we want to limit snpcall to just chr22 so the configuration already has CHRS = 22 (default was 1-22 & X).

For more information on configuration, see: GotCloud snpcall: Configuration File

  • Contains information on how to configure for exome/targeted sequencing

Run GotCloud SnpCall


Now that we have all of our input files, we need just a simple command to run:

  • When running at home if you don't have 8 CPUs, reduce the --numjobs setting (it will take longer to run).
${GC}/gotcloud snpcall --conf ${SS}/gotcloud.conf --numjobs 8 --region 22:36000000-37000000 --base_prefix ${SS} --outdir ${OUT}
  • ${GC}/gotcloud runs GotCloud
  • snpcall tells GotCloud you want to run the snpcall pipeline.
  • --conf tells GotCloud the name of the configuration file to use.
    • The configuration for this test was downloaded with the seqshop input files.
  • --numjobs tells GotCloud how many jobs to run in parallel
    • Depends on your system
  • --region 22:36000000-37000000
    • The sample files are just a small region of chromosome 22, so to save time, we tell GotCloud to ignore the other regions
  • --base_prefix tells GotCloud the prefix to append to relative paths.
    • The Configuration file cannot read environment variables, so we need to tell GotCloud the path to the input files, ${SS}
    • Alternatively, gotcloud.conf could be updated to specify the full paths
  • --outdir tells GotCloud where to write the output.
    • This could be specified in gotcloud.conf, but to allow you to use the ${OUT} to change the output location, it is specified on the command-line

Curious if it started running properly? Check out this screenshot:


This should take about 3-6 minutes to run.

  • It should end with a line like: Commands finished in 402 secs with no errors reported

If you cancelled GotCloud part way through, just rerun your GotCloud command and it will pick up where it left off.

If you want to understand more detailed step of GotCloud SNP calling, here is a schematic picture with a little bit more details


Examining GotCloud SnpCall Output

Let's look at the output directory:

ls ${OUT}
Do you see any new files or directories?
  • View Annotated Screenshot:


Let's look at the vcfs directory:

ls ${OUT}/vcfs

Just a chr22 directory, so look inside of there:

ls ${OUT}/vcfs/chr22
Can you identify the final filtered VCF and the associated summary file?
  • Answer & annotated directory listing:
  • Filtered VCF (SVM & hard filters): chr22.filtered.vcf.gz
  • Summary file: chr22.filtered.sites.vcf.summary


Now, let's look in the split directory for the VCF with just the passing variants:

ls ${OUT}/split/chr22
Which file do you think is the one you want?
  • Answer:
  • chr22.filtered.PASS.vcf.gz


Filtering Summary Statistics

cat ${OUT}/vcfs/chr22/chr22.filtered.sites.vcf.summary

View Screenshot


To understand how to interpret the filtering summary statistics, please refer to Understanding vcf-summary output

Filtered VCF

Let's look at the filtered sites file.

zless -S ${OUT}/vcfs/chr22/chr22.filtered.sites.vcf.gz
  • Scroll down until you find some variants.
    • Use space bar to jump a full page
    • Use down arrow to move down one line
  • Scroll right: lots of info fields, but no per sample genotype information
What is the first filtered out variant that you find & what filter did it fail?
  • Answer:
  • It failed SVM filter


Remember, use 'q' to exit out of less


Now, let's look at the filtered file with genotypes.

zless -S ${OUT}/vcfs/chr22/chr22.filtered.vcf.gz
  • Scroll down until you find some variants.
    • Use space bar to jump a full page
    • Use down arrow to move down one line
  • Scroll right until you should see per sample genotype information

Remember, use 'q' to exit out of less

  • View annotated screenshot:


Passing SNPs

Let's look at the file of just the pass sites:

zless -S ${OUT}/split/chr22/chr22.filtered.PASS.vcf.gz
  • Scroll down: they all look like they PASS

Remember, use 'q' to exit out of less


Let's check if they are all PASS.

zcat ${OUT}/split/chr22/chr22.filtered.PASS.vcf.gz |grep -v "^#"| cut -f 7| grep -v "PASS"

It will return nothing since there are no non-passing variants in this file.

Want an explanation of this command?
  • zcat ...: uncompress the zipped VCF
  • '|' : this takes the output of one command and sends it as input to the next
  • grep -v "^#" : exclude any lines that start with "#" - headers
  • cut -f 7 : extract the FILTER column (the 7th column)
  • grep -v "PASS" : exclude any rows that have a "PASS" in the FILTER column

Compare that to the filtered file we looked at before:

zcat ${OUT}/vcfs/chr22/chr22.filtered.vcf.gz |grep -v "^#"| cut -f 7| grep -v "PASS"
Do you see any filters?
  • Answer
  • Yes
    • It should have scrolled and you should see filters like:
      • INDEL5;SVM
      • INDEL5
      • SVM

GotCloud Genotype Refinement

To improve the quality of the genotypes, we run a genotype refinement pipeline.

This pipeline runs Beagle & thunder.

Genotype Refinement Input

The GotCloud genotype refinement pipeline takes as input ${OUT}/split/chr22/chr22.filtered.PASS.vcf.gz (the VCF file of PASS'ing SNPs from snpcall).

The bam list and the configuration file we used for GotCloud snpcall will tell GotCloud genotype refinement everything it needs to know, so no new input files need to be prepared.

Note: the configuration file overrides the THUNDER command to make it go faster than the default settings so the tutorial will run faster: ThunderConf.png

Running GotCloud Genotype Refinement

Since everything is setup, just run the following command (very similar to snpcall).

${GC}/gotcloud ldrefine --conf ${SS}/gotcloud.conf --numjobs 8 --region 22:36000000-37000000 --base_prefix ${SS} --outdir ${OUT}
  • Beagle will take about 1-3 minutes to complete
  • Thunder will automatically run and will take another 2-4 minutes

When completed, it should look like this:


Genotype Refinement Output

What's new in the output directory?
  • Answer
  • ls ${OUT}
    • beagle directory : Beagle output
    • thunder directory : Thunder output
    • umake.beagle.* : Contain the configuration & steps used in GotCloud beagle
    • umake.thunder.* : Contain the configuration & steps used in GotCloud thunder

Let's take a look at that interesting location we found in the alignment tutorial : chromosome 22, positions 36907000-36907100

Use tabix to extract that from the VCFs:

${GC}/bin/tabix ${OUT}/thunder/chr22/ALL/thunder/chr22.filtered.PASS.beagled.ALL.thunder.vcf.gz 22:36907000-36907100 |less -S

Remember, type 'q' to quit less.

Are there any variants in this region?
  • Answer:
    • Yes!
    • Positions:
      • 36907001; Ref: T, Alt: C - that's what we saw before
      • 36907098; Ref: T, Alt: C - that's what we saw before
What is HG00551's genotype at these positions?
  1. First check which sample number HG00551 is:
zcat ${OUT}/thunder/chr22/ALL/thunder/chr22.filtered.PASS.beagled.ALL.thunder.vcf.gz |grep "#CHROM"
  • That will help you figure out it's genotype.
  • Rerun the tabix command and scroll to the right to find HG00551's genotype:
${GC}/bin/tabix ${OUT}/thunder/chr22/ALL/thunder/chr22.filtered.PASS.beagled.ALL.thunder.vcf.gz 22:36907000-36907100 |less -S
  • Or you can do this to print HG00551 information out:
${GC}/bin/tabix ${OUT}/thunder/chr22/ALL/thunder/chr22.filtered.PASS.beagled.ALL.thunder.vcf.gz 22:36907000-36907100 | cut -f1-10
  • Answer:
    • It is the first sample
    • 0|1: Heterozygous (although low GQ - quality)
    • 1|1; Homozygous Alt (C)

    Note the '|' instead of '/'. The '|' indicates it is now phased.

Remember, type 'q' to quit less.


Did I find interesting variants?

The region we selected contains APOL1 gene, which is known to play an important role in kidney diseases such as nephrotic syndrome. One of the non-synonymous risk allele, rs73885139 located at position 22:36661906 increases the risk of nephrotic syndrome by >2-folds. Let's see if we found the interesting variant by looking at the VCF file by position.

${GC}/bin/tabix ${OUT}/vcfs/chr22/chr22.filtered.vcf.gz 22:36661906 | head -1 

Did you see a variant at the position?

22	36661906	.	A	G	23	PASS	DP=409;MQ=59;NS=62;AN=124;AC=2;AF=0.013847;
MQ10=0.000;MQ20=0.000;MQ30=0.000;SVM=1.45191	GT:DP:GQ:PL	0/0:4:28:0,12,65	

Let's check the sequence data to confirm that the variant really exists

${GC}/bin/samtools tview ${SS}/bams/HG01242.recal.bam ${SS}/ref22/human.g1k.v37.chr22.fa
  • Type 'g' to go to a specific position
  • Type 22:36661906 to move to the position
  • Press arrows to move between positions
  • Press 'b' if you want to color by base quality
  • Press '?' for more help

View Screenshot



Let's get some information on the BEAGLE VCF:

perl ${GC}/scripts/ --vcf1 ${SS}/ref22/1kg.omni.chr22.36Mb.vcf.gz --vcf2 ${OUT}/beagle/chr22/chr22.filtered.PASS.beagled.ALL.vcf.gz --out ${OUT}/diffs/bedDiff.beagle

Look at the results:

more ${OUT}/diffs/bedDiff.beagle.summary
  • Results
OVERALL:	43588	44293	0.9841
NREF-EITHER:	19644	20349	0.9654
NMAJ-EITHER:	14560	15265	0.9538
HOMREF:	23944	91	0	0.9962
HET:	355	11936	172	0.9577
HOMALT:	6	81	7708	0.9888
HOMMAJ:	29028	112	4	0.9960
HET:	380	11936	147	0.9577
HOMMIN:	2	60	2624	0.9769

Now, let's see if it improved after running Thunder VCF:

perl ${GC}/scripts/ --vcf1 ${SS}/ref22/1kg.omni.chr22.36Mb.vcf.gz --vcf2 ${OUT}/thunder/chr22/ALL/thunder/chr22.filtered.PASS.beagled.ALL.thunder.vcf.gz --out ${OUT}/diffs/bedDiff.thunder

Look at the results:

more ${OUT}/diffs/bedDiff.thunder.summary
  • Results
OVERALL:	43711	44293	0.9869
NREF-EITHER:	19777	20359	0.9714
NMAJ-EITHER:	14715	15297	0.9620
HOMREF:	23934	101	0	0.9958
HET:	272	12084	107	0.9696
HOMALT:	5	97	7693	0.9869
HOMMAJ:	28996	145	3	0.9949
HET:	272	12084	107	0.9696
HOMMIN:	2	53	2631	0.9795

There is an improvement.

What is GotCloud snpcall doing?

To run GotCloud, you really just needed a single command.

Well, that one command runs many steps. Here is a diagram of all the steps.


Aren't you glad you didn't have to configure & run each one yourself?

Return to Workshop Wiki Page

Return to main workshop wiki page: SeqShop: May 2015