MaayanLab / enrichr_issues

5 stars 3 forks source link

Error: lexical error: invalid char in json text #67

Open jeneaadams opened 1 year ago

jeneaadams commented 1 year ago

Describe the bug Hi, I've just started working with the enrichr API per instructions in #11. I get this error:

image

in this penultimate line of code data_ben <- fromJSON(content(response, as = "text")).

To Reproduce My code is below

baseurl = "https://maayanlab.cloud/speedrichr/api/"

#1. Upload a gene set for enrichment analysis 
genelist = readLines("~/foreground_gene_list.txt")
description = "Foreground gene list"

ENRICHR_URL = paste0(baseurl, "addList")
payload = list(
  list = upload_file("~/foreground_gene_list.txt"),
  description = description
)

response <- POST(ENRICHR_URL, body = payload, encode = "multipart")
data <- fromJSON(content(response, as = "text"))
print(toJSON(data, pretty = TRUE))

#2. upload the background 
backgroundgenes = readLines("~/background_gene_list.txt")

ENRICHR_URL = paste0(baseurl, "addbackground")
payload = list(
  background = backgroundgenes
)
response = POST(ENRICHR_URL, body = payload)
data_back = fromJSON(content(response, as = "text"))
print(toJSON(data_back, pretty = T))

#3. List available libraries

ENRICHR_URL <- paste0(baseurl, "listlibs")
response <- GET(ENRICHR_URL)
data_libs <- fromJSON(content(response, as = "text"))
print(toJSON(data_libs, pretty = TRUE))

#4. pass IDs 
library_name = "GO_Biological_Process_2018"

ENRICHR_URL = paste0(baseurl, "backgroundenrich")
payload = list(
  userListId = data$userListId, 
  backgroundid = data_back$backgroundid, 
  backgroundType = library_name
)

response <- POST(ENRICHR_URL, body = payload)
data_ben <- fromJSON(content(response, as = "text")) #error
print(toJSON(data_ben, pretty = TRUE))

Screenshots

image

Preview of the TXT file format of my gene lists: image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.