def __init__(self, *args, scene_kwargs={}, **kwargs): """ Initialise API interaction and fetch metadata of neurons in the Allen Database. """ if not connected_to_internet(): raise ConnectionError( "You will need to be connected to the internet to use the AllenMorphology class" ) Paths.__init__(self, *args, **kwargs) self.scene = Scene(add_root=False, display_inset=False, **scene_kwargs) # Create a Cache for the Cell Types Cache API self.ctc = CellTypesCache( manifest_file=os.path.join(self.morphology_allen, 'manifest.json')) # Get a list of cell metadata for neurons with reconstructions, download if necessary self.neurons = pd.DataFrame( self.ctc.get_cells(species=[CellTypesApi.MOUSE], require_reconstruction=True)) self.n_neurons = len(self.neurons) if not self.n_neurons: raise ValueError( "Something went wrong and couldn't get neurons metadata from Allen" ) self.downloaded_neurons = self.get_downloaded_neurons()
def __init__( self, base_dir=None, add_root=True, use_cache=True, scene_kwargs={}, **kwargs, ): """ Initialise the class instance to get a few useful paths and variables. :param base_dir: str, path to base directory in which all of brainrender data are stored. Pass only if you want to use a different one from what's default. :param add_root: bool, if True the root mesh is added to the rendered scene :param use_cache: if true data are loaded from a cache to speed things up. Useful to set it to false to help debugging. :param scene_kwargs: dict, params passed to the instance of Scene associated with this class """ Paths.__init__(self, base_dir=base_dir, **kwargs) # Get MCM cache cache_path = (Path(self.mouse_connectivity_volumetric) / "voxel_model_manifest.json") if not cache_path.exists(): if not connected_to_internet(): raise ValueError( "The first time you use this class it will need to download some data, but it seems that you're not connected to the internet." ) print( "Downloading volumetric data. This will take several minutes but it only needs to be done once." ) self.cache = VoxelModelCache(manifest_file=str(cache_path)) self.voxel_array = None self.target_coords, self.source_coords = None, None # Get projection cache paths self.data_cache = self.mouse_connectivity_volumetric_cache self.data_cache_projections = os.path.join(self.data_cache, "projections") self.data_cache_targets = os.path.join(self.data_cache, "targets") self.data_cache_sources = os.path.join(self.data_cache, "sources") for fold in [ self.data_cache_projections, self.data_cache_targets, self.data_cache_sources, ]: if not os.path.isdir(fold): os.mkdir(fold) # Get structures tree self.structure_tree = self.cache.get_structure_tree() # Get scene self.scene = Scene(add_root=add_root, **scene_kwargs) # Other vars self.use_cache = use_cache
def __init__(self, species=None, sex=None, base_dir=None, make_root=True, **kwargs): self.make_root = make_root Paths.__init__(self, base_dir=base_dir, **kwargs) # Get a list of available species self.species_info = pd.DataFrame( request( f"{self._base_url}/{self._url_paths['species_info']}").json()) self.species = list(self.species_info.scientific_name.values) # Get selected species self.structures, self.region_names, self.region_acronyms = ( None, None, None, ) self.sel_species = species self.sex = sex self.get_brain(species=species, sex=sex)
def __init__(self, base_dir=None, **kwargs): """ Handles the download of neurons morphology data from the Mouse Light project :param base_dir: path to directory to use for saving data (default value None) :param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py """ Paths.__init__(self, base_dir=base_dir, **kwargs)
def __init__(self, scene=None, render_neurites=True, mirror=False, neurite_radius=None, color_by_region=False, force_to_hemisphere=None, base_dir=None, render_dendrites=True, render_axons=True, color_neurites=True, axon_color=None, soma_color=None, dendrites_color=None, random_color=False, **kwargs): """ Set up variables used for rendering :param scene: instance of class brainrender.Scene (Default value = None) :param render_neurites: Bool, If true, axons and dendrites are rendered (Default value = True) :param render_dendrites: Bool, if render neurites is true and this is false dendrites are not rendred :param render_axons: Bool, if render neurites is true and this is false axons are not rendred :param neurite_radius: float with radius of axons and dendrites. If None default is used. (Default value = None) :param color_neurites: Bool, if True axons and neurites are colored differently from the soma (Default value = True) :param mirror: Bool if True neurons are mirrored so that there is a version in each hemisphere (Default value = None) :param soma_color: soma_color color of the neurons' soma. Also used for neurites if they are not to be colored differently (Default value = None) :param axon_color: color of the neurons' axon. If none or False, the soma's color is used. (Default value = None) :param dendrites_color: color of the neurons' dendrites. If none or False, the soma's color is used.(Default value = None) :param random_color: Bool, if True a random color is used for each neuron. (Default value = False) :param color_by_region: bool, if True, neurons are colored according to the Allen Brain Atlas color for the region the soma is in. (Default value = False) :param force_to_hemisphere: str, if 'left' or 'right' neurons are rendered in the selected hemisphere, if False or None they are rendered in the original hemisphere. (Default value = None) :param base_dir: path to directory to use for saving data (default value None) :param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py """ self.scene = scene # for the meaning of the arguments check self.render_neurons self.render_neurites = render_neurites self.render_dendrites = render_dendrites self.render_axons = render_axons self.neurite_radius = neurite_radius self.color_neurites = color_neurites self.axon_color = axon_color self.soma_color = soma_color self.dendrites_color = dendrites_color self.random_color = random_color self.mirror = mirror self.color_by_region = color_by_region self.force_to_hemisphere = force_to_hemisphere Paths.__init__(self, base_dir=base_dir, **kwargs) # Load cache metadata self.cache_metadata = load_json(self.morphology_cache_metadata)
def __init__(self, projection_metric="projection_energy", base_dir=None, **kwargs): """ Set up file paths and Allen SDKs :param base_dir: path to directory to use for saving data (default value None) :param path_fiprojection_metricle: - str, metric to quantify the strength of projections from the Allen Connectome. (default value 'projection_energy') :param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py """ Paths.__init__(self, base_dir=base_dir, **kwargs) self.projection_metric = projection_metric # get mouse connectivity cache and structure tree self.mcc = MouseConnectivityCache(manifest_file=os.path.join( self.mouse_connectivity_cache, "manifest.json")) self.structure_tree = self.mcc.get_structure_tree() # get ontologies API and brain structures sets self.oapi = OntologiesApi() self.get_structures_sets() # get reference space self.space = ReferenceSpaceApi() self.spacecache = ReferenceSpaceCache( manifest=os.path.join( self.annotated_volume, "manifest.json" ), # downloaded files are stored relative to here resolution=self.resolution, reference_space_key= "annotation/ccf_2017" # use the latest version of the CCF ) self.annotated_volume, _ = self.spacecache.get_annotation_volume() # mouse connectivity API [used for tractography] self.mca = MouseConnectivityApi() # Get tree search api self.tree_search = TreeSearchApi() # Get some metadata about experiments self.all_experiments = self.mcc.get_experiments(dataframe=True) self.strains = sorted( [x for x in set(self.all_experiments.strain) if x is not None]) self.transgenic_lines = sorted( set([ x for x in set(self.all_experiments.transgenic_line) if x is not None ]))
def __init__(self, atlas_name, *args, base_dir=None, **kwargs): # Create brainglobe atlas BrainGlobeAtlas.__init__(self, *args, atlas_name=atlas_name, **kwargs) # Add brainrender paths Paths.__init__(self, base_dir=base_dir, **kwargs) self.meshes_folder = ( None # where the .obj mesh for each region is saved ) # If it's a mouse atlas, add extra functionality if "Mus musculus" == self.metadata["species"]: ABA.__init__(self)
def __init__(self, atlas_name, *args, base_dir=None, **kwargs): # Create brainglobe atlas BrainGlobeAtlas.__init__( self, *args, atlas_name=atlas_name, print_authors=False, **kwargs ) # Add brainrender paths Paths.__init__(self, base_dir=base_dir, **kwargs) Enhanced.__init__(self) # If it's a mouse atlas, add extra functionality if "Mus musculus" == self.metadata["species"]: ABA.__init__(self)
def __init__(self, data_folder=None, base_dir=None, **kwargs): """ This class handles loading and parsing neuroanatomical data for the C. elegans connectome from https://www.biorxiv.org/content/10.1101/2020.04.30.066209v1 :param base_dir: path to directory to use for saving data (default value None) :param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py :param data_folder: str, path to a folder with data for the connectome # TODO replace with downloading data """ # Initialise atlas Paths.__init__(self, base_dir, **kwargs) # Get data if data_folder is None: raise ValueError( "No data folder was passed, use the 'atlas_kwargs' argument of Scene to pass a data folder path" ) if not os.path.isdir(data_folder): raise FileNotFoundError(f"The folder {data_folder} does not exist") self.data_folder = data_folder self._get_data()
def __init__(self, base_dir=None, **kwargs): """ Set up file paths :param base_dir: path to directory to use for saving data (default value None) :param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py """ # Specify atlas specific paths Paths.__init__(self, base_dir=base_dir, **kwargs) self.meshes_folder = None # where the .obj mesh for each region is saved # Get some atlas specific data # ! REPLACE these in the init method of your atlas self.annotated_volume = None # A 3d image with a scalar label at each region indicating # which brain region each voxel corresponds to self.regions = None # list of all regions in the atlas self.region_acronyms = None