---
title: "HiBED"
author: "Ze Zhang"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
    %\VignetteIndexEntry{HiBED}
    %\VignetteEngine{knitr::rmarkdown}
    %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(cache = FALSE, warning = FALSE, message = FALSE, 
                        cache.lazy = FALSE,collapse = TRUE, comment = "#>"
)
library(HiBED)
```

The HiBED package contains reference libraries derived from 
Illumina HumanMethylation450K and Illumina HumanMethylationEPIC DNA methylation 
microarrays (Zhang Z, Salas LA et al. 2023), consisting of 6 astrocyte,
12 endothelial, 5 GABAergic neuron, 5 glutamatergic neuron, 18 microglial, 
20 oligodendrocyte, and 5 stromal samples from public resources.

The reference libraries were used to estimate proportions of 7 major brain cell
types in 450K and EPIC bulk brain samples using a modified version of 
the algorithm constrained projection/quadratic programming described 
in Houseman et al. 2012. 


**Loading package:**  
```{r eval=TRUE}
library(HiBED)
```

**Objects included:**  
1. *HiBED_Libraries* contains 4 libraries for deconvolution  
```{r eval=TRUE}
data("HiBED_Libraries")
```

2. *HiBED_deconvolution function for brain cell deconvolution:*
 
 We offer the function HiBED_deconvolution to estimate proportions for 7 major
 brain cell types, including GABAergic neurons, glutamatergic neurons, 
 astrocytes, microglial cells, oligodendrocytes, endothelial cells, and stromal 
 cells. The estimates are calculated using modified CP/QP 
 method described in Houseman et al. 2012.    
 *see ?HiBED_deconvolution for details*  
```{r eval=TRUE}

# Step 1 load and process example
library(FlowSorted.Blood.EPIC)
library(FlowSorted.DLPFC.450k)
library(minfi)
Mset<-preprocessRaw(FlowSorted.DLPFC.450k)
             
Examples_Betas<-getBeta(Mset)


# Step 2: use the HiBED_deconvolution function in combinatation with the
# reference libraries for brain cell deconvolution.


 HiBED_result<-HiBED_deconvolution(Examples_Betas, h=2)
                                
 head(HiBED_result)


```

```{r}
sessionInfo()
```


**References**

Z Zhang, LA Salas et al. (2023) SHierarchical deconvolution for extensive cell 
type resolution in the human brain using DNA methylation. 
Under Review

J. Guintivano, et al. (2013). A cell epigenotype specific 
model for the correction of brain cellular heterogeneity bias and its 
application to age, brain region and major depression. Epigenetics, 
8(3):290–302, 2013. doi: [10.4161/epi.23924] 
(https://dx.doi.org/10.4161/epi.23924).

Weightman Potter PG, et al. (2021) Attenuated Induction of the Unfolded Protein 
Response in Adult Human Primary Astrocytes in Response to Recurrent Low Glucose. 
Front Endocrinol (Lausanne) 2021;12:671724. doi: 
[10.3389/fendo.2021.671724]
(https://dx.doi.org/10.3389/fendo.2021.671724).

Kozlenkov, et al. (2018) A unique role for DNA (hydroxy)methylation in 
epigenetic regulation of human inhibitory neurons. Sci. Adv. 2018;4:eaau6190. 
doi: [10.1126/sciadv.aau6190]
(https://dx.doi.org/10.1126/sciadv.aau6190). 

de Whitte, et al. (2022) Contribution of Age, Brain Region, Mood Disorder 
Pathology, and Interindividual Factors on the Methylome of Human Microglia. 
Biological Psychiatry March 15, 2022; 91:572–581. 
doi: [10.1016/j.biopsych.2021.10.020]
(https://doi.org/10.1016/j.biopsych.2021.10.020). 

X Lin, et al. (2018) Cell type-specific DNA methylation in neonatal cord tissue
and cord blood: A 850K-reference panel and comparison of cell-types. 
Epigenetics. 13:941–58. doi: 
[10.1080/15592294.2018.1522929]
(https://dx.doi.org/10.1080/15592294.2018.1522929).

LA Salas et al. (2022). Enhanced cell deconvolution of peripheral blood using 
DNA methylation for high-resolution immune profiling. 
Nature Communications 13(1):761. 
doi:[10.1038/s41467-021-27864-7](https://dx.doi.org/10.1038/s41467-021-27864-7).  

EA Houseman et al. (2012) DNA methylation arrays as surrogate
measures of cell mixture distribution. BMC Bioinformatics 13, 86.
doi: [10.1186/1471-2105-13-86](https://dx.doi.org/10.1186/1471-2105-13-86).  

[minfi](http://bioconductor.org/packages/release/bioc/html/minfi.html)
Tools to analyze & visualize Illumina Infinium methylation arrays.