Skip to content
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

neuprint_get_shortest_paths returns empty tibble if one of the cells has NULL as name or type #164

Open
artxz opened this issue Oct 26, 2022 · 6 comments

Comments

@artxz
Copy link

artxz commented Oct 26, 2022

for example, this works
neuprint_get_shortest_paths(1633411652, 1663767674)
but this does not
neuprint_get_shortest_paths(1850310331, 1663767674)

the returned queries look ok but the second one bodyid = 1850310331 has no name or type. It seems to cause a problem when building the returned dataframe

connTable <- dplyr::bind_rows(lapply(nc$data, function(d){ l <- d[[1]] tryCatch( dplyr::bind_rows(lapply(1:l, function(i){ data.frame(from=as.character(d[[2]][[i]][[1]]), to=as.character(d[[2]][[i+1]][[1]]), weight=d[[3]][[i]], depth=i, name.from=d[[2]][[i]][[2]],name.to=d[[2]][[i+1]][[2]], type.from=d[[2]][[i]][[3]],type.to=d[[2]][[i+1]][[3]], stringsAsFactors = FALSE) })), error = function(e) NULL) }))

One possible solution is to use, eg., I(list(d[[2]][[i]][[2]])) instead of d[[2]][[i]][[2]]

Similar problem with neuprint_get_paths

@jefferis
Copy link
Contributor

ah that's annoying. code looks pretty crufty

@artxz
Copy link
Author

artxz commented Oct 27, 2022

maybe it's not that bad with indentation?

      data.frame(from=as.character(d[[2]][[i]][[1]]),
                 to=as.character(d[[2]][[i+1]][[1]]),
                 weight=d[[3]][[i]],
                 depth=i,
                 name.from=I(list(d[[2]][[i]][[2]])), name.to=I(list(d[[2]][[i+1]][[2]])),
                 type.from=I(list(d[[2]][[i]][[3]])), type.to=I(list(d[[2]][[i+1]][[3]])),
                 stringsAsFactors = FALSE)

Another possibility

connTable <- dplyr::bind_rows(lapply(nc$data, function(d){
  l <- d[[1]]
  tryCatch( dplyr::bind_rows(lapply(1:l, function(i){
    d2 <- do.call(rbind, d[[2]][i:(i+1)])
    data.frame(from=as.character(d2[1]),
               to=as.character(d2[2]),
               weight=d[[3]][[i]],
               depth=i,
               name.from=I(d2[3]),name.to=I(d2[4]),
               type.from=I(d2[5]),type.to=I(d2[6]),
               stringsAsFactors = FALSE)
  })), error = function(e) NULL)
}))

@artxz
Copy link
Author

artxz commented Oct 27, 2022

also suggest add an ordinal number for each path, maybe something like this

connTable$path <- rep(seq(1,length(nc$data)), each= nc$data[[1]][[1]])

@CesiumChloride
Copy link

Hi I am wondering whether there is a fix or work around on this issue? Thanks!

@jefferis
Copy link
Contributor

jefferis commented Jan 9, 2024

@artxz’s suggestion was good but I didn’t get to implement. Will take a day or two to get to unless someone wants to offer a PR.

@CesiumChloride
Copy link

Sounds great! It would be super helpful if it is solved. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants