Skip to content

Commit

Permalink
Ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-tai committed Mar 30, 2017
1 parent 8d9f35b commit dede433
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
18 changes: 10 additions & 8 deletions R/importFilterHypermutators.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ importFilterHypermutators <- function(rSNVFileIn = c(),
for (file in rCNAFileIn) {
# readRDS, count gene CNAs and add to hash for sample @ CNA and nMUT
rCNA <- readRDS(file)
for (sample in colnames(rCNA)) {
for (sample in colnames(rCNA)[4:length(colnames(rCNA))]) {
totalSamples <- totalSamples + 1
# if key is in hash, increment CNA and nMUT for every gene if there is an abberation
for (copyNumberValue in rCNA[[sample]]) {
copyNumberValue <- as.double(copyNumberValue)
if (copyNumberValue != 0) {
if (!is.null(hashTable[[sample]])) {
prevCNACount <- hashTable[[sample]]$CNA
Expand Down Expand Up @@ -102,7 +103,7 @@ importFilterHypermutators <- function(rSNVFileIn = c(),
prevCNACount <- hashTable[[sample]]$CNA
prevSNVCount <- hashTable[[sample]]$SNV
prevTotalCount <- hashTable[[sample]]$total
assign(sample, list(CNA = prevCNACount, SNV = prevSNVCount + 1, nMUT = prevTotalCount + 1), envir = hashTable)
assign(sample, list(CNA = prevCNACount, SNV = prevSNVCount + 1, total = prevTotalCount + 1), envir = hashTable)
} else {
assign(sample, list(CNA = 0, SNV = 1, total = 1), envir = hashTable)
}
Expand All @@ -122,24 +123,24 @@ importFilterHypermutators <- function(rSNVFileIn = c(),

for (sample in ls(hashTable)) {
# num samples with only CNA
if (hashTable[[sample]]$SNV == 0) {
if (hashTable[[sample]]$SNV == 0 && hashTable[[sample]]$CNA > 0) {
numSamplesOnlyCNA <- numSamplesOnlyCNA + 1
}
# num samples with only SNV
else if (hashTable[[sample]]$CNA == 0) {
if (hashTable[[sample]]$CNA == 0 && hashTable[[sample]]$SNV > 0) {
numSamplesOnlySNV <- numSamplesOnlySNV + 1
}
# num samples with both SNV and CNA
else if (hashTable[[sample]]$CNA > 0 && hashTable[[sample]]$SNV > 0) {
if (hashTable[[sample]]$CNA > 0 && hashTable[[sample]]$SNV > 0) {
numSamplesBothSNVAndCNA <- numSamplesBothSNVAndCNA + 1
}
# num samples that exceeded threshold and need removal
else if (hashTable[[sample]]$total > xS) {
# num samples that exceeded threshold and need to be removed
if (hashTable[[sample]]$total > xS) {
numRemovedSamples <- numRemovedSamples + 1
removedSamples <- c(removedSamples, sample)
}
# num samples with no change
else {
if (hashTable[[sample]]$total <= xS) {
numSamplesNoChange <- numSamplesNoChange + 1
}
}
Expand All @@ -149,6 +150,7 @@ importFilterHypermutators <- function(rSNVFileIn = c(),
# for each rCNAFileIn
for (file in rCNAFileIn) {
rCNA <- readRDS(file)

# remove sample if sample in `removedSamples`
newRCNA <- rCNA[, !(names(rCNA) %in% removedSamples)]

Expand Down
15 changes: 10 additions & 5 deletions man/importFilterHypermutators.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
26 changes: 21 additions & 5 deletions tests/testthat/testFilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ logFileName(fPath = tempdir(), setOption = TRUE) # make tempdir() the log dir
logName <- unlist(getOption("rete.logfile"))
if (file.exists(logName)) { file.remove(logName)}

SNVfileName <- '../../inst/extdata/devSNV.rds'
CNAfileName <- '../../inst/extdata/devCNA.rds'
SNVfileName <- 'devSNV.rds'
CNAfileName <- 'devCNA.rds'

filteredSNVfileName <- paste(getwd(), "/filteredHypermutators_", basename(SNVfileName), sep = "")
filteredCNAfileName <- paste(getwd(), "/filteredHypermutators_", basename(CNAfileName), sep = "")
Expand Down Expand Up @@ -67,12 +67,28 @@ test_that("importFilterHypermutators rejects invalid xS arguments", {

test_that("importFilterHypermutators correctly removes hypermutators", {
# run importFilterHypermutators with a single hypermutator
testCNA <- readRDS('../../inst/extdata/devCNA.rds')
testSNV <- readRDS('../../inst/extdata/devSNV.rds')
testCNA <- readRDS(CNAfileName)
testSNV <- readRDS(SNVfileName)

# start off with a known number of samples in each CNA and SNV file
expect_equal(length(colnames(testCNA)[4:length(colnames(testCNA))]), 579)
expect_equal(length(testSNV$Tumor_Sample_Barcode), 15)

expect_error(importFilterHypermutators(rSNVFileIn = c(SNVfileName),
rCNAFileIn = c(CNAfileName),
xS = 15,
silent = FALSE,
writeLog = TRUE), NA)

# check output file
readRDS('')
processedCNA <- readRDS(filteredCNAfileName)
processedSNV <- readRDS(filteredSNVfileName)

# expect that 458 samples are removed from rCNA (579 - 458 = 121)
expect_equal(length(colnames(processedCNA)[4:length(colnames(processedCNA))]), 121)

# expect that no samples are removed from rSNV
expect_equal(length(processedSNV$Tumor_Sample_Barcode), 15)

# test cleanup
if (file.exists(filteredSNVfileName)) { file.remove(filteredSNVfileName)}
Expand Down

0 comments on commit dede433

Please sign in to comment.