Skip to content

Commit

Permalink
Remove github notes and small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
karissawhiting committed Sep 15, 2023
1 parent 25dd19b commit 4d75bf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion R/subset-by-frequency.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ subset_by_frequency <- function(gene_binary, t = .1, other_vars = NULL) {

# Remove all NA columns ----------------------------------------------
all_na_alt <- apply(alt_only, 2, function(x) {
sum(is.na(x)) == nrow(alt_only)
# sum(is.na(x)) == nrow(alt_only)
})

all_non_na_alt <- names(all_na_alt[!all_na_alt])
Expand Down
21 changes: 7 additions & 14 deletions R/summarize-by-gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ summarize_by_gene <- function(gene_binary, other_vars = NULL) {
select("sample_id") %>%
mutate(sample_index = paste0("samp", 1:nrow(gene_binary)))

<<<<<<< Updated upstream
alt_only <- as.matrix(select(gene_binary, -"sample_id"))
rownames(alt_only) <- sample_index$sample_index
=======
# data frame of only alterations
alt_only <- select(gene_binary, -"sample_id", -any_of(other_vars)) %>%
as.matrix()

# data frame of only alterations
alt_only <- as.data.frame(select(gene_binary, -"sample_id", -any_of(other_vars)))
row.names(alt_only) <- sample_index$sample_index
>>>>>>> Stashed changes

# check numeric class ---------
is_numeric <- apply(alt_only, 2, is.numeric)
Expand Down Expand Up @@ -106,13 +100,12 @@ summarize_by_gene <- function(gene_binary, other_vars = NULL) {
# join back to sample ID and other vars
simp_gene_binary <- all_bin %>%
left_join(sample_index, ., by = "sample_index") %>%
select(-c("sample_index")) %>%
as.data.frame()%>%
left_join(gene_binary %>%
select(any_of(c("sample_id", other_vars))))%>%
suppressMessages()
select(-c("sample_index"))

simp_gene_binary <- simp_gene_binary %>%
left_join(select(gene_binary, any_of(c("sample_id", other_vars))), by = "sample_id")

simp_gene_binary
return(simp_gene_binary)

}

Expand Down
5 changes: 4 additions & 1 deletion man/summarize_by_gene.Rd

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

15 changes: 8 additions & 7 deletions tests/testthat/test-summarize-by-gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ test_that("test what happens to columns with all NA", {

})

<<<<<<< Updated upstream
=======

# test_that("all columns must be numeric to continue", {
#
# })

test_that("other vars are retained", {
samples <- Reduce(intersect, list(gnomeR::mutations$sampleId, gnomeR::cna$sampleId,
samples <- Reduce(intersect, list(gnomeR::mutations$sampleId,
gnomeR::cna$sampleId,
gnomeR::sv$sampleId))


bin_impact <- create_gene_binary(samples=samples,
bin_impact <- create_gene_binary(samples = samples,
mutation = gnomeR::mutations,
cna = gnomeR::cna,
fusion = gnomeR::sv,
Expand All @@ -126,15 +126,16 @@ test_that("other vars are retained", {

set.seed(20230828)

bin_impact$random_color = sample(c("blue", "red",
"yellow"), size = 50, replace = TRUE)
bin_impact$random_color = sample(c("blue", "red", "yellow"),
size = 50, replace = TRUE)

expect_true("random_color" %in% names(bin_impact))
sum_impact <- summarize_by_gene(bin_impact,
other_vars = "random_color")

expect_true("random_color" %in% names(sum_impact))
expect_true("blue" %in% sum_impact$random_color)
>>>>>>> Stashed changes
})



0 comments on commit 4d75bf4

Please sign in to comment.