Skip to content

Commit

Permalink
Finish Release-1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
julienleroux5 committed Sep 22, 2024
2 parents d0ac53e + b91e59b commit 8ae6ab7
Show file tree
Hide file tree
Showing 40 changed files with 685 additions and 319 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ man-roxygen
^docs$
^pkgdown$
^\.github$
^vignettes/articles$
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Package: arcMS
Type: Package
Title: MS converter from UNIFI to Parquet and HDF5 formats
Version: 1.1.0
Version: 1.1.1
Authors@R: c(
person("Julien", "Le Roux", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0245-8536")),
person("Julien", "Sade", email = "[email protected]", role = "aut")
)
Maintainer: Julien Le Roux <[email protected]>
Description: Functions to connect to Waters UNIFI API and convert data to parquet or HDF5 format.
Description: Functions to connect to Waters UNIFI API and convert data to Parquet or HDF5 format.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Suggests:
testthat (>= 3.0.0),
Expand All @@ -22,7 +21,10 @@ Suggests:
shiny,
bs4Dash,
knitr,
rmarkdown
rmarkdown,
duckdb,
plotly,
fontawesome
Config/testthat/edition: 3
Imports:
methods,
Expand Down
6 changes: 4 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export(get_sample_infos)
export(get_samples_list)
export(run_app)
export(sample_dataset)
export(sample_dataset_ondisk)
export(sample_infos)
export(save_one_sample_data)
export(store_unifi_api_token)
exportClasses(connection_params)
exportClasses(sample_dataset)
exportClasses(sample_dataset_ondisk)
exportClasses(sample_infos)
exportMethods(add_sample_id)
exportMethods(connection_apihosturl)
exportMethods(connection_token)
exportMethods(get_analysis_name)
exportMethods(get_sample_data)
exportMethods(get_sample_id)
exportMethods(get_sample_metadata)
exportMethods(get_sample_metadata_json)
exportMethods(get_sample_name)
Expand All @@ -38,10 +38,12 @@ import(methods)
import(withr)
importFrom(RProtoBuf,readProtoFiles)
importFrom(Rcpp,evalCpp)
importFrom(arrow,open_dataset)
importFrom(arrow,read_parquet)
importFrom(arrow,write_parquet)
importFrom(checkmate,makeAssertion)
importFrom(checkmate,vname)
importFrom(dplyr,collect)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(future,multisession)
Expand Down
2 changes: 0 additions & 2 deletions R/LICENSE

This file was deleted.

21 changes: 0 additions & 21 deletions R/LICENSE.md

This file was deleted.

159 changes: 0 additions & 159 deletions R/README.Rmd

This file was deleted.

32 changes: 21 additions & 11 deletions R/convert_bin_to_ccs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' Convert bin value to CCS (Collision Cross Section) value
#'
#' This function converts bin values to CCS values for the given sample.
#' This conversion should be performed for a limited number of detected peaks
#' and not on raw data to avoid too many requests and useless CCS calculations
Expand All @@ -20,11 +21,10 @@

convert_bin_to_ccs <- function(sample_dataset, connection_params = NULL) {
# Check if sample_id is accessible
sample_metadata = get_sample_metadata(sample_dataset)
if (!"id" %in% names(sample_metadata)) {
stop("Sample ID is missing.")
sample_id = get_sample_id(sample_dataset)
if (is.null(sample_id)) {
stop("Sample ID is missing in sample_metadata. \nPlease add the sample ID to the sample_dataset object with the add_sample_id() method if needed.")
}
sample_id <- sample_metadata$id

# Check connection parameters
if (is.null(connection_params)) {
Expand All @@ -39,6 +39,14 @@ convert_bin_to_ccs <- function(sample_dataset, connection_params = NULL) {
}

sample_data = get_sample_data(sample_dataset)
# check if sample_data is Arrow pointer or data.table in RAM
if (inherits(sample_data, "FileSystemDataset")) {
sample_data = sample_data |> collect()
attr(sample_data, "sample_metadata") = NULL
attr(sample_data, "spectrum_metadata") = NULL
attr(sample_data, "sample_metadata_json") = NULL
attr(sample_data, "spectrum_metadata_json") = NULL
}

# Change rt column name if necessary
if ("retention_time" %in% names(sample_data)) {
Expand All @@ -61,21 +69,23 @@ convert_bin_to_ccs <- function(sample_dataset, connection_params = NULL) {
charges = rep(1, nrow(sample_data)),
retentiontimes = sample_data$rt
))
message(glue::glue("Requesting conversion of bin values to CCS to the UNIFI API..."))

# Make API call
response <- httr::POST(
url = sampleUrl,
body = body,
httr::add_headers(
"Content-Type" = "application/json",
"Authorization" = paste("Bearer", token)
response <- httr::POST(
url = sampleUrl,
body = body,
httr::add_headers(
"Content-Type" = "application/json",
"Authorization" = paste("Bearer", token)
)
)
)

# Check the response status
if (httr::status_code(response) != 200) {
stop("Error in API request: ", httr::content(response, "text", encoding = "UTF-8"))
}
message(glue::glue("Conversion done."))

# Update data with CCS values
ccs_values <- jsonlite::fromJSON(httr::content(response, "text", encoding = "UTF-8"))
Expand Down
2 changes: 2 additions & 0 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ setGeneric("connection_apihosturl", function(obj, ...) standardGeneric("connecti
setGeneric("connection_token", function(obj, ...) standardGeneric("connection_token"))
setGeneric("get_sample_metadata", function(obj, ...) standardGeneric("get_sample_metadata"))
setGeneric("get_sample_name", function(obj, ...) standardGeneric("get_sample_name"))
setGeneric("get_sample_id", function(obj, ...) standardGeneric("get_sample_id"))
setGeneric("get_analysis_name", function(obj, ...) standardGeneric("get_analysis_name"))
setGeneric("get_sample_metadata_json", function(obj, ...) standardGeneric("get_sample_metadata_json"))
setGeneric("get_spectrum_metadata", function(obj, ...) standardGeneric("get_spectrum_metadata"))
setGeneric("get_spectrum_metadata_json", function(obj, ...) standardGeneric("get_spectrum_metadata_json"))
setGeneric("get_sample_data", function(obj, ...) standardGeneric("get_sample_data"))
setGeneric("add_sample_id", function(obj, id, ...) standardGeneric("add_sample_id"))
7 changes: 4 additions & 3 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @importFrom utils head tail modifyList setTxtProgressBar txtProgressBar write.csv write.table read.csv data getFromNamespace
#' @importFrom stats ave
#' @importFrom magrittr %>%
#' @importFrom dplyr mutate select
#' @importFrom dplyr mutate select collect
#' @importFrom tidytable uncount unnest
#' @importFrom RProtoBuf readProtoFiles
#' @importFrom httr GET add_headers content POST
Expand All @@ -16,7 +16,7 @@
#' @importFrom future plan multisession
#' @importFrom future.apply future_lapply
#' @importFrom progressr progressor with_progress withProgressShiny
#' @importFrom arrow write_parquet read_parquet
#' @importFrom arrow write_parquet read_parquet open_dataset
#' @importFrom rhdf5 h5write h5createFile
NULL # need this for doc generation

Expand Down Expand Up @@ -47,5 +47,6 @@ NULL
#'
"_PACKAGE"
NULL

setOldClass("FileSystemDataset")
setClassUnion("dataframeOrDatatable", c("data.frame", "data.table"))
setClassUnion("dataframeOrDatatableOrArrowdataset", c("data.frame", "data.table", "FileSystemDataset"))
Loading

0 comments on commit 8ae6ab7

Please sign in to comment.