V(D)J recombination

V(D)J recombination stands as a fundamental mechanism within the adaptive immune system, crucial for formation of the immunoglobulins.

Table (Data format)

This is an example of a data format containing the necessary information for V(D)J recombination visualizations. The table includes mock data specifically generated for this purpose.

The “IGLJ” column contains the different IGLJ genes, while all the other columns correspond to the various IGLV genes.

Code
library(readxl)
library(reactable)

df <- read_excel("../inst/data/chordDiagram.xlsx") |>
      as.data.frame()


reactable(
  
  df, 
  theme = reactableTheme(
    backgroundColor  = "transparent"
  )
)

Chord diagram

Chord diagrams provide a circular visualization of relationships between multiple entities (nodes) through interconnected links.

Each entity is represented by a segment on the outer perimeter of the circular layout, with arcs drawn between them to show connections.

The size of each arc corresponds to the significance of the flow between the respective entities.

Chord diagrams can be constructed using the chordDiagram() function from the circlize package.

Chord diagram 1

This chord diagram illustrates the different recombinations between IGLJ genes and IGLV genes.

Code
library(readxl)
library(circlize)
library(data.table)


# change df
rownames(df) <- df$IGLJ
df$IGLJ = NULL
df = as.matrix(df)



# Define specific colors for names
grid.col1 = c(IGLJ3 = "#D53E4F",IGLJ2 = "#5E4FA2", IGLJ1 ="#66C2A5")

# Define specific colors for the IGJV sectors
iglj_colors <- c(IGLJ3 = "#D53E4F", IGLJ2 = "#5E4FA2", IGLJ1 ="#66C2A5")

# Extract sector names from the data frame that start with "IGJV"
iglj_sectors <- colnames(df)[startsWith(colnames(df), "IGLJ")]

# Exclude sectors that are already in grid.col1
iglj_sectors <- setdiff(iglj_sectors, names(grid.col1))



# Assign specific colors to the IGJV sectors
for (i in seq_along(iglj_sectors)) {
  grid.col1[iglj_sectors[i]] <- iglj_colors[i]
}


# Extract entity names from the data frame that start with "IGLV"
iglv_entities <- colnames(df)[startsWith(colnames(df), "IGLV")]

# Exclude entities that are already in grid.col1
iglv_entities <- setdiff(iglv_entities, names(grid.col1))



# Assign them the color "grey"
for (entity in iglv_entities) {
  grid.col1[entity] <- "grey10"
}


# chord diagram
# vertical symmetric
circos.clear()
circos.par(start.degree = -90)


# empty track
chordDiagram(df, grid.col = grid.col1, annotationTrack = c("grid", "names"),
             annotationTrackHeight = c(0.01, 0.001),
             preAllocateTracks = list(track.height = 0.1))


# customize labels
circos.track(track.index = 1, panel.fun = function(x, y) {
  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index, 
              facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5),
              cex = 0.7)
}, bg.border = NA)