/
SpreadsheetDataReader.py
144 lines (93 loc) · 4.5 KB
/
SpreadsheetDataReader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
############################################################
# A simple script to read the values in CElegansNeuronTables.xls.
# Note: this file will be replaced with a call to PyOpenWorm
# when that package is updated to read all of this data from the
# spreadseet
############################################################
from NeuroMLUtilities import ConnectionInfo
from xlrd import open_workbook
import os
spreadsheet_location = os.path.dirname(os.path.abspath(__file__))+"/../../../"
def readDataFromSpreadsheet(include_nonconnected_cells=False, neuron_connect=False):
# reading the NeuronConnect.xls file if neuron_connect = True
if neuron_connect:
conns = []
cells = []
filename = "%sNeuronConnectFormatted.xlsx"%spreadsheet_location
rb = open_workbook(filename)
print("Opened Excel file: " + filename)
for row in range(1,rb.sheet_by_index(0).nrows):
pre = str(rb.sheet_by_index(0).cell(row,0).value)
post = str(rb.sheet_by_index(0).cell(row,1).value)
syntype = rb.sheet_by_index(0).cell(row,2).value
num = int(rb.sheet_by_index(0).cell(row,3).value)
synclass = 'Generic_GJ' if 'EJ' in syntype else 'Chemical_Synapse'
conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
if pre not in cells:
cells.append(pre)
if post not in cells:
cells.append(post)
return cells, conns
else:
conns = []
cells = []
filename = "%sCElegansNeuronTables.xls"%spreadsheet_location
rb = open_workbook(filename)
print("Opened Excel file: " + filename)
known_nonconnected_cells = ['CANL', 'CANR', 'VC6']
for row in range(1,rb.sheet_by_index(0).nrows):
pre = str(rb.sheet_by_index(0).cell(row,0).value)
post = str(rb.sheet_by_index(0).cell(row,1).value)
syntype = rb.sheet_by_index(0).cell(row,2).value
num = int(rb.sheet_by_index(0).cell(row,3).value)
synclass = rb.sheet_by_index(0).cell(row,4).value
conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
if pre not in cells:
cells.append(pre)
if post not in cells:
cells.append(post)
if include_nonconnected_cells:
for c in known_nonconnected_cells: cells.append(c)
return cells, conns
def readMuscleDataFromSpreadsheet():
conns = []
neurons = []
muscles = []
filename = "%sCElegansNeuronTables.xls"%spreadsheet_location
rb = open_workbook(filename)
print("Opened Excel file: "+ filename)
sheet = rb.sheet_by_index(1)
for row in range(1,sheet.nrows):
pre = str(sheet.cell(row,0).value)
post = str(sheet.cell(row,1).value)
syntype = 'Send'
num = int(sheet.cell(row,2).value)
synclass = sheet.cell(row,3).value.replace(',', 'plus').replace(' ', '_')
conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
if pre not in neurons:
neurons.append(pre)
if post not in muscles:
muscles.append(post)
return neurons, muscles, conns
def main():
cells, conns = readDataFromSpreadsheet()
print("%i cells in spreadsheet: %s..."%(len(cells),sorted(cells)[0:3]))
from os import listdir
from os.path import isfile
cell_names = [ f[:-9] for f in listdir('%s/CElegans/morphologies/'%spreadsheet_location) if f.endswith('.java.xml')]
cell_names.remove('MDL08') # muscle
s_c = sorted(cell_names)
print("%i cell morphologies found: %s..."%(len(cell_names),s_c[0:3]))
for c in cells: cell_names.remove(c)
print("Difference: %s"%cell_names)
cells2, conns2 = readDataFromSpreadsheet(include_nonconnected_cells=True)
assert(len(cells2) == 302)
print("Lengths are equal if include_nonconnected_cells=True")
print("Found %s connections: %s..."%(len(conns2),conns2[0]))
neurons, muscles, conns = readMuscleDataFromSpreadsheet()
print("Found %i neurons connected to muscles: %s"%(len(neurons), sorted(neurons)))
print("Found %i muscles connected to neurons: %s"%(len(muscles), sorted(muscles)))
print("Found %i connections between neurons and muscles, e.g. %s"%(len(conns), conns[0]))
if __name__ == '__main__':
main()