forked from cabezuelo79/TFM_TCGA_PRAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script_Analisis_Pareado.R
134 lines (93 loc) · 6.21 KB
/
Script_Analisis_Pareado.R
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
##############################################################
####### Analisis de expresion genica mediante RNA-Seq#########
############## ESTUDIO PAREADO ###############################
###### Analisis de expresion diferencial con el paquete edgeR#
##############################################################
# Establecimiento de directorio de trabajo, donde se encuentra el archivo "PAREADO.txt"
setwd('C:/Users/JoseMaria/OneDrive - MERIDIEM SEEDS S.L/Documentos/Master/TFM/RNASeq_PRAD')
# Cargo el paquete necesario para la ejecución del analisis
library(edgeR)
# Obtengo la información del archivo "PAREADO.txt"
rawdataPAR <- read.delim("PAREADO.txt", check.names=FALSE, stringsAsFactors=FALSE)
# Construyo un objeto DGEList con la información del archivo, las dos primeras columnas son el simbolo e identidad de los genes, el resto las muestras
yPAR <- DGEList(counts=rawdataPAR[,3:106], genes=rawdataPAR[,1:2])
# Llevo a cabo la normalizacion de las muestras
yPAR <- calcNormFactors(yPAR)
# Cargo los vectores 'Tissue' y 'Patient' de forma manual
TissuePAR <- factor(c("N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T","N","T"))
PatientPAR <- factor(c("CH-5761","CH-5761","CH-5767","CH-5767","CH-5768","CH-5768","CH-5769","CH-5769","EJ-7115","EJ-7115","EJ-7123","EJ-7123","EJ-7125","EJ-7125","EJ-7314","EJ-7314","EJ-7315","EJ-7315","EJ-7317","EJ-7317","EJ-7321","EJ-7321","EJ-7327","EJ-7327","EJ-7328","EJ-7328","EJ-7330","EJ-7330","EJ-7331","EJ-7331","EJ-7781","EJ-7781","EJ-7782","EJ-7782","EJ-7783","EJ-7783","EJ-7784","EJ-7784","EJ-7785","EJ-7785","EJ-7786","EJ-7786","EJ-7789","EJ-7789","EJ-7792","EJ-7792","EJ-7793","EJ-7793","EJ-7794","EJ-7794","EJ-7797","EJ-7797","EJ-A8FO","EJ-A8FO","G9-6333","G9-6333","G9-6342","G9-6342","G9-6348","G9-6348","G9-6351","G9-6351","G9-6356","G9-6356","G9-6362","G9-6362","G9-6363","G9-6363","G9-6365","G9-6365","G9-6384","G9-6384","G9-6496","G9-6496","G9-6499","G9-6499","HC-7211","HC-7211","HC-7737","HC-7737","HC-7738","HC-7738","HC-7740","HC-7740","HC-7742","HC-7742","HC-7745","HC-7745","HC-7747","HC-7747","HC-7752","HC-7752","HC-7819","HC-7819","HC-8258","HC-8258","HC-8259","HC-8259","HC-8260","HC-8260","HC-8262","HC-8262","J4-A83J","J4-A83J"))
# Construyo un data frame con la informacion
data.frame(Sample=colnames(yPAR),PatientPAR,TissuePAR)
# Construyo la matriz de diseño en base a los dos factores ('Tissue' y 'Patient')
designPAR <- model.matrix(~PatientPAR+TissuePAR)
rownames(designPAR) <- colnames(yPAR)
# Calculo la dispersion estimada y visualizo la dispersion comun
yPAR <- estimateDisp(yPAR, designPAR, robust=TRUE)
yPAR$common.dispersion
# Visualizo la grafica del coeficiente de variacion biologica (BCV)
plotBCV(yPAR)
# Likelihood-ratio test
fitPAR <- glmFit(yPAR, designPAR)
lrtPAR <- glmLRT(fitPAR)
# Visualizo un plot multidimensional con los genes sub-expresados y sobre-expresados
plotMD(lrtPAR)
# Genero un elemento 'topTags' con el resultado obtenido (n=Inf para que incluya todos los resultados)
top_PAR <- topTags(lrtPAR,n=Inf)
# visualizo el resultado
top_PAR
# visualizo el resumen de genes sobre-expresados, genes sub-expresados y genes no significativos
summary(decideTests(lrtPAR))
##############################################################################################
############## COMPROBACION DE RESULTADOS OBTENIDOS MANUALMENTE ##############################
##############################################################################################
# Construyo el data frame 'TagetsPAR' con los counts y el tejido correspondiente
targetsPAR<-data.frame(filename=colnames(rawdataPAR[,3:106]),type=TissuePAR)
# Visualizo 'targetsPAR'
head(targetsPAR)
# Cambio 'filename' de factor a caracter
targetsPAR$filename<-as.character(targetsPAR$filename)
# Genero la media de counts para el primero de los genes diferencialmente expresados y tejido normal
controlPAR <- mean(as.numeric(yPAR$counts[yPAR$genes$`SYMBOL`=="TRIP6",targetsPAR[targetsPAR$type=="N","filename"]]))
# Visualizo el resultado
controlPAR
# Genero la media de counts para el primero de los genes diferencialmente expresados y tejido tumoral
samplePAR <- mean(as.numeric(yPAR$counts[yPAR$genes$`SYMBOL`=="TRIP6",targetsPAR[targetsPAR$type=="T","filename"]]))
# Visualizo el resultado
samplePAR
# Realizo el calculo de logFC manualmente
log2(samplePAR/controlPAR)
##############################################################################################
############## ANALISIS DE ENRIQUECIMIENTO FUNCIONAL GOSEQ ##############################
##############################################################################################
# Cargo los paquetes necesarios para el analisis
library(goseq)
library(GO.db)
# Genero un vector con los genes diferencialmente expresados (FDR < 0.05)
topPAR_DE <- top_PAR$table[top_PAR$table$FDR < 0.05,"SYMBOL"]
# Genero un vector 'universal' que contiene tanto los genes DE como los no DE
universePAR <- top_PAR$table$`SYMBOL`
# Construyo un vector apropiado para el analisis con 'goseq'
mytablePAR <- as.integer(unique(universePAR)%in%topPAR_DE)
names(mytablePAR) <- unique(universePAR)
# Veo la cantidad de genes DE (1) y no DE (0) y compruebo que este correcto
table(mytablePAR)
head(mytablePAR)
# Probability Weighting Function (pwf) utilizando 'geneSymbol' y genoma 'hg19'
pwf_PAR=nullp(mytablePAR,"hg19","geneSymbol")
# Compruebo el resultado
head(pwf_PAR)
# Realizo el analisis GO mediante la aproximación de Wallenius
GO.wall_PAR=goseq(pwf_PAR,"hg19","geneSymbol")
# Visualizo el resultado
GO.wall_PAR
# Llevo a cabo el enriquecimiento
enriched.GO_PAR <- GO.wall_PAR$category[p.adjust(GO.wall_PAR$over_represented_pvalue, method="BH")<.05]
# Visualizo el resultado
for(go in enriched.GO_PAR[1:10]){
print(GOTERM[[go]])
cat("--------------------------------------\n")
}
##### ANALISIS DE RUTAS KEGG #########
kegg_DE_PAR <- goseq(pwf_PAR,'hg19','geneSymbol',test.cats="KEGG")
# Visualizo el resultado
kegg_DE_PAR