File: download_prepare.Rmd

package info (click to toggle)
r-bioc-tcgabiolinks 2.25.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,392 kB
  • sloc: makefile: 5
file content (726 lines) | stat: -rw-r--r-- 27,609 bytes parent folder | download | duplicates (2)
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
---
title: "TCGAbiolinks: Downloading and preparing files for analysis"
date: "`r BiocStyle::doc_date()`"
vignette: >
  %\VignetteIndexEntry{"3. Downloading and preparing files for analysis"}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(progress = FALSE)
```

```{r message=FALSE, warning=FALSE, include=FALSE}
library(TCGAbiolinks)
library(SummarizedExperiment)
library(dplyr)
library(DT)
```

**TCGAbiolinks** has provided a few functions to download and prepare data from GDC for analysis.
This section starts by explaining the different downloads methods and the SummarizedExperiment object, which 
is the default data structure used in TCGAbiolinks, followed by some examples.


---

# Downloading and preparing data for analysis

<div class="panel panel-info">
<div class="panel-heading">Data download: Methods differences</div>
<div class="panel-body">


There are two methods to download GDC data using TCGAbiolinks:

- `client`: this method creates a MANIFEST file and downloads the data using [GDC Data Transfer Tool](https://gdc.cancer.gov/access-data/gdc-data-transfer-tool)
this method is more reliable but it might be slower compared to the api method.
- `api`: this method uses the [GDC Application Programming Interface (API)](https://gdc.cancer.gov/developers/gdc-application-programming-interface-api) to download the data.
This will create a MANIFEST file and the data downloaded will be compressed into a tar.gz file. If the size and the number of the files are too big this tar.gz will be too big
which might have a high probability of download failure. To solve that we created the `files.per.chunk` argument which will split the files
into small chunks, for example, if `chunks.per.download` is equal to 10 we will download only 10 files inside each tar.gz.

</div>
</div>



<div class="panel panel-info">
<div class="panel-heading">Data prepared: SummarizedExperiment object</div>
<div class="panel-body">


A [SummarizedExperiment object](http://www.nature.com/nmeth/journal/v12/n2/fig_tab/nmeth.3252_F2.html) 
has three main matrices that can be accessed using the [SummarizedExperiment package](http://bioconductor.org/packages/SummarizedExperiment/)): 

- Sample matrix information is accessed via `colData(data)`: stores sample information. TCGAbiolinks will add indexed clinical data and subtype information from marker TCGA papers.
- Assay matrix information is accessed via `assay(data)`: stores molecular data 
- Feature matrix information (gene information) is accessed via `rowRanges(data)`: stores metadata about the features, including their genomic ranges

</div>
</div>

<div class="panel panel-warning">
<div class="panel-heading">Summarized Experiment: annotation information</div>
<div class="panel-body">


When using the function `GDCprepare` there is an argument called `SummarizedExperiment`
which defines the output type a Summarized Experiment (default option) or a data frame.
To create a summarized Experiment object we annotate the data with genomic positions
with last patch release version of the genome available. 

For legacy data (data aligned to hg19) TCGAbiolinks is using GRCh37.p13 and for 
harmonized data (data aligned to hg38) now it is using Gencode version 36.

Unfortunately, some of the updates changes/remove gene symbols, change coordinates, etc. 
Which might introduce some loss of data. For example, if the gene was removed we cannot map
it anymore and that information will be lost in the `SummarizedExperiment`.

If you set `SummarizedExperiment` to `FALSE`, you will get the data unmodified 
just as they are in the files and ad your own annotation.

Also, there are no updated for DNA methylation data. But the last metadata available can be found
here: [http://zwdzwd.github.io/InfiniumAnnotation](http://zwdzwd.github.io/InfiniumAnnotation)

</div>
</div>


<div class="panel panel-danger">
<div class="panel-heading">simpleWarning in file.create(to[okay]) error </div>
<div class="panel-body">

If you received the warning/error `simpleWarning in file.create(to[okay])` 
try setting `directory`
as described by some users:
https://github.com/BioinformaticsFMRP/TCGAbiolinks/issues/153#issuecomment-856385673

in `GDCprepare` and `GDCdownload`
```
<simpleWarning in file.create(to[okay]): cannot create file ... reason 'No such file or directory'>
```

</div>
</div>


## Arguments 

### `GDCdownload`

| Argument 	| Description	|
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| query           | A query for GDCquery function        |
| token.file      | Token file to download controlled data (only for method = "client")           |
| method          | Uses the API (POST method) or gdc client tool. Options "api", "client". API is faster, but the data might get corrupted in the download, and it might need to be executed again     |
| directory       | Directory/Folder where the data was downloaded. Default: GDCdata         |
| files.per.chunk | This will make the API method only download n (files.per.chunk) files at a time. This may reduce the download problems when the data size is too large. Expected a integer number (example files.per.chunk = 6) |

### `GDCprepare`
| Argument 	| Description	|
|-------------------------------	|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------	|
| query 	| A query for GDCquery function 	|
| save 	| Save result as RData object? 	|
| save.filename 	| Name of the file to be save if empty an automatic will be created 	|
| directory 	| Directory/Folder where the data was downloaded. Default: GDCdata 	|
| summarizedExperiment 	| Create a summarizedExperiment? Default TRUE (if possible) 	|
| remove.files.prepared 	| Remove the files read? Default: FALSE This argument will be considered only if save argument is set to true 	|
| add.gistic2.mut 	| If a list of genes (gene symbol) is given, columns with gistic2 results from GDAC firehose (hg19) and a column indicating if there is or not mutation in that gene (hg38) (TRUE or FALSE - use the MAF file for more information) will be added to the sample matrix in the summarized Experiment object. 	|
| mut.pipeline 	| If add.gistic2.mut is not NULL this field will be taken in consideration. Four separate variant calling pipelines are implemented for GDC data harmonization. Options: muse, varscan2, somaticsniper, MuTect2. For more information: https://gdc-docs.nci.nih.gov/Data/Bioinformatics_Pipelines/DNA_Seq_Variant_Calling_Pipeline/ 	|
| mutant_variant_classification 	| List of mutant_variant_classification that will be consider a sample mutant or not. Default: "Frame_Shift_Del", "Frame_Shift_Ins", "Missense_Mutation", "Nonsense_Mutation", "Splice_Site", "In_Frame_Del", "In_Frame_Ins", "Translation_Start_Site", "Nonstop_Mutation" 	|

## Search and download data from legacy database using GDC api method

In this example we will download gene expression data from legacy database (data 
aligned against genome of reference hg19) using GDC api method and  we will show object data and metadata.
```{r results = 'hide', message=FALSE, warning=FALSE, eval = F}
query <- GDCquery(
    project = "TCGA-GBM",
    data.category = "Gene expression",
    data.type = "Gene expression quantification",
    platform = "Illumina HiSeq", 
    file.type  = "normalized_results",
    experimental.strategy = "RNA-Seq",
    barcode = c("TCGA-14-0736-02A-01R-2005-01", "TCGA-06-0211-02A-02R-2005-01"),
    legacy = TRUE
)
GDCdownload(
    query = query, 
    method = "api", 
    files.per.chunk = 10
)
data <- GDCprepare(query = query)
```

```{r message=FALSE, warning=FALSE, include=FALSE}
data <- gbm.exp.legacy
```

```{r message=FALSE, warning=FALSE}
# Gene expression aligned against hg19.
datatable(
    as.data.frame(colData(data)), 
    options = list(scrollX = TRUE, keys = TRUE, pageLength = 5), 
    rownames = FALSE)
# Only first 20 rows to make render faster
datatable(
    assay(data)[1:20,], 
    options = list(scrollX = TRUE, keys = TRUE, pageLength = 5), 
    rownames = TRUE
)

rowRanges(data)
```


## Search and download data for two samples from database

In this example we will download gene expression quantification from harmonized database 
(data aligned against genome of reference hg38).
Also, it shows the object data and metadata.

```{r results = 'hide', message=FALSE, warning=FALSE, eval=FALSE}
# Gene expression aligned against hg38
query <- GDCquery(
    project = "TCGA-GBM",
    data.category = "Transcriptome Profiling",
    data.type = "Gene Expression Quantification", 
    workflow.type = "STAR - Counts",
    barcode = c("TCGA-14-0736-02A-01R-2005-01", "TCGA-06-0211-02A-02R-2005-01")
)
GDCdownload(query = query)
data <- GDCprepare(query = query)
```

```{r message=FALSE, warning=FALSE, include=FALSE}
data <- gbm.exp.harmonized
```

```{r message=FALSE, warning=FALSE}
datatable(
    as.data.frame(colData(data)), 
    options = list(scrollX = TRUE, keys = TRUE, pageLength = 5), 
    rownames = FALSE
)

datatable(
    assay(data)[1:20,], 
    options = list(scrollX = TRUE, keys = TRUE, pageLength = 5), 
    rownames = TRUE
)

rowRanges(data)
```


# `GDCprepare`: Outputs

This function is still under development, it is not working for all cases. See the tables below with the status.
Examples of query, download, prepare can be found in this [gist](https://gist.github.com/tiagochst/a701bad3fa3800ade7063760755e0aad).

## Harmonized data

| Data.category               | Data.type                         | Workflow Type   | Output                                                                      |
|-----------------------------|-----------------------------------|-----------------|-----------------------------------------------------------------------------|
| Transcriptome Profiling     | Gene Expression Quantification    | STAR - Counts  | Dataframe or SummarizedExperiment|
|                             | Isoform Expression Quantification | Not needed      |        |
|                             | miRNA Expression Quantification   | Not needed      | Dataframe |
| Copy number variation       | Copy Number Segment               |                 | Dataframe  |
|                             | Masked Copy Number Segment        |                 | Dataframe  |
|                             | Gene Level Copy Number      |        | Dataframe  |
| DNA Methylation | Methylation Beta Value           |                 |   Dataframe or SummarizedExperiment   |
| Simple Nucleotide Variation | Masked Somatic Mutation           |                 |  Dataframe |
| Raw Sequencing Data         |               |       |          |
| Biospecimen                 | Slide Image        |         |         |
| Biospecimen                 | Biospecimen Supplement            |      |             |
| Clinical                    |                |       |                  |

## Legacy data
| Data.category               | Data.type                         | Platform                            | file.type          | Status          |
|-----------------------------|-----------------------------------|-------------------------------------|--------------------|-----------------|
| Transcriptome Profiling     |                                   |                                     |                    |                 |
| Copy number variation       | -                                 | Affymetrix SNP Array 6.0            | nocnv_hg18.seg     | Working         |
|                             | -                                 | Affymetrix SNP Array 6.0            | hg18.seg           | Working         |
|                             | -                                 | Affymetrix SNP Array 6.0            | nocnv_hg19.seg     | Working         |
|                             | -                                 | Affymetrix SNP Array 6.0            | hg19.seg           | Working         |
|                             | -                                 | Illumina HiSeq                      | Several            | Working         |
| Simple Nucleotide Variation | Simple somatic mutation           |                                     |                    |                 |
| Raw Sequencing Data         |                                   |                                     |                    |                 |
| Biospecimen                 |                                   |                                     |                    |                 |
| Clinical                    |                                   |                                     |                    |                 |
| Protein expression          |                                   | MDA RPPA Core                       | -                  | Working         |
| Gene expression             | Gene expression quantification    | Illumina HiSeq                      | normalized_results | Working         |
|                             |                                   | Illumina HiSeq                      | results            | Working         |
|                             |                                   | HT_HG-U133A                         | -                  | Working         |
|                             |                                   | AgilentG4502A_07_2                  | -                  | Data frame only |
|                             |                                   | AgilentG4502A_07_1                  | -                  | Data frame only |
|                             |                                   | HuEx-1_0-st-v2                      | FIRMA.txt          | Not Preparing   |
|                             |                                   |                                     | gene.txt           | Not Preparing   |
|                             | Isoform expression quantification |                                     |                    |                 |
|                             | miRNA gene quantification         |                                     |                    |                 |
|                             | Exon junction quantification      |                                     |                    |                 |
|                             | Exon quantification               |                                     |                    |                 |
|                             | miRNA isoform quantification      |                                     |                    |                 |
|                             |                                   |                                     |                    |                 |
| DNA methylation             |                                   | Illumina Human Methylation 450      | Not used           | Working         |
|                             |                                   | Illumina Human Methylation 27       | Not used           | Working         |
|                             |                                   | Illumina DNA Methylation OMA003 CPI | Not used           | Working         |
|                             |                                   | Illumina DNA Methylation OMA002 CPI | Not used           | Working         |
|                             |                                   | Illumina Hi Seq                     |                    | Not  working    |
| Raw Microarray Data         |                                   |                                     |                    |                 |
| Structural Rearrangement    |                                   |                                     |                    |                 |
| Other                       |                                   |                                     |                    |                 |



# Examples


## Harmonized database: data aligned against hg38


### Copy Number Variation

#### Copy Number Segment
```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-ACC", 
    data.category = "Copy Number Variation",
    data.type = "Copy Number Segment",
    barcode = c( "TCGA-OR-A5KU-01A-11D-A29H-01", "TCGA-OR-A5JK-01A-11D-A29H-01")
)
GDCdownload(query)
data <- GDCprepare(query)
```


#### Gene Level Copy Number

```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-ACC",
    data.category = "Copy Number Variation",
    data.type = "Gene Level Copy Number",              
    access = "open"
)
GDCdownload(query)
data <- GDCprepare(query)
```


#### Allele-specific Copy Number Segment

```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-ACC",
    data.category = "Copy Number Variation",
    data.type = "Allele-specific Copy Number Segment",              
    access = "open"
)
GDCdownload(query)
data <- GDCprepare(query)
```

#### Masked Copy Number Segment

```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-ACC",
    data.category = "Copy Number Variation",
    data.type = "Masked Copy Number Segment",              
    access = "open"
)
GDCdownload(query)
data <- GDCprepare(query)
```

### Transcriptome Profiling 

#### Gene Expression Quantification

For more examples, please check: http://rpubs.com/tiagochst/TCGAbiolinks_RNA-seq_new_projects

```{r, eval = FALSE}
# mRNA pipeline: https://gdc-docs.nci.nih.gov/Data/Bioinformatics_Pipelines/Expression_mRNA_Pipeline/
query.exp.hg38 <- GDCquery(
    project = "TCGA-GBM", 
    data.category = "Transcriptome Profiling", 
    data.type = "Gene Expression Quantification", 
    workflow.type = "STAR - Counts",
    barcode =  c("TCGA-14-0736-02A-01R-2005-01", "TCGA-06-0211-02A-02R-2005-01")
)
GDCdownload(query.exp.hg38)
expdat <- GDCprepare(
    query = query.exp.hg38,
    save = TRUE, 
    save.filename = "exp.rda"
)
```


#### miRNA Expression Quantification
```{r, eval = FALSE}
library(TCGAbiolinks)
query.mirna <- GDCquery(
    project = "TARGET-AML", 
    experimental.strategy = "miRNA-Seq",
    data.category = "Transcriptome Profiling", 
    barcode = c("TARGET-20-PATDNN","TARGET-20-PAPUNR"),
    data.type = "miRNA Expression Quantification"
)
GDCdownload(query.mirna)
mirna <- GDCprepare(
    query = query.mirna,
    save = TRUE, 
    save.filename = "mirna.rda"
)

```


#### Isoform Expression Quantification
```{r, eval = FALSE}

query.isoform <- GDCquery(
    project = "TARGET-AML", 
    experimental.strategy = "miRNA-Seq",
    data.category = "Transcriptome Profiling", 
    barcode = c("TARGET-20-PATDNN","TARGET-20-PAPUNR"),
    data.type = "Isoform Expression Quantification"
)
GDCdownload(query.isoform)

isoform <- GDCprepare(
    query = query.isoform,
    save = TRUE, 
    save.filename = "mirna-isoform.rda"
)
```

### DNA methylation

#### Beta-values

```{r, eval = FALSE}
query_met.hg38 <- GDCquery(
    project = "TCGA-BRCA", 
    data.category = "DNA Methylation", 
    data.type = "Methylation Beta Value",
    platform = "Illumina Human Methylation 27", 
    barcode = c("TCGA-B6-A0IM")
)
GDCdownload(query_met.hg38)
data.hg38 <- GDCprepare(query_met.hg38)

query_met.hg38 <- GDCquery(
    project= "TCGA-LGG", 
    data.category = "DNA Methylation", 
    data.type = "Methylation Beta Value",
    platform = "Illumina Human Methylation 450", 
    barcode = c("TCGA-HT-8111-01A-11D-2399-05","TCGA-HT-A5R5-01A-11D-A28N-05")
)
GDCdownload(query_met.hg38)
data.hg38 <- GDCprepare(query_met.hg38)


query_met.hg38 <- GDCquery(
    project= "HCMI-CMDC", 
    data.category = "DNA Methylation", 
    data.type = "Methylation Beta Value",
    platform = "Illumina Methylation Epic", 
    barcode = c("HCM-BROD-0045")
)
GDCdownload(query_met.hg38)
data.hg38 <- GDCprepare(query_met.hg38)
```

#### IDAT files

```{R, eval = FALSE}
query <- GDCquery(
    project = "TCGA-BRCA",
    data.category = "DNA Methylation",
    data.type = "Masked Intensities",
    platform = "Illumina Human Methylation 27",
    legacy = FALSE
)
GDCdownload(query, files.per.chunk=10)
betas <- GDCprepare(query)

query <- GDCquery(
    project = "HCMI-CMDC",
    data.category = "DNA Methylation",
    data.type = "Masked Intensities",
    platform = "Illumina Methylation Epic",
    legacy = FALSE
)
GDCdownload(query, files.per.chunk=10)
betas <- GDCprepare(query)


query <- GDCquery(
    project = "CPTAC-3",
    data.category = "DNA Methylation",
    data.type = "Masked Intensities",
    platform = "Illumina Methylation Epic",
    legacy = FALSE
)
GDCdownload(query, files.per.chunk=10)
betas <- GDCprepare(query)

query <- GDCquery(
    project = "TCGA-BRCA",
    data.category = "DNA Methylation",
    data.type = "Masked Intensities",
    platform = "Illumina Methylation Epic",
    legacy = FALSE
)
GDCdownload(query, files.per.chunk=10)
betas <- GDCprepare(query)


```


### Proteome Profiling 

#### Protein Expression Quantification

```{r, eval = FALSE}
query.rppa <- GDCquery(
    project = "TCGA-ESCA", 
    data.category = "Proteome Profiling",
    data.type = "Protein Expression Quantification"
)
GDCdownload(query.rppa) 
rppa <- GDCprepare(query.rppa) 
```

### Clinical

```{R, eval = FALSE}

query <- GDCquery(
    project = "TCGA-COAD",
    data.category = "Clinical",
    data.type = "Clinical Supplement",
    data.format = "BCR XML",
    barcode = "TCGA-A6-5664"
)
GDCdownload(query)
drug <- GDCprepare_clinic(query,"drug")

query <- GDCquery(
    project = "TCGA-COAD",
    data.category = "Clinical",
    data.type = "Clinical Supplement",
    data.format = "BCR OMF XML",
    barcode = "TCGA-AD-6964"
)
GDCdownload(query)


query <- GDCquery(
    project = "TCGA-ACC", 
    data.category = "Clinical",
    data.type = "Clinical Supplement", 
    data.format = "BCR Biotab"
)
GDCdownload(query)
clinical.BCRtab.all <- GDCprepare(query)
names(clinical.BCRtab.all)

query <- GDCquery(
    project = "TCGA-ACC", 
    data.category = "Clinical",
    data.type = "Clinical Supplement", 
    data.format = "BCR Biotab",
    file.type = "radiation"
)
GDCdownload(query)
clinical.BCRtab.radiation <- GDCprepare(query)
```

### Simple Nucleotide Variation 

#### Masked Somatic Mutation

For more information please check:
https://docs.gdc.cancer.gov/Data/Bioinformatics_Pipelines/DNA_Seq_Variant_Calling_Pipeline/

```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-HNSC", 
    data.category = "Simple Nucleotide Variation",
    data.type = "Masked Somatic Mutation",
    access = "open"
)
GDCdownload(query)
maf <- GDCprepare(query)
```

### Single cell

GDC Single Cell RNA-Seq information: 
https://docs.gdc.cancer.gov/Data/Bioinformatics_Pipelines/Expression_mRNA_Pipeline/#scrna-seq-pipeline-single-nuclei

```{r, eval = FALSE}
query.sc.analysis <- GDCquery(
    project = "CPTAC-3", 
    data.category = "Transcriptome Profiling",
    legacy = FALSE,
    access = "open",
    data.type = "Single Cell Analysis",
    data.format =  "TSV"
)  
GDCdownload(query.sc.analysis)
Single.Cell.Analysis.list <- GDCprepare(query.sc.analysis)
```

```{r, eval = FALSE,include=F}
query.hdF5 <- GDCquery(
    project = "CPTAC-3", 
    data.category = "Transcriptome Profiling",
    legacy = FALSE,
    access = "open",
    data.type = "Single Cell Analysis",
    barcode = c("CPT0167860015","CPT0206880004"),
    data.format =  "HDF5"
)  
GDCdownload(query.hdF5)
df.HDF5 <- GDCprepare(query.hdF5)
```

```{r, eval = FALSE}
query.raw.counts <- GDCquery(
    project = "CPTAC-3", 
    data.category = "Transcriptome Profiling",
    legacy = FALSE,
    access = "open",
    data.type = "Gene Expression Quantification",
    barcode = c("CPT0167860015","CPT0206880004"),
    workflow.type = "CellRanger - 10x Raw Counts"
)  
GDCdownload(query.raw.counts)
raw.counts.list <- GDCprepare(query.raw.counts)
```

```{r, eval = FALSE}
query.filtered.counts <- GDCquery(
    project = "CPTAC-3", 
    data.category = "Transcriptome Profiling",
    legacy = FALSE,
    access = "open",
    data.type = "Gene Expression Quantification",
    barcode = c("CPT0167860015","CPT0206880004"),
    workflow.type = "CellRanger - 10x Filtered Counts"
)  
GDCdownload(query.filtered.counts)
filtered.counts.list <- GDCprepare(query.filtered.counts)
```


```{r, eval = FALSE}
query.sc.dea <- GDCquery(
    project = "CPTAC-3", 
    data.category = "Transcriptome Profiling",
    legacy = FALSE,
    access = "open",
    data.type = "Differential Gene Expression",
    barcode = c("CPT0167860015","CPT0206880004"),
    workflow.type = "Seurat - 10x Chromium"
)  
GDCdownload(query.sc.dea)
sc.dea.list <- GDCprepare(query.sc.dea)
```

## Legacy archive: data aligned against hg19

### DNA methylation: Get all TCGA IDAT files

```{r message=FALSE, warning=FALSE, eval =FALSE}
#-------------------------------------------------------
# Example to idat files from TCGA projects
#-------------------------------------------------------
projects <- TCGAbiolinks:::getGDCprojects()$project_id
projects <- projects[grepl('^TCGA',projects,perl=T)]
match.file.cases.all <- NULL
for(proj in projects){
    print(proj)
    query <- GDCquery(
        project = proj,
        data.category = "Raw microarray data",
        data.type = "Raw intensities", 
        experimental.strategy = "Methylation array", 
        legacy = TRUE,
        file.type = ".idat",
        platform = "Illumina Human Methylation 450"
    )
    match.file.cases <- getResults(query,cols=c("cases","file_name"))
    match.file.cases$project <- proj
    match.file.cases.all <- rbind(match.file.cases.all,match.file.cases)
    tryCatch(
        GDCdownload(query, method = "api", files.per.chunk = 20),
        error = function(e) GDCdownload(query, method = "client")
    )
}
# This will create a map between idat file name, cases (barcode) and project
readr::write_tsv(match.file.cases.all, path =  "idat_filename_case.txt")
# code to move all files to local folder
for(file in dir(".",pattern = ".idat", recursive = T)){
    TCGAbiolinks::move(file,basename(file))
}
```


### DNA methylation

```{r, eval = FALSE}
query_meth.hg19 <- GDCquery(
    project= "TCGA-LGG", 
    data.category = "DNA methylation", 
    platform = "Illumina Human Methylation 450", 
    barcode = c("TCGA-HT-8111-01A-11D-2399-05","TCGA-HT-A5R5-01A-11D-A28N-05"), 
    legacy = TRUE
)
GDCdownload(query_meth.hg19)
data.hg19 <- GDCprepare(query_meth.hg19)
```


### Protein expression
```{r, eval = FALSE}
query <- GDCquery(
    project = "TCGA-GBM",
    data.category = "Protein expression",
    legacy = TRUE, 
    barcode = c("TCGA-OX-A56R-01A-21-A44T-20","TCGA-08-0357-01A-21-1898-20")
)
GDCdownload(query)
data <- GDCprepare(
    query, save = TRUE, 
    save.filename = "gbmProteinExpression.rda",
    remove.files.prepared = TRUE
)
```


### Gene expression
```{r, eval = FALSE}
# Aligned against Hg19
query.exp.hg19 <- GDCquery(
    project = "TCGA-GBM",
    data.category = "Gene expression",
    data.type = "Gene expression quantification",
    platform = "Illumina HiSeq", 
    file.type  = "normalized_results",
    experimental.strategy = "RNA-Seq",
    barcode = c("TCGA-14-0736-02A-01R-2005-01", "TCGA-06-0211-02A-02R-2005-01"),
    legacy = TRUE
)
GDCdownload(query.exp.hg19)
data <- GDCprepare(query.exp.hg19)
```