cran / CytobankAPI

:exclamation: This is a read-only mirror of the CRAN R package repository. CytobankAPI — Cytobank API Wrapper for R
Other
0 stars 0 forks source link

Download FlowSOM - CytobankAPI 2.0.0 #1

Open mvarewyck opened 2 years ago

mvarewyck commented 2 years ago

With the CytobankAPI_2.0.0 downloading FlowSOM data fails for Cytobank preview-mars In the Cytobank preview there is no example experiment with FlowSOM so we had to make up an example ourselves. I can't push changes to this repos, so below is example code to reproduce the error and a suggested fix.

library(CytobankAPI)

myToken <- ##

experiment_id <- 5426
UserSession <- CytobankAPI::authenticate(
  site = "preview-mars", 
  auth_token = myToken, 
  long_timeout = 6*60*60
)
timeout <- UserSession@short_timeout

flowsomInfo <- flowsom.list(UserSession = UserSession, experiment_id = experiment_id,
    output = "default")

# fail to run CytobankAPI::flowsom.show
flowsomData <- flowsom.show(UserSession = UserSession, 
  experiment_id = experiment_id, 
  flowsom_id = flowsomInfo$id)

# Debug: where does the error come from?
flowsom_id <- flowsomInfo$id
## flowsom.show: https://github.com/cran/CytobankAPI/blob/master/R/flowsom.R#L284-L292
resp <- GET(paste(UserSession@site, "/experiments/", experiment_id, "/advanced_analyses/flowsom/", flowsom_id, "?include_settings=1", sep=""),
                 add_headers(Authorization=paste("Bearer", UserSession@auth_token)),
                 timeout(timeout)
)
flowsom_response <- CytobankAPI:::parse(resp, "FlowSOM")

## create_flowsom_object: https://github.com/cran/CytobankAPI/blob/master/R/flowsom.R#L420
CytobankAPI:::create_flowsom_object(UserSession, flowsom_response)

populations.list(UserSession, flowsom_response$flowsom$sourceExperiment)

## populations.list: https://github.com/cran/CytobankAPI/blob/master/R/populations.R#L40-L57
experiment_id <- flowsom_response$flowsom$sourceExperiment
resp <- GET(paste(UserSession@site, "/experiments/", experiment_id, "/populations", sep=""),
  add_headers(Authorization=paste("Bearer", UserSession@auth_token)),
  timeout(timeout)
)
CytobankAPI:::build_population_list(CytobankAPI:::parse(resp, "populations")$populations)

population_list_info <- CytobankAPI:::parse(resp, "populations")$populations

## build_population_list: https://github.com/cran/CytobankAPI/blob/master/R/populations.R#L103-L119
cyto_dataframe <- CytobankAPI:::cyto_dataframe
population_list <- list()

# **Requires the Ungated population -- WEIRD HACK REQUIRED, SHOULD BE RETURNED FORMALLY VIA API INSTEAD**
ungated <- cyto_dataframe(list(list(id=NA_character_, name="Ungated", version=as.integer(-1), experimentId=NA_character_, gateSetId=as.integer(0), createdAt=NA_character_, updatedAt=NA_character_)))
ungated$definition <- apply(ungated, 1, function(row) list(gates=list(), negGates=list(), tailoredPerPopulation=list()))
population_list <- c(population_list, list(ungated))

for (population in population_list_info)
{
  print(population$name)
  # Need to encapsulate built population within list in order to do.call the rbind
  population_list <- c(population_list, list(CytobankAPI:::build_population(population)))
}

do.call(rbind, population_list)

population_list[[1]]
### compensationId is missing for the first one !!
population_list[[2]]

FIX: In file R/populations.R line 108: compensationId is missing

    ungated <- cyto_dataframe(list(list(id=NA_character_, name="Ungated", version=as.integer(-1), experimentId=NA_character_, 
          compensationId=as.integer(0), gateSetId=as.integer(0), createdAt=NA_character_, updatedAt=NA_character_)))
gaborcsardi commented 2 years ago

Hi, this is a read only mirror of CRAN, please see the package authors in the DESCRIPTION file. Look for Maintainer, BugReports and URL. Thanks!

ymo-beckman commented 2 years ago

Hi @mvarewyck and @gaborcsardi . Thanks for provide the detail information, we will fix this issue soon.

ymo-beckman commented 1 year ago

Hi @mvarewyck and @gaborcsardi . Thanks for provide the detail information, we will fix this issue soon.

Hi @mvarewyck. We have fixed this issue. Please check it.