Created
March 6, 2013 20:21
-
-
Save slarson/5102708 to your computer and use it in GitHub Desktop.
Sample revision of d3-converter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#OpenWorm CSV to JSON | |
#Author: Gaston Gentile | |
import gspread, getpass, os | |
os.system('clear') | |
#Primer paso, los datos son tomados / First Step, data is taken. | |
def start(): | |
print 'Convert CSV to JSON' | |
user = raw_input("Gmail user: ") | |
pwd = getpass.getpass("Gmail Password: ") | |
gc = gspread.login(user,pwd) | |
docurl = raw_input("Spreadsheet url: ") | |
sh = gc.open_by_url(docurl)#apertura del documento / Open Doc. | |
worksheet = sh.worksheet("Single Neurons")#Seleccion de la hoja / Sheet selection. | |
print 'Taking values...' | |
#Toma los valores de las celdas / Take value of celds. | |
colb = worksheet.col_values(2) | |
cold = worksheet.col_values(4) | |
colf = worksheet.col_values(6) | |
#Segundo paso, datos convertidos / Second Step, converted data. | |
print 'Converting values to JSON...' | |
celd = 2 | |
celegans = open('celegans.json','w') | |
head = {'name': 'NeuroNetwork'} | |
chld = {} | |
for i in range(301): | |
chld = {'name': cold[celd] } | |
listOfReceptors = colf[celd] | |
pythonListOfReceptors = listOfReceptors.split() | |
jsonList = [{'name': cold[celd], 'size': 3000}] | |
for j in pythonListOfReceptors: | |
jsonList.append({'name': j, 'size': 3000}) | |
chld['children'] = jsonList | |
celd += 1 | |
head['children'] = chld | |
celegans.write(json.dumps(head, sort_keys=False, indent=4)) | |
celegans.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I could run the script, but the structure still is not the correct, here are my modifications:
I could run the script, but the structure still is not the correct. Here are my modifications:
Start with the modifications:
First, for not copy and paste the link of the sheet, I automate this step.
Second, I change the listOfReceptors to listOfNeurotransmitters, and I remove the index.
Third, I modify the jsonList variable to jsonListN (N for Neurotransmitters), and also I add jsonListR (R for Receptors).
Forth, in this loop I have a problem, the Neurotransmitters and Receptors are write in the json file, but not interspersed (namely: neurotransmitter, receptor, neurotransmitter, receptor, etc.), is written in blocks, namely first all the neurotransmitters and then all the receptors.
Other problem, is the name of each neuron, only appear in the first time, then do not appear.