6. Tutorial: Download histology images from the Human Protein Atlas

library(BiocStyle)
library(HPAanalyze)
library(dplyr)

The case

What to do if you want to systematically download images from HPA?

The solution

Download the images

dir.create("img")
for (i in 1:nrow(CCNB1_expr[[1]])) {
    download.file(CCNB1_expr[[1]]$imageUrl[i],
                  destfile = paste0("img/", CCNB1_ab$id[1], "_",
                                    CCNB1_expr[[1]]$patientId[i], "_",
                                    CCNB1_expr[[1]]$tissueDescription2[i],
                                    ## the extra i below ensures unique file name
                                    i, ".jpg"),
                  mode = "wb")
}

Notes

While the HPA website displays two images for many of the samples, this method only provides one.

If you wish to filter the results by tissueDescription or snomedCode, it’s important to note that the value you are searching for may be present in any of the columns. To address this, you can use the filter_all(any_vars()) function from the dplyr package.