def main(): token = 'collman15v2' channel = 'annotation' metadata = readMetadata('cleft_class.csv') nd = ND(hostname='synaptomes.neurodata.io/nd/') for ridx in metadata.keys(): robj = createRamonSynapse(ridx, metadata[ridx], 0, confidence=1, author='Forrest Collman') nd.post_ramon(token, channel, robj) print "Successfully posted ramon obj {}".format(ridx)
def create_ramon_volume(self, token, channel, annofile, ramonobj, conncomp=0, remote='neurodata'): """ Use ndio to put annotated nifti volume to a remote This first prototype only uploads annotation labels TODO: Extend to parse upload params from filename Arguments: data: nifti volume to convert Returns: Success or failure """ import ndio.convert.nifti as ndnifti if remote is 'neurodata': import ndio.remote.neurodata as ND nd = ND() else: raise ValueError("remote option not implemented.") anno = ndnifti.import_nifti(annofile) anno = np.int32(anno) if conncomp is 1: anno = mahotas.labeled.label(anno, Bc=np.ones([3, 3, 3]))[0] # relabel ids from 1 print('relabeling IDs...') anno, n_label = mahotas.labeled.relabel(anno) print('reserving IDs...') n_label = int(n_label) ids = nd.reserve_ids(token, channel, n_label) # ids is 0 indexed # anno begins at 1 # TODO: guarantee that these are contiguous anno[anno > 0] += ids[0] - 1 ramon_list = [] for x in range(0, n_label): r = ramonobj r.id = ids[x] ramon_list.append(r) return anno, ramon_list
def get_mana_volume(self, token, channel, x_start, x_stop, y_start, y_stop, z_start, z_stop, resolution, server='openconnecto.me', remote='neurodata', outdir='.'): """ Use ndio to get volume from a remote and convert to NIFTI. We recommend users use ITK-Snap for annotations. Arguments: token (str): Token to identify data to download channel (str): Channel resolution (int): Resolution level Q_start (int): The lower bound of dimension 'Q' Q_stop (int): The upper bound of dimension 'Q' server: default server for remote remote: name for remote to use outdir: location for nifti file Returns: Downloaded data. """ import ndio.convert.nifti as ndnifti import os.path if remote is 'neurodata': import ndio.remote.neurodata as ND nd = ND(server) else: raise ValueError("remote option not implemented.") image = nd.get_cutout(token, channel, x_start, x_stop, y_start, y_stop, z_start, z_stop, resolution=resolution) fileout = '{}_{}_x{}-{}_y{}-{}_z{}-{}_r{}' \ '.nii'.format(token, channel, x_start, x_stop, y_start, y_stop, z_start, z_stop, resolution) print(fileout) ndnifti.export_nifti(os.path.abspath(os.path.join( outdir, fileout)), image) return fileout
import ndio.convert.nifti as ndnii #import nifti workflow print 'imported nifti convert' data = ndnii.load("Fear199_400_600_1850_2050_450_550_res2_anno.nii") #numpy array from my file print 'made numpy array' print data.shape #check array shape import ndio.remote.neurodata as ND #import neurodata print 'imported neurodata remote' oo = ND() #instantiate neurodata print 'instance of neurodata created' #oo.delete_channel("Fear199", "GLMannotation") #print 'deleted f****d up channel' oo.create_channel('Fear199', 'GLMAnnotationFixed', oo.ANNOTATION, 'uint32', False) #make channel to add annotation print 'created new channel' oo.post_cutout('Fear199', 'GLMAnnotationFixed', 0, 0, 0, data, 2) #token, channel, z, x, y, data, resolution print 'uploaded data to channel' print 'done'
def gen_ramon_graph(token_synapse, channel_synapse, token_neurons, channel_neurons, resolution, is_directed=False, save_graphml=None): # TODO support segment graphs # TODO support filter synapses # TODO support multiple servers # TODO support other graph output options # TODO support enriched graph import numpy as np import ndio.remote.neurodata as ND import ndio.ramon as ramon import networkx as nx nd = ND() id_synapse = nd.get_ramon_ids(token_synapse, channel_synapse, ramon_type=ramon.RAMONSynapse) print('There are: {} synapses'.format(len(id_synapse))) # Instantiate graph instance if is_directed is False: # undirected case G = nx.Graph() else: G = nx.DiGraph() # for each synapse for x in range(np.shape(id_synapse)[0]): #print(str(x).zfill(4),end=" ") s = nd.get_ramon_metadata(token_synapse, channel_synapse, [id_synapse[x]])[0] # for each segment segments = s.segments[:, 0] direction = s.segments[:, 1] # 1: axon/pre, 2: dendrite/post # print direction if len(segments) != 2: print('multi-way synapses not implemented!') raise s1 = nd.get_ramon_metadata(token_neurons, channel_neurons, [segments[0]])[0] n1 = s1.neuron s2 = nd.get_ramon_metadata(token_neurons, channel_neurons, [segments[1]])[0] n2 = s2.neuron if is_directed is False or (direction[0] == 1 and direction[1] == 2): if G.has_edge(n1, n2): # edge already exists, increase weight G[n1][n2]['weight'] += 1 else: # new edge. add with weight=1 G.add_edge(n1, n2, weight=1) elif direction[0] == 2 and direction[1] == 1: if G.has_edge(n2, n1): # edge already exists, increase weight G[n2][n1]['weight'] += 1 else: # new edge. add with weight=1 G.add_edge(n2, n1, weight=1) else: print('1 pre and 1 post synaptic partner are' ' required for directed graph estimation.') raise if save_file is not None: # Save graphml graph nx.write_graphml(G, save_graphml)