---
title: "DEPRECATED Coloc: relaxing the single causal variant assumption"
author: "Chris Wallace"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{DEPRECATED Coloc: relaxing the single causal variant assumption}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Multiple causal variants 

*This describes deprecated functions - the [SuSiE approach](a06_SuSiE.html) is more accurate and should be used instead*

We load some simulated data.

```{r   }
library(coloc)
data(coloc_test_data)
attach(coloc_test_data) # contains D3, D4 that we will use in this vignette
```

First, let us do a standard coloc (single causal variant) analysis to
serve as a baseline comparison.  The analysis concludes there is
colocalisation, because it "sees" the SNPs on the left which are
strongly associated with both traits.  But it misses the SNPs on the
right of the top left plot which are associated with only one trait.

```{r sens0, fig.width=8,fig.height=6    }
library(coloc)
my.res <- coloc.abf(dataset1=D3, dataset2=D4)
class(my.res)
## print.coloc_abf
my.res
sensitivity(my.res,"H4 > 0.9")
```

Even though the sensitivity analysis itself looks good, the Manhattan plots suggest we are violating the assumption of a single causal variant per trait.  
We can use =finemap.signals= to test whether there are additional signals after conditioning.

```{r}
finemap.signals(D3,method="cond")
finemap.signals(D4,method="cond")
```

Note that every colocalisation conditions out every other signal except one for each trait.  For that reason, trying to colocalise many signals per trait is not recommended. Instead, use pthr to set the significance (p value) required to call a signal.  If you set if too low, you will capture signals that are non-significant, or too high and you will miss true signals.  pthr=5e-8 would correspond to a genome-wide significance level for common variants in a European study, but we typically choose a slightly relaxed pthr=1e-6 on the basis that if there is one GW-significant signal in a region, we expect there is a greater chance for secondary signals to exist.


```{r}
finemap.signals(D3,method="cond",pthr=1e-20) ## too small
finemap.signals(D4,method="cond",pthr=0.1) ## too big
```

Now we can ask coloc to consider these as separate signals using the coloc.signals() function.

```{r   }
res <- coloc.signals(D3,D4,method="cond",p12=1e-6,pthr=1e-6)
res
```

Note that because we are doing multiple colocalisations, sensitivity() needs to know which to consider:
```{r sens, fig.width=8,fig.height=6 }
sensitivity(res,"H4 > 0.9",row=1)
sensitivity(res,"H4 > 0.9",row=2)
```


Because these signals are truly independent, we could also split them by using masking, which doesn't condition at all, but restricts the search space for colocalisation to SNPs which are not in LD with any-but-one of each signal SNP.  Here you also need to consider r2thr which sets the maximum \(r^2\) between two SNPs for them to be considered independent.
```{r , fig.width=8,fig.height=6   }
finemap.signals(D3,method="mask")
finemap.signals(D4,method="mask")
resm=coloc.signals(D3,D4,method="mask",p12=1e-6,pthr=1e-6,r2thr=0.01)
resm
sensitivity(resm,"H4 > 0.9",row=1)
sensitivity(resm,"H4 > 0.9",row=2)
```

