-
Notifications
You must be signed in to change notification settings - Fork 0
/
IFN score script.Rmd
34 lines (25 loc) · 1.26 KB
/
IFN score script.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---
title: "Untitled"
output: html_document
date: "2024-10-02"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Before creating the IFN count tables, all sample raw counts (both control & disease) should be normalized together, ideally with the TPM method but any other method will work if raw counts are not available. Then the combined normalized table should be split in two as seen below:
This script requires two dataframes:
1)A dataframe of disease interferon counts/transcripts with row names being the interferon genes and column names being the sample names, labeled "IFN_disease"
2)A dataframe of control interferon data with a similar structure as above labeled "IFN_controls"
```{r Calculate Score}
IFN_control_means <- apply(IFN_controls, 1, mean)
IFN_control_sds <- apply(IFN_controls, 1, sd)
standardize_row <- function(row) {
(row - IFN_control_means) / IFN_control_sds
}
IFN_disease_standardized <- t(apply(t(IFN_disease), 1, standardize_row))
row_sums <- rowSums(IFN_disease_standardized)
#These two following lines will create a new dataframe with two columns, one being the patient ID and the other being their assigned IFN score
IFN_column <- data.frame(Sum = row_sums)
IFN_column$Sample_ID <- rownames(IFN_column)
print(IFN_column)
```