Skip to content

Commit

Permalink
added pvacview mouse anchor position support
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhtnp committed Jun 11, 2024
1 parent 2a44403 commit b2aa013
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
82 changes: 63 additions & 19 deletions pvactools/tools/pvacview/anchor_and_helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ anchor_data[[9]] <- read.table(curl("https://raw.githubusercontent.com/griffithl
anchor_data[[10]] <- read.table(curl("https://raw.githubusercontent.com/griffithlab/pVACtools/ae938113ddbbe6c6eeecebf94459d449facd2c2f/tools/pvacview/data/Normalized_anchor_predictions_10_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)
anchor_data[[11]] <- read.table(curl("https://raw.githubusercontent.com/griffithlab/pVACtools/ae938113ddbbe6c6eeecebf94459d449facd2c2f/tools/pvacview/data/Normalized_anchor_predictions_11_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)

## Load Mouse Anchor data
mouse_anchor_data <- list()
mouse_anchor_data[[8]] <- read.table(curl("https://raw.githubusercontent.com/ldhtnp/pVACtools/add_mouse_anchors/pvactools/tools/pvacview/data/mouse_anchor_predictions_8_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)
mouse_anchor_data[[9]] <- read.table(curl("https://raw.githubusercontent.com/ldhtnp/pVACtools/add_mouse_anchors/pvactools/tools/pvacview/data/mouse_anchor_predictions_9_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)
mouse_anchor_data[[10]] <- read.table(curl("https://raw.githubusercontent.com/ldhtnp/pVACtools/add_mouse_anchors/pvactools/tools/pvacview/data/mouse_anchor_predictions_10_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)
mouse_anchor_data[[11]] <- read.table(curl("https://raw.githubusercontent.com/ldhtnp/pVACtools/add_mouse_anchors/pvactools/tools/pvacview/data/mouse_anchor_predictions_11_mer.tsv"), sep = "\t", header = TRUE, stringsAsFactors = FALSE)

#get binding affinity colors cutoffs given HLA

scale_binding_affinity <- function(allele_specific_binding_thresholds, use_allele_specific_binding_thresholds, binding_threshold, hla, current_ba) {
Expand Down Expand Up @@ -75,10 +82,23 @@ peptide_coloring <- function(hla_allele, peptide_row) {
return(c("#999999"))
}
position <- as.numeric(peptide_row["x_pos"])
anchor_score <- as.numeric(anchor_data[[peptide_length]][anchor_data[[peptide_length]]["HLA"] == hla_allele][2:(peptide_length + 1)])
value_bins <- cut(anchor_score, breaks = seq(0, 1, len = 100),
include.lowest = TRUE)
colors <- colorRampPalette(c("lightblue", "blue"))(99)[value_bins]
if (any(hla_allele == anchor_data[[peptide_length]]["HLA"])) {
anchor_score <- as.numeric(anchor_data[[peptide_length]][anchor_data[[peptide_length]]["HLA"] == hla_allele][2:(peptide_length + 1)])
value_bins <- cut(anchor_score, breaks = seq(0, 1, len = 100),
include.lowest = TRUE)
colors <- colorRampPalette(c("lightblue", "blue"))(99)[value_bins]
} else if (any(hla_allele == mouse_anchor_data[[peptide_length]]["Allele"])) {
mouse_position_data <- (mouse_anchor_data[[peptide_length]][mouse_anchor_data[[peptide_length]]["Allele"] == hla_allele][2:(peptide_length + 1)])
colors <- list()
for (i in 1:length(mouse_position_data)) {
if (mouse_position_data[i] == "True") {
colors <- append(colors, "blue")
} else {
colors <- append(colors, "lightblue")
}
}
}

return(colors[[position]])
}
#calculate per-length anchor score for HLA allele
Expand All @@ -87,28 +107,40 @@ anchor_weights_for_alleles <- function(hla_alleles) {
for (hla_allele in hla_alleles) {
if (any(hla_allele == anchor_data[[8]]["HLA"])) {
eight_mer_scores <- append(anchor_data[[8]][anchor_data[[8]]["HLA"] == hla_allele][1:(8 + 1)], "8mer", 1)
} else if (any(hla_allele == mouse_anchor_data[[8]]["Allele"])) {
eight_mer_scores <- append(mouse_anchor_data[[8]][mouse_anchor_data[[8]]["Allele"] == hla_allele][1:(8 + 1)], "8mer", 1)
}
else {
eight_mer_scores <- c(hla_allele, "8mer")
}

if (any(hla_allele == anchor_data[[9]]["HLA"])) {
nine_mer_scores <- append(anchor_data[[9]][anchor_data[[9]]["HLA"] == hla_allele][1:(9 + 1)], "9mer", 1)
} else if (any(hla_allele == mouse_anchor_data[[9]]["Allele"])) {
nine_mer_scores <- append(mouse_anchor_data[[9]][mouse_anchor_data[[9]]["Allele"] == hla_allele][1:(9 + 1)], "9mer", 1)
}
else {
nine_mer_scores <- c(hla_allele, "9mer")
}

if (any(hla_allele == anchor_data[[10]]["HLA"])) {
ten_mer_scores <- append(anchor_data[[10]][anchor_data[[10]]["HLA"] == hla_allele][1:(10 + 1)], "10mer", 1)
} else if (any(hla_allele == mouse_anchor_data[[10]]["Allele"])) {
ten_mer_scores <- append(mouse_anchor_data[[10]][mouse_anchor_data[[10]]["Allele"] == hla_allele][1:(10 + 1)], "10mer", 1)
}
else {
ten_mer_scores <- c(hla_allele, "10mer")
}

if (any(hla_allele == anchor_data[[11]]["HLA"])) {
eleven_mer_scores <- append(anchor_data[[11]][anchor_data[[11]]["HLA"] == hla_allele][1:(11 + 1)], "11mer", 1)
} else if (any(hla_allele == mouse_anchor_data[[11]]["Allele"])) {
eleven_mer_scores <- append(mouse_anchor_data[[11]][mouse_anchor_data[[11]]["Allele"] == hla_allele][1:(11 + 1)], "11mer", 1)
}
else {
eleven_mer_scores <- c(hla_allele, "11mer")
}

scores <- list(eight_mer_scores, nine_mer_scores, ten_mer_scores, eleven_mer_scores)
scores <- lapply(scores, `length<-`, 13)
scores <- transpose(data.frame(scores))
Expand All @@ -120,23 +152,35 @@ anchor_weights_for_alleles <- function(hla_alleles) {
#calculate anchor list for specific peptide length and HLA allele combo given contribution cutoff
calculate_anchor <- function(hla_allele, peptide_length, anchor_contribution) {
result <- tryCatch({
anchor_raw_data <- as.numeric(anchor_data[[peptide_length]][anchor_data[[peptide_length]]["HLA"] == hla_allele][2:(peptide_length + 1)])
if (any(is.na(anchor_raw_data))) {
return("NA")
}
names(anchor_raw_data) <- as.character(1:length(anchor_raw_data))
anchor_raw_data <- anchor_raw_data[order(unlist(anchor_raw_data), decreasing = TRUE)]
count <- 0
anchor_list <- list()
for (i in 1:length(anchor_raw_data)) {
if (count >= anchor_contribution) {
return(anchor_list)
}else {
count <- count + anchor_raw_data[[i]]
anchor_list <- append(anchor_list, names(anchor_raw_data[i]))
if (any(hla_allele == anchor_data[[peptide_length]]["HLA"])) {
anchor_raw_data <- as.numeric(anchor_data[[peptide_length]][anchor_data[[peptide_length]]["HLA"] == hla_allele][2:(peptide_length + 1)])
if (any(is.na(anchor_raw_data))) {
return("NA")
}
names(anchor_raw_data) <- as.character(1:length(anchor_raw_data))
anchor_raw_data <- anchor_raw_data[order(unlist(anchor_raw_data), decreasing = TRUE)]
count <- 0
anchor_list <- list()
for (i in 1:length(anchor_raw_data)) {
if (count >= anchor_contribution) {
return(anchor_list)
} else {
count <- count + anchor_raw_data[[i]]
anchor_list <- append(anchor_list, names(anchor_raw_data[i]))
}
}
} else if (any(hla_allele == mouse_anchor_data[[peptide_length]]["Allele"])) {
mouse_position_data <- (mouse_anchor_data[[peptide_length]][mouse_anchor_data[[peptide_length]]["Allele"] == hla_allele][2:(peptide_length + 1)])
anchor_list <- list()
for (i in 1:length(mouse_position_data)) {
if (mouse_position_data[i] == "True") {
anchor_list <- append(anchor_list, as.character(i))
}
}
return(anchor_list)
} else {
return("NA")
}
return(anchor_list)
}, error = function(e) { return("NA") })
}

Expand Down
2 changes: 1 addition & 1 deletion pvactools/tools/pvacview/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ server <- shinyServer(function(input, output, session) {
peptide_table <- do.call("rbind", lapply(peptide_names, table_formatting, peptide_data))
peptide_table_filtered <- Filter(function(x) length(unique(x)) != 1, peptide_table)
peptide_table_names <- names(peptide_table_filtered)
hla_list <- peptide_table_names[grepl("^HLA-*", peptide_table_names)]
hla_list <- df$metricsData$alleles
hla_data <- data.frame(hla = hla_list)
hla_sep <- max(nchar(peptide_table$`Peptide Sequence`))
hla_data$y_pos <- 1
Expand Down

0 comments on commit b2aa013

Please sign in to comment.