Individuals

Step 4: Filtering haplotypes and calculating haplotype frequencies

procedure

After processing all BAM files in the given directory and storing all observed haplotypes in a table for each sample, SMAP haplotype-sites loops over all tables to create an integrated genotyping matrix that contains all observed haplotypes across all BAM files and collects their absolute read counts. The next step is to switch from absolute read count per haplotype to relative read depth per haplotype per locus, i.e. to calculate haplotype frequencies. The haplotype frequency is calculated per haplotype per locus per sample (haplotype count per sample/total read count per locus per sample; range 0-100%).

../../../_images/SMAP_haplotype_step4_Shotgun.png

filters

read errors create false positive haplotypes

Randomly distributed read errors that happen to co-localize with the SMAP/SNP positions erroneously create low frequency haplotypes. Example data are shown in the scheme above, see tables below for the occurence in real GBS data of 8 diploid individuals.

false positive haplotypes are removed from the data set with a minimum frequency threshold (option -f)

Haplotypes that never reach a user-defined minimum haplotype frequency threshold (default 0%) in at least one of the samples, are removed entirely from the haplotype count table. After this filter, the haplotype frequency is recalculated on the remaining read counts per haplotype per locus per sample. The effect of adjusting this filter is illustrated in real data in the tables below. Please compare the tables below at subsequent steps of filtering: -f 0 filtering is effectively no filter (all haplotype observations > 0% are kept). Most noise from low frequency haplotypes can effectively be removed with -f 1 or -f 5 . We recommend to test the effect of this parameter on your own data, and to inspect the haplotype frequency histograms generated (see Graphical output).

low frequency haplotypes may also be masked (per locus/sample) using the frequency_mask (option -m)

Haplotypes that reach the user defined -f value in at least one BAM file are retained. However, observations of the same haplotype in other BAM files but with a haplotype frequency lower than the -f value are also retained, potentially allowing noise. These values may additionaly be masked with option -m. The option -m masks all haplotype frequencies lower than set value by substituting them with NaN’s or another value defined by --undefined_representation. The other haplotype frequencies are not recalculated.

The following tabs show real experimental data of two loci. All detected haplotypes are reported using the default -f 0, demonstrating how haplotype frequency filtering removes noise.

Haplotype frequency distributions

The different tabs below show the typical haplotype frequency distributions of diploid or tetraploid individuals for GBS or HiPlex data. Vertical lines in the haplotype frequency distributions show the thresholds by which haplotype frequency is transformed into discrete call classes. The commands to run SMAP haplotype-sites on these datatypes are shown below each graph.

../../../_images/2n_ind_GBS_SE_Dom_001.haplotype.frequency.histogram.png
smap haplotype-sites /path/to/BAM/ /path/to/BED/ /path/to/VCF/ -mapping_orientation stranded -partial include --no_indels --min_read_count 10 -f 5 -p 8 --min_distinct_haplotypes 2 --plot_type png --plot all -o 2n_ind_GBS_SE_NI_DOMdiplo --discrete_calls dominant --frequency_interval_bounds 10

Step 5: Transforming haplotype frequencies to discrete calls in individuals

procedure

If individual genotypes are analysed in, the final step is to transform observed haplotype frequencies per individual back to discrete haplotype calls using --discrete_calls. SMAP haplotype-sites uses simple, user-defined haplotype frequency thresholds to define discrete genotypic classes. The multi-allelic nature of haplotype calling is retained, and the final genotype call table lists the absence/presence (0/1) or dosage (0/1/2 diploids; 0/1/2/3/4 tetraploids) of each haplotype per individual.

Next, the total count of discrete haplotypes per locus per sample is calculated and output as a table. See examples below.

Alternatively, haplotype read depth data generated with SMAP haplotype-sites may be used as input for genotype calling in individuals using statistical methods, for instance Clark et al. 2019.

../../../_images/SMAP_haplotype_step6.png

Haplotype count tables

If SMAP haplotype-sites is run using --discrete_calls the analysis continues by creating discrete haplotype calls per individual sample. For each sample and for each locus, haplotype frequencies are transformed to discrete calls using simple user-defined frequency thresholds based on the observed haplotype frequency spectrum.

Next, the total count of discrete haplotypes per locus per sample is calculated and output as table. See examples below.

Per diploid sample, loci with a total haplotype count different from a set value (--dosage_filter) are removed (set to `NaN´ ). The recommended value for this filter is 2 for diploids and 4 for tetraploids. The haplotype frequency is then calculated across the set of samples (count per haplotype/total haplotype count per locus * 100%). This measure identifies the haplotypes that are supported by sufficient read depth in individual genotypes, but rare across the sample set (e.g. population).

Haplotype call tables

Haplotype allele frequencies are calculated as the number of observations of a haplotype divided by the total number of haplotype observations (ploidy (or --dosage_filter value) x number of samples with observations) on that locus. In -f 0 filtering, all haplotypes are retained. It is recommended to try out different values and decide which value suits your data best.

Step 6: Filtering for high quality dosage calls in individuals

procedure

If individual genotypes are analysed in mode for dosage calls, the final step is to check if the total number of alleles equals that expected for the ploidy of the individual (2 in diploids, and 4 in tetraploids). All locus/sample combinations that do not show the expected number of haplotypes are removed from the genotyping table. In addition, two scores are calculated per sample: the completeness of observations across all tested loci, and the proportion of loci with correct genotype call, across all observed loci for that sample. two scores are calculated per locus: the completeness of observations across all tested sample, and the proportion of samples with correct genotype call, across all observed samples for that locus. A list is created with loci that display a minimum correctness across all observations, and only good quality loci are reported in the final genotype table. SMAP haplotype-sites uses simple, user-defined correctness filters to select high quality genotyping data, and the final genotype call table lists the dosage (0/1/2 diploids; 0/1/2/3/4 tetraploids) of each haplotype per individual.

Output

Tabular output

By default, SMAP haplotype-sites will return two .tsv files.

haplotype counts

Read_counts_cx_fx_mx.tsv (with x the value per option used in the analysis) contains the read counts (-c) and haplotype frequency (-f) filtered and/or masked (-m) read counts per haplotype per locus as defined in the BED file from SMAP delineate. This is the file structure:

Locus

Haplotypes

Sample1

Sample2

Sample..

Chr1:100-200

00010

0

13

34

Chr1:100-200

01000

19

90

28

Chr1:100-200

00110

60

0

23

Chr1:450-600

0010

70

63

87

Chr1:450-600

0110

108

22

134

relative haplotype frequency

Haplotype_frequencies_cx_fx_mx.tsv contains the relative frequency per haplotype per locus in sample (based on the corresponding count table: Read_counts_cx_fx_mx.tsv). The transformation to relative frequency per locus-sample combination inherently normalizes for differences in total number of mapped reads across samples, and differences in amplification efficiency across loci. This is the file structure:

Locus

Haplotypes

Sample1

Sample2

Sample..

Chr1:100-200

00010

0

0.13

0.40

Chr1:100-200

01000

0.24

0.87

0.33

Chr1:100-200

00110

0.76

0

0.27

Chr1:450-600

0010

0.39

0.74

0.39

Chr1:450-600

0110

0.61

0.26

0.61

Graphical output

haplotype diversity

By default, SMAP haplotype-sites will generate graphical output summarizing haplotype diversity. haplotype_diversity_across_sampleset.png shows a histogram of the number of distinct haplotypes per locus across all samples.

haplotype frequency distribution per sample

Graphical output of the haplotype frequency distribution for each individual sample can be switched on using the option --plot all. sample_haplotype_frequency_distribution.png shows the haplotype frequency distribution across all loci detected per sample. It is the graphical representation of each sample-specific column in haplotypes_cx_fx_mx.tsv. Using the option --discrete_calls, this plot will also show the defined discrete calling boundaries.

quality of genotype calls per locus and per sample

After discrete genotype calling with option --discrete_calls, SMAP haplotype-sites will evaluate the observed sum of discrete dosage calls per locus per sample versus the expected value per locus (set with option -z, recommended use: 2 for diploid, 4 for tetraploid).

The quality of genotype calls per sample is calculated in two ways: the fraction of loci with calls in that sample versus the total number of loci across all samples (sample_call_completeness); the fraction of loci with expected sum of discrete dosage calls (-z) versus the total number of observed loci in that sample (sample_call_correctness). These scores are calculated separately per sample, and SMAP haplotype-sites plots the distribution of those scores across the sample set (sampleset_call_completeness; sampleset_call_correctness).

Similarly, the quality of genotype calls per locus is calculated in two ways: the fraction of samples with calls for that locus versus the total number of samples (locus_call_completeness); the fraction of samples with expected sum of discrete dosage calls (-z) versus the total number of observed samples for that locus (locus_call_correctness). These scores are calculated separately per locus, and SMAP haplotype-sites plots the distribution of those scores across the locus set (locusset_call_completeness; locusset_call_correctness).

Both graphs and the corresponding tables (one for samples and one for loci) can be evaluated to identify poorly performing samples and/or loci. We recommend to eliminate these from further analysis by removing BAM files from the run directory and/or loci from the SMAP delineate BED file with SMAPs, and iterate through rounds of data analysis combined with sample and locus quality control.


Summary of Commands

Mandatory options:

type of reads: -mapping_orientation stranded or -mapping_orientation ignore

locus coverage: -partial include (for GBS) or -partial exclude (for HiPlex and for Shotgun)
alignments_dir ############# (str) ### Path to the directory containing BAM and BAI files. All BAM files should be in the same directory. Positional mandatory argument, should be the first argument after smap haplotype-sites [no default].
bed ##################### (str) ### Path to the BED file containing sites for which haplotypes will be reconstructed. For GBS experiments, the BED file should be generated using SMAP delineate. For HiPlex data, a BED6 file can be provided, with the 4th and 5th column being blank and the chromosome name, locus start position site, locus end position site and strand information populating the first, second, third and sixth column respectively. Positional mandatory argument, should be the second argument after smap haplotype-sites.
vcf ##################### (str) ### Path to the VCF file (in VCFv4.1 format) containing variant positions. It should contain at least the first 9 columns listing the SNP positions, sample-specific genotype calls across the sampleset are not required. Positional mandatory argument, should be the third argument after smap haplotype-sites.
-p, --processes ########### (int) ### Number of parallel processes [1].
--plot ######################### Select which plots are to be generated. Choosing “nothing” disables plot generation. Passing “summary” only generates graphs with information for all samples while “all” will also enable generate per-sample plots [default “summary”].
-t, --plot_type ################## Use this option to choose plot format, choices are png and pdf [png].
-o, --out ############### (str) ### Basename of the output file without extension [SMAP_haplotype_sites].
-u, --undefined_representation ####### Value to use for non-existing or masked data [NaN].
-h, --help ##################### Show the full list of options. Disregards all other parameters.
-v, --version ################### Show the version. Disregards all other parameters.
--debug ######################## Enable verbose logging.

Options may be given in any order.