Is this the output you're looking for each of the 188?
# libraries
library(jsonlite)
# data
gist <- "https://gist.githubusercontent.com/technocrat/7c6602553011f31dabddf1f12077f6a2/raw/1eb5fb0e673df107844d8048d81aede5568f9f85/test_json.json"
intake <- read_json(gist)
# functions
get_addn <- function(x) {
step1 = strsplit(subject[x],":")
step2 = lapply(step1,trimws)
addn = as.numeric(gsub(".$","",step2[[1]][2]))
return(addn)
}
get_note <- function(x) {
step1 = strsplit(subject[x],":")
step2 = lapply(step1,trimws)
note = gsub("^.|.$","",step2[[1]][1])
return(note)
}
get_var <- function(x) {
step1 = strsplit(subject[x],":")[[1]][2]
step2 = gsub("[^A-Z0-9]+",",",step1)
step3 = gsub(",","",step2)
return(step3)
}
populate_receiver <- function(x) {
new_row = data.frame(
gene = get_var(3),
summary = get_var(4),
notes6 = get_note(6),
addn6 = get_addn(6),
note7 = get_note(7),
addn7 = get_addn(7),
notes8 = get_note(8),
addn8 = get_addn(8),
notes9 = get_note(9),
addn9 = get_addn(9),
notes10 = get_note(10),
addn10 = get_addn(10),
notes11 = get_note(11),
addn11 = get_addn(11),
notes12 = get_note(12),
addn12 = get_addn(12),
notes13 = get_note(13),
addn13 = get_addn(13),
notes14 = get_note(14),
addn14 = get_addn(14),
notes15 = get_note(15),
addn15 = get_addn(15),
notes16 = get_note(16),
addn16 = get_addn(16),
notes17 = get_note(17),
addn17 = get_addn(17),
notes18 = get_note(18),
addn18 = get_addn(18),
notes19 = get_note(19),
addn19 = get_addn(19),
notes20 = get_note(20),
addn20 = get_addn(20)
)
return(new_row)
}
unbox <- function(x) toJSON(intake[x][[1]][[1]], auto_unbox = TRUE)
# pick one item for development
test_case <- unbox(1)
# unpack
subject <- fromJSON(test_case)
# create receiver to add processed items
receiver <- data.frame(
gene = as.character(),
summary = as.character(),
notes6 = as.character(),
addn6 = as.numeric(),
notes7 = as.character(),
addn7 = as.numeric(),
notes8 = as.character(),
addn8 = as.numeric(),
notes9 = as.character(),
addn9 = as.numeric(),
notes10 = as.character(),
addn10 = as.numeric(),
notes11 = as.character(),
addn11 = as.numeric(),
notes12 = as.character(),
addn12 = as.numeric(),
notes13 = as.character(),
addn13 = as.numeric(),
notes14 = as.character(),
addn14 = as.numeric(),
notes15 = as.character(),
addn15 = as.numeric(),
notes16 = as.character(),
addn16 = as.numeric(),
notes17 = as.character(),
addn17 = as.numeric(),
notes18 = as.character(),
addn18 = as.numeric(),
notes19 = as.character(),
addn19 = as.numeric(),
notes20 = as.character(),
addn20 = as.numeric()
)
for (i in 1) receiver = rbind(receiver, populate_receiver(i))
receiver
#> gene summary
#> 1 AAK1 AAK1AP21TAAK1AP2T
#> notes6 addn6
#> 1 This gene is specifically associated with the test case 1
#> note7 addn7
#> 1 This gene is specifically associated with the biology of cells 1
#> notes8 addn8
#> 1 This gene is specifically associated with the biology of proteins 1
#> notes9 addn9
#> 1 This gene is specifically associated with the biology of metabolites 1
#> notes10 addn10
#> 1 This gene is involved in mediating the induction 2
#> notes11 addn11
#> 1 This gene is implicated in mediated damage 2
#> notes12 addn12
#> 1 This gene is involved in mediating attachment 3
#> notes13 addn13
#> 1 This gene is implicated in the process of replication 2
#> notes14 addn14
#> 1 This gene is involved in mediating entry 3
#> notes15 addn15
#> 1 This gene is implicated in the impairment 2
#> notes16 addn16
#> 1 This gene is involved in conferring drug resistance 2
#> notes17 addn17
#> 1 This gene is involved in mediating the response to blockage 3
#> notes18 addn18
#> 1 This gene is involved in mediating the initiation of cells 2
#> notes19 addn19
#> 1 This gene is involved in mediating the blockage 4
#> notes20 addn20
#> 1 This gene is involved in mediating the priming of the cells NA
# for legibility
t(receiver)
#> [,1]
#> gene "AAK1"
#> summary "AAK1AP21TAAK1AP2T"
#> notes6 "This gene is specifically associated with the test case"
#> addn6 "1"
#> note7 "This gene is specifically associated with the biology of cells"
#> addn7 "1"
#> notes8 "This gene is specifically associated with the biology of proteins"
#> addn8 "1"
#> notes9 "This gene is specifically associated with the biology of metabolites"
#> addn9 "1"
#> notes10 "This gene is involved in mediating the induction"
#> addn10 "2"
#> notes11 "This gene is implicated in mediated damage"
#> addn11 "2"
#> notes12 "This gene is involved in mediating attachment"
#> addn12 "3"
#> notes13 "This gene is implicated in the process of replication"
#> addn13 "2"
#> notes14 "This gene is involved in mediating entry"
#> addn14 "3"
#> notes15 "This gene is implicated in the impairment"
#> addn15 "2"
#> notes16 "This gene is involved in conferring drug resistance"
#> addn16 "2"
#> notes17 "This gene is involved in mediating the response to blockage"
#> addn17 "3"
#> notes18 "This gene is involved in mediating the initiation of cells"
#> addn18 "2"
#> notes19 "This gene is involved in mediating the blockage"
#> addn19 "4"
#> notes20 "This gene is involved in mediating the priming of the cells"
#> addn20 NA
Created on 2024-01-07 with [reprex v2.0.2]