forked from HMS-IDAC/UnMicst
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unmicstWrapper.py
89 lines (72 loc) · 3.36 KB
/
unmicstWrapper.py
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
import os, argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--tool", help="which UnMicst tool?", default = 'unmicst-solo')
parser.add_argument("imagePath", help="path to the .tif file")
parser.add_argument("--model", help="type of model. For example, nuclei vs cytoplasm")
parser.add_argument("--outputPath", help="output path of probability map")
parser.add_argument("--channel", help="channel to perform inference on", nargs = '+', type=int, default=[1])
parser.add_argument("--classOrder", help="background, contours, foreground", type = int, nargs = '+', default=-1)
parser.add_argument("--mean", help="mean intensity of input image. Use -1 to use model", type=float, default=-1)
parser.add_argument("--std", help="mean standard deviation of input image. Use -1 to use model", type=float, default=-1)
parser.add_argument("--scalingFactor", help="factor by which to increase/decrease image size by", type=float,
default=1)
parser.add_argument("--stackOutput", help="save probability maps as separate files", action='store_true')
parser.add_argument("--GPU", help="explicitly select GPU", type=int, default = 0)
parser.add_argument("--outlier",
help="map percentile intensity to max when rescaling intensity values. Max intensity as default",
type=float, default=-1)
parser.add_argument("--verbose", help="display error messages for debugging", action='store_true')
args = parser.parse_args()
scriptPath =os.path.dirname(os.path.realpath(__file__))
cmd="python " + scriptPath + os.sep
channel = args.channel
classOrder = args.classOrder
GPU = args.GPU
channel[:] = [number - 1 for number in channel]
if classOrder != -1:
classOrder[:] = [number - 1 for number in classOrder]
GPU = GPU -1
if args.tool == 'unmicst-duo':
cmd = cmd + "UnMicst2.py "
if len(args.channel)==2:
channel = str(channel[0]) +" " + str(channel[1])
else:
channel = str(channel[0])
elif args.tool == 'unmicst-legacy':
cmd = cmd + "UnMicst.py "
channel = str(channel[0])
print('')
print("WARNING! YOU HAVE OPTED TO USE UNMICST legacy, WHICH IS GETTING TIRED AND OLD. CONSIDER USING unmicst-solo OR unmicst-duo (IF YOU ALSO HAVE A NUCLEAR ENVELOPE STAIN")
print('')
elif args.tool == 'UnMicstCyto2':
cmd = cmd + "UnMicstCyto2.py "
channel = str(channel[0])
else:
cmd = cmd + "UnMicst1-5.py "
channel = str(channel[0])
print('')
print(
"WARNING! USING unmicst-solo AS DEFAULT. THIS MODEL HAS BEEN TRAINED ON MORE TISSUE TYPES. IF YOU WANT THE LEGACY MODEL, USE --tool unmicst-legacy")
print('')
cmd = cmd + " " + args.imagePath
cmd = cmd + " --channel " + str(channel)
cmd = cmd + " --outputPath " + str(args.outputPath)
cmd = cmd + " --mean " + str(args.mean)
cmd = cmd + " --std " + str(args.std)
cmd = cmd + " --scalingFactor " + str(args.scalingFactor)
cmd = cmd + " --GPU " + str(GPU)
cmd = cmd + " --outlier " + str(args.outlier)
if args.stackOutput:
cmd = cmd + " --stackOutput "
if args.model:
cmd = cmd + " --model " + str(args.model)
if args.classOrder == -1:
cmd = cmd
else:
cmd = cmd + " --classOrder " + str(classOrder[0]) + " " + str(classOrder[1]) + " " + str(
classOrder[2])
if args.verbose:
cmd = cmd + " --verbose"
print(cmd)
os.system(cmd)