Skip to content

Commit 23271ae

Browse files
committed
Allow user to run segmentation without GUI; Adaptation of static analysis for screening
Former-commit-id: 6fb0f0a
1 parent 75c0094 commit 23271ae

File tree

5 files changed

+81
-45
lines changed

5 files changed

+81
-45
lines changed

maars_lib/src/main/java/maars/main/MaarsSegmentation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MaarsSegmentation implements Runnable {
2222
private String posNb_;
2323
private SegPombeParameters segPombeParam_;
2424
private Boolean batchMode = false;
25-
private Double tolerance = 10.0;
25+
private Double tolerance = Double.MAX_VALUE;
2626

2727
/**
2828
* * Constructor :

maars_lib/src/main/java/maars/segmentPombe/SegPombe.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void convertCorrelationToBinaryImage(Boolean batchMode, Double tolerance)
215215
this.binImage.setCalibration(imageToAnalyze.getCalibration());
216216
}
217217

218-
if (!batchMode || tolerance == Integer.MAX_VALUE) {
218+
if (!batchMode || tolerance == Double.MAX_VALUE) {
219219
this.binImage.show();
220220
WaitForUserDialog waitForUserDialog = new WaitForUserDialog("Optimize (or not) segmentation of "+
221221
imageToAnalyze.getShortTitle()+ ", and click ok.");

maars_lib/src/main/resources/processMitosis.py

+72-41
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
22
# !/usr/bin/env python3
33

4-
from cellh5 import cellh5, cellh5write
4+
import cellh5, cellh5write
55
import multiprocessing as mp
66
import numpy as np
77
import pandas as pd
@@ -219,18 +219,21 @@ def getkts2polesStats(spotsInFrame):
219219
# return (xs, ys)
220220

221221
def getSpotGeos(poleSpots, ktSpots, radius = 0.25):
222-
spots = poleSpots[[pos_x, pos_y]].join(ktSpots[[pos_x, pos_y]], how="outer", lsuffix=poleSuffix, rsuffix=ktSuffix)
223-
geos = pd.DataFrame(columns = ["phase", "poleNb", "ktNb", "poleCenter_X","poleCenter_Y",\
224-
"ktCenter_X","ktCenter_Y", "poleCenter2KtCenter_X", "poleCenter2KtCenter_Y", \
225-
"ktXpos_std", "ktYpos_std", "kts2ktCenter_mean","kts2ktCenter_std", "kts2ktCenter_max","kts2ktCenter_min", \
226-
"convexHull_area",
227-
"kts2poleCenter_mean","kts2poleCenter_std", "kts2poleCenter_max","kts2poleCenter_min", \
228-
"kts2poles_mean", "kts2poles_std", "kts2poles_max", "kts2poles_min", \
229-
"kt2Sp_mean", "kt2Sp_std", "kt2Sp_max", "kt2Sp_min", \
230-
"proj2SpCenter_mean", "proj2SpCenter_std","proj2SpCenter_max","proj2SpCenter_min"])
231-
for f in spots.index.levels[0]:
232-
geos.loc[f] = computeGeometries(spots.loc[f])
233-
return geos
222+
if poleSpots is not None and ktSpots is not None:
223+
spots = poleSpots[[pos_x, pos_y]].join(ktSpots[[pos_x, pos_y]], how="outer", lsuffix=poleSuffix, rsuffix=ktSuffix)
224+
geos = pd.DataFrame(columns = ["phase", "poleNb", "ktNb", "poleCenter_X","poleCenter_Y",\
225+
"ktCenter_X","ktCenter_Y", "poleCenter2KtCenter_X", "poleCenter2KtCenter_Y", \
226+
"ktXpos_std", "ktYpos_std", "kts2ktCenter_mean","kts2ktCenter_std", "kts2ktCenter_max","kts2ktCenter_min", \
227+
"convexHull_area",
228+
"kts2poleCenter_mean","kts2poleCenter_std", "kts2poleCenter_max","kts2poleCenter_min", \
229+
"kts2poles_mean", "kts2poles_std", "kts2poles_max", "kts2poles_min", \
230+
"kt2Sp_mean", "kt2Sp_std", "kt2Sp_max", "kt2Sp_min", \
231+
"proj2SpCenter_mean", "proj2SpCenter_std","proj2SpCenter_max","proj2SpCenter_min"])
232+
for f in spots.index.levels[0]:
233+
geos.loc[f] = computeGeometries(spots.loc[f])
234+
return geos
235+
else:
236+
return
234237

235238
def getDotProjectionOnSp(sp1x, sp1y, sp2x, sp2y, dotx, doty):
236239
px = sp2x-sp1x
@@ -287,6 +290,19 @@ def computeGeometries(spotsInFrame):
287290
# plt.show()
288291
return [phase] + params
289292

293+
def isInMitosis(cellNb, features_dir, channel):
294+
csvPath = features_dir + str(cellNb) + '_' + channel + '.csv'
295+
if path.lexists(csvPath):
296+
oneCell = pd.read_csv(csvPath)
297+
spLens = oneCell['SpLength']
298+
if len(spLens[spLens > 0]) > 0:
299+
return str(cellNb) + "_" + channel, spLens
300+
else:
301+
return
302+
else:
303+
return
304+
305+
290306
if __name__ == '__main__':
291307
args = set_attributes_from_cmd_line()
292308
baseDir = args.baseDir
@@ -321,17 +337,25 @@ def computeGeometries(spotsInFrame):
321337
cellRois = pd.read_csv(baseDir + path.sep + seg +posPrefix + 'Results.csv')
322338
cellNbs = getAllCellNumbers(features_dir)
323339
tasks = []
324-
for cellNb in cellNbs:
325-
tasks.append((features_dir, cellNb, -4, minSegLen, channel))
326-
results = [pool.apply_async(getMitoticElongation, t) for t in tasks]
340+
isStatic=True
341+
if isStatic:
342+
for cellNb in cellNbs:
343+
tasks.append((cellNb, features_dir, channel))
344+
results = [pool.apply_async(isInMitosis, t) for t in tasks]
345+
else:
346+
for cellNb in cellNbs:
347+
tasks.append((features_dir, cellNb, -4, minSegLen, channel))
348+
results = [pool.apply_async(getMitoticElongation, t) for t in tasks]
327349
elongationRegions = dict()
328350
for result in results:
329351
res = result.get()
330352
if res is None:
331353
continue
332354
elongationRegions[res[0]] = res[1]
333-
334-
timePoints = analyse_each_cell(pool, minSegLen, elongationRegions, cellRois, mitosisDir)
355+
if isStatic:
356+
timePoints = None
357+
else:
358+
timePoints = analyse_each_cell(pool, minSegLen, elongationRegions, cellRois, mitosisDir)
335359
if ch5:
336360
description = ("cell", "cell_shape_features")
337361
with cellh5write.CH5FileWriter(mitosisDir + "mitosisAnalysis.ch5") as cfw:
@@ -372,7 +396,10 @@ def computeGeometries(spotsInFrame):
372396
for c in chs:
373397
##### save features data#######
374398
curId = str(cellNb) + "_" + c
375-
features = pd.read_csv(features_dir + curId + ".csv")
399+
try:
400+
features = pd.read_csv(features_dir + curId + ".csv")
401+
except :
402+
continue
376403
# cow_feature = cpw.add_region_object(c + '_features')
377404
# regObjs.append(cow_feature)
378405
# for t in features['Frame']:
@@ -387,33 +414,37 @@ def computeGeometries(spotsInFrame):
387414
pd.DataFrame({"Frame":features.index, "mitoRegion":np.empty(len(features.index))})
388415
, on='Frame', how='outer')
389416
changePoints = pd.DataFrame({"Frame":features.index,"ChangePoints":np.empty(len(features.index))})
390-
for chPoiInd in timePoints.loc[str(cellNb)].values:
391-
changePoints.loc[chPoiInd] = [1, chPoiInd]
417+
if timePoints != None:
418+
for chPoiInd in timePoints.loc[str(cellNb)].values:
419+
changePoints.loc[chPoiInd] = [1, chPoiInd]
392420
features = pd.merge(features, changePoints, on='Frame', how='outer')
393421
featuresOfCurrentCell[c] = features
394422
##### save spot data#######
395423
spotsData = TMxml2dflib.getAllSpots(fluoDir + spots + str(cellNb) + "_" + c + ".xml")
396-
del spotsData["name"]
397-
cow_spot = cpw.add_region_object(c + '_spot')
398-
for t in spotsData.index.levels[0]:
399-
cow_spot.write(t=t, object_labels=spotsData.loc[t]['ID'])
400-
cow_spot.finalize()
401-
402-
regObjs.append(cow_spot)
403-
404-
cfew_spot_features = cpw.add_object_feature_matrix(object_name=c + '_spot',
405-
feature_name=c + '_spot_features', n_features=len(spotsData.columns),
406-
dtype=np.float16)
407-
cfew_spot_features.write(spotsData.astype(np.float16))
408-
cfew_spot_features.finalize()
409-
410-
spotsOfCurrentCell[c] = spotsData
411-
cfewSpotMats.append(cfew_spot_features)
424+
print(spotsData.shape[0])
425+
if spotsData.shape[0] > 1:
426+
spotsData.drop('name', axis=1, inplace=True)
427+
cow_spot = cpw.add_region_object(c + '_spot')
428+
for t in spotsData.index.levels[0]:
429+
cow_spot.write(t=t, object_labels=spotsData.loc[t]['ID'])
430+
cow_spot.finalize()
431+
432+
regObjs.append(cow_spot)
433+
434+
cfew_spot_features = cpw.add_object_feature_matrix(object_name=c + '_spot',
435+
feature_name=c + '_spot_features', n_features=len(spotsData.columns),
436+
dtype=np.float16)
437+
cfew_spot_features.write(spotsData.astype(np.float16))
438+
cfew_spot_features.finalize()
439+
440+
spotsOfCurrentCell[c] = spotsData
441+
cfewSpotMats.append(cfew_spot_features)
412442
geos = getSpotGeos(spotsOfCurrentCell[channel], spotsOfCurrentCell["GFP"])
413-
geos['Frame'] = list(geos.index)
414-
features = pd.merge(featuresOfCurrentCell[channel], geos, on='Frame', how='outer')
415-
features.set_index('Frame', inplace=True)
416-
features.sort_index(inplace=True)
443+
if geos is not None:
444+
geos['Frame'] = list(geos.index)
445+
features = pd.merge(featuresOfCurrentCell[channel], geos, on='Frame', how='outer')
446+
features.set_index('Frame', inplace=True)
447+
features.sort_index(inplace=True)
417448
cfewFeatureMats = list()
418449
for c in chs:
419450
cfew_features = cpw.add_object_feature_matrix(object_name=c + '_features',

maars_post/src/main/java/maars/headless/batchFluoAnalysis/MaarsFluoAnalysis.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.Executors;
2727
import java.util.concurrent.Future;
2828
import java.util.concurrent.atomic.AtomicBoolean;
29+
import java.util.regex.Matcher;
2930
import java.util.regex.Pattern;
3031

3132
/**
@@ -154,10 +155,13 @@ public static String[] getPositionSuffix(String path){
154155
HashMap<String, String> namesDic = populateSeriesImgNames(path + File.separator + tifName);
155156
String[] names = new String[namesDic.size()];
156157
names = namesDic.keySet().toArray(names);
158+
Pattern pattern = Pattern.compile(".*MMStack_(.*)");
157159
String[] pos = new String[names.length];
158160
for (int i =0; i< names.length; i++){
159-
String[] splitName = names[i].split("_");
160-
pos[i] = splitName[splitName.length-1];
161+
Matcher matcher = pattern.matcher(names[i]);
162+
while (matcher.find()) {
163+
pos[i] = matcher.group(1);
164+
}
161165
}
162166
return pos;
163167
}

maars_post/src/main/java/maars/headless/batchSegmentation/DefaultBatchSegmentation.java

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private void launchSeg(String[] dirs, String configName) {
3737
String segPath = d + File.separator + parameter.getSegmentationParameter(MaarsParameters.SEG_PREFIX);
3838
String[] posNbs = MaarsFluoAnalysis.getPositionSuffix(segPath);
3939
for (String pos: posNbs){
40+
IJ.log(pos);
4041
for (String f : FileUtils.getTiffWithPattern(segPath, ".*.tif")){
4142
if (Pattern.matches(".*MMStack_" + pos+"\\.ome\\.tif", f)){
4243
ImagePlus img = IJ.openImage(segPath + File.separator + f);

0 commit comments

Comments
 (0)