-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-abnomic.Rmd
2132 lines (1808 loc) · 78 KB
/
04-abnomic.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Comparación de la respuesta de anticuerpos ante _Plasmodium vivax_ mediante Microarreglos de proteínas"
author: "Andree Valle Campos"
date: '`r Sys.Date()`'
output:
#html_document:
#pdf_document:
html_notebook:
toc: yes
toc_depth: 6
toc_float:
collapsed: yes
#theme: united
code_folding: "hide"
#fig_caption: TRUE
#number_sections: TRUE
bibliography: malaria.bib
link-citations: yes
#csl: american-medical-association.csl
editor_options:
chunk_output_type: console
# params:
# non_parametric: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, #fig.path = "01-",
warning = FALSE)
# knitr::opts_knit$set(root.dir = '../.')
options(width = 90) # expand limits of CONSOLE output
```
## Microarray Data Analysis
+ __UPDATE:__
- Ir al contraste de los __resultados__ con la __lista de Ag de N6__. [Ver aquí.](#n6-subset)
### Dependencies
This document has the following dependencies:
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(haven)
library(broom)
library(biobroom)
library(ggrepel)
library(forcats)
library(stringr)
# library("Rmisc") #multiploting ggplots
library(Biobase) #ExpressionSet
library(genefilter) #DataCondensation
library(limma) #DifferentialAnalysisOfGenes
library(NMF) #AnnotatedHeatmaps!!!
#library(PerformanceAnalytics) #GRAPHICAL CORRELATIONS
#library(beeswarm)
#library(vioplot)
#library(beanplot)
#library(htmlTable) #HTMLtables -minimalistic- without 'ResultsAsis'
#library(knitr) #better it seems
library(patchwork)
library(qvalue)
theme_set(theme_bw())
```
### Input
```{r}
raw<-read.csv("data-raw/RawData.csv")
```
```{r, eval=FALSE}
raw %>% View()
raw %>% dplyr::count(Spot.Type)
raw %>% dim()
raw %>% glimpse()
raw %>%
as_tibble() %>%
select(-(Index:Description)) %>%
colnames() %>% enframe() %>%
mutate(start=
case_when(
str_starts(value,"L")~str_replace(value,"(...).+", "\\1"),
str_starts(value,"P")~str_replace(value,"(....).+", "\\1"),
TRUE ~ "non")) %>%
dplyr::count(start)
# samples si tiene ubicacion de los 8 controles
# las lecturas de Ab no estan en el archivo de valores crudos
# pero si estan en los archivo excel
readr::read_csv("data-raw/samples.csv") %>%
filter(Study=="Controls") %>%
select(-Study)
readr::read_csv("data-raw/samples.csv") %>%
# rownames_to_column() %>%
# as_tibble() %>%
# dplyr::count(Study)
# dplyr::count(Study,Group)
select(value=Sample.ID) %>%
mutate(start=
case_when(
str_starts(value,"L")~str_replace(value,"(...).+", "\\1"),
str_starts(value,"PQ")~str_replace(value,"(....).+", "\\1"),
TRUE ~ "non")) %>%
dplyr::count(start)
```
### 1. Tidy up
#### ivtt antigens
```{r}
anti <- raw %>%
dplyr::filter(Spot.Type=="IVTT.AG") %>% #head()
select(ID,11:ncol(.)) %>% #head()
gather(sample_name, expression, -ID) %>%
mutate(expression=as.numeric(expression)) %>%
reshape2::acast(ID ~ sample_name,
value.var = "expression") #%>% class()
# dimensión
dim(anti)
# seis lecturas por proteína de las 8 primeras muestras
head(anti[,1:8])
```
#### ivtt controls
```{r}
ctrl <- raw %>%
dplyr::filter(Spot.Type=="IVTT.CTRL") %>% #head()
select(ID,11:ncol(.)) %>% #head()
summarise_if(is.numeric,funs(median)) %>%
# MEDIAN to NORMALIZE against noDNA controls
mutate(ID="noDNA") %>%
gather(sample_name, expression, -ID) %>%
mutate(expression=as.numeric(expression)) %>%
reshape2::acast(ID ~ sample_name,
value.var = "expression") #%>% class()
# dimensión
dim(ctrl)
# seis lecturas por proteína de las 8 primeras muestras
ctrl[,1:8]
```
```{r}
ctrm <- NULL # crear objeto vacío
# loop para generar una matriz de las dimensiones de `anti`
for(i in 1:nrow(anti)){
ctrm <- rbind(ctrm,ctrl)
}
# dimensiones de la matriz con la mediana de ctrls `noDNA` creada
dim(ctrm)
# matriz con la mediana de ctrls `noDNA` para las 8 primeras muestras
head(ctrm[,1:8]) #%>% class()
```
#### purified proteins
```{r}
pure <- raw %>%
dplyr::filter(Spot.Type=="PURIFIED.PROTEIN") %>% #dim() #dplyr::count(Species)
#separate(Description,c("gene", "conc"), sep=",",remove = FALSE) %>% #dplyr::count(gene)
#select(ID,Species,gene,14:ncol(.)) %>%
select(ID,11:ncol(.)) %>%
gather(sample_name, expression, -ID) %>%
mutate(expression=as.numeric(expression)) %>%
reshape2::acast(ID ~ sample_name,
value.var = "expression") #%>% class()
```
#### gene names
```{r}
# generate a list (df) of gene names and gene ID's
ln <- raw %>%
dplyr::filter(Spot.Type=="IVTT.AG") %>% #head()
select(ID,Gene.ID,Description,Species)
lg <- ln %>% #dplyr::count(Gene.ID)
group_by(Gene.ID,Species) %>% dplyr::count() %>% #filter(Species=="Pv") %>% arrange(desc(n))
ungroup()
readr::write_csv(lg, "data/04-listgen-raw.csv")
readr::write_csv(lg %>% select(Gene.ID), "data/04-listgen.csv")
```
#### feature data
```{r}
feat <- raw %>%
dplyr::filter(Spot.Type=="IVTT.AG") %>%
#DO NOT WORKS!
#dplyr::mutate(ID=as.character(ID)) %>%
#dplyr::mutate(ID= stringr::str_replace(ID, "(.....)_(\\d{6})_(.+)","\\3"))
#separate(ID,c("id.sp","id.cod","id.res"),sep = "_",remove = FALSE) %>%
#separate(id.cod,c("id.cod","id.num")) %>%
#unite(id.num,id.num,id.res)
#THIS WORKS!
#dplyr::mutate(num=seq(from=33, to=32+n())) %>% #dplyr::count(num) %>% dplyr::count(n)
#unite(Description,Description,num,sep=" _") %>%
#dplyr::mutate(Description=as.factor(Description)) %>%
#select(ID,1:10) %>% #head()
select(ID,Gene.ID,Description,Species) %>% #head()
as.data.frame() %>%
column_to_rownames(var="ID")#%>% class()
feat_d <- new("AnnotatedDataFrame", data=feat)
```
#### phenotype data
- __join__ `sample.csv` with `03-sevrcov.rds` and `primaquine` sample data
- __create__ categorical variables from numerical: `edad` and `episodio_previo_num`
+ `cut()`advantage: automatic factor labels.
```{r}
sevdb_3 <- readRDS("data/03-sevrcov.rds") %>% #dplyr::count(episodio_previo)
dplyr::rename(Sample.ID="codigo") %>%
mutate(edad_CAT=cut(edad,c(0,18,40,65,Inf)),
expo_CAT=cut(episodio_previo_num,c(-Inf,0,1,4,Inf))) %>% #%>%
select(Sample.ID,sev_WHO_num,episodio_previo_num,#en_zona_endemica,#edad,#,parasitemia
sev_WHO:expo_CAT,-Study#,-episodio_previo_num
)
```
```{r, message=FALSE}
pridb <- #readr::read_csv("analysis/more/ADi-NAMRU6_Data/samples.csv") %>% ## BUSCAR ORIGINAL!!!
readr::read_csv("data-raw/ADi-NAMRU6_Data-samples.csv") %>% ## ENCONTRÉ ORIGINAL
filter(Study=="Primaquine") %>%
select(Sample.ID,Cat.Age.WHO:Anemia.HTO)
```
```{r, message=FALSE}
pheno <- readr::read_csv("data-raw/samples.csv") %>%
#dplyr::count(Sample.Type)
dplyr::filter(Sample.Type!="Control") %>% #str()
select(Sample.ID, 1:9, -Sample.Type,-Subject.ID) %>%
#dplyr::count(Filename)
dplyr::arrange(Sample.ID) %>%
full_join(
sevdb_3 %>%
mutate(
sev_WHO_num_precat = as.character(sev_WHO_num),
sev_WHO_num_precat = as.numeric(sev_WHO_num_precat),
sev_WHO_cat = case_when(
sev_WHO_num_precat == 0 ~ "0",
sev_WHO_num_precat == 1 ~ "1",
sev_WHO_num_precat > 1 ~ "1+"),
sev_WHO_cat = as.factor(sev_WHO_cat)
) %>% #count(sev_WHO_cat,sev_WHO_num_precat,sev_WHO_num)
select(-sev_WHO_num_precat)
,by = "Sample.ID") %>%
full_join(pridb,by = "Sample.ID") %>%
dplyr::arrange(Sample.ID) %>%
# # manual imputation of one observation # warning! (post-hoc decision)
# # filter(!is.na(sev_WHO) & is.na(episodio_previo)) %>% glimpse()
# mutate(episodio_previo=as.character(episodio_previo)) %>%
# mutate(episodio_previo=case_when(
# Sample.ID=="LIM2017"~"sin",
# TRUE~episodio_previo)) %>%
# mutate(episodio_previo=as.factor(episodio_previo)) %>%
# # filter(Sample.ID=="LIM2017") %>% glimpse()
as.data.frame() %>%
column_to_rownames(var="Sample.ID")
pheno_d <- new("AnnotatedDataFrame", data=pheno)
#colnames(norx)
```
### 2. Normalization + Transformation
```{r log-norm}
# custom function
# definir resultado para los valores menores o iguales a cero:
log2.NA = function(x) {log2(ifelse(x>0, x, NA))}
# normalización con respecto a los controles `noDNA` c/ transformación log2
norm <- log2.NA(anti/ctrm)
head(norm[,1:6])
```
```{r}
test <- anti/ctrm
```
```{r ratio-test, eval=FALSE, echo=FALSE}
test <- anti/ctrm
test %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name,expression,-rowname) %>%
filter(expression <= 0)
anti %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name,expression,-rowname) %>%
dplyr::filter(rowname=="PVX_113590_2o2.849",sample_name=="LIM2077") # 21
norm %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name,expression,-rowname) %>%
dplyr::filter(rowname=="PVX_113590_2o2.849",sample_name=="LIM2077") # 21
```
```{r vsn-norm}
```
#### outlier
```{r}
ndb <- norm %>% as.data.frame() %>%
gather(sample_name,expression)
p <- ndb %>%
full_join(ndb %>%
group_by(sample_name) %>%
dplyr::summarise(avg=mean(expression)) %>%
ungroup(),
by="sample_name") %>%
dplyr::arrange(avg) %>%
ggplot(aes(reorder(sample_name,avg,order = TRUE),expression)) +
geom_boxplot() +
theme(axis.text.x = element_blank()) +
labs(title="Outlier visualization")
```
```{r}
# EDIT specific value under CONDITIONAL STATEMENT:
# source: https://github.com/tidyverse/dplyr/issues/425
norx <- norm %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name,expression,-rowname) %>%
#dplyr::filter(expression < -5) #%>% dim()
mutate(expression= ifelse(expression < -5, NA, expression)) %>% # RULE TO EDIT a value of a column!
#dplyr::filter(rowname=="PVX_111175.544",sample_name=="LIM2017") # 21
reshape2::acast(rowname ~ sample_name,
value.var = "expression") #%>% class()
# norm %>% write_rds("data/04-eset_assay.rds")
#norm["PVX_111175.544","LIM2017"] <- NA ## messy modification
#anti %>% as.data.frame() %>%
# rownames_to_column() %>%
# gather(sample_name,expression,-rowname) %>%
# dplyr::filter(rowname=="PVX_111175.544",sample_name=="LIM2017") # 21
#
#ctrl %>% as.data.frame() %>%
# rownames_to_column() %>%
# gather(sample_name,expression,-rowname) %>%
# dplyr::filter(sample_name=="LIM2017") # 13550.5
```
```{r, fig.height=4, fig.width=15}
q <- norx %>% as.data.frame() %>%
gather(sample_name,expression) %>%
full_join(ndb %>%
group_by(sample_name) %>%
dplyr::summarise(avg=mean(expression)) %>%
ungroup(),
by="sample_name") %>%
dplyr::arrange(avg) %>%
ggplot(aes(reorder(sample_name,avg,order = TRUE),expression)) +
geom_boxplot() +
theme(axis.text.x = element_blank()) +
labs(title="Conditional edition of a single element")
# Rmisc::multiplot(p,q,cols = 2)
p+q
```
### 3. ExpressionSet
- __arrange__ `norx` rownames wrt `feat_d` ones.
- __create__ the expression set
```{r}
head(norx[,1:5])
head(norx[feat_d %>% rownames(),1:5])
```
```{r}
eset <- ExpressionSet(assayData = norx[feat_d %>% rownames(),],
phenoData = pheno_d,
featureData = feat_d)
eset
```
#### subset eset
**per Pv/Pf chip and Pq/Sev experiment**
```{r}
#eset
# ExpressionSet subseted by both SAMPLES and FEATURE covariates!!!!
##
eset.VIVAX.PQ<-eset[featureData(eset)$Species=="Pv",
phenoData(eset)$Study=="Primaquine"]
#eset.VIVAX.PQ
#
eset.FALCIP.PQ<-eset[featureData(eset)$Species=="Pf",
phenoData(eset)$Study=="Primaquine"]
#eset.FALCIP.PQ
##
eset.VIVAX.SEV<-eset[featureData(eset)$Species=="Pv",
phenoData(eset)$Study!="Primaquine"]
eset.VIVAX.SEV
#
eset.FALCIP.SEV<-eset[featureData(eset)$Species=="Pf",
phenoData(eset)$Study!="Primaquine"]
#eset.FALCIP.SEV
##
```
```{r, eval=FALSE}
summary(pData(eset))
varMetadata(eset)
table(pData(eset)$Study)
table(pData(eset)$Group)
```
#### specific pData
```{r}
pData(eset.VIVAX.SEV) <- pData(eset.VIVAX.SEV) %>%
select(Filename:expo_CAT,sev_WHO_cat,-Filename,-Slide,-Pad,-Probing.Day)
eset.VIVAX.SEV
```
```{r}
pData(eset.VIVAX.PQ) <- pData(eset.VIVAX.PQ) %>%
select(Study,Group,Weight:Anemia.HTO)
#eset.VIVAX.PQ
```
### 4. Filtering
```{r, echo=TRUE}
#
#eset # 1014 features X 200 samples (10%= 20)
#
#eset.VIVAX.PQ # 515 features X 140 samples (10%= 14)
#eset.FALCIP.PQ # 499 features X 140 samples (10%= 14)
#eset.VIVAX.SEV # 515 features X 60 samples (10%= 6)
#eset.FALCIP.SEV # 499 features X 60 samples (10%= 6)
#
############################## [START] GENEFILTER for each DATASET (n=4)
f1 <- kOverA(20,1) ## expression measure above 1 in at least 20 samples
ffun <- filterfun(f1)
wh1 <- genefilter(exprs(eset),ffun) # WHOLE data set
#sum(wh1) # 526 -> 818 ---------------------------------------------------->>>> (ALL of this are WITHOUT mean centering)
#
# GENERATE the NEW ExpressionSet
eset.FILTER<-eset[wh1,]
#eset.FILTER
############################## GENEFILTER for VIVAX PRIMAQUINE
f2 <- kOverA(14,1) ## expression measure above 1 in at least 14 samples
ffun2 <- filterfun(f2)
wh2 <- genefilter(exprs(eset.VIVAX.PQ),ffun2) # WHOLE data set
#sum(wh2) # 252 -> 397
#
# GENERATE the NEW ExpressionSet
eset.VIVAX.PQ.FILTER<-eset.VIVAX.PQ[wh2,]
#eset.VIVAX.PQ.FILTER
############################## GENEFILTER for FALCIPARUM PRIMAQUINE
f2 <- kOverA(14,1) ## expression measure above 1 in at least 14 samples
ffun2 <- filterfun(f2)
wh3 <- genefilter(exprs(eset.FALCIP.PQ),ffun2) # WHOLE data set
#sum(wh3) # 279 -> 430
#
# GENERATE the NEW ExpressionSet
eset.FALCIP.PQ.FILTER<-eset.FALCIP.PQ[wh3,]
#eset.FALCIP.PQ.FILTER
############################## [DONE] GENEFILTER for VIVAX SEVERE
f3 <- kOverA(6,1) ## expression measure above 1 in at least 6 samples
ffun3 <- filterfun(f3)
wh4 <- genefilter(exprs(eset.VIVAX.SEV),ffun3) # WHOLE data set
#sum(wh4) # 255 -> 394
#
# GENERATE the NEW ExpressionSet
eset.VIVAX.SEV.FILTER<-eset.VIVAX.SEV[wh4,]
eset.VIVAX.SEV.FILTER
############################## [DONE] GENEFILTER for FALCIPARUM SEVERE
f3 <- kOverA(6,1) ## expression measure above 1 in at least 6 samples
ffun3 <- filterfun(f3)
wh5 <- genefilter(exprs(eset.FALCIP.SEV),ffun3) # WHOLE data set
#sum(wh5) # 280 -> 419
#
# GENERATE the NEW ExpressionSet
eset.FALCIP.SEV.FILTER<-eset.FALCIP.SEV[wh5,]
#eset.FALCIP.SEV.FILTER
############################## [END] OF GENEFILTER
#
# results
#
#eset.FILTER
#eset.VIVAX.PQ.FILTER # 252 /515 features X 140 samples
#eset.FALCIP.PQ.FILTER # 279 /499 features X 140 samples
#eset.VIVAX.SEV.FILTER # 255 /515 features X 60 samples
#eset.FALCIP.SEV.FILTER # 280 /499 features X 60 samples
#
##########################################################
```
```{r}
eset.VIVAX.SEV %>%
readr::write_rds("data/04-eset_vivax_sev.rds")
eset.VIVAX.SEV.FILTER %>%
readr::write_rds("data/04-eset_vivax_sev_filter.rds")
```
### 0. Descriptive Statistics
#### Preprocessing
##### Distributions per step
raw -> normalized -> transformed -> filtered
```{r, fig.width=12, fig.height=3.5}
a <- anti %>% as.data.frame() %>%
gather(sample_name,expression) %>%
dplyr::mutate(labl="Raw")
b <- test %>% as.data.frame() %>%
gather(sample_name,expression) %>%
filter(expression >= 0) %>%
dplyr::mutate(labl="Normalized")
c <- norx %>% as.data.frame() %>%
gather(sample_name,expression) %>%
dplyr::mutate(labl="Transformed")
d <- exprs(eset.VIVAX.SEV.FILTER) %>% as.data.frame() %>%
gather(sample_name,expression) %>%
dplyr::mutate(labl="Filtered*")
preprocessing_plot <- rbind(a,b,c,d) %>%
dplyr::mutate(labl=forcats::fct_relevel(labl,
"Raw",
"Normalized",
"Transformed",
"Filtered*")) %>%
ggplot(aes(expression)) +
geom_histogram() + theme_bw() +
#facet_grid(.~labl,scales = "free") +
facet_wrap(~labl,nrow = 1,ncol = 4,scales = "free") +
labs(
x = "Value",
y = "Count",
# title="Preprocessing: Data distribution per step",
caption="*subset of samples from the severe vivax malaria study and probes with P. vivax antigens") +
theme(
strip.background = element_rect(colour = "black"#, fill = "white"
),
strip.text.x = element_text(colour = "black",size = 12#, face = "bold"
))
preprocessing_plot
ggsave("figure/04-fig01-preprocessing_distribution.png",
height = 2.25,width = 8,dpi = "retina")
```
```{r, fig.width=16, fig.height=4,eval=FALSE,echo=FALSE}
a <- anti %>% as.data.frame() %>%
gather(sample_name,expression) %>%
ggplot(aes(expression)) +
geom_histogram() +
labs(title="RAW") + theme_bw()
b <- test %>% as.data.frame() %>%
gather(sample_name,expression) %>%
filter(expression >= 0) %>%
ggplot(aes(expression)) +
geom_histogram() +
labs(title="NORMALIZED") + theme_bw()
c <- norx %>% as.data.frame() %>%
gather(sample_name,expression) %>%
ggplot(aes(expression)) +
geom_histogram() +
labs(title="TRANSFORMED") + theme_bw()
d <- exprs(eset.VIVAX.SEV.FILTER) %>% as.data.frame() %>%
gather(sample_name,expression) %>%
ggplot(aes(expression)) +
geom_histogram() +
labs(title="SEVERE VIVAX FILTERED DATA") + theme_bw()
# Rmisc::multiplot(a,b,c,d,cols = 4)
a+b+c+d
```
*Of sample covariates, feature covariates and microarray whole dataset*
#### Sample covariates
- just show the results from `03-sevrcov.Rmd`
- compare against initial stratification and after update!
##### Reclassification
- Smith-Nuñez, correo __28oct2016__:
+ La base de datos epidemiológicos inicial pasó por __control de calidad y reingreso de fichas__.
+ __Acción:__
- Contrastar y Crear una DB consenso,
- Redefinir clasificación OMS de Malaria Severa,
- Reclasificar muestras,
- Filtrar muestras seleccionadas para el ensayo de Microarreglo de Proteínas.
```{r}
pData(eset) %>%
group_by(Group,sev_WHO) %>% dplyr::count()
```
```{r}
pData(eset) %>%
group_by(sev_WHO, episodio_previo) %>% dplyr::count()
```
#### Feature covariates
- maybe a graph of the slides with all the coordinates? :)
##### Load PlasmoDB Metadata
- __Write `data/04-listgen.csv`__ with all the gene names. [here](#gene-names)
- __Create PlasmoDB strategy__, select required features, and download data.
- __Tidy PlasmoDB data frame__ output:
+ __Programaticaly renamed all__ variable/column names using __regex__.
```{r, message=FALSE}
all <- readr::read_tsv("data/04-listgen.tsv") %>% #colnames() %>% #class()
#make.names(unique = TRUE) %>%
rename_all(
funs(
#stringr::str_to_lower(.) %>%
stringr::str_replace_all(., '\\s', '\\.') %>%
stringr::str_replace_all(., '\\[|\\]', '') %>%
stringr::str_replace_all(., '\\#.', '') %>%
stringr::str_replace_all(., 'Computed.', '') %>%
stringr::str_replace_all(., '\\/', '\\_')
)
) %>%
# janitor::clean_names()
# select(-source_id,-X18) %>%
select(-source_id,-...18) %>%
dplyr::rename(Gene.Name=Gene.Name.or.Symbol) %>%
dplyr::mutate_all(
funs(
stringr::str_replace_all(.,"N/A",replacement = NA_character_)
)) %>%
dplyr::mutate(SignalP.Scores=
stringr::str_replace(SignalP.Scores,
"^NN.{0,}","SP")) %>%
dplyr::mutate(
NonSyn_Syn.SNP.Ratio.All.Strains=
as.numeric(NonSyn_Syn.SNP.Ratio.All.Strains),
Total.SNPs.All.Strains=as.numeric(Total.SNPs.All.Strains),
Transcript.Length=as.numeric(Transcript.Length),
Ortholog.count=as.numeric(Ortholog.count)) %>%
# dplyr::mutate(
# SignalP=stringr::str_replace(SignalP.Scores, "^NN.{0,}","SP")) %>%
#group_by(SignalP.Scores,SignalP) %>% dplyr::count()
dplyr::rename(SignalP=SignalP.Scores) %>%
dplyr::mutate(
Gene.Name= ifelse(Gene.ID == "PVX_003775", "MSP4", Gene.Name)) %>%
dplyr::mutate(
Gene.Name= ifelse(Gene.ID == "PVX_003770", "MSP5", Gene.Name)) %>%
dplyr::mutate(
Gene.Name= ifelse(Gene.ID == "PVX_097625", "MSP8", Gene.Name)) %>%
dplyr::mutate(
Gene.Name= ifelse(Gene.ID == "PVX_114145", "MSP10", Gene.Name)) %>%
dplyr::mutate(
Gene.Name= ifelse(Gene.ID == "PVX_116780", "SFT2", Gene.Name))
#lg
# head(all)
all
#raw %>% filter(Gene.ID=="PVX_003775")#only_2o2 --> IS THIS SUGGESTING A MISTAKE IN ID TIPYING? --> COMPARE!
#raw %>% filter(stringr::str_detect(Description, "MSP7"))
all %>%
readr::write_rds("data/04-listgen-microarray_chip-raw.rds")
all %>%
unite(id.name, Gene.Name, Gene.ID, sep = " / ", remove = FALSE) %>%
mutate(id.name=str_replace(id.name,"NA / ","")) %>%
mutate(id.name=str_replace(id.name,"/","-")) %>%
janitor::clean_names() %>%
readr::write_rds("data/04-listgen-microarray_chip-clean.rds")
```
```{r, message=FALSE}
full <- readr::read_tsv("data/04-listall.tsv") %>% #colnames() %>% #class()
#make.names(unique = TRUE) %>%
rename_all(
funs(
#stringr::str_to_lower(.) %>%
stringr::str_replace_all(., '\\s', '\\.') %>%
stringr::str_replace_all(., '\\[|\\]', '') %>%
stringr::str_replace_all(., '\\#.', '') %>%
stringr::str_replace_all(., 'Computed.', '') %>%
stringr::str_replace_all(., '\\/', '\\_')
)
) %>%
select(-source_id,-...8) %>%
dplyr::rename(Gene.Name=Gene.Name.or.Symbol) %>%
dplyr::mutate_all(
funs(
stringr::str_replace_all(.,"N/A",replacement = NA_character_)
)) #%>%
#dplyr::mutate(SignalP.Scores=stringr::str_replace(SignalP.Scores, "^NN.{0,}","SP")) %>%
#dplyr::mutate(NonSyn_Syn.SNP.Ratio.All.Strains=as.numeric(NonSyn_Syn.SNP.Ratio.All.Strains),
# Total.SNPs.All.Strains=as.numeric(Total.SNPs.All.Strains),
# Transcript.Length=as.numeric(Transcript.Length),
# Ortholog.count=as.numeric(Ortholog.count)) %>%
#dplyr::mutate(SignalP=stringr::str_replace(SignalP.Scores, "^NN.{0,}","SP")) %>%
#group_by(SignalP.Scores,SignalP) %>% dplyr::count()
#dplyr::rename(SignalP=SignalP.Scores) %>%
#dplyr::mutate(Gene.Name= ifelse(Gene.ID == "PVX_003775", "MSP4", Gene.Name)) %>%
#dplyr::mutate(Gene.Name= ifelse(Gene.ID == "PVX_003770", "MSP5", Gene.Name)) %>%
#dplyr::mutate(Gene.Name= ifelse(Gene.ID == "PVX_097625", "MSP8", Gene.Name)) %>%
#dplyr::mutate(Gene.Name= ifelse(Gene.ID == "PVX_114145", "MSP10", Gene.Name)) %>%
#dplyr::mutate(Gene.Name= ifelse(Gene.ID == "PVX_116780", "SFT2", Gene.Name))
#lg
# head(full)
full
#raw %>% filter(Gene.ID=="PVX_003775")#only_2o2 --> IS THIS SUGGESTING A MISTAKE IN ID TIPYING? --> COMPARE!
#raw %>% filter(stringr::str_detect(Description, "MSP7"))
```
##### GO distribution
```{r,fig.height=5,fig.width=7.7}
all_go <- all %>% select(Gene.ID,Product.Description,GO.Components) %>%
separate(GO.Components, c("c1","c2","c3"),sep = ",") %>%
mutate_at(vars(c1:c3), funs(trimws)) %>%
gather(component,GO.Components,-Gene.ID,-Product.Description) %>%
filter(GO.Components!="NA") %>% #dplyr::count(GO.Components) %>% dplyr::arrange(desc(n)) #%>% filter(n>1)
dplyr::mutate(summary.db="Pf/Pv500 microarray",
protype= stringr::str_count(Product.Description, "hypothetical"),
protype=as.factor(protype),
protype= forcats::fct_recode(protype, "hypothetical"="1", "known"="0")) %>%
select(Gene.ID,Product.Description,protype,summary.db,GO.Components) #%>% dplyr::count(protype)
full_go <- full %>% select(Gene.ID,Product.Description,GO.Components) %>%
separate(GO.Components, c("c1","c2","c3"),sep = ",") %>%
mutate_at(vars(c1:c3), funs(trimws)) %>%
gather(component,GO.Components,-Gene.ID,-Product.Description) %>%
filter(GO.Components!="NA") %>% #dplyr::count(GO.Components) %>% dplyr::arrange(desc(n)) #%>% filter(n>1)
dplyr::mutate(summary.db="P. vivax whole genome",
protype= stringr::str_count(Product.Description, "hypothetical"),
protype=as.factor(protype),
protype= forcats::fct_recode(protype, "hypothetical"="1", "known"="0")) %>%
select(Gene.ID,Product.Description,protype,summary.db,GO.Components) #%>% dplyr::count(protype)
go_ord <- rbind(full_go,all_go) %>% #class()
group_by(GO.Components,summary.db) %>%
dplyr::summarise(count=n()) %>% ungroup() %>%
dplyr::arrange(desc(count)) %>%
spread(summary.db,count) %>%
dplyr::rename(micro="Pf/Pv500 microarray",
whole="P. vivax whole genome") %>%
dplyr::arrange(desc(micro)) %>%
replace_na(list(micro = 0)) %>%
filter(micro>1)
#rbind(a,b,c,d)
rbind(full_go,all_go) %>%
inner_join(go_ord,by = "GO.Components") %>%
dplyr::arrange(desc(micro)) %>%
#replace_na(list(SignalP = "na")) %>%
ggplot(aes(#x=summary.db#, fill=GO.Components
x=reorder(GO.Components,micro,order = TRUE), fill=protype
)) +
geom_bar(#position = "fill"
#position = "identity"
) +
facet_grid(.~summary.db#, scales = "free"#, space = "free"
) +#
coord_flip() + theme_bw() +
scale_fill_discrete(name="Protein",
labels=c("with annotation", "hypothetical")) +
theme(legend.position=c(-.73, 0.04),#"bottom"
legend.margin = margin(0,0,0,0),
axis.title.y=element_blank()
#legend.text = element_text(size = 8),
#legend.title = element_text(size = 8)
) +
labs(title="Gene Ontology: Pf/Pv500 microarray proteins",
subtitle="Cellular Component prediction compared to P. vivax genome") +
theme(strip.background = element_rect(colour = "black"#, fill = "white"
),
strip.text.x = element_text(colour = "black"#,#size = 12,
#face = "bold"
))
```
```{r,fig.height=3.5,fig.width=6}
#rbind(a,b,c,d)
rbind(full_go,all_go) %>%
inner_join(go_ord %>%
filter(micro>3),by = "GO.Components") %>%
dplyr::arrange(desc(micro)) %>%
#replace_na(list(SignalP = "na")) %>%
ggplot(aes(#x=summary.db#, fill=GO.Components
x=reorder(GO.Components,micro,order = TRUE), fill=protype
)) +
geom_bar(#position = "fill"
#position = "identity"
) +
facet_grid(.~summary.db#, scales = "free"#, space = "free"
) +#
coord_flip() + theme_bw() +
scale_fill_discrete(name="Protein",
labels=c("with annotation", "hypothetical")) +
theme(#legend.position=c(-.38, -0.04),#"bottom"
# legend.position=c(.85, 0.15),
# legend.margin = margin(0,0,0,0),
axis.title.y=element_blank()
#legend.text = element_text(size = 8),
#legend.title = element_text(size = 8)
) +
# labs(title="Gene Ontology: Pf/Pv500 microarray proteins",
# subtitle="Predicted Cellular Components compared to P. vivax genome") +
theme(
strip.background =
element_rect(colour = "black"#, fill = "white"
),
strip.text.x = element_text(colour = "black"#,#size = 12,
#face = "bold"
))
ggsave("figure/04-fig04-microarray_genome_comparison.png",
height = 3.5,width = 6.5,dpi = "retina")
```
```{r}
library(treemapify)
rbind(full_go,all_go) %>%
inner_join(go_ord %>%
filter(micro>3),by = "GO.Components") %>%
dplyr::arrange(desc(micro)) %>%
janitor::clean_names() %>%
dplyr::count(summary_db,go_components) %>%
ggplot(aes(area = n,
fill = go_components,
label = go_components#,
# subgroup = summary_db
)) +
geom_treemap(colour = "black") +
facet_wrap(~summary_db) +
# geom_treemap_subgroup_border(color = "black") +
# geom_treemap_subgroup_text(place = "middle",
# grow = T,
# alpha = 0.5,
# colour = "black",
# fontface = "italic",
# min.size = 0) +
geom_treemap_text(colour = "black",
place = "bottomleft",
reflow = T) +
colorspace::scale_fill_discrete_qualitative(palette = "Set 3") +
theme_classic() +
theme(legend.position = "none")
ggsave("figure/04-fig04-microarray_genome_comparison-tree.png",
height = 3.5,width = 6.5,dpi = "retina")
```
```{r}
# rbind(full_go,all_go) %>%
# inner_join(go_ord,by = "GO.Components") %>%
# dplyr::arrange(desc(micro))
# go_ord %>%
# avallecam::print_inf()
# rbind(full_go,all_go) %>% #class()
# group_by(GO.Components,summary.db) %>%
# dplyr::summarise(count=n()) %>% ungroup() %>%
# dplyr::arrange(desc(count))
library(compareGroups)
microarray_proteins <- rbind(full_go,all_go) %>%
inner_join(go_ord %>%
filter(micro>3),by = "GO.Components") %>%
dplyr::arrange(desc(micro)) %>%
janitor::clean_names() %>%
dplyr::mutate(go_components=fct_infreq(go_components)) %>%
dplyr::select(protype, summary_db, go_components) %>%
# dplyr::count(go_components) %>%
compareGroups(summary_db~., data=.,
max.xlev = 30,
chisq.test.perm = TRUE) %>%
createTable(digits = 1)
microarray_proteins %>% export2md()
microarray_proteins %>%
export2xls("table/04-tab01-microarray_proteins.xls")
```
#### Microarray data
##### Heteroskedasticity
*pre- & post- transformation/normalization*
```{r, fig.height=3, fig.width=6}
m <- anti %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name, expression, -rowname) %>%
#mutate(expression= ifelse(expression < 30, NA, expression)) %>%
#dplyr::filter(rowname=="PVX_111175.544",sample_name=="LIM2017") # 21
#dplyr::filter(sample_name=="PQSJ103")
group_by(sample_name) %>%
dplyr::summarise(mean= mean(expression),
sd= sd(expression)) %>%
#dplyr::filter(mean<5000)
dplyr::mutate(labl="Raw")
n <- norx %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name, expression, -rowname) %>%
group_by(sample_name) %>%
dplyr::summarise(mean= mean(expression),
sd= sd(expression)) %>%
dplyr::mutate(labl="Transformed")
heteroskedasticity_plot <- rbind(m,n) %>%
dplyr::mutate(labl=forcats::fct_relevel(labl,
"Raw",
"Transformed")) %>%
ggplot(aes(mean,sd)) +
geom_point(alpha=0.5) +
theme_bw() +
geom_smooth(linetype=0) +
facet_wrap(~labl,nrow = 1,ncol = 2,scales = "free") +
labs(
# title="Mean-variance dependence"
x = "Mean",
y = "Standard deviation"
) +
theme(strip.background = element_rect(colour = "black"#, fill = "white"
),
strip.text.x = element_text(colour = "black",size = 10#, face = "bold"
))
heteroskedasticity_plot
ggsave("figure/04-fig02-heteroskedasticity_prepos.png",
height = 2.5,width = 5,dpi = "retina")
```
```{r,eval=FALSE}
# this may require adjusting the height of each
# plot inside the patchwork
preprocessing_plot +
heteroskedasticity_plot +
plot_layout(ncol = 1) +
plot_annotation(tag_levels = "A")
ggsave("figure/04-fig02-mix-preprocessing_heteroskedasticity.png",
height = 5,width = 5,dpi = "retina")
```
```{r, fig.height=3, fig.width=6,eval=FALSE,echo=FALSE}
m <- anti %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name, expression, -rowname) %>%
#mutate(expression= ifelse(expression < 30, NA, expression)) %>%
#dplyr::filter(rowname=="PVX_111175.544",sample_name=="LIM2017") # 21
#dplyr::filter(sample_name=="PQSJ103")
group_by(sample_name) %>% dplyr::summarise(mean= mean(expression),
sd= sd(expression)) %>%
#dplyr::filter(mean<5000)
ggplot(aes(mean,sd)) +
geom_point() +
#geom_smooth() +
labs(title="Mean-variance dependence",
subtitle="Raw data") + theme_bw()
n <- norx %>% as.data.frame() %>%
rownames_to_column() %>%
gather(sample_name, expression, -rowname) %>%