In [1]:
import numpy as np
import ndio.remote.neurodata as neurodata
import ndio.ramon as ramon
import time
import ndio

start = time.time()

token = 'kasthuri2015_ramon_v4'
channel = 'neurons'
res = 3

In [2]:
'''
Identify available objects: 
1600 different neurons within this small region of mammalian brain (several billionths of the whole brain)
'''
nd = neurodata()

id_segment = nd.get_ramon_ids(token, channel, ramon_type=ramon.RAMONSegment)
id_neuron = nd.get_ramon_ids(token, channel, ramon_type=ramon.RAMONNeuron)
print 'Number of RAMON segments (unique objects) is: ' + str(len(id_segment))
print 'In the 3 volume cylinder we identified {} (RAMON) neurons'.format(len(id_neuron))


Number of RAMON segments (unique objects) is: 3945
In the 3 volume cylinder we identified 1907 (RAMON) neurons

In [3]:
# Retrieve metadata for all objects

# Get all segments
segAll = nd.get_ramon(token,channel,id_segment)

print '\ntime elapsed so far: ' + str(time.time()-start)


time elapsed so far: 246.337639093

In [4]:
# Sanity check

c = 0
for s in segAll:
    if s.kvpairs['is_spine'] == '1':
            c += 1
print c
print len(segAll)


1295
3945

In [5]:
# get all data in 3 cylinders
import numpy as np

# A priori known bounds for cylinders.  Alternatively we could sweep over entire volume - this is more efficient.

xbox = [173,449] #[694,1794]
ybox = [437, 615] #[1750, 2460]
zbox = [1004, 1379];
res = 5
# data are pre-masked
segments = nd.get_cutout(token, channel, xbox[0], xbox[1], ybox[0], ybox[1], zbox[0], zbox[1], resolution = res)

In [46]:
im = nd.get_cutout('kasthuri11cc', 'image', xbox[0], xbox[1], ybox[0], ybox[1], zbox[0], zbox[1], resolution = res)
import ndparse as ndp
%matplotlib inline  

ndp.plot(im, segments, slice =100, cmap1='gray', alpha=0.3)# for each object, loop through and relabel



In [7]:
'''
Identify Spines and Axons
'''

spine_id = []
spine_idx = []
axon_neurites = []
axon_neurons = []
axon_idx = []
c = 0

for x in segAll:
    #print x
    if x.segmentclass == 1:
        axon_neurites.append(int(x.id))
        axon_neurons.append(int(x.neuron))
        axon_idx.append(c)
    if x.kvpairs['is_spine'] == '1':
        spine_id.append(int(x.id))
        spine_idx.append(c)
    c += 1
print 'The total number of axon neurites in the three cylinders is: ' + str(len(axon_neurites))
print 'The total number of axons in the three cylinders is: ' + str(len(np.unique(axon_neurons)))

print 'The total number of spines in the three cylinders is: ' + str(len(spine_id))


The total number of axon neurites in the three cylinders is: 1766
The total number of axons in the three cylinders is: 1423
The total number of spines in the three cylinders is: 1295

In [8]:
# for each spinedil, add edge for each axon touch.neuron, [3, 3, 1]
# for each spine, add edge for each axon edge, which is spine.synapse.otherpartner.neuron
# save both graphs
# for each node in both graphs, add node attribute = spine or axon

import copy
segments2 = copy.copy(segments)
segments2 = np.ravel(segments)
t = time.time()

for x in range(0,len(spine_id)):
    segments2[segments2 == id_segment[spine_idx[x]]]
print str(time.time()-t)


31.7236480713

In [9]:
# TODO BETTER

# make spine mask
# make axon mask

spine_vol = np.zeros_like(segments)
for i in spine_id:
    #print i 
    spine_vol[segments == i] = i

axon_vol = np.zeros_like(segments)
for i in axon_neurites:
    #print i 
    axon_vol[segments == i] = i

In [10]:
spine_dil = copy.copy(spine_vol)

import mahotas
# dilate all spines
spine_dil = mahotas.dilate(spine_dil, Bc=np.ones([11,11,3]))

# remove all spines in original (to avoid overlap weirdness)
spine_dil[spine_vol > 0] = 0

In [11]:
# touch graph
# scale 5, epsilon, multiedge

import networkx as nx
graph_touch = nx.Graph()
axon_neurons = np.asarray(axon_neurons)

for i in spine_id:
    graph_touch.add_node(i)
    graph_touch[i]['type'] = 'spine'

for i in axon_neurons:
    graph_touch.add_node(i)
    graph_touch[i]['type'] = 'axon'

for s in spine_id:
    print str(s).zfill(4),

    val = axon_vol[s == spine_dil]
    val = np.unique(val)
    val = val[val > 0]
    
    for v in val:
        # TODO smarter way
        r = nd.get_ramon(token,'neurons',v)
        
        graph_touch.add_edge(s,r.neuron)
        #print v
        #print np.where(r.neuron == axon_neurons)


0133 0132 0131 0130 0137 0136 0135 0134 0139 0138 0025 0026 0027 0020 0021 0022 0023 0028 0029 0004 0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 0059 0058 0057 0051 0115 0114 0117 0116 0111 0110 0113 0112 0080 0081 0119 0118 0003 0108 0109 0102 0103 0100 0101 0106 0107 0104 0105 0038 0033 0032 0031 0037 0036 0035 0034 0060 0061 0062 0064 0065 0099 0151 0150 0152 0047 0042 0040 0041 0146 0147 0144 0145 0142 0143 0140 0141 0148 0149 0077 0076 0079 0078 0211 0428 0289 0288 0281 0280 0283 0282 0285 0284 0287 0286 0457 0302 0298 0299 0296 0297 0294 0295 0375 0293 0290 0291 0196 0191 0190 0275 0276 0277 0278 0279 0429 0443 0364 0425 0424 0300 0441 0446 0445 0444 0292 0419 0438 0439 0437 0434 0435 0432 0433 0430 0431 0334 0452 0331 0455 0456 0332 0179 0178 0177 0176 0175 0174 0173 0172 0171 0170 0182 0183 0180 0181 0186 0187 0184 0185 0188 0189 0168 0169 0164 0165 0166 0167 0160 0161 0162 0163 0153 0155 0154 0157 0156 0159 0158 0327 0374 0203 0359 0669 0662 0661 0660 0696 0697 0818 0819 0810 0811 0812 0813 0814 0815 0816 0817 0719 0718 0674 0675 0713 0829 0828 0825 0824 0827 0826 0821 0820 0823 0822 0708 0701 0702 0797 0796 0830 0794 0793 0792 0834 0835 0838 0839 0799 0798 0844 0843 0842 0841 0840 0641 0640 0643 0642 0645 0644 0647 0646 0656 0657 0654 0652 0653 0658 0659 0631 0632 0634 0637 0638 0464 0462 0729 0836 0832 0833 0831 0489 0487 0486 0485 0484 0801 0837 0809 0808 0476 0477 0474 0475 0803 0802 0478 0800 0807 0806 0805 0804 1070 1071 0995 0994 0997 0996 0999 0998 1015 1068 1061 1060 1063 1062 1065 1067 1066 1258 1085 1029 1028 1018 0918 1251 0914 0911 0913 0912 0977 0976 0847 0846 0845 0906 0907 0849 0848 1009 1000 0854 0855 0856 0857 0850 0851 0852 0853 0858 0859 1038 1039 1032 1033 1030 1031 1036 1037 1034 1035 1025 1024 1027 1026 1021 1020 1023 1022 0861 0860 0883 0882 0880 0887 0886 0885 0884 0889 0888 0878 0879 0877 0872 0873 0890 0891 0892 0893 0894 0898 0899 1043 1040 1045 1044 1059 1305 1306 1307 1303 1260 1308 2095 2094 2097 2096 2019 2014 2017 2013 1317 1315 1314 1313 1311 1310 1319 1562 1828 1557 1556 1559 1558 1827 1821 1822 1825 1667 1666 1662 1322 1320 1324 1325 1485 1489 1659 1338 1453 1341 1343 2025 2021 1452 2023 2028 1817 1818 1819 1611 1441 1560 1363 1278 1279 1273 1275 1276 1277 1609 1608 1280 1607 2964 2653 2655 2099 2098 3128 2404 2150 2403 2384 2383 2410 2392 2393 2391 2149 2774 3144 3145 3147 3148 3149 2381 2380 2664 2382 2662 2663 2660 2386 2389 2388 2669 2769 2766 3151 3157 3156 2671 2673 2379 2678 2370 2371 2689 2369 2110 3084 3086 2362 2361 2115 2109 2108 2103 2102 2101 2100 2107 2106 2105 2734 2639 2634 2741 2740 2742 2674 2727 2725 2724 2722 2729 3258 3259 3250 3251 3252 3253 3254 3255 3256 3257 3249 3248 3243 3241 3240 3247 3246 3245 3244 3261 3260 3263 3262 3264 3158 3168 3169 3166 3167 3165 3162 3163 3160 3161 3179 3171 3170 3172 3175 3174 3177 3232 3233 3236 3237 3234 3235 3238 3239 3180 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3333 3332 3331 3330 3337 3336 3335 3334 3339 3338 3276 3277 3274 3275 3272 3273 3270 3309 3306 3307 3304 3305 3302 3303 3278 3279 3319 3318 3267 3266 3269 3310 3313 3312 3314 3317 3316 3298 3299 3268 3294 3295 3296 3297 3290 3291 3292 3293 3364 3365 3360 3361 3362 3363 3289 3288 3287 3286 3285 3284 3283 3282 3281 3280 3308 3348 3349 3342 3343 3340 3341 3346 3347 3344 3345 3300 3301 3355 3354 3357 3356 3351 3350 3353 3359 3416 3417 3414 3415 3412 3410 3411 3418 3419 3401 3400 3403 3402 3405 3404 3407 3406 3409 3408 3377 3444 3375 3374 3441 3440 3443 3442 3386 3387 3384 3385 3382 3383 3380 3381 3389 3368 3457 3391 3465 3464 3462 3461 3396 3399 3398 3468 3367 3452 3450 3456 3369 3454 3455 3366 3459 3467 3466 3392 3463 3449 3448 3379 3378 3445 3376 3446 3373 3371 3370 3460 3438 3439 3430 3431 3432 3433 3434 3435 3436 3437 3397 3429 3428 3423 3422 3421 3420 3427 3426 3425 3424 3498 3499 3496 3497 3494 3495 3492 3493 3490 3491 3557 3556 3555 3554 3553 3551 3550 3559 3558 3489 3481 3480 3483 3482 3485 3484 3487 3486 3562 3563 3560 3561 3566 3567 3564 3565 3568 3474 3475 3476 3477 3470 3471 3472 3473 3570 3479 3508 3500 3501 3502 3503 3504 3505 3469 3518 3513 3512 3517 3516 3515 3514 3526 3527 3525 3522 3523 3520 3521 3528 3529 3531 3530 3533 3532 3535 3534 3537 3536 3539 3538 3545 3546 3547 3540 3541 3542 3543 3548 3549 3610 3592 3612 3613 3654 3655 3656 3650 3651 3652 3653 3616 3594 3647 3646 3643 3641 3665 3664 3672 3660 3579 3578 3575 3574 3577 3576 3571 3573 3572 3580 3581 3661 3585 3587 3588 3589 3669 3668 3615 3593 3611 3591 3590 3597 3596 3595 3617 3618 3619 3599 3598 3614 3602 3600 3605 3604 3609 3608 3584 3638 3639 3637 3634 3635 3631 3628 3625 3627 3626 3663 3662 3679 3676 3677 3699 3694 3695 3697 3681 3700 3798 3809 3808 3801 3800 3803 4263 4267 4270 4363 4315 4317 4479 4475 4474 4476 4405 4401 4402 4481 4482 4419 4420 4421 4426 4427 4425 4398 4559 4538 4535 4536 4537 4530 4533 4529 4585 4584 4586 4583 4649 4642 4644 4645 4620 4621 4623 4625 4619 4617 4592 4593 4668 4669 4665 4667 4663 4589 4588 4724 4726 4758 4752 4755 4774 4772 4693 4695 4694 4715 4718 4815 4922 5020 4923 5146 5147 5144 5145 5142 5140 5141 5159 5158 5150 5153 5152 5154 5157 5128 5139 5138 5137 5135 5134 5133 5132 5131 5130 5116 5148 5149 5161 5162 5163 5164 5143 5173 5172 5171 5177 5176 5175 5260 5189 5252 5253 5250 5251 5255 5258 5259 5249 5248 5245 5244 5247 5246 5240 5243 5238 5239 5235 5236 5237 5181 5186 5187 5185 5188 5224 5216 5214 5199 5198 5197 5196 5191 5193 5192 5165 5166 5201 5200 5308 5309 5307 5311 5310 5326 5323 5329 5333 5335 5337 5339 5338 5340 5341 5342 5357 5355 5359 5361 5476 5472 5473 5471 5379 5378 5374 5377 5380 5381 5382 5383 5384 5386 5387 5388 5460 5462 5465 5464 5467 5414 5415 5416 5417 5410 5411 5412 5418 5406 5402 5401 5409 5433 5437 5434 5438 5439 5458 5459 5451 5453 5456 5449 5448 5443 5442 5441 5440 5446 5444 5509 5504 5505 5503 5501 5581 5510 5513 5512 5515 5514 5498 5499 5494 5495 5496 5490 5491 5492 5493 5566 5560 5562 5478 5479 5489 5488 5486 5485 5484 5483 5482 5481 5579 5548 5549 5542 5540 5546 5544 5555 5554 5557 5551 5553 5552 5559 5558 5520 5524 5525 5526 5527 5528 5529 5532 5531 5530 5537 5535 5538 5586 5584 5582 5583 5629 5626 5625 5624 5622 5588 5589 5593 5619 5591 5590 5618 5592 5594 5597 5596 5598 5610 5617 5614 5605 5604 5607 5606 5601 5600 5603 5602 5682 5679 5662 5621 5665 5664 5656 5654 5655 5653 5638 5635 5632 5742 5699 5727 5820 5829 5872 5873 5865 5862 5895 5813 5886 5988 5987 6008 5990 5916 5968 6004 5977 5946 5921 5922 5923 6098 6040 6114 6027 6244 6493

In [12]:
print graph_touch.number_of_edges()
print graph_touch.number_of_nodes()


17039
2718

In [ ]:


In [13]:
print '\ntime elapsed so far: ' + str(time.time()-start)


time elapsed so far: 2614.13832593

In [14]:
'''# Relabel everything
import copy
neurons = copy.copy(segments)

def ismember(a, b):
    bind = {}
    for i, elt in enumerate(b):
        if elt not in bind:
            bind[elt] = i
    return [bind.get(itm, None) for itm in a]  # None can be replaced by any other "not in b" value

for s in range(0,len(id_segment)):
    print s
    neurons[ismember(id_segment[s],segments)] = segAll[s].neuron
    '''
# synapse graph
#ndp.plot(spine_dil,slice=100)

#notaxon = np.setdiff1d(np.asarray(id_segment),np.asarray(axon_neurites))
#notspine = np.setdiff1d(np.asarray(id_segment),np.asarray(spine_id))    
#axon_vol = mahotas.labeled.remove_regions(segments, notaxon)
#s2 = mahotas.dilate(segments,np.ones([3,3,1]))


Out[14]:
'# Relabel everything\nimport copy\nneurons = copy.copy(segments)\n\ndef ismember(a, b):\n    bind = {}\n    for i, elt in enumerate(b):\n        if elt not in bind:\n            bind[elt] = i\n    return [bind.get(itm, None) for itm in a]  # None can be replaced by any other "not in b" value\n\nfor s in range(0,len(id_segment)):\n    print s\n    neurons[ismember(id_segment[s],segments)] = segAll[s].neuron\n    '

In [52]:
# Synapse graph
import networkx as nx
graph_synapse = nx.Graph()

for i in spine_id:
    graph_synapse.add_node(i)
    graph_synapse[i]['type'] = 'spine'

for i in axon_neurons:
    graph_synapse.add_node(i)
    graph_synapse[i]['type'] = 'axon'

for s in spine_id:
    print str(s).zfill(4),
    r = nd.get_ramon(token,'neurons',s)
    
    if len(r.synapses) > 0:
        syn = r.synapses[0]
        ss = nd.get_ramon(token, 'synapses', syn)
    
        axon = ss.kvpairs['presynaptic']
    
        if axon is not None:
            axon = int(axon)
            graph_synapse.add_edge(s,axon,weight=1)


 0133 0132 0131 0130 0137 0136 0135 0134 0139 0138 0025 0026 0027 0020 0021 0022 0023 0028 0029 0004 0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 0059 0058 0057 0051 0115 0114 0117 0116 0111 0110 0113 0112 0080 0081 0119 0118 0003 0108 0109 0102 0103 0100 0101 0106 0107 0104 0105 0038 0033 0032 0031 0037 0036 0035 0034 0060 0061 0062 0064 0065 0099 0151 0150 0152 0047 0042 0040 0041 0146 0147 0144 0145 0142 0143 0140 0141 0148 0149 0077 0076 0079 0078 0211 0428 0289 0288 0281 0280 0283 0282 0285 0284 0287 0286 0457 0302 0298 0299 0296 0297 0294 0295 0375 0293 0290 0291 0196 0191 0190 0275 0276 0277 0278 0279 0429 0443 0364 0425 0424 0300 0441 0446 0445 0444 0292 0419 0438 0439 0437 0434 0435 0432 0433 0430 0431 0334 0452 0331 0455 0456 0332 0179 0178 0177 0176 0175 0174 0173 0172 0171 0170 0182 0183 0180 0181 0186 0187 0184 0185 0188 0189 0168 0169 0164 0165 0166 0167 0160 0161 0162 0163 0153 0155 0154 0157 0156 0159 0158 0327 0374 0203 0359 0669 0662 0661 0660 0696 0697 0818 0819 0810 0811 0812 0813 0814 0815 0816 0817 0719 0718 0674 0675 0713 0829 0828 0825 0824 0827 0826 0821 0820 0823 0822 0708 0701 0702 0797 0796 0830 0794 0793 0792 0834 0835 0838 0839 0799 0798 0844 0843 0842 0841 0840 0641 0640 0643 0642 0645 0644 0647 0646 0656 0657 0654 0652 0653 0658 0659 0631 0632 0634 0637 0638 0464 0462 0729 0836 0832 0833 0831 0489 0487 0486 0485 0484 0801 0837 0809 0808 0476 0477 0474 0475 0803 0802 0478 0800 0807 0806 0805 0804 1070 1071 0995 0994 0997 0996 0999 0998 1015 1068 1061 1060 1063 1062 1065 1067 1066 1258 1085 1029 1028 1018 0918 1251 0914 0911 0913 0912 0977 0976 0847 0846 0845 0906 0907 0849 0848 1009 1000 0854 0855 0856 0857 0850 0851 0852 0853 0858 0859 1038 1039 1032 1033 1030 1031 1036 1037 1034 1035 1025 1024 1027 1026 1021 1020 1023 1022 0861 0860 0883 0882 0880 0887 0886 0885 0884 0889 0888 0878 0879 0877 0872 0873 0890 0891 0892 0893 0894 0898 0899 1043 1040 1045 1044 1059 1305 1306 1307 1303 1260 1308 2095 2094 2097 2096 2019 2014 2017 2013 1317 1315 1314 1313 1311 1310 1319 1562 1828 1557 1556 1559 1558 1827 1821 1822 1825 1667 1666 1662 1322 1320 1324 1325 1485 1489 1659 1338 1453 1341 1343 2025 2021 1452 2023 2028 1817 1818 1819 1611 1441 1560 1363 1278 1279 1273 1275 1276 1277 1609 1608 1280 1607 2964 2653 2655 2099 2098 3128 2404 2150 2403 2384 2383 2410 2392 2393 2391 2149 2774 3144 3145 3147 3148 3149 2381 2380 2664 2382 2662 2663 2660 2386 2389 2388 2669 2769 2766 3151 3157 3156 2671 2673 2379 2678 2370 2371 2689 2369 2110 3084 3086 2362 2361 2115 2109 2108 2103 2102 2101 2100 2107 2106 2105 2734 2639 2634 2741 2740 2742 2674 2727 2725 2724 2722 2729 3258 3259 3250 3251 3252 3253 3254 3255 3256 3257 3249 3248 3243 3241 3240 3247 3246 3245 3244 3261 3260 3263 3262 3264 3158 3168 3169 3166 3167 3165 3162 3163 3160 3161 3179 3171 3170 3172 3175 3174 3177 3232 3233 3236 3237 3234 3235 3238 3239 3180 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3333 3332 3331 3330 3337 3336 3335 3334 3339 3338 3276 3277 3274 3275 3272 3273 3270 3309 3306 3307 3304 3305 3302 3303 3278 3279 3319 3318 3267 3266 3269 3310 3313 3312 3314 3317 3316 3298 3299 3268 3294 3295 3296 3297 3290 3291 3292 3293 3364 3365 3360 3361 3362 3363 3289 3288 3287 3286 3285 3284 3283 3282 3281 3280 3308 3348 3349 3342 3343 3340 3341 3346 3347 3344 3345 3300 3301 3355 3354 3357 3356 3351 3350 3353 3359 3416 3417 3414 3415 3412 3410 3411 3418 3419 3401 3400 3403 3402 3405 3404 3407 3406 3409 3408 3377 3444 3375 3374 3441 3440 3443 3442 3386 3387 3384 3385 3382 3383 3380 3381 3389 3368 3457 3391 3465 3464 3462 3461 3396 3399 3398 3468 3367 3452 3450 3456 3369 3454 3455 3366 3459 3467 3466 3392 3463 3449 3448 3379 3378 3445 3376 3446 3373 3371 3370 3460 3438 3439 3430 3431 3432 3433 3434 3435 3436 3437 3397 3429 3428 3423 3422 3421 3420 3427 3426 3425 3424 3498 3499 3496 3497 3494 3495 3492 3493 3490 3491 3557 3556 3555 3554 3553 3551 3550 3559 3558 3489 3481 3480 3483 3482 3485 3484 3487 3486 3562 3563 3560 3561 3566 3567 3564 3565 3568 3474 3475 3476 3477 3470 3471 3472 3473 3570 3479 3508 3500 3501 3502 3503 3504 3505 3469 3518 3513 3512 3517 3516 3515 3514 3526 3527 3525 3522 3523 3520 3521 3528 3529 3531 3530 3533 3532 3535 3534 3537 3536 3539 3538 3545 3546 3547 3540 3541 3542 3543 3548 3549 3610 3592 3612 3613 3654 3655 3656 3650 3651 3652 3653 3616 3594 3647 3646 3643 3641 3665 3664 3672 3660 3579 3578 3575 3574 3577 3576 3571 3573 3572 3580 3581 3661 3585 3587 3588 3589 3669 3668 3615 3593 3611 3591 3590 3597 3596 3595 3617 3618 3619 3599 3598 3614 3602 3600 3605 3604 3609 3608 3584 3638 3639 3637 3634 3635 3631 3628 3625 3627 3626 3663 3662 3679 3676 3677 3699 3694 3695 3697 3681 3700 3798 3809 3808 3801 3800 3803 4263 4267 4270 4363 4315 4317 4479 4475 4474 4476 4405 4401 4402 4481 4482 4419 4420 4421 4426 4427 4425 4398 4559 4538 4535 4536 4537 4530 4533 4529 4585 4584 4586 4583 4649 4642 4644 4645 4620 4621 4623 4625 4619 4617 4592 4593 4668 4669 4665 4667 4663 4589 4588 4724 4726 4758 4752 4755 4774 4772 4693 4695 4694 4715 4718 4815 4922 5020 4923 5146 5147 5144 5145 5142 5140 5141 5159 5158 5150 5153 5152 5154 5157 5128 5139 5138 5137 5135 5134 5133 5132 5131 5130 5116 5148 5149 5161 5162 5163 5164 5143 5173 5172 5171 5177 5176 5175 5260 5189 5252 5253 5250 5251 5255 5258 5259 5249 5248 5245 5244 5247 5246 5240 5243 5238 5239 5235 5236 5237 5181 5186 5187 5185 5188 5224 5216 5214 5199 5198 5197 5196 5191 5193 5192 5165 5166 5201 5200 5308 5309 5307 5311 5310 5326 5323 5329 5333 5335 5337 5339 5338 5340 5341 5342 5357 5355 5359 5361 5476 5472 5473 5471 5379 5378 5374 5377 5380 5381 5382 5383 5384 5386 5387 5388 5460 5462 5465 5464 5467 5414 5415 5416 5417 5410 5411 5412 5418 5406 5402 5401 5409 5433 5437 5434 5438 5439 5458 5459 5451 5453 5456 5449 5448 5443 5442 5441 5440 5446 5444 5509 5504 5505 5503 5501 5581 5510 5513 5512 5515 5514 5498 5499 5494 5495 5496 5490 5491 5492 5493 5566 5560 5562 5478 5479 5489 5488 5486 5485 5484 5483 5482 5481 5579 5548 5549 5542 5540 5546 5544 5555 5554 5557 5551 5553 5552 5559 5558 5520 5524 5525 5526 5527 5528 5529 5532 5531 5530 5537 5535 5538 5586 5584 5582 5583 5629 5626 5625 5624 5622 5588 5589 5593 5619 5591 5590 5618 5592 5594 5597 5596 5598 5610 5617 5614 5605 5604 5607 5606 5601 5600 5603 5602 5682 5679 5662 5621 5665 5664 5656 5654 5655 5653 5638 5635 5632 5742 5699 5727 5820 5829 5872 5873 5865 5862 5895 5813 5886 5988 5987 6008 5990 5916 5968 6004 5977 5946 5921 5922 5923 6098 6040 6114 6027 6244 6493

In [47]:
print graph_synapse.number_of_edges()
print graph_synapse.number_of_nodes()


2537
3359

In [53]:
nx.write_edgelist(graph_synapse, 'kasthuri2015_ramon_v4_graph_synapse.edgelist')
#nx.write_graphml(graph_synapse, 'kasthuri2015_ramon_v4_graph_synapse.graphml')
nx.write_edgelist(graph_touch, 'kasthuri2015_ramon_v4_graph_touch.edgelist')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-53-43655c88ec1b> in <module>()
      1 nx.write_edgelist(graph_synapse, 'kasthuri2015_ramon_v4_graph_synapse.edgelist')
----> 2 nx.write_graphml(graph_synapse, 'kasthuri2015_ramon_v4_graph_synapse.graphml')
      3 nx.write_edgelist(graph_touch, 'kasthuri2015_ramon_v4_graph_touch.edgelist')

<decorator-gen-325> in write_graphml(G, path, encoding, prettyprint)

/Users/graywr1/anaconda2/lib/python2.7/site-packages/networkx/utils/decorators.py in _open_file(func, *args, **kwargs)
    218         # Finally, we call the original function, making sure to close the fobj.
    219         try:
--> 220             result = func(*new_args, **kwargs)
    221         finally:
    222             if close_fobj:

/Users/graywr1/anaconda2/lib/python2.7/site-packages/networkx/readwrite/graphml.py in write_graphml(G, path, encoding, prettyprint)
     80     """
     81     writer = GraphMLWriter(encoding=encoding,prettyprint=prettyprint)
---> 82     writer.add_graph_element(G)
     83     writer.dump(path)
     84 

/Users/graywr1/anaconda2/lib/python2.7/site-packages/networkx/readwrite/graphml.py in add_graph_element(self, G)
    349         self.add_attributes("graph", graph_element, data, default)
    350         self.add_nodes(G,graph_element)
--> 351         self.add_edges(G,graph_element)
    352         self.xml.append(graph_element)
    353 

/Users/graywr1/anaconda2/lib/python2.7/site-packages/networkx/readwrite/graphml.py in add_edges(self, G, graph_element)
    323                                        target=make_str(v))
    324                 default=G.graph.get('edge_default',{})
--> 325                 self.add_attributes("edge", edge_element, data, default)
    326                 graph_element.append(edge_element)
    327 

/Users/graywr1/anaconda2/lib/python2.7/site-packages/networkx/readwrite/graphml.py in add_attributes(self, scope, xml_obj, data, default)
    295         """Appends attributes to edges or nodes.
    296         """
--> 297         for k,v in data.items():
    298             default_value=default.get(k)
    299             obj=self.add_data(make_str(k), type(v), make_str(v),

AttributeError: 'str' object has no attribute 'items'

In [ ]:
print '\ntime elapsed so far: ' + str(time.time()-start)

In [42]:
len(r.synapses)


Out[42]:
0

In [21]:
syn = r.synapses[0]




In [22]:
syn


Out[22]:
1379

In [ ]: