Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jpquast committed Sep 30, 2024
1 parent 6909b03 commit 6f12493
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ importFrom(httr,modify_url)
importFrom(httr,timeout)
importFrom(janitor,clean_names)
importFrom(janitor,make_clean_names)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(methods,is)
importFrom(plotly,ggplotly)
Expand Down Expand Up @@ -193,5 +192,3 @@ importFrom(utils,data)
importFrom(utils,download.file)
importFrom(utils,head)
importFrom(utils,untar)
importFrom(xml2,read_html)
importFrom(xml2,read_xml)
6 changes: 3 additions & 3 deletions R/assign_peptide_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ assign_peptide_type <- function(data,
)) %>%
# Reassign semi-tryptic peptides at position 2 to fully-tryptic if no start == 1
dplyr::mutate(pep_type = dplyr::if_else(
pep_type == "semi-tryptic" & {{ start }} == 2 & !.data$has_start_1 & .data$C_term_tryp,
.data$pep_type == "semi-tryptic" & {{ start }} == 2 & !.data$has_start_1 & .data$C_term_tryp,
"fully-tryptic",
.data$pep_type
)) %>%
# Reassign non-tryptic peptides at position 2 to semi-tryptic if no start == 1
dplyr::mutate(pep_type = dplyr::if_else(
pep_type == "non-tryptic" & {{ start }} == 2 & !.data$has_start_1 & !.data$C_term_tryp,
.data$pep_type == "non-tryptic" & {{ start }} == 2 & !.data$has_start_1 & !.data$C_term_tryp,
"fully-tryptic",
.data$pep_type
)) %>%
Expand All @@ -111,7 +111,7 @@ assign_peptide_type <- function(data,
result <- data %>%
dplyr::left_join(
peptide_data %>%
dplyr::select({{ aa_before }}, {{ last_aa }}, {{ aa_after }}, {{ protein_id }}, {{ start }}, .data$pep_type),
dplyr::select({{ aa_before }}, {{ last_aa }}, {{ aa_after }}, {{ protein_id }}, {{ start }}, "pep_type"),
by = c(
rlang::as_name(rlang::enquo(aa_before)),
rlang::as_name(rlang::enquo(last_aa)),
Expand Down
2 changes: 1 addition & 1 deletion R/qc_cvs.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The function does not handle log2 transformed data.",
dplyr::mutate({{ condition }} := forcats::fct_expand({{ condition }}, "combined")) %>%
dplyr::mutate({{ condition }} := replace({{ condition }}, .data$type == "cv_combined", "combined")) %>%
dplyr::mutate({{ condition }} := forcats::fct_relevel({{ condition }}, "combined")) %>%
dplyr::select(-.data$type) %>%
dplyr::select(-"type") %>%
dplyr::group_by({{ condition }}) %>%
dplyr::mutate(median = stats::median(.data$values)) %>%
dplyr::distinct()
Expand Down
12 changes: 6 additions & 6 deletions R/try_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#' @importFrom curl has_internet
#' @importFrom httr GET timeout http_error message_for_status http_status content accept
#' @importFrom readr read_tsv read_csv
#' @importFrom jsonlite fromJSON
#' @importFrom xml2 read_html read_xml
#'
#' @return A data frame that contains the table from the url.
try_query <-
Expand Down Expand Up @@ -90,11 +88,13 @@ try_query <-
# Change variable to not show progress if readr is used
options(readr.show_progress = FALSE)

# Check if the content is gzip compressed
if (!is.null(query_result$headers[["content-encoding"]]) && query_result$headers[["content-encoding"]] == "gzip") {
# Retrieve the content as raw bytes using httr::content
raw_content <- httr::content(query_result, type = "raw")
# Retrieve the content as raw bytes using httr::content
raw_content <- httr::content(query_result, type = "raw")
# Check for gzip magic number (1f 8b) before decompression
compressed <- length(raw_content) >= 2 && raw_content[1] == as.raw(0x1f) && raw_content[2] == as.raw(0x8b)

# Check if the content is gzip compressed
if (!is.null(query_result$headers[["content-encoding"]]) && query_result$headers[["content-encoding"]] == "gzip" && compressed) {
# Decompress the raw content using base R's `memDecompress`
decompressed_content <- memDecompress(raw_content, type = "gzip")

Expand Down
2 changes: 1 addition & 1 deletion man/assign_peptide_type.Rd

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

18 changes: 9 additions & 9 deletions tests/testthat/test-auxiliary_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (Sys.getenv("TEST_PROTTI") == "true") {
last_aa = last_aa,
aa_after = aa_after,
protein_id = protein_id,
start_pos = start
start = start
))
})
expect_is(assigned_types, "data.frame")
Expand All @@ -61,9 +61,9 @@ if (Sys.getenv("TEST_PROTTI") == "true") {

test_that("find_peptide and assign_peptide_type work", {
expect_is(assigned_types, "data.frame")
expect_equal(nrow(assigned_types), 3)
expect_equal(nrow(assigned_types), 6)
expect_equal(ncol(assigned_types), 9)
expect_equal(assigned_types$pep_type, c("fully-tryptic", "fully-tryptic", "non-tryptic"))
expect_equal(assigned_types$pep_type, c("fully-tryptic", "semi-tryptic", "non-tryptic", "non-tryptic", "fully-tryptic", "fully-tryptic"))
})

test_that("deprecated sequence_coverage works", {
Expand All @@ -75,9 +75,9 @@ if (Sys.getenv("TEST_PROTTI") == "true") {
))
})
expect_is(coverage, "data.frame")
expect_equal(nrow(coverage), 3)
expect_equal(nrow(coverage), 6)
expect_equal(ncol(coverage), 10)
expect_equal(unique(round(coverage$coverage, digits = 1)), 7.7)
expect_equal(unique(round(coverage$coverage, digits = 1)), c(7.7, 3.2))
})

coverage <- calculate_sequence_coverage(
Expand All @@ -88,14 +88,14 @@ if (Sys.getenv("TEST_PROTTI") == "true") {

test_that("calculate_sequence_coverage works", {
expect_is(coverage, "data.frame")
expect_equal(nrow(coverage), 3)
expect_equal(nrow(coverage), 6)
expect_equal(ncol(coverage), 10)
expect_equal(unique(round(coverage$coverage, digits = 1)), 7.7)
expect_equal(unique(round(coverage$coverage, digits = 1)), c(7.7, 3.2))
})

plot_data <- coverage %>%
dplyr::mutate(
fold_change = c(3, -0.4, 2.1),
fold_change = c(3, -0.4, 2.1, 0.1, -0.1, 0.2),
protein_length = nchar(protein_sequence)
)

Expand All @@ -121,7 +121,7 @@ if (Sys.getenv("TEST_PROTTI") == "true") {
end_position = end,
protein_length = protein_length,
coverage = coverage,
protein_id = protein_id,
facet = protein_id,
colouring = pep_type
)
expect_is(p, "ggplot")
Expand Down

0 comments on commit 6f12493

Please sign in to comment.