-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exporting gWalks into json files #156
Comments
Thanks for trying the package! Have you tried using the Here's an example signature:
(where gwalk is an instantiated For the |
Thanks for the reply. Yes, I tried it. When I use it on a gWalk that contains all the walks obtained with peel function
I get this error
I tried it also on the rds files that have gWalks with a specific length and containing a specific gene and I could produce a json file with
However, it is empty when I import it to gGnome.js browser. |
Can you post the exact code you're using (including the calls for the |
yes, this is the part that returns the error message
and the output of gwalk is
Please let me know if you need anything else. |
Any chance you can upload one of the |
Hi @shihabdider, did you get a chance to look at the data I sent you? |
@mesut-unal Sorry for the long delay! (It's been a hectic month). I'll take a look now and get back to you by end of day. |
OK it seems like there's an issue with a mismatch between the length of custom_json <- function (
walk,
filename = ".",
save = TRUE,
verbose = FALSE,
annotations = NULL,
nfields = NULL,
efields = NULL,
stack.gap = 1e+05,
include.graph = TRUE,
settings = list(y_axis = list(title = "copy number", visible = TRUE)),
cid.field = NULL,
no.y = FALSE
) {
message("custom_json")
if (length(walk) == 0) {
warning("This is an empty gWalk so no JSON will be produced.")
return(NA)
}
if (length(walk$edges) == 0) {
warning("There are no edges in this gWalk so no JSON will be produced.")
return(NA)
}
non.alt.exist = any(walk$dt[, sapply(sedge.id, length) == 0])
if (non.alt.exist) {
return(refresh(walk[walk$dt[, sapply(sedge.id, length) > 0]])$json(filename = filename, save = save, verbose = verbose, annotations = annotations, nfields = nfields, efields = efields, stack.gap = stack.gap, include.graph = include.graph, settings = settings, no.y = no.y))
}
if (include.graph) {
graph.js = refresh(walk$graph)$json(filename = NA, save = FALSE, verbose = verbose, annotations = annotations, nfields = nfields, efields = efields, settings = settings, no.y = no.y)
}
pids = split(walk$dt[, .(pid = walk.id, strand = "+", type = ifelse(walk$circular, "cycle", "path"))], 1:walk$length)
efields = unique(c("type", efields))
protected_efields = c("cid", "source", "sink", "title", "weight")
rejected_efields = intersect(efields, protected_efields)
if (length(rejected_efields) > 0) {
warning(sprintf("The following fields were included in efields: \"%s\", but since these are conserved fields in the json walks output then they will be not be included in efields. If these fields contain important metadata that you want included in the json output, then consider renaming these field names in your gWalk object.", paste(rejected_efields, collapse = "\" ,\"")))
efields = setdiff(efields, rejected_efields)
}
missing_efields = setdiff(efields, names(walk$edges$dt))
if (length(missing_efields) > 0) {
warning(sprintf("Invalid efields value/s provided: \"%s\". These fields were not found in the gWalk and since will be ignored.", paste(missing_efields, collapse = "\" ,\"")))
efields = intersect(efields, names(walk$edges$dt))
}
sedu = dunlist(walk$sedge.id)
print("#############")
print(sedu)
cids = lapply(unname(split(cbind(data.table(cid = sedu$V1, source = walk$graph$edges[sedu$V1]$left$dt$snode.id, sink = -walk$graph$edges[sedu$V1]$right$dt$snode.id, title = "", weight = 1), walk$graph$edges[sedu$V1]$dt[, ..efields], fill = TRUE), sedu$listid)), function(x) unname(split(x, 1:nrow(x))))
snu = dunlist(walk$snode.id)
snu$ys = gGnome:::draw.paths.y(walk$grl) %>% unlist
protected_nfields = c("chromosome", "startPoint", "endPoint", "y", "type", "strand", "title")
rejected_nfields = intersect(nfields, protected_nfields)
if (length(rejected_nfields) > 0) {
warning(sprintf("The following fields were included in nfields: \"%s\", but since these are conserved fields in the json walks output then they will be not be included in nfields. If these fields contain important metadata that you want included in the json output, then consider renaming these field names in your gWalk object.", paste(rejected_nfields, collapse = "\" ,\"")))
nfields = setdiff(nfields, rejected_nfields)
}
missing_nfields = setdiff(nfields, names(walk$nodes$dt))
if (length(missing_nfields) > 0) {
warning(sprintf("Invalid nfields value/s provided: \"%s\". These fields were not found in the gWalk and since will be ignored.", paste(missing_nfields, collapse = "\" ,\"")))
nfields = intersect(nfields, names(walk$edges$dt))
}
iids = lapply(unname(split(cbind(data.table(iid = abs(snu$V1)), walk$graph$nodes[snu$V1]$dt[, .(chromosome = seqnames, startPoint = start, endPoint = end, y = snu$ys, type = "interval", strand = ifelse(snu$V1 > 0, "+", "-"), title = abs(snu$V1))], walk$graph$nodes[snu$V1]$dt[, ..nfields]), snu$listid)), function(x) unname(split(x, 1:nrow(x))))
walks.js = lapply(1:min(length(walk), length(cids), length(iids)),
function(x) c(as.list(pids[[x]]), list(cids = rbindlist(cids[[x]])), list(iids = rbindlist(iids[[x]]))))
if (include.graph) {
out = c(graph.js, list(walks = walks.js))
}
else {
out = list(walks = walks.js)
}
if (save) {
if (verbose) {
message("Saving JSON to: ", filename)
}
jsonlite::write_json(out, filename, pretty = TRUE, auto_unbox = TRUE, digits = 4)
return(normalizePath(filename))
}
else {
return(out)
}
}
walk = readRDS("226295-WG01_walks.rds")
custom_json(walk, filename="test.json", verbose = TRUE, include.graph = FALSE) |
Hi @shihabdider , thanks for taking a look at it and preparing the custom json. Did you get a chance to try the output on gGnome.js browser? I still get the same problem with the custom_json, browser shows an empty page. |
Dear developers, I am using gGnome for a project. It is really helpful for getting the walks, but I am having trouble exporting all the walks to a json file that is suitable for gGnome.js browser (from the rds files). I tried writing them into csv files by using nodes, edges, grl info so that I can compile a json from them. It works and I can visualize them in gGnome.js, but I need to double check if I am extracting everything correctly. There are variables and names whose explanation I can't find such as edges.in and edges.out columns in gNodes. For instance, I see (4)->,1560(1)-> in one of the rows, but I can't be sure what these numbers are. I can't see 1560 anywhere else in the csv files I extracted. I'd appreciate if you can tell me where I can obtain such details and/or a gWalks-to-json function that I can cross check my results. I see that you have
gen_gg_json_files
jsUtils.R, but I haven't been able to use it without an error. I'd appreciate your help.The text was updated successfully, but these errors were encountered: