-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvToJSON.py
More file actions
executable file
·99 lines (82 loc) · 2.4 KB
/
csvToJSON.py
File metadata and controls
executable file
·99 lines (82 loc) · 2.4 KB
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
#! /usr/env/python
# this script converts the csv energy tables into a JSON file
import io
import pprint
import json
def getValues(fileName):
#read in 2-2 loop
infile = io.open(fileName, 'r')
# get only first line
firstLine = infile.readline()
lineList = firstLine.strip().split(",")
colsToRowsToValues = {}
for col in lineList[1:]: #skip the first item because it's just table label
if col not in colsToRowsToValues:
colsToRowsToValues[col] = {}
else:
continue
# get all the other rows
for line in infile:
lineList = line.strip().split(",")
row = lineList[0] # row names
# get index and value for all keys in loop_2_2 (col names)
num = 1
for col, value in colsToRowsToValues.iteritems():
if row not in colsToRowsToValues[col]:
colsToRowsToValues[col][row] = lineList[num]
num += 1
infile.close()
return colsToRowsToValues
loop_2_2 = getValues('csv/Loop_2_2.csv')
f = open('loop_2_2.json', 'w')
json.dump(loop_2_2, f)
f.close()
loop_1_2 = getValues('csv/Loop_1_2.csv')
f = open('loop_1_2.json', 'w')
json.dump(loop_1_2, f)
f.close()
bulge_1nt = getValues('csv/Bulge_1nt.csv')
f = open('bulge_1nt.json', 'w')
json.dump(bulge_1nt, f)
f.close()
bulge_2nt = getValues('csv/Bulge_2nt.csv')
f = open('bulge_2nt.json', 'w')
json.dump(bulge_2nt, f)
f.close()
bulge_3nt = getValues('csv/Bulge_3nt.csv')
f = open('bulge_3nt.json', 'w')
json.dump(bulge_3nt, f)
f.close()
bulge_4nt = getValues('csv/Bulge_4nt.csv')
f = open('bulge_4nt.json', 'w')
json.dump(bulge_4nt, f)
f.close()
bulge_5nt = getValues('csv/Bulge_5nt.csv')
f = open('bulge_5nt.json', 'w')
json.dump(bulge_5nt, f)
f.close()
bulge_6nt = getValues('csv/Bulge_6nt.csv')
f = open('bulge_6nt.json', 'w')
json.dump(bulge_6nt, f)
f.close()
hairpin = getValues('csv/Hairpin.csv')
f = open('hairpin.json', 'w')
json.dump(hairpin, f)
f.close()
loop_1_1_GG = getValues('csv/Loop_1_1_GG.csv')
f = open('loop_1_1_GG.json', 'w')
json.dump(loop_1_1_GG, f)
f.close()
loop_1_1_UU = getValues('csv/Loop_1_1_UU.csv')
f = open('loop_1_1_UU.json', 'w')
json.dump(loop_1_1_UU, f)
f.close()
loop_1_1_noboost = getValues('csv/Loop_1_1.csv')
f = open('loop_1_1_noboost.json', 'w')
json.dump(loop_1_1_noboost, f)
f.close()
#rnaTypes = ['loop_2_2', 'loop_1_2', 'bulge_1nt', 'bulge_2nt', 'bulge_3nt',
# 'Bulge_4nt', 'Bulge_5nt', 'Bulge_6nt', 'Hairpin', 'Loop_1_1_GG', 'Loop_1_1_UU']
#for rna in rnaTypes:
# f.open(rna + '.json', 'w')
# json.dump(#what do i use here)