-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperiment.py
More file actions
67 lines (55 loc) · 1.97 KB
/
Copy pathexperiment.py
File metadata and controls
67 lines (55 loc) · 1.97 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
import os
import tempfile
from zlib import decompress, compress, error as zerr
from rpy2 import robjects
from subprocess import call
class PlateExperiment:
def __init__(self, postData):
# decompress if compressed with zlib
# checks for a zlib header in bytestring which could invoke
# false negatives
if postData.has_key('compressed'):
for key in postData.keys():
try:
postData[key] = decompress(postData[key])
except zerr as ze:
print 'ZLIB: %s' %(ze)
pass
# write files out to temp
self.tmpDir = tempfile.mkdtemp(suffix='_ks')
for f in postData['files']:
print f
fopen = open(os.path.join(self.tmpDir, f), 'w')
fopen.write(postData[f])
fopen.close()
try:
# parse EnVision Plate Reader datasets
self.pr = PlateReader(self.tmpDir, postData['files'])
finally:
# delete temp files
print 'DELETE: %s' %(self.tmpDir)
call(['rm', '-rf', self.tmpDir])
class PlateReader:
'''
parse EnVision plate reader using cellHTS2 package
for the R programming language
'''
def __init__(self, expDir, files):
'''
expDir: tmp directory with experimental data files
'''
robjects.r('library')('cellHTS2') # import
# cellHTS2 object
self.dataset = self.readPlateList(expDir, files)
def readPlateList(self, expDir, files):
'''
wrapper for cellHTS2 method of the same name
'''
return robjects.r('readPlateList')(files[0], path=expDir)
def attr(self, attrName):
'''
valid attributes for cellHTS2 object:
assayData, phenoData, featureData, plateList, intensityFiles,
plateData, experimentData, plateConf, screenLog, screenDesc
'''
return robjects.r('attr')(self.dataset, attrName)