How to use the brainrender.Utils.data_io.listdir function in brainrender

To help you get started, we’ve selected a few brainrender examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BrancoLab / BrainRender / tests / test_utils.py View on Github external
def test_io():
    fld = os.getcwd()
    if not isinstance(listdir(fld), list):
        raise ValueError(f"listdir returned: {listdir(fld)}")
    if not isinstance(get_subdirs(fld), list):
        raise ValueError(f"get_subdirs returned: {get_subdirs(fld)}")
github BrancoLab / BrainRender / tests / test_utils.py View on Github external
def test_io():
    fld = os.getcwd()
    if not isinstance(listdir(fld), list):
        raise ValueError(f"listdir returned: {listdir(fld)}")
    if not isinstance(get_subdirs(fld), list):
        raise ValueError(f"get_subdirs returned: {get_subdirs(fld)}")
github BrancoLab / BrainRender / brainrender / Utils / parsers / mouselight.py View on Github external
allowed_components = ['soma', 'axon', 'dendrites']
				skipped_components = []
			elif not self.render_dendrites and not self.render_axons:
				allowed_components = ['soma']
				skipped_components = ['axon', 'dendrites']
			elif not self.render_dendrites:
				allowed_components = ['soma', 'axon']
				skipped_components = ['dendrites']
			else:
				allowed_components = ['soma', 'dendrites']
				skipped_components = ['axon']
		else:
			allowed_components = ['soma']
			skipped_components = ['axon', 'dendrites']

		neuron_files = [f for f in listdir(self.morphology_cache) if neuron_name in f]
		if not neuron_files: return None
		else:
			neuron_actors = {}
			for f in neuron_files:
				component = os.path.split(f)[-1].split(".")[0].split("_")[-1]
				if component not in allowed_components and component not in skipped_components:
					raise ValueError("Weird file name, unsure what to do: {}".format(f))
				elif component not in allowed_components and component in skipped_components:
					continue
				neuron_actors[component] = load(f)
			return neuron_actors
github BrancoLab / BrainRender / brainrender / atlases / sba.py View on Github external
:param atlas_folder: path to folder with atlas data. The folder content must include:
                    - volumetric data (e.g. as .nii)
                    - label to acronym look up file (lbl_to_acro.json)
                    - label to rgb look up file (lbl_to_rgb.json)
                    - label to full name look up file (lbl_to_name.json)

                    Optionally the folder can contain a .obj file with the root (whole brain) mesh
        """

        Atlas.__init__(self, base_dir=base_dir, **kwargs)

        # Get folder content
        if not os.path.isdir(atlas_folder):
            raise FileNotFoundError(f"The folder passed doesn't exist: {atlas_folder}")

        content = listdir(atlas_folder)
        if not [f for f in content if f.endswith('.nii')]: # TODO expand to support multiple formats
            raise ValueError("Could not find volumetric data")

        if not [f for f in content if "lbl_to_acro.json" in f]:
            raise FileNotFoundError("Could not find file with label to acronym lookup")

        if not [f for f in content if "lbl_to_rgb.json" in f]:
            raise FileNotFoundError("Could not find file with label to color lookup")

        if not [f for f in content if "lbl_to_name.json" in f]:
            raise FileNotFoundError("Could not find file with label to full name lookup")

        self.lbl_to_acro_lookup = load_json([f for f in content if "lbl_to_acro.json" in f][0])
        self.lbl_to_rgb_lookup = load_json([f for f in content if "lbl_to_rgb.json" in f][0])
        self.lbl_to_name_lookup = load_json([f for f in content if "lbl_to_name.json" in f][0])
github BrancoLab / BrainRender / brainrender / Utils / AllenMorphologyAPI / AllenMorphology.py View on Github external
def add_neuron(self, neuron, shadow_axis=None, shadow_offset=-20,   
					**kwargs):
		if isinstance(neuron, list):
			neurons = neuron
		else:
			if isinstance(neuron, str):
				if os.path.isdir(neuron):
					neurons = listdir(neuron)
				elif os.path.isfile(neuron):
					neurons = [neuron]
				else: 
					raise ValueError(neuron)
			else:
				neurons = [neuron]
		
		actors = []
		for neuron in neurons:
			if isinstance(neuron, str):
				neuron = self.parse_neuron_swc(neuron,  **kwargs)
			elif isinstance(neuron, Morphology):
				neuron = self.parse_neurons_swc_allen(neuron, **kwargs)

			actor = self.scene.add_vtkactor(neuron)
github BrancoLab / BrainRender / brainrender / atlases / celegans.py View on Github external
subdirs = get_subdirs(self.data_folder)
        if not subdirs:
            raise ValueError(
                "The data folder should include a subfolder which stores the neurons .obj files"
            )

        try:
            self.objs_fld = [f for f in subdirs if "objs_smoothed" in f][0]
        except:
            raise FileNotFoundError(
                "Could not find subdirectory with .obj files"
            )

        # Get filepath to each .obj
        self.neurons_files = [
            f for f in listdir(self.objs_fld) if f.lower().endswith(".obj")
        ]

        # Get synapses and skeleton files
        try:
            skeletons_file = [
                f
                for f in listdir(self.data_folder)
                if f.endswith("skeletons.json")
            ][0]
        except:
            raise FileNotFoundError(
                "Could not find file with neurons skeleton data"
            )

        try:
            synapses_file = [
github BrancoLab / BrainRender / brainrender / ABA / gene_expression / ge_utils.py View on Github external
def load_cached_gene(cache, metric, grid_size):
    """
        Loads a gene's data from cache
    """
    files = [
        f for f in listdir(cache) if metric in f and not f.endswith(".mhd")
    ]
    if not files:
        return None
    if len(files) > 1:
        raise NotImplementedError("Deal with more than one file found")
    else:
        return read_raw(files[0], grid_size)
github BrancoLab / BrainRender / brainrender / atlases / celegans.py View on Github external
self.objs_fld = [f for f in subdirs if "objs_smoothed" in f][0]
        except:
            raise FileNotFoundError(
                "Could not find subdirectory with .obj files"
            )

        # Get filepath to each .obj
        self.neurons_files = [
            f for f in listdir(self.objs_fld) if f.lower().endswith(".obj")
        ]

        # Get synapses and skeleton files
        try:
            skeletons_file = [
                f
                for f in listdir(self.data_folder)
                if f.endswith("skeletons.json")
            ][0]
        except:
            raise FileNotFoundError(
                "Could not find file with neurons skeleton data"
            )

        try:
            synapses_file = [
                f
                for f in listdir(self.data_folder)
                if f.endswith("synapses.csv")
            ][0]
        except:
            raise FileNotFoundError("Could not find file with synapses data")
github BrancoLab / BrainRender / brainrender / atlases / celegans.py View on Github external
f
                for f in listdir(self.data_folder)
                if f.endswith("synapses.csv")
            ][0]
        except:
            raise FileNotFoundError("Could not find file with synapses data")

        # load data
        self.skeletons_data = load_json(skeletons_file)
        self.synapses_data = pd.read_csv(synapses_file, sep=";")

        # Get neurons metadata
        try:
            metadata_file = [
                f
                for f in listdir(self.data_folder)
                if "neuron_metadata.csv" in f
            ][0]
        except:
            raise FileNotFoundError(
                f"Could not find neurons metadata file {metadata_file}"
            )

        self.neurons_metadata = pd.read_csv(metadata_file)
        self.neurons_names = list(self.neurons_metadata.neuron.values)