PIgLET: Program for Ig clusters¶
Introduction¶
In adaptive immune receptor repertoire analysis, determining the germline variable (V) allele associated with each T- and B-cell receptor sequence is a crucial step. This process is highly impacted by allele annotations. Aligning sequences, assigning them to specific germline alleles, and inferring individual genotypes are challenging when the repertoire is highly mutated, or sequence reads do not cover the whole V region.
PIgLET was created to provide a solution for this challenge. The package includes two main tools. The first, creates an alternative naming scheme for the V alleles, based on the proposed approach in Peres at. el [@peres2022ighv]. The second, is an allele based genotype, that determined the presence of an allele based on a threshold derived from a naive population.
The naming scheme is compatible with current annotation tools and pipelines. Analysis results can be converted from the proposed naming scheme to the nomenclature determined by the International Union of Immunological Societies (IUIS). The package genotype inference method is accompanied by an online interactive website, to allow researchers to further explore the approach on real data IGHV reference book.
Package Overview¶
PIgLET is a suite of computational tools that improves genotype inference and downstream AIRR-seq data analysis. The package as two main tools. The first is Allele Clusters, this tool is designed to reduce the ambiguity within the IGHV alleles. The ambiguity is caused by duplicated or similar alleles which are shared among different genes. The second tool is an allele based genotype, that determined the presence of an allele based on a threshold derived from a naive population.
Allele Similarity Cluster:¶
This section provides the functions that support the main tool of creating the allele similarity cluster form an IGHV germline set.
inferAlleleClusters
: The main function of the section to create the allele clusters based on a germline set.ighvDistance
: Calculate the distance between IGHV aligned germline sequences.ighvClust
: Hierarchical clustering of the distance matrix fromighvDistance
.generateReferenceSet
: Generate the allele clusters reference set.plotAlleleCluster
: Plots the Hierarchical clustering.artificialFRW1Germline
: Artificially create an IGHV reference set with framework1 (FWR1) primers.
Allele based genotype:¶
This section provides the functions to infer the IGHV genotype using the allele based method and the allele clusters thresholds
inferGenotypeAllele
: Infer the IGHV genotype using the allele based method.assignAlleleClusters
: Renames the v allele calls based on the new allele clusters.germlineASC
: Converts IGHV germline set to ASC germline set.recentAlleleClusters
: Download the most recent version of the allele clusters table archive from Zenodo.extractASCTable
: Extracts the allele cluster table from the Zenodo archive file.zenodoArchive
: An R6 object to query the Zenodo api.
Allele Similarity Cluster¶
Introduction¶
The term Allele similarity clusters (ASC), defines alleles that have a degree of germline proximity. The proximity is defined as the Levenshtein distance between the coding region of the alleles’ germline sequences. A distance matrix of all alleles’ Levenshtein distance is constructed and the hierarchical tree is calculated. The tree leaves are then clustered by 95% similarity which creates the alleles clusters.
Library amplicon length {#sec-amplicon-Length}¶
Even though, we wish that all repertoires data available will cover the entire V region this is not always the case. Hence, we adapted our protocols to fit partial V coverage libraries. For the beginning we chose two library amplicon length, BIOMED-2 primers and Adaptive region coverage. The table below summaries the naming for each of the amplicon lengths and see Fig. \@ref(fig:plot-amplicon) for coverage illustration:
Library amplicon length | Coverage | Similar known protocol |
---|---|---|
S1 | Full length - 1 to 318 (IMGT numbering) | 5’ Race |
S2 | Starting within the framework 1 region | BIOMED-2 |
S3 | End of the V region | Adaptive |
Inferring Allele Similarity Clusters {#sec-asc}¶
The main function in this section inferAlleleClusters
returns an S4
object that includes the ASC allele cluster table alleleClusterTable
with the new names and the default thresholds, the renamed germline set
alleleClusterSet
, and the germline set hierarchical clustering
hclustAlleleCluster
, and the similarity threshold parameters
threshold
. Further by using the plot function on the returned object,
a colorful visualization of the allele clusters dendrogram and threshold
is received.
The function receives as an input a germline reference set of allele sequences, the filtration parameters for the 3’ and 5’ regions, and two similarity thresholds for the ASC clusters and families.
To create the clusters we will first load data from the package:
- The IGHV germline reference - this reference set was download from IMGT in July 2022.
library(piglet)
data(HVGERM)
- The allele functionality table - the table contains functionality information for each of the alleles. Download from IMGT in July 2022
data(hv_functionality)
Before clustering the germline set, we will remove non functional alleles, alleles that do not start on the first 5’ nucleotide, and those that are shorter than 318 bases.
germline <- HVGERM
## keep only functional alleles
germline <- germline[hv_functionality$allele[hv_functionality$functional=="F"]]
## keep only alleles that start from the first position of the V sequence
germline <- germline[!grepl("^[.]", germline)]
## keep only alleles that are at minimum 318 nucleotide long
germline <- germline[nchar(germline) >= 318]
## keep only localized alleles (remove NL)
germline <- germline[!grepl("NL", names(germline))]
germline <- HVGERM
## keep only functional alleles
germline <- germline[hv_functionality$allele[hv_functionality$functional=="F"]]
## keep only alleles that start from the first position of the V sequence
germline <- germline[!grepl("^[.]", germline)]
## keep only alleles that are at minimum 318 nucleotide long
germline <- germline[nchar(germline) >= 318]
## keep only localized alleles (remove NL)
germline <- germline[!grepl("NL", names(germline))]
Then we will create the ASC clusters using the inferAlleleClusters
function. For better clustering results with the human IGHV reference
set, it is recommended to set the trim_3prime_side
parameter to 318.
Here, we will use the default similarity thresholds 75% for the family
and 95% for the clusters.
asc <- inferAlleleClusters(
germline_set = germline,
trim_3prime_side = 318,
mask_5prime_side = 0,
family_threshold = 75,
allele_cluster_threshold = 95)
The output of inferAlleleClusters
is an S4
object of type
GermlineCluster
that contains several slots:
Slot | Description |
---|---|
germlineSet | The input germline set with the 3’ and 5’ modifications (If defined) |
alleleClusterSet | The input germline set with the ASC name scheme, if exists without duplicated sequences |
alleleClusterTable | The allele similarity cluster with the new names and the default thresholds |
threshold | The input family and allele cluster similarity thresholds |
hclustAlleleCluster | Germline set hierarchical clustering, an hclust object |
We can use the S4 plot method to plot the hierarchical clustering of the germline set as seen below in Fig. \@ref(fig:asc-plot).
plot(asc)
Artificial framework 1 reference set¶
As described in section \@ref(sec-amplicon-Length), not all repertoires data available covers the entire V region. Hence, a modified reference set for the sequenced region can help us further understand the results we can obtain from certain library protocols.
Hence, we created the function artificialFRW1Germline
, to mimic the
seen coding region of targeted framework 1 (FRW1) primers for a given
reference set. The primers were obtained from BIOMED-2 protocol
[@van2003design].
Essentially the function matches the primer to each of the germline set sequences and either mask or trim the region. The returned object is a character vector with the named sequence in the desire length (Trimmed/Masked).
To demonstrate the use of the function, we can use the cleaned germline
set from above (block 1).
In this case we will mask the FRW1 region, this will return the sequences with the Ns instead of DNA
nucleotide. The function output a log of the process, this output can be
repressed using the quite=TRUE
flag.
germline_frw1 <- artificialFRW1Germline(germline, mask_primer = T)
#> 282/286 germline sequences have passed
#> Counts by primers:
#> VH1-FR1:53,VH2-FR1:25,VH3-FR1:122,VH4-FR1:69,VH5-FR1:10,VH6-FR1:3
We will look at one sequence, IGHV1-8*01
to see the masking (Fig. \@ref(fig:nuc-plot))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.
We can use the artificial germline set to infer the ASC clusters in the same fashion as in section \@ref(sec-asc).
Allele based genotype¶
Introduction¶
Genotyping an Individual’s repertoire is becoming a common practice in down stream analysis. There are several tools nowadays to achieve such inference, namely TIgGER [@TIgGER] and IgDiscover [@IgDIscover]. Though the methods are doing a fine job at inferring the genotype in high accuracy, they often neglect to detect lowly frequent alleles. The set of restriction the methods operates under enhance the specificity over the sensitivity.
Aside from low frequent alleles, another limitation that can hinder genotype inference is sequence multiple assignment. Each sequence in the repertoire is assigned its inferred V(D)J alleles for each of the segments. The assignments can be influenced by several factors, such as sequencing errors, somatic hyper mutations, amplicon length, and the initial reference set. This confounding factors can results in assigning more than a single allele per sequence segment. This multiple assignment has a downstream affect on the genotype inference. Each tool tries to deal with this effect in various ways.
In PIgLET the Allele based genotype section is dedicated to the ASC-based genotype inference.
ASC-based thresholds¶
Introduction {#sec-genotype}¶
Briefly, the ASC-based threshold were determined based on a population of a large naive IGH repertoire cohort. For each allele a specific threshold was determined based on the population usage, the haplotype information (if available) and based on the alleles presented in the individual. The thresholds were adjusted based on a genomic validation approach with a coupled dataset, of both repertoire and long read data. At base the default threshold for any allele is $0.0001$, this value is also what the function inferAlleleClusters
returns for each of the alleles in the germline set. For more information on the specific threshold please review the manuscript Peres at al. [@peres2022ighv] and the IGHV reference
book.
Retriving Zenodo archive¶
The ASC-based threshold, found in the manuscript and the IGHV reference book are archived in Zenodo and can be retrieved using PIgLET.
To retrieve the archive files we can use the recentAlleleClusters
function. The function can get a path value for locally saving the archive files with the path
flag, if non is supplied then the function save the files in a temporary directory. The flag get_file=TRUE
, will return the downloaded file full path.
zenodo_doi <- "10.5281/zenodo.7401189"
asc_archive <-
recentAlleleClusters(doi = zenodo_doi, get_file = TRUE)
#> Files will be downloaded to tmp directory: /tmp/Rtmpn83kLa
To extract the ASC threshold table we can use the extractASCTable
function
allele_cluster_table <- extractASCTable(archive_file = asc_archive)
The table is has identical ASC clusters to the table we created above (block 2).
#> # A tibble: 6 × 3
#> new_allele imgt_allele.piglet imgt_allele.zenodo
#> <chr> <chr> <chr>
#> 1 IGHVF1-G1*01 IGHV3-72*01 IGHV3-72*01
#> 2 IGHVF1-G2*01 IGHV3-73*01 IGHV3-73*01
#> 3 IGHVF1-G2*02 IGHV3-73*02 IGHV3-73*02
#> 4 IGHVF1-G3*01 IGHV3-49*02 IGHV3-49*02
#> 5 IGHVF1-G3*02 IGHV3-49*01 IGHV3-49*01
#> 6 IGHVF1-G3*03 IGHV3-49*05 IGHV3-49*05
We can now extract the threshold from the Zenodo archive table and fill the table created using the PIgLET. We recommend that in case an allele does not have a threshold in the archive to keep the default threshold of $0.0001$.
Inferring ASC-based genotype¶
Genotype inference has an increasing importance in downstream analysis, as described in \@ref(sec-genotype) an individual genotype inference can help reduce bias within the repertoire annotations. Based on the reference book, the ASC clusters, and the ASC-based threshold we developed in PIgLET a genotype inference function which is based on the ASC-based genotype.
The function inferGenotypeAllele
infer an subject genotype using the
absolute fraction and the allele based threshold. Essentially, for each
unique allele that is found in the repertoire, its absolute fraction is
calculated and compared to the population derived threshold. In case the
allele’s fraction is above the threshold then it is inferred into the
subject genotype.
Recommendations:
- For naive repertoires:
- Filter the repertoire for up to 3 mutation within the V region
- Setting the flag
find_unmutated=T
. Not needed if the above mutation filter is applied
- For non-naive repertoires:
- Cloning the repertoire and selecting a single clonal representative with the least amount of mutations
- Setting the flag
single_assignment=F
. In this case the function treats cases of multiple allele call assignment as belonging to all groups.
Below is a demonstration of inferring the genotype for an example dataset taken from TIgGER [@TIgGER] package.
The data is b cell repertoire data from individual (PGP1) in AIRR format. The records were annotated with by IMGT/HighV-QUEST.
# loading TIgGER AIRR-seq b cell data
data <- tigger::AIRRDb
For using the genotype inference function on non ASC name scheme
annotations, we first need to transform the v_call
column to the ASC
alleles. We will use the ASC-table downloaded from Zenodo archive and
the example data
First we will collapse allele duplication in the ASC-table
allele_cluster_table <-
allele_cluster_table %>% dplyr::group_by(new_allele, func_group, thresh) %>%
dplyr::summarise(imgt_allele = paste0(sort(unique(imgt_allele)), collapse = "/"),
.groups = "keep")
Now, we can transform the data
# storing original v_call values
data$v_call_or <- data$v_call
# assigning the ASC alleles
asc_data <- assignAlleleClusters(data, allele_cluster_table)
head(asc_data[, c("v_call", "v_call_or")])
#> # A tibble: 6 × 2
#> v_call v_call_or
#> <chr> <chr>
#> 1 IGHVF5-G29*03 IGHV1-2*02
#> 2 IGHVF5-G30*02 IGHV1-18*01
#> 3 IGHVF5-G26*10 IGHV1-69*06
#> 4 IGHVF5-G26*07 IGHV1-69*04
#> 5 IGHVF5-G27*02 IGHV1-8*01
#> 6 IGHVF5-G28*03,IGHVF5-G28*02 IGHV1-46*01,IGHV1-46*03
If we have not inferred the ASC clustered and generated the renamed
germline set, we can use the germlineASC
to obtain it. We need to
supply the function the ASC-table and an IGHV germline set.
# reforming the germline set
asc_germline <- germlineASC(allele_cluster_table, germline = HVGERM)
Once we have both the modified dataset and germline reference set, we can infer the genotype. The function returns the genotype table with the following columns
gene | alleles | imgt_alleles | counts | absolute_fraction | absolute_threshold | genotyped_alleles | genotype_imgt_alleles |
---|---|---|---|---|---|---|---|
allele cluster | the present alleles | the imgt nomenclature | the number of reads | the absolute fraction | the population driven allele | the alleles which | the imgt nomenclature |
# inferring the genotype
asc_genotype <- inferGenotypeAllele(
asc_data,
alleleClusterTable = allele_cluster_table,
germline_db = asc_germline,
find_unmutated = T
)
head(asc_genotype)
#> gene alleles imgt_alleles counts absolute_fraction absolute_threshold genotyped_alleles genotyped_imgt_alleles
#> 1: IGHVF5-G22 01 IGHV1-24*01 105 0.0221613 0.0001 01 IGHV1-24*01
#> 2: IGHVF5-G23 01 IGHV1-69-2*01 31 0.0065429 0.0001 01 IGHV1-69-2*01
#> 3: IGHVF5-G24 02,03 IGHV1-58*01,IGHV1-58*02 23,18 0.0048544,0.0037991 0.0001,0.0001 02,03 IGHV1-58*01,IGHV1-58*02
#> 4: IGHVF5-G26 15,07,10,01 IGHV1-69*01/IGHV1-69D*01,IGHV1-69*04,IGHV1-69*06,IGHV1-69*02 515,469,280,9 0.1086956,0.0989869,0.0590967,0.0018995 0.0010,0.0010,0.0010,0.0010 15,07,10,01 IGHV1-69*01/IGHV1-69D*01,IGHV1-69*04,IGHV1-69*06,IGHV1-69*02
#> 5: IGHVF5-G27 02 IGHV1-8*01 467 0.0985648 0.0001 02 IGHV1-8*01
#> 6: IGHVF5-G28 03 IGHV1-46*01 624 0.1317011 0.0010 03 IGHV1-46*01
For plotting the genotype with TIgGER plotGenotype
, we need to do a
small modification to our genotype table
# get the genotype alleles
alleles <- unlist(strsplit(asc_genotype$genotyped_imgt_alleles, ","))
# get the genes
genes <- gsub("[*][0-9]+", "", alleles)
# extract the alleles
alleles <- sapply(strsplit(alleles, "[*]"), "[[", 2)
# make sure to extract only alleles
alleles <- gsub("([0-9]+).*$", "\\1", alleles)
# create the genotype
genotype <- data.frame(alleles = alleles, gene = genes)
# plot the genotype
tigger::plotGenotype(genotype = genotype)
Contact¶
For help, questions, or suggestions, please contact: