```{r setup, include = FALSE} # Do not change this chunk, except use_snapshot. library(ggplot2) library(dplyr) options(HTTPUserAgent = "3MB001-course", timeout = 60) # error = TRUE: the report knits even if a chunk fails, and the error shows in # the HTML. Before you hand in, there must be no errors left. knitr::opts_chunk$set(error = TRUE, message = FALSE) # If UniProt is down, set this to TRUE to read the course's saved copy. use_snapshot <- FALSE snapshot_file <- "data/uniprot-features-2026-11-19.csv" snapshot_url <- paste0("https://henriksson-lab.github.io/course_cellbiology/", "bioinfo-sorting-signals/", snapshot_file) # Data record, filled in by the fetch chunk below. data_source <- "not fetched yet" data_date <- "not fetched yet" data_release <- "not reported" ``` All code is given except **two blanks**, marked `___`. Fill them in, knit, and answer tasks T6 and T7 on the course page. # Fetch 14 proteins from UniProt Fourteen human proteins with known destinations. One request asks UniProt for their signal peptide, transit peptide and transmembrane features, and their sequence. ```{r proteins} proteins <- data.frame( accession = c("P02768", "P01308", "Q8NBP7", "P11021", "P27824", "P07237", "P11279", "P04062", "P01130", "P02786", "P25705", "O75390", "P37198", "P04406"), destination = c("Secreted", "Secreted", "Secreted", "ER", "ER", "ER", "Lysosome", "Lysosome", "Cell surface", "Cell surface", "Mitochondrion", "Mitochondrion", "Nuclear pore", "Cytosol")) uniprot_url <- paste0( "https://rest.uniprot.org/uniprotkb/accessions?accessions=", paste(proteins$accession, collapse = ","), "&fields=accession,gene_primary,ft_signal,ft_transit,ft_transmem,sequence", "&format=tsv") ``` ```{r fetch} read_snapshot <- function() { file <- if (file.exists(snapshot_file)) snapshot_file else snapshot_url data_source <<- "Course snapshot of UniProtKB" data_date <<- "2026-11-19" data_release <<- "2026_04" read.csv(file, check.names = FALSE, colClasses = "character") } if (use_snapshot) { raw <- read_snapshot() } else { raw <- tryCatch({ x <- read.delim(uniprot_url, check.names = FALSE, quote = "", colClasses = "character") data_source <- "UniProtKB REST API" data_date <- as.character(Sys.Date()) headers <- curlGetHeaders(uniprot_url) release <- grep("^x-uniprot-release:", headers, ignore.case = TRUE, value = TRUE) if (length(release) > 0) data_release <- trimws(sub("^[^:]*:", "", release[1])) x }, error = function(e) { message("UniProt unavailable, using the course snapshot") read_snapshot() }) } ``` # Make the feature table Each feature column becomes TRUE (annotated) or FALSE (not annotated). The last four residues come from the end of the sequence with `substr()`. ```{r features} has_feature <- function(x) !is.na(x) & x != "" features <- raw |> transmute(accession = Entry, gene = `Gene Names (primary)`, signal_peptide = has_feature(`Signal peptide`), transit_peptide = has_feature(`Transit peptide`), transmembrane = has_feature(Transmembrane), last_four = substr(Sequence, nchar(Sequence) - 3, nchar(Sequence))) |> left_join(proteins, by = "accession") head(features, 3) ``` # Blank 1: which proteins end in KDEL? Replace `___` with the four letters of the ER retrieval signal, in quotes. ```{r kdel} features |> filter(last_four == ___) |> select(gene, destination, last_four) ``` # Blank 2: a feature map The table is reshaped to one row per protein and feature (given). Fill in the `aes()` mapping: features on the x axis, genes on the y axis, and the fill colour showing whether the feature is present. The column names are `feature`, `gene` and `present`. ```{r long} long <- bind_rows(lapply( c("signal_peptide", "transit_peptide", "transmembrane"), function(f) data.frame(gene = features$gene, destination = features$destination, feature = f, present = features[[f]]))) ``` ```{r feature-map, fig.width = 6, fig.height = 7} ggplot(long, aes(x = ___, y = ___, fill = ___)) + geom_tile(colour = "white") + facet_grid(destination ~ ., scales = "free_y", space = "free_y") + scale_fill_manual(values = c("FALSE" = "grey90", "TRUE" = "#207a72")) + theme_minimal() + theme(strip.text.y = element_text(angle = 0)) + labs(x = "Sequence feature", y = NULL, fill = "Present", caption = paste("Source:", data_source, "release", data_release)) ``` # Data - Source: `r data_source`, release `r data_release`, retrieved `r data_date`. - Request: `r uniprot_url` - Licence: UniProt data, CC BY 4.0. # Session information ```{r session-info} sessionInfo() ```