# Shazam: Tuning clonal assignment thresholds with Tuning clonal assignment thresholds with ... (shazam)…

• Published on
16-Jul-2018

• View
212

0

Embed Size (px)

Transcript

• Shazam: Tuning clonal assignment thresholds withnearest neighbor distances

Namita Gupta, Susanna Marquez and Nima Nouri

2018-03-30

ContentsExample data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Calculating nearest neighbor distances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Using nearest neighbor distances to determine clonal assignment thresholds . . . . . . . . 2Calculating nearest neighbor distances independently for subsets of data . . . . . . . . . . 6Calculating nearest neighbor distances across groups rather than within a groups . . . . . 7

Estimating the optimal distance threshold for partitioning clonally related sequences is accomplishedby calculating the distance from each sequence in the data set to its nearest neighbor and findingthe break point in the resulting bi-modal distribution that separates clonally related from unrelatedsequences. This is done via the following steps:

1. Calculating of the nearest neighbor distances for each sequence.2. Generating a histogram of the nearest neighbor distances followed by either manual inspect

for the threshold separating the two modes or automated threshold detection.

Example data

A small example Change-O database is included in the alakazam package. Calculating the nearestneighbor distances requires the following fields (columns) to be present in the Change-O database:

SEQUENCE_ID V_CALL J_CALL JUNCTION JUNCTION_LENGTH

# Subset example data to one samplelibrary(shazam)data(ExampleDb, package="alakazam")db

• sequences. Furthermore, for more leniency toward ambiguous V(D)J segment calls, the parameterfirst can be set to FALSE. Setting first=FALSE will use the union of all possible genes to groupsequences, rather than the first gene in the field. The model parameter determines which underlyingSHM model is used to calculate the distance. The default model is single nucleotide Hammingdistance with gaps considered as a match to any nucleotide (ham). Other options include a humanIg-specific single nucleotide model similar to a transition/transversion model (hh_s1f) and thecorresponding 5-mer context model from Yaari et al, 2013 (hh_s5f), an analogous pair of mousespecific models from Cui et al, 2016 (mk_rs1nf and mk_rs5nf), and amino acid Hamming distance(aa).

Note: Human and mouse distance measures that are backward compatible with SHazaM v0.1.4and Change-O v0.3.3 are also provide as hs1f_compat and m1n_compat, respectively.

For models that are not symmetric (e.g., distance from A to B is not equal to the distance from B toA), there is a symmetry parameter that allows the user to specify whether the average or minimumof the two distances is used to determine the overall distance.

# Use nucleotide Hamming distance and normalize by junction lengthdist_ham

• xlab("Hamming distance") +ylab("Count") +scale_x_continuous(breaks=seq(0, 1, 0.1)) +geom_histogram(color="white", binwidth=0.02) +geom_vline(xintercept=0.12, color="firebrick", linetype=2)

plot(p1)

0

20

40

60

80

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7

Hamming distance

Cou

nt

By manual inspection, the length normalized ham model distance threshold would be set to a valuenear 0.12 in the above example.

# Generate HH_S5F distance histogramp2

• 0

10

20

30

40

0 5 10 15 20 25 30 35 40 45 50

HH_S5F distance

Cou

nt

In this example, the unnormalized hh_s5f model distance threshold would be set to a value near 7.

Automated threshold detection via a mixture model

The findThreshold function includes approaches for automatically determining a clonal assign-ment threshold. The "gmm" method (gamma/Gaussian mixture method) of findThreshold(method="gmm") performs a maximum-likelihood fitting procedure over the distance-to-nearest dis-tribution using one of four combinations of univariate density distribution functions: "norm-norm"(two Gaussian distributions), "norm-gamma" (lower Guassian and upper gamma distribution),"gamma-norm" (lower gamm and upper Guassian distribution), and "gamma-gamma" (two gammadistributions). By default, the threshold will be selected by calculating the distance at which the av-erage of sensitivity and specificity reaches its maximum (cutoff="optimal"). Alternative thresholdselection criteria are also providing, including the curve intersection (cutoff="intersect"), userdefined sensitivity (cutoff="user", sen=x), or user defined specificity (cutoff="user", spc=x)

In the example below the mixture model method (method="gmm") is used to find the optimal thresholdfor separating clonally related sequences by fitting two gamma distributions (model="gamma-gamma").The red dashed-line shown in figure below defines the distance where the average of the sensitivityand specificity reaches its maximum.

# Find threshold using gmm methodoutput

• 0

1

2

3

4

0.0 0.2 0.4 0.6Distance

Den

sity

GMM Method: gammagamma

# Print thresholdprint(output)

##  0.1578929

Note: The shape of histogram plotted by plotGmmThreshold is governed by the binwidth parame-ter. Meaning, any change in bin size will change the form of the distribution, while the gmm methodis completely bin size independent and only engages the real input data.

Automated threshold detection via smoothed density

The density method will look for the minimum in the valley between two modes of a smootheddistribution based on the input vector (distances), which will generally be the DIST_NEARESTcolumn from the distToNearest output. Determining the optimal bandwidth parameter forsmoothing the distribution can be computationally intensive. The bandwidth tuning is typicallyrobust when subsampling down to 15,000 distances, though the ideal subsampling count will dependupon the data set. The input vector can be subsampled to the size specified using the subsampleparameter. Below is an example of using the density method for threshold detection.

# Find threshold using density methodoutput

• 0

1

2

3

4

0.0 0.3 0.6Distance

Den

sity

Density Method

# Print thresholdprint(output)

##  0.1226913

Calculating nearest neighbor distances independently for subsets of data

The fields argument to distToNearest will split the input data.frame into groups based onvalues in the specified fields (columns) and will treat them independently. For example, if theinput data has multiple samples, then fields="SAMPLE" would allow each sample to be analyzedseparately.

In the previous examples we used a subset of the original example data. In the following example, wewill use the two available samples, -1h and +7d, and will set fields="SAMPLE". This will reproduceprevious results for sample -1h and add results for sample +7d.

dist_fields

• geom_vline(xintercept=0.12, color="firebrick", linetype=2) +facet_grid(SAMPLE ~ ., scales="free_y")

plot(p4)

+7d

1h

0.0 0.2 0.4 0.6

0

100

200

300

400

0

20

40

60

80

Grouped Hamming distance

Cou

nt

In this case, the threshold selected for -1h seems to work well for +7d as well.

Calculating nearest neighbor distances across groups rather than within a groups

Specifying the cross argument to distToNearest forces distance calculations to be performedacross groups, such that the nearest neighbor of each sequence will always be a sequence in adifferent group. In the following example we set cross="SAMPLE", which will group the data into-1h and +7d sample subsets. Thus, nearest neighbor distances for sequences in sample -1h will berestricted to the closest sequence in sample +7d and vice versa.

dist_cross

• +7d

1h

0.0 0.2 0.4 0.6

0

100

200

300

0

10

20

30

Crosssample Hamming distance

Cou

nt

This can provide a sense of overlap between samples or a way to compare within-sample variationto cross-sample variation.

8

Example dataCalculating nearest neighbor distancesUsing nearest neighbor distances to determine clonal assignment thresholdsCalculating nearest neighbor distances independently for subsets of dataCalculating nearest neighbor distances across groups rather than within a groups
{"ft_lang_label":"__label__en","ft_lang_prob":0.80183494,"math_prob":0.98113674,"size":7998,"snap":"2019-35-2019-39","text_gpt3_token_len":1954,"char_repetition_ratio":0.17112835,"word_repetition_ratio":0.122380555,"special_character_ratio":0.23593399,"punctuation_ratio":0.1562719,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9847631,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-18T11:29:16Z\",\"WARC-Record-ID\":\"<urn:uuid:990e5642-accc-40fb-bce7-592913411f5d>\",\"Content-Length\":\"102422\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4c9382a3-b574-438f-99bd-c137e5b363a8>\",\"WARC-Concurrent-To\":\"<urn:uuid:1a997701-1264-4421-951d-bd421a917c6f>\",\"WARC-IP-Address\":\"78.46.67.66\",\"WARC-Target-URI\":\"https://pdfslide.net/documents/shazam-tuning-clonal-assignment-thresholds-with-tuning-clonal-assignment-thresholds.html\",\"WARC-Payload-Digest\":\"sha1:MNZLPBHQMLAAYUVTM5UXC4MORZSOPIX3\",\"WARC-Block-Digest\":\"sha1:GCRR2OAJRN3CPR3UDI3FMZ4DN6PPB75Z\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514573284.48_warc_CC-MAIN-20190918110932-20190918132932-00328.warc.gz\"}"}