This repository was archived by the owner on Mar 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.py
More file actions
executable file
·71 lines (63 loc) · 2.49 KB
/
collection.py
File metadata and controls
executable file
·71 lines (63 loc) · 2.49 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
import httplib, urllib, tempfile
#from elementtree.ElementTree import fromstring
from xml.etree.ElementTree import fromstring
class Collection:
def get_collection(self,cid,name,password):
self.cid = cid
params = urllib.urlencode({'name': name, 'password': password})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("birg.cs.wright.edu")
conn.request("GET","/omics_analysis/spectra_collections/" + str(cid) + ".xml",params,headers)
r = conn.getresponse()
print r.status, r.reason
if r.status != 200:
return r
f = tempfile.TemporaryFile()
data = r.read()
e = fromstring(data)
data_e = e.find("data")
f.write(data_e.text)
conn.close()
f.seek(0)
data_start = False
for line in f:
fields = line.rstrip().split("\t")
if fields[0] == 'X' or fields[0] == 'x':
data_start = True
self.x = []
self.Y = []
for i in range(0,len(fields)-1):
self.Y.append([])
elif data_start:
self.x.append(float(fields[0]))
for i in range(0,len(fields)-1):
self.Y[i].append(float(fields[i+1]))
f.seek(0)
self.metadata = {}
for line in f:
fields = line.rstrip().split("\t")
if fields[0] == 'X' or fields[0] == 'x':
break
else:
# Try to convert to numbers
values = []
for i in range(0,len(self.Y)):
values.append(None)
all_empty = True
try:
for i in range(1,len(fields)):
if fields[i] != None:
all_empty = False
v1 = int(fields[i])
v2 = float(fields[i])
if v1 == v2:
values[i-1] = v1
else:
values[i-1] = v2
except ValueError:
values = [] # Has at least one string
if len(values) == 0 and len(fields) > 1:
values = fields[1:len(fields)+1]
self.metadata[fields[0]] = values
f.close()
return r