Created
May 11, 2021 10:55
-
-
Save markziemann/fed8701d95c459c815044a05f4a8107d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Compare DEG tools" | |
author: "Mark Ziemann" | |
date: "`r Sys.Date()`" | |
output: | |
html_document: | |
toc: true | |
theme: cosmo | |
--- | |
## Introduction | |
In this tutorial we will demonstrate how to calculate delta-beta values in an epigenetics study starting with a matrix of beta values which contains disease and normal samples. | |
The general approach is to filter these samples (columns) into separate matrices and then calculate the mean beta value for each probe then calculate the delta-beta. | |
## Fake data generation | |
The first part is to create a matrix of data. | |
In this case the matrix will be 10 rows (genes) and 10 columns (samples). | |
```{r,make_data} | |
vec <- rnorm(n = 100,sd = 1,mean = 0) | |
mx <- matrix(data = vec,nrow = 10) | |
colnames(mx) <- paste("sample",1:10) | |
rownames(mx) <- paste("probe",1:10) | |
mx[1:6,1:5] | |
``` | |
Now need to decide which samples are control and which are disease. | |
This will be coded in your sample sheet but here I'll just select them by random. | |
```{r,samplegroups} | |
my_disease_samples <- sample(x = colnames(mx),size = 5,replace=FALSE) | |
my_disease_samples | |
my_ctrl_samples <- setdiff(colnames(mx),my_disease_samples) | |
my_ctrl_samples | |
``` | |
## Column filtering | |
Now need to filter the matrix based on the column names. | |
```{r,colselect} | |
mx_disease <- mx[, colnames(mx) %in% my_disease_samples] | |
dim(mx_disease) | |
mx_ctrl <- mx[, colnames(mx) %in% my_ctrl_samples] | |
dim(mx_ctrl) | |
``` | |
## Calculate beta and delta-beta values | |
Next, calculate the beta values for the two groups and find the difference | |
```{r,betavals} | |
betavals_disease <- rowMeans(mx_disease) | |
betavals_ctrl <- rowMeans(mx_ctrl) | |
deltabetavals <- betavals_disease - betavals_ctrl | |
head(deltabetavals) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment