Skip to content

Commit

Permalink
Get lineage clone data from the hemibrainr google drive
Browse files Browse the repository at this point in the history
* Inc. example of co-plotting lineages, FAFB and hemibrain
  • Loading branch information
alexanderbates committed Feb 11, 2021
1 parent 84e0176 commit 83cce97
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/flywire_tracing.R
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,7 @@ flywire_workflow <- function(flywire.id,
# hidden, caches result for 5min in current session
sheet_properties.memo <- memoise::memoise(googlesheets4::sheet_properties, ~memoise::timeout(5*60))


library(fafbseg)
id = fafb14_to_flywire_ids("10655926",only.biggest = TRUE)
flywire_ntplot(id$flywire.id, cleft.threshold = 30, local = local)
125 changes: 125 additions & 0 deletions R/lineage_clones.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@


#' Download light-level lineage clone data from Ito et al. 2013 or Yu et al. 2013
#'
#'@description Get registered light-level clonal data of central brain, secondary developmental lineages. Most neurons in the fly brain hail from one of these lineages.
#'You can find their meta information in \code{\link{hemibrain_hemilineages}}.
#'
#' @param x a specific lineage, e.g. ALlv1. If \code{NULL}, the default, all lineages are fetched
#' @param brain the brainspace in which hemibrain neurons have been registered. Defaults to raw voxel space for the FlyWire project.
#' @param dataset whether to get clonal data from Ito et al. 2013 \code{"Ito"} or Yu et al. 2013 \code{"Lee"}.
#' @param local \code{FALSE} or path. By default (\code{FALSE}) data is read from \code{options()$Drive_hemibrain_data}), but the user can specify an alternative path.
#'
#' @references Ito M, Masuda N, Shinomiya K, Endo K, Ito K.
#' Systematic analysis of neural projections reveals clonal composition of the Drosophila brain.
#' Curr Biol. 2013 Apr 22;23(8):644-55. doi: 10.1016/j.cub.2013.03.015. Epub 2013 Mar 28. PMID: 23541729.
#'
#' @references Yu HH, Awasaki T, Schroeder MD, Long F, Yang JS, He Y, Ding P, Kao JC, Wu GY, Peng H, Myers G, Lee T.
#' Clonal development and organization of the adult Drosophila central brain. Curr Biol. 2013 Apr 22;23(8):633-43.
#' doi: 10.1016/j.cub.2013.02.057. Epub 2013 Mar 28. PMID: 23541733; PMCID: PMC3637848.
#'
#' @examples
#' \donttest{
#' \dontrun{
#' # Loads all processed flywire neurons as a neuronlistfh object
#' lee.lins = lineage_clones(brain = "FAFB14", dataset = "Lee")
#' ito.lins = lineage_clones(brain = "FAFB14", dataset = "Ito")
#'
#' # Plot WEDd1
#' lee.lins.wedd1 = subset(lee.lins, ItoLee_Lineage == "WEDd1")
#' nopen3d()
#' plot3d(xyzmatrix(lee.lins.wedd1),
#' add = TRUE, col = hemibrain_bright_colors["blue"])
#'
#' # Plot WEDd1 from the other clonal data set
#' ito.lins.wedd1 = subset(ito.lins, ItoLee_Lineage == "WEDd1")
#' nopen3d()
#' plot3d(xyzmatrix(ito.lins.wedd1),
#' add = TRUE, col = hemibrain_bright_colors["cyan"])
#'
#' # Get flywire neurons
#' fw.neurons = flywire_neurons()
#' fw.neurons.wedd1 = subset(fw.neurons, ItoLee_Hemilineage == "WEDd1")
#' plot3d(fw.neurons.wedd1,
#' col = hemibrain_bright_colors["red"], soma = 4000)
#'
#' # What are the equivalent hemibrain neurons?
#' cbf.hl = subset(hemibrain_hemilineages, ItoLee_Lineage == "WEDd1")
#' hb.neurons = hemibrain_neurons(brain="FAFB14")
#' hb.neurons.wedd1 = subset(hb.neurons,cellBodyFiber%in%cbf.hl$cellBodyFiber)
#' plot3d(hb.neurons.wedd1, col = hemibrain_bright_colors["orange"], soma = 4000)
#'
#'}}
#'@return A \code{neuronlist} object containing flywire skeletons. In the meta-data, it might be useful for some users to note that
#'you will get:
#'
##' \itemize{
##' \item{"flywire.id"}{ The ID given to the corresponding volumetric body in flywire.
##' These are used to do things like fetch volumes and are the input to the \code{skeletor} function. However, they are highly volatile and
##' change a lot with active tracing.}
##' \item{"flywire.xyz"}{ The voxel coordinate of a single point in this neuron, usually a cell body fiber tract position. This is a more accurate way
##' of keeping tract of neuron as it will always correspond to the same 'neuron' even though its related flywire.id will change with merge/split events in flywire.}
##' \item{"hemilineage"}{ An estimated hemilineage identity from both of two naming systems, Ito et al. 2013 and Wong et al. 2013}
##' \item{"side"}{ An estimate as to the 'side', i.e. brain hemisphere, in which the neuron lies}
##' \item{"skid"}{ The 'skeleton ID' of this neuron's match in CATMAID for FAFBv14}
##' \item{"FAFB.xyz"}{ The coordinates in nanometres of a point in the neuron, in FAFBv14 space}
##' \item{"hemibrain_match"}{ The bodyid of an estimated hemibrain match}
##' }
#'
#'@export
#'@seealso \code{\link{hemibrain_neurons}}, \code{\link{flywire_neurons}}
lineage_clones <- function(x = NULL,
local = FALSE,
brain = c("FAFB14", "FlyWire", "JRCFIB2018Fraw","JRCFIB2018F","FAFB","JFRC2", "JFRC2013","JRC2018F","FCWB"),
dataset = c("Ito","Lee")
){
brain = match.arg(brain)
dataset = match.arg(dataset)
if(brain == "JRCFIB2018Fraw"){
brain = "JRCFIB2018F"
scale = TRUE
}else if (brain %in% c("FAFB","FlyWire")){
brain = "FAFB14"
scale = FALSE
}else{
scale = FALSE
}

# Get Google drive folder
savedir = good_savedir(local = local)
neuronsdir = file.path(savedir,"light_level/lineages/")
fhdir = file.path(neuronsdir,dataset,brain)

# Exists?
if(!file.exists(fhdir)){
stop("Cannot find file: ", fhdir)
}

# Read
message("Loading ", fhdir)
filelist = list.files(path = fhdir, pattern = ".rds", full.names = TRUE)
filelist = sort(filelist,decreasing = TRUE)
if(length(filelist)){
fh.file = filelist[1]
neurons.fh = nat::read.neuronlistfh(fh.file)
test = tryCatch(neurons.fh[[1]], error = function(e){
warning(e)
try(file.remove(paste0(attributes(neurons.fh)$db@datafile,"___LOCK")), silent = FALSE)
})
attr(neurons.fh,"df") = neurons.fh[,]
}else{
warning("neuronlistfh (.rds) file not found at: ", fhdir)
return(NULL)
}

# Scale neurons if needs be
if(scale){
neurons.fh = scale_neurons(neurons.fh,scaling=8/1000)
}

# Return
if(!is.null(x)){
neurons.fh = neurons.fh[names(neurons.fh)%in%x,]
}
neurons.fh
}
1 change: 1 addition & 0 deletions data-raw/lineage_clones.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Make dotprops objects for lineage clones

0 comments on commit 83cce97

Please sign in to comment.