For now, the Nexus web application can be used to get a token. We are looking for other simpler alternatives.
Once a token is obtained then proceed to paste it below.
import getpass
TOKEN = getpass.getpass()
from kgforge.core import KnowledgeGraphForge
# Let target the sscx dissemination project in Nexus
ORG = "public"
PROJECT = "sscx"
forge = KnowledgeGraphForge("prod-forge-nexus.yml",bucket=f"{ORG}/{PROJECT}",token=TOKEN)
forge.types()
# Supported filters for the time being are:
from kgforge.core.commons.strategies import ResolvingStrategy
text = "somatosensory"
limit=10
# other Search strategy can be ResolvingStrategy.BEST_MATCH, ResolvingStrategy.EXACT_MATCH
brain_region = forge.resolve(text, scope="ontology", target="terms", strategy=ResolvingStrategy.ALL_MATCHES, limit=limit)
forge.as_dataframe(brain_region).head(100)
# Supported filters for the time being are:
_type = "ReconstructedCell"
classification_type="nsg:MType"
mType="L4_NBC"
brainRegion = "primary somatosensory cortex"
layer = "layer 4"
encodingFormat="application/swc"
limit=2
forge.template("Dataset")
path = forge.paths("Dataset") # to have autocompletion on the properties
data = forge.search(path.type.id == _type,
path.annotation.hasBody.type ==classification_type,
path.annotation.hasBody.label ==mType,
path.brainLocation.brainRegion.label == brainRegion,
path.brainLocation.layer.label == layer,
path.distribution.encodingFormat == encodingFormat,
limit=limit)
print(str(len(data))+" dataset of type '"+_type+"' found.")
DISPLAY_LIMIT = 10
reshaped_data = forge.reshape(data, keep=["id","name","subject","brainLocation.brainRegion.id","brainLocation.brainRegion.label","brainLocation.layer.id","brainLocation.layer.label", "contribution","brainLocation.layer.id","brainLocation.layer.label","distribution.name","distribution.contentUrl","distribution.encodingFormat"])
forge.as_dataframe(reshaped_data[:DISPLAY_LIMIT])
dirpath = "./downloaded/"
forge.download(data, "distribution.contentUrl", dirpath)
# Supported filters for the time being are:
_type = "Trace"
classification_type="nsg:EType"
eType="cADpyr"
brainRegion = "primary somatosensory cortex"
layer = "layer 5"
encodingFormat="application/nwb"
limit=10
path = forge.paths("Dataset") # to have autocompletion on the properties
data = forge.search(path.type.id == _type,
path.annotation.hasBody.type ==classification_type,
path.annotation.hasBody.label ==eType,
path.brainLocation.brainRegion.label == brainRegion,
path.brainLocation.layer.label == layer,
path.distribution.encodingFormat == encodingFormat,
limit=limit)
print(str(len(data))+" data of type '"+_type+"' found.")
DISPLAY_LIMIT = 10
reshaped_data = forge.reshape(data, keep=["id","name","subject","brainLocation.brainRegion.id","brainLocation.brainRegion.label","brainLocation.layer.id","brainLocation.layer.label", "contribution","brainLocation.layer.id","brainLocation.layer.label","distribution.name","distribution.contentUrl","distribution.encodingFormat"])
forge.as_dataframe(reshaped_data[:DISPLAY_LIMIT])
dirpath = "./downloaded/"
forge.download(data, "distribution.contentUrl", dirpath)
# Supported filters for the time being are:
_type = "LayerThickness"
brainRegion = "primary somatosensory cortex"
layer = "layer 2"
encodingFormat="application/xlsx"
limit=10
path = forge.paths("Dataset") # to have autocompletion on the properties
data = forge.search(path.type.id == _type,
path.brainLocation.layer.label == layer,
path.brainLocation.brainRegion.label == brainRegion,
path.distribution.encodingFormat == encodingFormat,
limit=limit)
print(str(len(data))+" data of type '"+_type+"' found.")
DISPLAY_LIMIT = 10
reshaped_data = forge.reshape(data, keep=["id","name","subject","brainLocation.brainRegion.id","brainLocation.brainRegion.label","brainLocation.layer.id","brainLocation.layer.label", "contribution","brainLocation.layer.id","brainLocation.layer.label","distribution.name","distribution.contentUrl","distribution.encodingFormat"])
forge.as_dataframe(reshaped_data[:DISPLAY_LIMIT])
dirpath = "./downloaded/"
forge.download(data, "distribution.contentUrl", dirpath)
# Supported filters for the time being are:
_type = "NeuronDensity"
brainRegion = "primary somatosensory cortex"
layer = "layer 2"
encodingFormat="application/xlsx"
limit=10
path = forge.paths("Dataset") # to have autocompletion on the properties
data = forge.search(path.type.id == _type,
path.brainLocation.layer.label == layer,
path.brainLocation.brainRegion.label == brainRegion,
path.distribution.encodingFormat == encodingFormat,
limit=limit)
print(str(len(data))+" data of type '"+_type+"' found.")
DISPLAY_LIMIT = 10
reshaped_data = forge.reshape(data, keep=["id","name","subject","brainLocation.brainRegion.id","brainLocation.brainRegion.label","brainLocation.layer.id","brainLocation.layer.label", "contribution","brainLocation.layer.id","brainLocation.layer.label","distribution.name","distribution.contentUrl","distribution.encodingFormat"])
forge.as_dataframe(reshaped_data[:DISPLAY_LIMIT])
dirpath = "./downloaded/"
forge.download(data, "distribution.contentUrl", dirpath)
# Let target the bbp/atlas project in Nexus
forge_atlas = KnowledgeGraphForge("prod-forge-nexus.yml", bucket="bbp/atlas", token=TOKEN)
Atlas related types: AtlasRelease CellPositions BrainParcellationDataLayer CellDensityDataLayer GeneExpressionVolumetricDataLayer GliaCellDensity NISSLImageDataLayer
# Supported filters for the time being are:
_type = "CellPositions"
limit=10
path = forge_atlas.paths("Dataset") # to have autocompletion on the properties
data = forge_atlas.search(path.type.id == _type,
limit=limit)
print(str(len(data))+" data of type '"+_type+"' found.")
DISPLAY_LIMIT = 10
reshaped_data = forge_atlas.reshape(data, keep=["id","name","brainLocation.brainRegion.id","brainLocation.brainRegion.label", "contribution","distribution.name","distribution.contentUrl","distribution.encodingFormat"])
forge_atlas.as_dataframe(reshaped_data[:DISPLAY_LIMIT])
dirpath = "./downloaded/"
forge_atlas.download(data, "distribution.contentUrl", dirpath)