data-raw/ObjectsForTests.R

# CREATE INPUT OBJECT vcfs_NoCancer_ForPanel TO TEST applySimulatedPanel FUNCTION 
################################################################################

# Specify human assembly of reference, either "hg19" or "hg38"
assembly <- "hg19"

# Load built-in list of 4 vcfs generated by WES
data(ExampleWESvcfs)

# Load the design of the WES
data(ExampleWESdesign)

# Read the design of the gene panel that you want to simulate
data(ExamplePaneldesign)

# Filter for gene panel simulation (remove known cancer mutations)
vcfs_NoCancer_ForPanel <- applyFilters(ExampleWESvcfs, 
                                       assembly="hg19", 
                                       design=ExamplePaneldesign, 
                                       vaf.cutoff=NULL, 
                                       remove.cancer=T, 
                                       tsList=NULL, 
                                       variantType=NULL)
usethis::use_data(vcfs_NoCancer_ForPanel, internal=FALSE, compress="gzip")


# CREATE INPUT OBJECT vcfs_all TO TEST applyTMB FUNCTION 
################################################################################


# Read vcf filenames
vcf_files <- list(Horizon5="Horizon5_ExamplePanel.vcf", 
                HorizonFFPEmild="HorizonFFPEmild_ExamplePanel.vcf")
# For each vcf file, get the absolute path
vcf_files <- lapply(vcf_files
                    , function(x) system.file("extdata", x, package = "TMBleR", mustWork = TRUE))
# Read in the files
vcfs <- readVcfFiles(vcf_files, assembly = "hg19")
# Read in input the panel sequencing design
designPanel <- readDesign(system.file("extdata"
                                      , "ExamplePanel_GeneIDs_Only10GenesForTest.txt"
                                      , package = "TMBleR"
                                      , mustWork = TRUE)
                                      , assembly = "hg19"
                                      , ids= "entrezgene_id")

# Apply different filters
# Filter 1: remove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes)
vcfs_NoCancer <- applyFilters(  vcfs
                                , assembly="hg19"
                                , design=designPanel
                                , vaf.cutoff=NULL
                                , remove.cancer=T
                                , tsList=NULL
                                , variantType=NULL)

# Filter 2: remove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes) and synonymous 
# mutations
vcfs_NoCancer_NoSynonymous <- applyFilters(vcfs, 
                                           assembly="hg19",
                                           design=designPanel, 
                                           vaf.cutoff=NULL, 
                                           remove.cancer=T, 
                                           tsList=NULL, 
                                           variantType=c("synonymous"))

# Concatenate all filtered and unfiltered vcfs
vcfs_all <- c(vcfs_NoCancer, 
              vcfs_NoCancer_NoSynonymous )
usethis::use_data(vcfs_all, internal=FALSE, compress="gzip")


# CREATE INPUT OBJECTS TMBs_SimulatedPanel AND TMBs_WES TO TEST 
# correlateTMBvalues AND plotCorrelation FUNCTIONS 
################################################################################
# Specify human assembly of reference, either "hg19" or "hg38"
assembly <- "hg19"

# Load built-in list of 4 vcfs generated by WES
data(ExampleWESvcfs)

# Load the design of the WES
data(ExampleWESdesign)

# Load the design of the gene panel that you want to simulate
data(ExamplePaneldesign)

# Filter for gene panel simulation (remove known cancer mutations)
vcfs_NoCancer_ForPanel <- applyFilters(ExampleWESvcfs, 
                                       assembly="hg19", 
                                       design=ExamplePaneldesign, 
                                       vaf.cutoff=NULL, 
                                       remove.cancer=T, 
                                       tsList=NULL, 
                                       variantType=NULL)

# Filter for original WES (remove synonymous mutations)
vcfs_NoSynonymous_WES <- applyFilters(ExampleWESvcfs, 
                                      assembly="hg19", 
                                      design=ExampleWESdesign, 
                                      vaf.cutoff=NULL, 
                                      remove.cancer=F, 
                                      tsList=NULL, 
                                      variantType=c("synonymous"))

# Subset the WES dataset so that it will only contain variants in the regions t
# argeted by the panel you want to simulate
SimulatedPanel_NoCancer <- applySimulatePanel(vcfs_NoCancer_ForPanel, 
                                              WES.design=ExampleWESdesign,
                                              panel.design=ExamplePaneldesign, 
                                              assembly="hg19")

# Perform TMB quantification on the simulated panel
TMBs_SimulatedPanel <- applyTMB(SimulatedPanel_NoCancer, assembly="hg19")

# Perform TMB quantification on the original Whole Exome sequencing
TMBs_WES <- applyTMB(vcfs_NoSynonymous_WES, assembly="hg19")

# Save in RDS object
usethis::use_data(TMBs_SimulatedPanel, internal=FALSE, compress="gzip")
usethis::use_data(TMBs_WES, internal=FALSE, compress="gzip")


# CREATE INPUT OBJECTS TMB_res TO TEST plotTMB FUNCTION 
################################################################################
# Read vcf filenames
vcf_files <- list(Horizon5="Horizon5_ExamplePanel.vcf", 
                  HorizonFFPEmild="HorizonFFPEmild_ExamplePanel.vcf")
# For each vcf file, get the absolute path
vcf_files <- lapply(vcf_files
                    , function(x) system.file("extdata", x, package = "TMBleR", mustWork = TRUE))
# Read in the files
vcfs <- readVcfFiles(vcf_files, assembly = "hg19")

# Read in input the panel sequencing design
designPanel <- readDesign(system.file("extdata"
                                      , "ExamplePanel_GeneIDs.txt"
                                      , package = "TMBleR"
                                      , mustWork = TRUE)
                                      , assembly = "hg19"
                                      , ids = "entrezgene_id")

# Apply different filters
# Filter 1: remove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes)
vcfs_NoCancer <- applyFilters(  vcfs
                                , assembly="hg19"
                                , design=ExamplePaneldesign
                                , vaf.cutoff=NULL
                                , remove.cancer=T
                                , tsList=NULL
                                , variantType=NULL)

# Filter 2: remove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes) and synonymous 
# mutations
vcfs_NoCancer_NoSynonymous <- applyFilters(vcfs, 
                                           assembly="hg19",
                                           design=ExamplePaneldesign, 
                                           vaf.cutoff=NULL, 
                                           remove.cancer=T, 
                                           tsList=NULL, 
                                           variantType=c("synonymous"))

# Filter 3: remove synonymous mutations
vcfs_NoSynonymous <- applyFilters(vcfs, 
                                  assembly="hg19", 
                                  design=ExamplePaneldesign, 
                                  vaf.cutoff=NULL, 
                                  remove.cancer=F, 
                                  tsList=NULL, 
                                  variantType=c("synonymous"))

# Filter 4: remove synonymous mutations and mutations with variant allele 
# frequency < 0.05
vcfs_NoSynonymous_VAFFilter <- applyFilters(vcfs, 
                                            assembly="hg19", 
                                            design=ExamplePaneldesign, 
                                            vaf.cutoff=0.05, 
                                            remove.cancer=F, 
                                            tsList=NULL, 
                                            variantType=c("synonymous"))

# Filter 5: remove mutations with variant allele frequency < 0.05
vcfs_VAFFilter <- applyFilters(vcfs, 
                               assembly="hg19", 
                               design=ExamplePaneldesign, 
                               vaf.cutoff=0.05,
                               remove.cancer=F, 
                               tsList=NULL, 
                               variantType=NULL)

# Filter 6: reemove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes) and mutations with 
# variant allele frequency < 0.05
vcfs_NoCancer_VAFFilter <- applyFilters(vcfs, 
                                        assembly="hg19", 
                                        design=ExamplePaneldesign, 
                                        vaf.cutoff=0.05, 
                                        remove.cancer=T, 
                                        tsList=NULL, 
                                        variantType=NULL)

# Filter 7: remove known cancer mutations (e.g. coding mutations described in 
# COSMIC and truncating mutations in tumor suppressor genes), synonymous 
# mutations and mutations with variant allele frequency < 0.05
vcfs_NoCancer_VAFFilter_NoSynonymous <- applyFilters(vcfs, 
                                                     assembly="hg19", 
                                                     design=ExamplePaneldesign, 
                                                     vaf.cutoff=0.05, 
                                                     remove.cancer=T, 
                                                     tsList=NULL, 
                                                     variantType=c("synonymous"))

# Use the applyInputToTMB() function to format an unfiltered vcs as required in 
# input by the applyTMB function, to perform TMB quantification
vcfs_nonfiltered <- applyInputToTMB(vcfs, design=ExamplePaneldesign)

# Concatenate all filtered and unfiltered vcfs
vcfs_all <- c(vcfs_NoCancer, 
              vcfs_NoCancer_NoSynonymous, 
              vcfs_NoSynonymous, 
              vcfs_NoSynonymous_VAFFilter, 
              vcfs_VAFFilter, 
              vcfs_NoCancer_VAFFilter, 
              vcfs_NoCancer_VAFFilter_NoSynonymous, 
              vcfs_nonfiltered )

# Perform TMB quantification
TMB_res=applyTMB(vcfs_all, assembly = "hg19")
usethis::use_data(TMB_res, internal=FALSE, compress="gzip")
acc-bioinfo/TMBleR documentation built on Dec. 18, 2021, 10:21 p.m.