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

Anh N. Tran1*

1Northwestern University, Illinois, USA

*trannhatanh89@gmail.com

#### 2021-05-19

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

# 1 The case

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

# 2 The solution

## 2.1 Get the download links

    CCNB1xml <- hpaXmlGet("ENSG00000134057")

    CCNB1_ab <- hpaXmlAntibody(CCNB1xml)
    CCNB1_ab
    #> # A tibble: 4 x 4
    #>   id        releaseVersion releaseDate RRID
    #>   <chr>     <chr>          <chr>       <chr>
    #> 1 CAB000115 1.2            2006-03-13  <NA>
    #> 2 CAB003804 2.0            2006-10-30  AB_562272
    #> 3 HPA030741 12.0           2013-12-05  AB_2673586
    #> 4 HPA061448 16.0           2016-12-04  AB_2684522
    #> # A tibble: 4 x 4
    #>   id        releaseDate releaseVersion RRID
    #>   <chr>     <chr>       <chr>          <chr>
    #> 1 CAB000115 2006-03-13  1.2            <NA>
    #> 2 CAB003804 2006-10-30  2              AB_562272
    #> 3 HPA030741 2013-12-05  12             AB_2673586
    #> 4 HPA061448 2016-12-04  16             AB_2684522

    CCNB1_expr <- hpaXmlTissueExpr(CCNB1xml)
    str(CCNB1_expr[[1]])
    #> tibble [334 x 18] (S3: tbl_df/tbl/data.frame)
    #>  $ patientId         : chr [1:334] "1447" "1452" "1470" "1647" ...
    #>  $ age               : chr [1:334] "45" "44" "65" "63" ...
    #>  $ sex               : chr [1:334] "Female" "Female" "Male" "Male" ...
    #>  $ staining          : chr [1:334] NA NA NA NA ...
    #>  $ intensity         : chr [1:334] NA NA NA NA ...
    #>  $ quantity          : chr [1:334] NA NA NA NA ...
    #>  $ location          : chr [1:334] NA NA NA NA ...
    #>  $ imageUrl          : chr [1:334] "http://images.proteinatlas.org/115/2043_B_2_8.jpg" "http://images.proteinatlas.org/115/2043_B_1_8.jpg" "http://images.proteinatlas.org/115/2043_B_3_8.jpg" "http://images.proteinatlas.org/115/2043_B_1_7.jpg" ...
    #>  $ snomedCode1       : chr [1:334] "M-00100" "M-00100" "M-00100" "M-00100" ...
    #>  $ snomedCode2       : chr [1:334] "T-04000" "T-04000" "T-1X700" "T-64300" ...
    #>  $ snomedCode3       : chr [1:334] NA NA "T-28000" NA ...
    #>  $ snomedCode4       : chr [1:334] NA NA NA NA ...
    #>  $ snomedCode5       : chr [1:334] NA NA NA NA ...
    #>  $ tissueDescription1: chr [1:334] "Normal tissue, NOS" "Normal tissue, NOS" "Normal tissue, NOS" "Normal tissue, NOS" ...
    #>  $ tissueDescription2: chr [1:334] "Breast" "Breast" "Cartilage tissue" "Duodenum" ...
    #>  $ tissueDescription3: chr [1:334] NA NA "Lung" NA ...
    #>  $ tissueDescription4: chr [1:334] NA NA NA NA ...
    #>  $ tissueDescription5: chr [1:334] NA NA NA NA ...
    #>  - attr(*, "reshapeWide")=List of 5
    #>   ..$ v.names: NULL
    #>   ..$ timevar: chr "attr"
    #>   ..$ idvar  : chr "index"
    #>   ..$ times  : chr [1:16] "sex" "age" "patientId" "staining" ...
    #>   ..$ varying: chr [1, 1:16] "value.sex" "value.age" "value.patientId" "value.staining" ...
    #> Classes 'tbl_df', 'tbl' and 'data.frame':    331 obs. of  18 variables:
    #>  $ patientId         : chr  "1653" "1721" "1725" "598" ...
    #>  $ age               : chr  "53" "60" "57" "7" ...
    #>  $ sex               : chr  "Male" "Female" "Male" "Male" ...
    #>  $ staining          : chr  NA NA NA NA ...
    #>  $ intensity         : chr  NA NA NA NA ...
    #>  $ quantity          : chr  NA NA NA NA ...
    #>  $ location          : chr  NA NA NA NA ...
    #>  $ imageUrl          : chr  "http://v18.proteinatlas.org/images/115/2043_B_4_5.jpg" "http://v18.proteinatlas.org/images/115/2043_B_6_5.jpg" "http://v18.proteinatlas.org/images/115/2043_B_5_5.jpg" "http://v18.proteinatlas.org/images/115/2043_A_2_2.jpg" ...
    #>  $ snomedCode1       : chr  "M-00100" "M-00100" "M-00100" "M-00100" ...
    #>  $ snomedCode2       : chr  "T-93000" "T-93000" "T-93000" "T-66000" ...
    #>  $ snomedCode3       : chr  NA NA NA NA ...
    #>  $ snomedCode4       : chr  NA NA NA NA ...
    #>  $ snomedCode5       : chr  NA NA NA NA ...
    #>  $ tissueDescription1: chr  "Normal tissue, NOS" "Normal tissue, NOS" "Normal tissue, NOS" "Normal tissue, NOS" ...
    #>  $ tissueDescription2: chr  "Adrenal gland" "Adrenal gland" "Adrenal gland" "Appendix" ...
    #>  $ tissueDescription3: chr  NA NA NA NA ...
    #>  $ tissueDescription4: chr  NA NA NA NA ...
    #>  $ tissueDescription5: chr  NA NA NA NA ...

## 2.2 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],
                                        ".jpg"),
                      mode = "wb")
    }

# 3 Copyright

Anh Tran, 2018-2021

Please cite: Tran, A.N., Dussaq, A.M., Kennell, T. et al. HPAanalyze: an R package that facilitates the retrieval and analysis of the Human Protein Atlas data. BMC Bioinformatics 20, 463 (2019) https://doi.org/10.1186/s12859-019-3059-z