---
title: "supplementary file 3"
output: html_document
---
##DEG analysis
##normal: RNAseq matrix for normal tissue; tumor: RNAseq matrix for tumor tissue
library(limma)
comparison <- cbind(normal, tumor)
condition <- c(rep(c("Normal tissue"), ncol(normal)), rep(c("Tumor tissue"), ncol(tumor)))
meta_list <- factor(condition, levels=c("Normal tissue", "Tumor tissue"))
meta_design <- model.matrix(~meta_list)
colnames(meta_design) <- levels(meta_list)
rownames(meta_design) <- colnames(comparison)
dge <- DGEList(counts = comparison)
dge <- calcNormFactors(dge)
logCPM <- cpm(dge, log = TRUE, prior.count = 3)
fit <- lmFit(logCPM, meta_design)
fit <- eBayes(fit, trend = TRUE)
result_meta <- topTable(fit, coef = 2, n = Inf)

##lasso Cox regression
##sig_gene: the input of gene matrix
library(glmnet)
set.seed(520)
cvfit = cv.glmnet(t(sig_gene), Surv(survival$OS, survival$EVENT), 
                  family = "cox") 
coef.min = coef(cvfit, s = "lambda.min") 
active.min = which(coef.min != 0)
geneids <- rownames(sig_gene)[active.min]
index.min = coef.min[active.min]
new <- cbind(geneids, index.min) %>%
  data.frame
new$index.min <- as.character(new$index.min) %>%
  as.numeric()
signature <- as.matrix(t(sig_gene[geneids,])) %*% as.matrix(index.min) 

