Skip to content

Commit 068a552

Browse files
authored
Make worker compatible with either CP2 or CP3 (#88)
* Test if pipeline is CP2 or CP3 * misc fixes
1 parent 42ca1cb commit 068a552

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

worker/cp-worker.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ def runCellProfiler(message):
107107
message['Metadata']=metadataForCall[:-1]
108108
elif 'output_structure' in message.keys():
109109
if message['output_structure']!='': #support for explicit output structuring
110+
watchtowerlogger=watchtower.CloudWatchLogHandler(log_group=LOG_GROUP_NAME, stream_name=message['Metadata'],create_log_group=False)
110111
logger.addHandler(watchtowerlogger)
111112
metadataID = message['output_structure']
112-
watchtowerlogger=watchtower.CloudWatchLogHandler(log_group=LOG_GROUP_NAME, stream_name=message['Metadata'],create_log_group=False)
113113
for eachMetadata in message['Metadata'].split(','):
114114
if eachMetadata.split('=')[0] not in metadataID:
115115
printandlog('Your specified output structure does not match the Metadata passed',logger)
116116
else:
117117
metadataID = string.replace(metadataID,eachMetadata.split('=')[0],eachMetadata.split('=')[1])
118-
printandlog('metadataID =',metadataID)
118+
printandlog('metadataID ='+metadataID, logger)
119119
else: #backwards compatability with 1.0.0 and/or no desire to structure output
120120
metadataID = '-'.join([x.split('=')[1] for x in message['Metadata'].split(',')]) # Strip equal signs from the metadata
121121
else: #backwards compatability with 1.0.0 and/or no desire to structure output
@@ -143,12 +143,20 @@ def runCellProfiler(message):
143143
logger.addHandler(watchtowerlogger)
144144

145145
# Build and run CellProfiler command
146+
cp2 = False
147+
with open(os.path.join(replaceValues['DATA'],replaceValues['PL']), 'r') as openpipe:
148+
for line in openpipe:
149+
if 'DateRevision:2' in line: #comes from a CP2 pipeline
150+
cp2 = True
151+
cmdstem = 'cellprofiler -c -r -b '
152+
if not cp2:
153+
cmdstem = 'cellprofiler -c -r '
146154
cpDone = localOut + '/cp.is.done'
147155
if message['pipeline'][-3:]!='.h5':
148-
cmd = 'cellprofiler -c -r -b -p %(DATA)s/%(PL)s -i %(DATA)s/%(IN)s -o %(OUT)s -d ' + cpDone
156+
cmd = cmdstem + '-p %(DATA)s/%(PL)s -i %(DATA)s/%(IN)s -o %(OUT)s -d ' + cpDone
149157
cmd += ' --data-file=%(DATA)s/%(FL)s -g %(Metadata)s'
150158
else:
151-
cmd = 'cellprofiler -c -r -b -p %(DATA)s/%(PL)s -o %(OUT)s -d ' + cpDone + ' --data-file=%(DATA)s/%(FL)s -g %(Metadata)s'
159+
cmd = cmdstem + '-p %(DATA)s/%(PL)s -o %(OUT)s -d ' + cpDone + ' --data-file=%(DATA)s/%(FL)s -g %(Metadata)s'
152160
cmd = cmd % replaceValues
153161
print('Running', cmd)
154162
logger.info(cmd)

0 commit comments

Comments
 (0)