Skip to content

Commit

Permalink
Merge pull request #48 from msk-access/develop
Browse files Browse the repository at this point in the history
Automate to plot
  • Loading branch information
rhshah authored Apr 2, 2021
2 parents 415937f + ba3f285 commit cc00ff3
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 471 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ vignettes/*.pdf
# R Environment Variables
.Renviron

# gitbook
docs/*


# MAC
.DS_Store
4 changes: 2 additions & 2 deletions R/compile_reads.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ compile_reads <- function(
cmo_patient_id == x,
# plasma bams -- duplex and simplex bam
.(
Sample_Barcode = cmo_sample_id_plasma, duplex_bam = bam_path_plasma_duplex,
Sample_Barcode = as.character(cmo_sample_id_plasma), duplex_bam = bam_path_plasma_duplex,
simplex_bam = bam_path_plasma_simplex, cmo_patient_id, Sample_Type = "duplex", dmp_patient_id
)
] %>%
Expand All @@ -94,7 +94,7 @@ compile_reads <- function(
cmo_patient_id == x&paired=='Paired',
# buffy coat + DMP bams -- standard bam only
.(
Sample_Barcode = cmo_sample_id_normal, standard_bam = bam_path_normal,
Sample_Barcode = as.character(cmo_sample_id_normal), standard_bam = bam_path_normal,
cmo_patient_id, Sample_Type = "unfilterednormal", dmp_patient_id
)
]),
Expand Down
3 changes: 2 additions & 1 deletion R/filter_calls.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ filter_calls = function(
group_by(Hugo_Symbol,Chromosome,Start_Position,End_Position,Variant_Classification,Reference_Allele,Tumor_Seq_Allele2) %>%
summarise(duplex_support_num = length(which(t_alt_count >= 2))) %>%
filter(duplex_support_num > 0,.preserve = T) %>%
transmute(Hugo_Symbol, Chromosome=as.character(Chromosome), Start_Position, End_Position, Variant_Classification, Reference_Allele, Tumor_Seq_Allele2, duplex_support_num) %>%
data.table()

# for each patient produce the correct results ----------------------------
Expand Down Expand Up @@ -104,7 +105,7 @@ filter_calls = function(
maf.file = maf.file %>%
mutate(t_var_freq = paste0(t_alt_count,'/',t_total_count,'(',round(t_alt_count/t_total_count,4),')')) %>%
transmute(Hugo_Symbol,Tumor_Sample_Barcode,Chromosome = as.character(Chromosome),Start_Position,End_Position,Variant_Classification,
HGVSp_Short,Reference_Allele,Tumor_Seq_Allele2,t_var_freq,ExAC_AF) %>%
HGVSp_Short=as.character(HGVSp_Short),Reference_Allele,Tumor_Seq_Allele2,t_var_freq,ExAC_AF) %>%
data.table()

return(maf.file)
Expand Down
3 changes: 1 addition & 2 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
* [Filter Calls](analysis/filter-calls.md)
* [SV Incorporation](analysis/sv-incorporation.md)
* [CNA Processing](analysis/cna-processing.md)
* [Plot All Events](analysis/plot-all-events.md)
* [Create Patient Report](analysis/create-report.md)
* [Intermediate File Organization](analysis/intermediate-file-organization.md)

56 changes: 56 additions & 0 deletions docs/analysis/create-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
description: Step 5 -- Create a report showing genomic alteration data for all samples of a patient.
---

# Patient report

The final step takes the processed data from the previous steps and plots the genomic alterations over all samples of each patient. The report includes several sections with interactive plots:

### 1. Patient information
The first section displays the patient ID, DMP id (if provided), tumor type (if provided), and each sample. Any provided sample meta-information is also display for each sample.

### 2. Plot of SNV variant allele frequencies
The second section shows SNV/INDEL events are plotted out by VAFs over timepoints. Above the panel it also display sample timepoint annotation, such as treatment information (if provided). If you provide IMPACT sample information, it will segregate each mutation by whether it is known to be clonal in IMPACT, subclonal in IMPACT, or is present in ACCESS only. There are additional tabs that display a table of mutation data and methods description.

### 3. Plot of copy number alterations
The third section shows CNAs that are plotted by fold-change\(fc\) for each ACCESS sample and gene. If there are no CNAs, then this section is not displayed.

### 4. Plot of clonal SNV/INDEL VAFs adjusted for copy number
If you provided an IMPACT sample, this last section will show SNV/INDEL events that are plotted out by VAFs over timepoints. However, the VAFs are corrected for IMPACT copy number information. Details of the method are shown under the `Description` tab in this section. Similar to section 2, sample timepoint annotations are shown above the plot.

### Usage

```text
Rscript reports/create_report.R -h
usage: create_report.R [-h] -t TEMPLATE -p PATIENT_ID -r RESULTS -rc
CNA_RESULTS_DIR -tt TUMOR_TYPE -m METADATA [-d DMP_ID]
[-ds DMP_SAMPLE_ID] [-dm DMP_MAF] [-o OUTPUT]
optional arguments:
-h, --help show this help message and exit
-t TEMPLATE, --template TEMPLATE
Path to Rmarkdown template file.
-p PATIENT_ID, --patient-id PATIENT_ID
Patient ID
-r RESULTS, --results RESULTS
Path to CSV file containing mutation and genotype
results for the patient.
-rc CNA_RESULTS_DIR, --cna-results-dir CNA_RESULTS_DIR
Path to directory containing CNA results for the
patient.
-tt TUMOR_TYPE, --tumor-type TUMOR_TYPE
Tumor type
-m METADATA, --metadata METADATA
Path to file containing meta data. Should contain a
'cmo_sample_id_plasma', 'sex', and 'collection_date'
columns. Can also optionally include a 'timepoint'
column (e.g. for treatment information).
-d DMP_ID, --dmp-id DMP_ID
DMP patient ID (optional).
-ds DMP_SAMPLE_ID, --dmp-sample-id DMP_SAMPLE_ID
DMP sample ID (optional).
-dm DMP_MAF, --dmp-maf DMP_MAF
Path to DMP MAF file (optional).
-o OUTPUT, --output OUTPUT
Output file
```
50 changes: 0 additions & 50 deletions docs/analysis/plot-all-events.md

This file was deleted.

48 changes: 48 additions & 0 deletions reports/create_report.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env Rscript

library(knitr)
library(rmarkdown)
library(argparse)


parser <- ArgumentParser()

parser$add_argument("-t", "--template", required=T, help="Path to Rmarkdown template file.")
parser$add_argument("-p", "--patient-id", required=T, help="Patient ID")
parser$add_argument("-r", "--results", required=T, help="Path to CSV file containing mutation and genotype results for the patient.")
parser$add_argument("-rc", "--cna-results-dir", required=T, help="Path to directory containing CNA results for the patient.")
parser$add_argument("-tt", "--tumor-type", required=T, help="Tumor type")
parser$add_argument("-m", "--metadata", required=T, help="Path to file containing meta data for each sample. Should contain a \'cmo_sample_id_plasma\', \'sex\', and \'collection_date\' columns. Can also optionally include a \'timepoint\' column (e.g. for treatment information).")
parser$add_argument("-d", "--dmp-id", help="DMP patient ID (optional).")
parser$add_argument("-ds", "--dmp-sample-id", help="DMP sample ID (optional).")
parser$add_argument("-dm", "--dmp-maf", help="Path to DMP MAF file (optional).")
parser$add_argument("-o", "--output", help="Output file")

args <- parser$parse_args()

dmp_maf <- NULL
if (!is.null(args$dmp_maf)) {
dmp_maf <- normalizePath(args$dmp_maf)
}


input_text <- knitr::knit_expand(
normalizePath(args$template),
PATIENT_ID=args$patient_id,
RESULTS=normalizePath(args$results),
CNA_RESULTS_DIR=normalizePath(args$cna_results_dir),
TUMOR_TYPE=args$tumor_type,
DMP_ID=args$dmp_id,
DMP_SAMPLE_ID=args$dmp_sample_id,
DMP_MAF_PATH=dmp_maf,
METADATA=normalizePath(args$metadata)
)

tmp <- tempfile(fileext = ".Rmd")
cat(input_text, file = tmp)

rmarkdown::render(
tmp,
output_format = "html_document",
output_dir = normalizePath(dirname(args$output)),
output_file=args$output)
7 changes: 0 additions & 7 deletions reports/knitr.R

This file was deleted.

Loading

0 comments on commit cc00ff3

Please sign in to comment.