Example #1
0
    def __init__(self):
        # 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()

        # get reference space
        self.space = ReferenceSpaceApi()
        self.spacecache = ReferenceSpaceCache(
            manifest=os.path.join(
                self.annotated_volume_fld, "manifest.json"
            ),  # downloaded files are stored relative to here
            resolution=int(self.resolution[0]),
            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()
Example #2
0
    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
            ]))
Example #3
0
    def __init__(self, resolution, reference_space_key, **kwargs):

        if not 'version' in kwargs:
            kwargs['version'] = self.MANIFEST_VERSION

        if not 'base_uri' in kwargs:
            kwargs['base_uri'] = None

        super(ReferenceSpaceCache, self).__init__(**kwargs)

        self.resolution = resolution
        self.reference_space_key = reference_space_key

        self.api = ReferenceSpaceApi(base_uri=kwargs['base_uri'])
Example #4
0
    def __init__(self, projection_metric="projection_energy", paths_file=None):
        """ path_file {[str]} -- [Path to a YAML file specifying paths to data folders, to replace default paths] (default: {None}) """

        Paths.__init__(self, paths_file=paths_file)

        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(
                "Data/ABA", "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
            ]))
Example #5
0
    def __init__(self,  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 kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py

        """

        Atlas.__init__(self, base_dir=base_dir, **kwargs)
        self.meshes_folder = self.mouse_meshes # where the .obj mesh for each region is saved

        # 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_fld, "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()

        # Store all regions metadata [If there's internet connection]
        if self.other_sets is not None: 
            self.regions = self.other_sets["Structures whose surfaces are represented by a precomputed mesh"].sort_values('acronym')
            self.region_acronyms = list(self.other_sets["Structures whose surfaces are represented by a precomputed mesh"].sort_values(
                                                'acronym').acronym.values)
Example #6
0
# Download structures tree and meshes:
######################################
oapi = OntologiesApi()  # ontologies
struct_tree = spacecache.get_structure_tree()  # structures tree

# Find id of set of regions with mesh:
select_set = "Structures whose surfaces are represented by a precomputed mesh"

all_sets = pd.DataFrame(oapi.get_structure_sets())
mesh_set_id = all_sets[all_sets.description == select_set].id.values[0]

structs_with_mesh = struct_tree.get_structures_by_set_id([mesh_set_id])

meshes_dir = (save_dir / "meshes")  # directory to save meshes into
space = ReferenceSpaceApi()
for s in structs_with_mesh:
    name = s["id"]
    try:
        space.download_structure_mesh(structure_id=s["id"],
                                      ccf_version="annotation/ccf_2017",
                                      file_name=meshes_dir / f"{name}.obj")
    except (exceptions.HTTPError, ConnectionError):
        print(s)

# Loop over structures, remove entries not used in brainglobe:
for struct in structs_with_mesh:
    [struct.pop(k) for k in ["graph_id", "structure_set_ids"]]

with open(save_dir / "structures.json", "w") as f:
    json.dump(structs_with_mesh, f)
Example #7
0
import nibabel as nib  # pip install nibabel, if nibabel is not already installed
import numpy as np
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.config.manifest import Manifest

# the annotation download writes a file, so we will need somwhere to put it
annotation_dir = 'annotation'
Manifest.safe_mkdir(annotation_dir)

annotation_path = os.path.join(annotation_dir, 'annotation.nrrd')

# this is a string which contains the name of the latest ccf version
annotation_version = ReferenceSpaceApi.CCF_VERSION_DEFAULT

# download annotations
mcapi = ReferenceSpaceApi()
mcapi.download_annotation_volume(annotation_version, 50, annotation_path)
annotation = nrrd.read(annotation_path)

# read nrrd data and header
_nrrd = nrrd.read(annotation_path)
data = _nrrd[0]
header = _nrrd[1]

# create header and for RAS orientation
space_value = header['space directions']
affine = np.eye(4) * 0.001 * space_value[0, 0]
affine[3][3] = 1
# ensure RAS orientation
data = np.swapaxes(data, 2, 0)
data = np.flip(data, 2)