CoCalc Public Fileswww / tables / j0n_invariants / transform_odd_lratio.pyOpen with one click!
Author: William A. Stein
1
#! /usr/bin/python
2
# transform.py -- transform data's data into my database format.
3
# William Stein
4
5
import os, string, sys
6
7
OUTDIR = "/home/was/magma_database/data/odd_lratios.data/"
8
cmd = "l_ratios"
9
10
if len(sys.argv) != 2:
11
print "Usage: " + sys.argv[0] + " data_file"
12
13
if not os.path.exists(sys.argv[1]):
14
print "file " + sys.argv[1] + " does not exist."
15
sys.exit(1)
16
17
data = open(sys.argv[1], "r").read() # we have tons of memory
18
19
i = 0
20
data = data[string.find(data,"J["):]
21
while string.find(data,"J[") != -1:
22
data = data[string.find(data,"J[")+2:]
23
j = string.find(data,"]")
24
N = data[:j]
25
data = data[string.find(data,cmd + " := ")+len(cmd + " := "):]
26
i = string.find(data,"],")
27
f = data[:i+1]
28
data = data[i+2:]
29
print N,":",f
30
fname = OUTDIR + "[%s,2]"%str(N)
31
print "fname = ", fname
32
out = open(fname,"w")
33
out.write(f)
34
out.close()
35
os.system('bzip2 -f -- "%s"'%fname)
36
37
38
39
40