Newer
Older
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/env python
"""
Import analysis data in two datasets: one dataset for videos and one dataset for matlab files.
"""
from ch.systemsx.cisd.openbis.generic.shared.api.v1.dto import SearchCriteria
from ch.systemsx.cisd.openbis.generic.shared.api.v1.dto import SearchSubCriteria
import os
import glob
import re
import time
import shutil, sys
from time import *
from datetime import *
print '###################################'
tz=localtime()[3]-gmtime()[3]
d=datetime.now()
print d.strftime("%Y-%m-%d %H:%M:%S GMT"+"%+.2d" % tz+":00")
def copyTextFile(incomingPath):
for textfile in glob.glob(os.path.join(incomingPath, 'OriginalDataDirectory.txt')):
rawDataFile = incomingPath + '/RawDataDirectory.txt'
shutil.copyfile(textfile, rawDataFile)
copyTextFile(incoming.getPath())
def extractSpaceCode(incomingPath):
spaceCode = "SINERGIA"
return spaceCode
def extractPlateCode(incomingPath):
for textfile in glob.glob(os.path.join(incomingPath, 'RawDataDirectory.txt')):
text = open(textfile, "r")
lineIndex =0
for line in text:
lineIndex=lineIndex+1
if re.match('PLATE', line):
token_list = re.split(r"[ ]",line)
token_list = [ item.strip() for item in token_list ]
token_list = filter(lambda x: len(x) > 0, token_list)
plateCode = token_list[0]
return plateCode
extractPlateCode(incoming.getPath())
def extractDataSetCode(incomingPath):
dataSetCode = ''
for textfile in glob.glob(os.path.join(incomingPath, 'RawDataDirectory.txt')):
text = open(textfile, "r")
lineIndex =0
for line in text:
lineIndex=lineIndex+1
# if re.match('/raid', line):
if re.match('/Users', line):
token_list = re.split(r"[/]",line)
token_list = [ item.strip() for item in token_list ]
token_list = filter(lambda x: len(x) > 0, token_list)
# dataSetCode = token_list[8] # right position for /raid
dataSetCode = token_list[10] #right position for local use
#plateCode = line
return dataSetCode
extractDataSetCode(incoming.getPath())
def get_videos(incomingPath):
directory = incomingPath + '/videos'
if not os.path.exists(directory):
os.makedirs(directory)
for mp4 in glob.glob(os.path.join(incomingPath, '*.mp4')):
(incomingPath, file) = os.path.split(mp4)
(filename, extension) = os.path.splitext(file)
stage= filename
shutil.move(incomingPath +'/'+file, directory)
for webm in glob.glob(os.path.join(incomingPath, '*.webm' )):
(incomingPath, file) = os.path.split(webm)
(filename, extension) = os.path.splitext(file)
stage= filename
shutil.move(incomingPath +'/'+file, directory)
for jpg in glob.glob(os.path.join(incomingPath, '*.jpg')):
(incomingPath, file) = os.path.split(jpg)
(filename, extension) = os.path.splitext(file)
stage= filename
shutil.move(incomingPath +'/'+file, directory)
for html in glob.glob(os.path.join(incomingPath, '*.html')):
(incomingPath, file) = os.path.split(html)
(filename, extension) = os.path.splitext(file)
stage= filename
shutil.move(incomingPath +'/'+file, directory)
get_videos(incoming.getPath())
def get_matfiles(incomingPath):
matDir = incomingPath + '/matfiles'
if not os.path.exists(matDir):
os.makedirs(matDir)
for mat in glob.glob(os.path.join(incomingPath, '*.mat')):
(incomingPath, file) = os.path.split(mat)
(filename, extension) = os.path.splitext(file)
stage = filename[:3]
shutil.move(incomingPath +'/'+file, matDir)
for txt in glob.glob(os.path.join(incomingPath, 'OriginalDataDirectory.txt')):
(incomingPath, file) = os.path.split(txt)
(filename, extension) = os.path.splitext(file)
stage = filename[:3]
shutil.move(incomingPath +'/'+file, matDir)
get_matfiles(incoming.getPath())
tr = service.transaction(incoming, factory)
incoming = tr.getIncoming()
data_set = tr.createNewDataSet()
data_set.setDataSetType("HCS_IMAGE_SEGMENTATION_TRACKING_FEATURES")
data_set2 = tr.createNewDataSet()
data_set2.setDataSetType("HCS_ANALYSIS_SEGMENTATION_AND_FEATURES")
sampleIdentifier = "/"+extractSpaceCode(incoming.getPath())+"/"+extractPlateCode(incoming.getPath())
print sampleIdentifier
plate = tr.getSample(sampleIdentifier)
data_set.setSample(plate)
data_set2.setSample(plate)
# Get the search service
search_service = tr.getSearchService()
sc = SearchCriteria()
sc.addMatchClause(SearchCriteria.MatchClause.createAttributeMatch(SearchCriteria.MatchClauseAttribute.CODE, extractDataSetCode(incoming.getPath()) ));
foundDataSets = search_service.searchForDataSets(sc)
if foundDataSets.size() > 0:
data_set.setParentDatasets([ds.getDataSetCode() for ds in foundDataSets])
data_set2.setParentDatasets([ds.getDataSetCode() for ds in foundDataSets])
videoPath = incoming.getPath() + '/videos'
tr.moveFile(videoPath, data_set)
matPath = incoming.getPath() + '/matfiles'
tr.moveFile(matPath, data_set2)