-
Notifications
You must be signed in to change notification settings - Fork 5
/
05-feature-selection.html
1418 lines (1117 loc) · 45.8 KB
/
05-feature-selection.html
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Selección de genes</title>
<meta charset="utf-8" />
<meta name="author" content="Leonardo Collado-Torres" />
<meta name="date" content="2020-08-05" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-137796972-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137796972-1');
</script>
<link rel="stylesheet" href="xaringan-themer.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# <strong>Selección de genes</strong>
## <strong>Bioconductor</strong> para datos transcriptómicos de célula única (<strong>scRNA-seq</strong>) – <strong>CDSB2020</strong>
### <a href="http://lcolladotor.github.io/">Leonardo Collado-Torres</a>
### 2020-08-05
---
class: inverse
.center[
<a href="https://osca.bioconductor.org/"><img src="https://raw.githubusercontent.com/Bioconductor/OrchestratingSingleCellAnalysis-release/master/images/cover.png" style="width: 30%"/></a>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
<a href='https://clustrmaps.com/site/1b5pl' title='Visit tracker'><img src='//clustrmaps.com/map_v2.png?cl=ffffff&w=150&t=n&d=rP3KLyAMuzVNcJFL-_C-B0XnLNVy8Sp6a8HDaKEnSzc'/></a>
]
.footnote[Descarga los materiales con `usethis::use_course('comunidadbioinfo/cdsb2020')` o revisalos en línea vía [**comunidadbioinfo.github.io/cdsb2020**](http://comunidadbioinfo.github.io/cdsb2020).]
<style type="text/css">
/* From https://github.com/yihui/xaringan/issues/147 */
.scroll-output {
height: 80%;
overflow-y: scroll;
}
/* https://stackoverflow.com/questions/50919104/horizontally-scrollable-output-on-xaringan-slides */
pre {
max-width: 100%;
overflow-x: scroll;
}
/* From https://github.com/yihui/xaringan/wiki/Font-Size */
.tiny{
font-size: 40%
}
/* From https://github.com/yihui/xaringan/wiki/Title-slide */
.title-slide {
background-image: url(https://raw.githubusercontent.com/Bioconductor/OrchestratingSingleCellAnalysis/master/images/Workflow.png);
background-size: 33%;
background-position: 0% 100%
}
</style>
---
# Diapositivas de Peter Hickey
Ve las diapositivas [aquí](https://docs.google.com/presentation/d/19J2FyjKlBQdAkku4Oa6UZ6SA-Y4P7AEKCRIbEQWA9ho/edit#slide=id.ga100bba375887aa_0)
---
# Código de R
.scroll-output[
```r
# Usemos datos de pbmc4k
library('BiocFileCache')
```
```
## Loading required package: dbplyr
```
```r
bfc <- BiocFileCache()
raw.path <-
bfcrpath(
bfc,
file.path(
"http://cf.10xgenomics.com/samples",
"cell-exp/2.1.0/pbmc4k/pbmc4k_raw_gene_bc_matrices.tar.gz"
)
)
untar(raw.path, exdir = file.path(tempdir(), "pbmc4k"))
library('DropletUtils')
```
```
## Loading required package: SingleCellExperiment
```
```
## Loading required package: SummarizedExperiment
```
```
## Loading required package: GenomicRanges
```
```
## Loading required package: stats4
```
```
## Loading required package: BiocGenerics
```
```
## Loading required package: parallel
```
```
##
## Attaching package: 'BiocGenerics'
```
```
## The following objects are masked from 'package:parallel':
##
## clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
## clusterExport, clusterMap, parApply, parCapply, parLapply,
## parLapplyLB, parRapply, parSapply, parSapplyLB
```
```
## The following objects are masked from 'package:stats':
##
## IQR, mad, sd, var, xtabs
```
```
## The following objects are masked from 'package:base':
##
## anyDuplicated, append, as.data.frame, basename, cbind, colnames,
## dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
## grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
## order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
## rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
## union, unique, unsplit, which, which.max, which.min
```
```
## Loading required package: S4Vectors
```
```
##
## Attaching package: 'S4Vectors'
```
```
## The following object is masked from 'package:base':
##
## expand.grid
```
```
## Loading required package: IRanges
```
```
## Loading required package: GenomeInfoDb
```
```
## Loading required package: Biobase
```
```
## Welcome to Bioconductor
##
## Vignettes contain introductory material; view with
## 'browseVignettes()'. To cite Bioconductor, see
## 'citation("Biobase")', and for packages 'citation("pkgname")'.
```
```
## Loading required package: DelayedArray
```
```
## Loading required package: matrixStats
```
```
##
## Attaching package: 'matrixStats'
```
```
## The following objects are masked from 'package:Biobase':
##
## anyMissing, rowMedians
```
```
##
## Attaching package: 'DelayedArray'
```
```
## The following objects are masked from 'package:matrixStats':
##
## colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges
```
```
## The following objects are masked from 'package:base':
##
## aperm, apply, rowsum
```
```r
library('Matrix')
```
```
##
## Attaching package: 'Matrix'
```
```
## The following object is masked from 'package:S4Vectors':
##
## expand
```
```r
fname <- file.path(tempdir(), "pbmc4k/raw_gene_bc_matrices/GRCh38")
sce.pbmc <- read10xCounts(fname, col.names = TRUE)
# Anotación de los genes
library('scater')
```
```
## Loading required package: ggplot2
```
```r
rownames(sce.pbmc) <- uniquifyFeatureNames(rowData(sce.pbmc)$ID, rowData(sce.pbmc)$Symbol)
library('EnsDb.Hsapiens.v86')
```
```
## Loading required package: ensembldb
```
```
## Loading required package: GenomicFeatures
```
```
## Loading required package: AnnotationDbi
```
```
## Loading required package: AnnotationFilter
```
```
##
## Attaching package: 'ensembldb'
```
```
## The following object is masked from 'package:stats':
##
## filter
```
```r
location <- mapIds(
EnsDb.Hsapiens.v86,
keys = rowData(sce.pbmc)$ID,
column = "SEQNAME",
keytype = "GENEID"
)
```
```
## Warning: Unable to map 144 of 33694 requested IDs.
```
]
---
.scroll-output[
```r
# Detección de _droplets_ con células
set.seed(100)
e.out <- emptyDrops(counts(sce.pbmc))
sce.pbmc <- sce.pbmc[, which(e.out$FDR <= 0.001)]
# Control de calidad
stats <-
perCellQCMetrics(sce.pbmc, subsets = list(Mito = which(location == "MT")))
high.mito <- isOutlier(stats$subsets_Mito_percent,
type = "higher")
sce.pbmc <- sce.pbmc[, !high.mito]
# Normalización de los datos
library('scran')
set.seed(1000)
clusters <- quickCluster(sce.pbmc)
sce.pbmc <- computeSumFactors(sce.pbmc, cluster = clusters)
sce.pbmc <- logNormCounts(sce.pbmc)
```
]
---
# Ejercicios
--
* ¿Cómo determinamos cuales eran los genes mitocondriales?
--
* ¿Cómo decidimos filtrar las células?
--
* ¿Puedes explicar como normalizamos los datos?
???
* Usando Ensembl v86 para humano
* Usamos los resultados de `emptyDrops()` con un límite de 0.1% FDR y el filtro de 3 desviaciones sobre la mediana (MAD) en la expresión mitocondrial.
* Encontramos unos clusters rápidos para las célulasy usamos esa información para calcular los factores de tamaño.
---
.scroll-output[
```r
# Set de datos de ejemplo: 416B ------------------------------------------------
library('scRNAseq')
sce.416b <- LunSpikeInData(which = "416b")
```
```
## snapshotDate(): 2020-04-27
```
```
## see ?scRNAseq and browseVignettes('scRNAseq') for documentation
```
```
## loading from cache
```
```
## see ?scRNAseq and browseVignettes('scRNAseq') for documentation
```
```
## loading from cache
```
```
## see ?scRNAseq and browseVignettes('scRNAseq') for documentation
```
```
## loading from cache
```
```
## snapshotDate(): 2020-04-27
```
```
## loading from cache
```
```r
sce.416b$block <- factor(sce.416b$block)
# Anotación de genes
library('AnnotationHub')
```
```
##
## Attaching package: 'AnnotationHub'
```
```
## The following object is masked from 'package:Biobase':
##
## cache
```
```r
ens.mm.v97 <- AnnotationHub()[["AH73905"]]
```
```
## snapshotDate(): 2020-04-27
```
```
## loading from cache
```
```r
rowData(sce.416b)$ENSEMBL <- rownames(sce.416b)
rowData(sce.416b)$SYMBOL <- mapIds(
ens.mm.v97,
keys = rownames(sce.416b),
keytype = "GENEID",
column = "SYMBOL"
)
```
```
## Warning: Unable to map 563 of 46604 requested IDs.
```
```r
rowData(sce.416b)$SEQNAME <- mapIds(
ens.mm.v97,
keys = rownames(sce.416b),
keytype = "GENEID",
column = "SEQNAME"
)
```
```
## Warning: Unable to map 563 of 46604 requested IDs.
```
```r
rownames(sce.416b) <- uniquifyFeatureNames(rowData(sce.416b)$ENSEMBL,
rowData(sce.416b)$SYMBOL)
# Control de calidad
mito <- which(rowData(sce.416b)$SEQNAME == "MT")
stats <- perCellQCMetrics(sce.416b, subsets = list(Mt = mito))
qc <- quickPerCellQC(
stats,
percent_subsets = c("subsets_Mt_percent", "altexps_ERCC_percent"),
batch = sce.416b$block
)
sce.416b <- sce.416b[, !qc$discard]
# Normalización
sce.416b <- computeSumFactors(sce.416b)
sce.416b <- logNormCounts(sce.416b)
```
]
---
# Ejercicios
--
* ¿Cómo determinamos cuales eran los genes mitocondriales?
--
* ¿Cómo decidimos filtrar las células?
--
* ¿Puedes explicar como normalizamos los datos?
???
* Ensembl v87 para ratón
* Usamos el filtro de 3 desviaciones sobre la mediana (MAD) en la expresión mitocondrial además del porcentaje de expresión del ERCCC tomando en cuenta el grupo de muestras de secuenciación (batch).
* Calculamos los factores de tamaño de librería con los parámetros de defecto sin ningún cambio extra.
---
.scroll-output[
```r
# Varianza de las log-counts ---------------------------------------------------
dec.pbmc <- modelGeneVar(sce.pbmc)
# Visualicemos la relación entre la media y la varianza
fit.pbmc <- metadata(dec.pbmc)
plot(fit.pbmc$mean, fit.pbmc$var,
xlab = "Mean of log-expression",
ylab = "Variance of log-expression")
curve(fit.pbmc$trend(x),
col = "dodgerblue",
add = TRUE,
lwd = 2)
```
![](05-feature-selection_files/figure-html/all_code4-1.png)<!-- -->
```r
# Ordenemos por los genes más interesantes para checar
# los datos
dec.pbmc[order(dec.pbmc$bio, decreasing = TRUE), ]
```
```
## DataFrame with 33694 rows and 6 columns
## mean total tech bio p.value FDR
## <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
## LYZ 1.97770 5.11595 0.827277 4.28867 7.03222e-271 6.90916e-267
## S100A9 1.94951 4.58859 0.827542 3.76105 9.35459e-209 6.12726e-205
## S100A8 1.71828 4.45723 0.819402 3.63783 2.60470e-199 1.27956e-195
## HLA-DRA 2.09694 3.72690 0.823663 2.90324 1.69876e-126 2.38433e-123
## CD74 2.89840 3.30912 0.793203 2.51592 7.30211e-103 6.83269e-100
## ... ... ... ... ... ... ...
## PTMA 3.83013 0.471105 0.740525 -0.269420 0.993177 1
## HLA-B 4.50161 0.475348 0.755807 -0.280459 0.994059 1
## EIF1 3.24261 0.478352 0.771316 -0.292963 0.994987 1
## TMSB4X 6.08483 0.408394 0.742840 -0.334446 0.998864 1
## B2M 5.95481 0.304437 0.714661 -0.410224 0.999950 1
```
]
---
# Ejercicios
--
* ¿Qué tipo de objeto nos regresó `modelGeneVar()`?
--
* ¿`dec.pbmc` es una tabla? ¿O contiene mayor información?
--
* ¿Qué tipo de objeto es `fit.pbmc` y que objetos con nombres contiene?
--
* ¿Qué tipo de objeto es `fit.pbmc$trend`?
--
* ¿Donde podemos encontrar más detalles de esta función?
--
???
Respuestas
* Es un `DFrame`
* No, contiene más información dentro de `metadata(dec.pbmc)`
* `class(metadata(dec.pbmc))` y `sapply(metadata(dec.pbmc), class)`
* Una función
* Checa `?fitTrendVar` y si quieres también checa el código fuente (para mí es muy útil este paso) https://github.com/MarioniLab/scran/blob/master/R/fitTrendVar.R
---
.scroll-output[
```r
# Coeficiente de variación -----------------------------------------------------
dec.cv2.pbmc <- modelGeneCV2(sce.pbmc)
# Visualicemos la relación con la media
fit.cv2.pbmc <- metadata(dec.cv2.pbmc)
plot(fit.cv2.pbmc$mean, fit.cv2.pbmc$cv2, log = "xy")
```
```
## Warning in xy.coords(x, y, xlabel, ylabel, log): 14044 x values <= 0 omitted
## from logarithmic plot
```
```r
curve(fit.cv2.pbmc$trend(x),
col = "dodgerblue",
add = TRUE,
lwd = 2)
```
![](05-feature-selection_files/figure-html/all_code5-1.png)<!-- -->
```r
# Ordenemos por los genes más interesantes para checar
# los datos
dec.cv2.pbmc[order(dec.cv2.pbmc$ratio, decreasing = TRUE), ]
```
```
## DataFrame with 33694 rows and 6 columns
## mean total trend ratio p.value FDR
## <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
## HIST1H2AC 0.9045169 267.718 1.55979 171.6372 0 0
## GNG11 0.6905688 219.323 1.98064 110.7334 0 0
## PRTFDC1 0.0412511 3034.952 29.98682 101.2096 0 0
## TNNC2 0.1021577 1210.585 12.22872 98.9952 0 0
## PF4 1.1083758 128.809 1.30995 98.3316 0 0
## ... ... ... ... ... ... ...
## AC023491.2 0 NaN Inf NaN NaN NaN
## AC233755.2 0 NaN Inf NaN NaN NaN
## AC233755.1 0 NaN Inf NaN NaN NaN
## AC213203.1 0 NaN Inf NaN NaN NaN
## FAM231B 0 NaN Inf NaN NaN NaN
```
]
---
.scroll-output[
```r
# En la presencia de muestras técnicas añadidas (spike-ins) --------------------
dec.spike.416b <- modelGeneVarWithSpikes(sce.416b, "ERCC")
# Ordenemos por los genes más interesantes para checar
# los datos
dec.spike.416b[order(dec.spike.416b$bio, decreasing = TRUE), ]
```
```
## DataFrame with 46604 rows and 6 columns
## mean total tech bio p.value FDR
## <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
## Lyz2 6.61097 13.8497 1.57131 12.2784 1.48993e-186 1.54156e-183
## Ccl9 6.67846 13.1869 1.50035 11.6866 2.21856e-185 2.19979e-182
## Top2a 5.81024 14.1787 2.54776 11.6310 3.80016e-65 1.13040e-62
## Cd200r3 4.83180 15.5613 4.22984 11.3314 9.46221e-24 6.08574e-22
## Ccnb2 5.97776 13.1393 2.30177 10.8375 3.68706e-69 1.20193e-66
## ... ... ... ... ... ... ...
## Rpl5-ps2 3.60625 0.612623 6.32853 -5.71590 0.999616 0.999726
## Gm11942 3.38768 0.798570 6.51473 -5.71616 0.999459 0.999726
## Gm12816 2.91276 0.838670 6.57364 -5.73497 0.999422 0.999726
## Gm13623 2.72844 0.708071 6.45448 -5.74641 0.999544 0.999726
## Rps12l1 3.15420 0.746615 6.59332 -5.84670 0.999522 0.999726
```
```r
# In the absence of spike-ins --------------------------------------------------
set.seed(0010101)
dec.pois.pbmc <- modelGeneVarByPoisson(sce.pbmc)
# Ordenemos por los genes más interesantes para checar
# los datos
dec.pois.pbmc[order(dec.pois.pbmc$bio, decreasing = TRUE), ]
```
```
## DataFrame with 33694 rows and 6 columns
## mean total tech bio p.value FDR
## <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
## LYZ 1.97770 5.11595 0.621547 4.49440 0 0
## S100A9 1.94951 4.58859 0.627306 3.96128 0 0
## S100A8 1.71828 4.45723 0.669428 3.78781 0 0
## HLA-DRA 2.09694 3.72690 0.596372 3.13053 0 0
## CD74 2.89840 3.30912 0.422624 2.88650 0 0
## ... ... ... ... ... ... ...
## ATP5J 0.619524 0.455659 0.507720 -0.0520614 0.947965 1
## NEDD8 0.846016 0.561648 0.614758 -0.0531099 0.914573 1
## NDUFA1 0.866546 0.561477 0.621858 -0.0603808 0.938119 1
## SAP18 0.765422 0.515946 0.582614 -0.0666679 0.965154 1
## SUMO2 1.361306 0.618400 0.698946 -0.0805452 0.966130 1
```
```r
# Considerando factores experimentales -----------------------------------------
dec.block.416b <- modelGeneVarWithSpikes(sce.416b, "ERCC",
block = sce.416b$block)
dec.block.416b[order(dec.block.416b$bio, decreasing = TRUE), ]
```
```
## DataFrame with 46604 rows and 7 columns
## mean total tech bio p.value FDR
## <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
## Lyz2 6.61235 13.8619 1.58416 12.2777 0.00000e+00 0.00000e+00
## Ccl9 6.67841 13.2599 1.44553 11.8143 0.00000e+00 0.00000e+00
## Top2a 5.81275 14.0192 2.74571 11.2734 3.89855e-137 8.43398e-135
## Cd200r3 4.83305 15.5909 4.31892 11.2719 1.17783e-54 7.00721e-53
## Ccnb2 5.97999 13.0256 2.46647 10.5591 1.20380e-151 2.98405e-149
## ... ... ... ... ... ... ...
## Gm12816 2.91299 0.842574 6.67730 -5.83472 0.999989 0.999999
## Gm5786 2.90717 0.879485 6.71686 -5.83738 0.999994 0.999999
## Rpl9-ps4 3.26421 0.807057 6.64932 -5.84226 0.999988 0.999999
## Gm13623 2.72788 0.700296 6.63875 -5.93845 0.999998 0.999999
## Rps12l1 3.15425 0.750775 6.70033 -5.94955 0.999995 0.999999
## per.block
## <DataFrame>
## Lyz2 6.35652:13.3748:2.08227:...:6.86819:14.3490:1.08605:...
## Ccl9 6.68726:13.0778:1.65923:...:6.66956:13.4420:1.23184:...
## Top2a 5.34891:17.5972:3.91642:...:6.27659:10.4411:1.57501:...
## Cd200r3 4.60115:15.7870:5.55587:...:5.06496:15.3948:3.08197:...
## Ccnb2 5.56701:15.4150:3.46931:...:6.39298:10.6362:1.46362:...
## ... ...
## Gm12816 2.86995:0.624143:7.43036:...:2.95604:1.061004:5.92424:...
## Gm5786 2.96006:0.902872:7.49911:...:2.85427:0.856098:5.93462:...
## Rpl9-ps4 3.60690:0.543276:7.36805:...:2.92151:1.070839:5.93058:...
## Gm13623 2.83129:0.852901:7.39442:...:2.62447:0.547692:5.88308:...
## Rps12l1 3.14399:0.716670:7.57246:...:3.16452:0.784881:5.82819:...
```
```r
dec.block.416b$per.block
```
```
## DataFrame with 46604 rows and 2 columns
## 20160113 20160325
## <DataFrame> <DataFrame>
## 1 0.0000000:0.00000:0.0000000:... 0:0:0:...
## 2 0.0000000:0.00000:0.0000000:... 0:0:0:...
## 3 0.0000000:0.00000:0.0000000:... 0:0:0:...
## 4 0.0000000:0.00000:0.0000000:... 0:0:0:...
## 5 0.0158182:0.02327:0.0754413:... 0:0:0:...
## ... ... ...
## 46600 0.0000:0.00000:0.00000000:... 0.0000:0.00000:0.00000000:...
## 46601 0.0000:0.00000:0.00000000:... 0.0000:0.00000:0.00000000:...
## 46602 0.0000:0.00000:0.00000000:... 0.0000:0.00000:0.00000000:...
## 46603 0.0000:0.00000:0.00000000:... 0.0000:0.00000:0.00000000:...
## 46604 14.8189:2.90986:0.00884549:... 15.2007:3.41768:0.00618922:...
```
```r
dec.block.416b$per.block$X20160113
```
```
## NULL
```
---
# Ejercicios
--
* ¿Qué tipo de objeto es `dec.block.416b$per.block`?
???
* `class(dec.block.416b$per.block)` es un `DataFrame` con 2 columnas, donde cada una es a la vez un `DataFrame`
]
---
.scroll-output[
```r
# Seleccionando los genes altamente variables (HVG) ----------------------------
# Utiliza modelGeneVar() detrás de cámaras
hvg.pbmc.var <- getTopHVGs(dec.pbmc, n = 1000)
str(hvg.pbmc.var)
```
```
## chr [1:1000] "LYZ" "S100A9" "S100A8" "HLA-DRA" "CD74" "CST3" "TYROBP" ...
```
```r
# Utiliza modelGeneVarWithSpikes() detrás de cámaras
hvg.416b.var <- getTopHVGs(dec.spike.416b, n = 1000)
str(hvg.416b.var)
```
```
## chr [1:1000] "Lyz2" "Ccl9" "Top2a" "Cd200r3" "Ccnb2" "Gm10736" "Hbb-bt" ...
```
```r
# O utiliza modelGeneCV2() al especificar `var.field`
hvg.pbmc.cv2 <- getTopHVGs(dec.cv2.pbmc,
var.field = "ratio", n = 1000)
str(hvg.pbmc.cv2)
```
```
## chr [1:1000] "HIST1H2AC" "GNG11" "PRTFDC1" "TNNC2" "PF4" "HGD" "PPBP" ...
```
]
---
# Ejercicios
--
* ¿Qué porcentaje de los genes altamente variables (HVG) se sobrelapan entre los dos sets de pbmc?
--
* Extra: haz un diagrama de venn de los 2 conjuntos de genes HVG de pbmc
???
* `table(hvg.pbmc.var %in% hvg.pbmc.cv2)`
---
.scroll-output[
* Busca código de R escrito por otrxs, por ejemplo: https://github.com/LieberInstitute/brainseq_phase2/search?p=2&q=venn&unscoped_q=venn
```r
if (!requireNamespace("gplots", quietly = TRUE))
install.packages("gplots")
if (!requireNamespace("VennDiagram", quietly = TRUE))
BiocManager::install("VennDiagram")
## Un diagrama de venn rápido pero sencillo
gplots::venn(list('var' = hvg.pbmc.var, 'cv2' = hvg.pbmc.cv2))
```
![](05-feature-selection_files/figure-html/all_code7b-1.png)<!-- -->
```r
## Otro más bonito pero más complejo
v <- VennDiagram::venn.diagram(
list('var' = hvg.pbmc.var, 'cv2' = hvg.pbmc.cv2),
filename = NULL,
fill = c('forest green', 'orange')
)
grid::grid.newpage()
grid::grid.draw(v)
```
![](05-feature-selection_files/figure-html/all_code7b-2.png)<!-- -->
]
---
.scroll-output[
```r
# Seleccionando los HVGs usando significancia estadística ----------------------
# Utiliza modelGeneVar() detrás de cámaras
hvg.pbmc.var.2 <- getTopHVGs(dec.pbmc, fdr.threshold = 0.05)
str(hvg.pbmc.var.2)
```
```
## chr [1:651] "LYZ" "S100A9" "S100A8" "HLA-DRA" "CD74" "CST3" "TYROBP" ...
```
```r
# Utiliza modelGeneVarWithSpikes() detrás de cámaras
hvg.416b.var.2 <- getTopHVGs(dec.spike.416b,
fdr.threshold = 0.05)
str(hvg.416b.var.2)
```
```
## chr [1:2568] "Lyz2" "Ccl9" "Top2a" "Cd200r3" "Ccnb2" "Gm10736" "Hbb-bt" ...
```
```r
# O utiliza modelGeneCV2() al especificar `var.field`
hvg.pbmc.cv2.2 <- getTopHVGs(dec.cv2.pbmc,
var.field = "ratio", fdr.threshold = 0.05)
str(hvg.pbmc.cv2.2)
```
```
## chr [1:1699] "HIST1H2AC" "GNG11" "PRTFDC1" "TNNC2" "PF4" "HGD" "PPBP" ...
```
]
---
# Ejercicios
--
* ¿Qué lista de HVGs de pbmc es más larga?
--
* Haz un diagrama de venn con estas listas de HVGs de pbmc.
???
* `hvg.pbmc.cv2.2`
---
.scroll-output[
```r
# Seleccionando como HVGs a los genes arriba de la curva -----------------------
# Utiliza modelGeneVar() detrás de cámaras
hvg.pbmc.var.3 <- getTopHVGs(dec.pbmc, var.threshold = 0)
str(hvg.pbmc.var.3)
```
```
## chr [1:12792] "LYZ" "S100A9" "S100A8" "HLA-DRA" "CD74" "CST3" "TYROBP" ...
```
```r
# Utiliza modelGeneVarWithSpikes() detrás de cámaras
hvg.416b.var.3 <- getTopHVGs(dec.spike.416b,
var.threshold = 0)
str(hvg.416b.var.3)
```
```
## chr [1:11087] "Lyz2" "Ccl9" "Top2a" "Cd200r3" "Ccnb2" "Gm10736" "Hbb-bt" ...
```
```r
# O utiliza modelGeneCV2() al especificar `var.field` y
# el valor de `var.threshold`
hvg.pbmc.cv2.3 <- getTopHVGs(dec.cv2.pbmc,
var.field = "ratio", var.threshold = 1)
str(hvg.pbmc.cv2.2)
```
```
## chr [1:1699] "HIST1H2AC" "GNG11" "PRTFDC1" "TNNC2" "PF4" "HGD" "PPBP" ...
```
]
---
.scroll-output[
```r
# Usando todo al mismo tiempo --------------------------------------------------
dec.pbmc <- modelGeneVar(sce.pbmc)
chosen <- getTopHVGs(dec.pbmc, prop = 0.1)
str(chosen)
```
```
## chr [1:1279] "LYZ" "S100A9" "S100A8" "HLA-DRA" "CD74" "CST3" "TYROBP" ...
```
```r
# Seleccionando el subconjunto de HVGs -----------------------------------------