-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGlobalOpt.java
More file actions
165 lines (129 loc) · 7.02 KB
/
Copy pathGlobalOpt.java
File metadata and controls
165 lines (129 loc) · 7.02 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
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
155
156
157
158
159
160
161
162
163
164
165
package cmd;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import io.SpatialDataContainer;
import align.AlignTools;
import align.GlobalOptSIFT;
import picocli.CommandLine;
import picocli.CommandLine.Option;
import picocli.CommandLine.Command;
import util.Threads;
import org.apache.logging.log4j.Logger;
import util.LoggerUtil;
@Command(name = "st-align-global", mixinStandardHelpOptions = true, version = "0.3.2-SNAPSHOT", description = "Spatial Transcriptomics as IMages project - global alignment of all slices")
public class GlobalOpt implements Callable<Void> {
private static final Logger logger = LoggerUtil.getLogger();
@Option(names = {"-c", "--container"}, required = true, description = "input N5 container path, e.g. -i /home/ssq.n5.")
private String containerPath = null;
@Option(names = {"-d", "--datasets"}, required = false, description = "ordered, comma separated list of one or more datasets, e.g. -d 'Puck_180528_20,Puck_180528_22' (default: all, in order as saved in N5 metadata)")
private String datasets = null;
// general display options
@Option(names = {"--skipDisplayResults"}, required = false, description = "do not show a preview of the aligned stack (default: false)")
private boolean skipDisplayResults = false;
// alignment options
@Option(names = {"--ignoreQuality"}, required = false, description = "ignore the amount of RANSAC inlier ratio, otherwise used it to determine - if necessary - which pairwise connections to remove during global optimization (default: false)")
private boolean ignoreQuality = false;
@Option(names = {"-l", "--lambda"}, required = false, description = "lambda of the affine model regularized with the rigid model, 0.0 means fully affine, 1.0 means just rigid (default: 0.1)")
private double lambda = 0.1;
@Option(names = {"--maxAllowedError"}, required = false, description = "maximally allowed error during global optimization (default: 300.0 for slideseq)")
private double maxAllowedError = 300.0;
@Option(names = {"--maxIterations"}, required = false, description = "maximum number of iterations (default: 3000)")
private int maxIterations = 3000;
@Option(names = {"--minIterations"}, required = false, description = "minimum number of iterations (default: 500)")
private int minIterations = 500;
@Option(names = {"--relativeThreshold"}, required = false, description = "relative threshold for dropping pairwise connections, i.e. if the pairwise error is n-times higher than the average error (default: 3.0)")
private double relativeThreshold = 300.0;
@Option(names = {"--absoluteThreshold"}, required = false, description = "absolute error threshold for dropping pairwise connections - consult the results of pairwise matching to identify a reasonable number (default: 160.0 for slideseq)")
private double absoluteThreshold = 160.0;
// ICP parameters
@Option(names = {"--skipICP"}, required = false, description = "skip the ICP refinement step (default: false)")
private boolean skipICP = false;
@Option(names = {"--icpIterations"}, required = false, description = "maximum number of ICP iterations for each pair of slides (default: 100)")
private int icpIterations = 100;
@Option(names = {"--icpErrorFraction"}, required = false, description = "distance at which locations will be assigned as corresponding during ICP, relative to median distance between all locations (default: 1.0)")
private double icpErrorFraction = 1.0;
@Option(names = {"--maxAllowedErrorICP"}, required = false, description = "maximum error allowed during ICP runs after model fit - consult the results of pairwise matching to identify a reasonable number (default: 140.0 for slideseq)")
private double maxAllowedErrorICP = 140.0;
@Option(names = {"--maxIterationsICP"}, required = false, description = "maximum number of iterations during ICP (default: 500)")
private int maxIterationsICP = 500;
@Option(names = {"--minIterationsICP"}, required = false, description = "minimum number of iterations during ICP (default: 500)")
private int minIterationsICP = 500;
@Option(names = {"-rf", "--renderingFactor"}, required = false, description = "FOR DISPLAY ONLY: factor for the amount of filtering or radius used for rendering, corresponds to smoothness for Gauss, e.g -rf 2.0 (default: 4.0)")
private double smoothnessFactor = AlignTools.defaultSmoothnessFactor;
@Option(names = {"-g", "--gene"}, required = false, description = "FOR DISPLAY ONLY: gene to display, e.g. -g Calm2")
private String gene = AlignTools.defaultGene;
@Override
public Void call() throws Exception {
if (! SpatialDataContainer.exists(containerPath)) {
logger.error("Container '{}' does not exist. Stopping.", containerPath);
return null;
}
if (!SpatialDataContainer.isCompatibleContainer(containerPath)) {
logger.error("Global alignment does not work for single dataset '{}'. Stopping.", containerPath);
return null;
}
final ExecutorService service = Executors.newFixedThreadPool(8);
SpatialDataContainer container = SpatialDataContainer.openExisting(containerPath, service);
final List<String> datasetNames;
if (datasets != null && !datasets.trim().isEmpty()) {
datasetNames = Arrays.stream(datasets.split(","))
.map(String::trim)
.collect(Collectors.toList());
}
else {
logger.warn("No input datasets specified. Trying to open all datasets in '{}' ...", containerPath);
datasetNames = container.getDatasets();
}
for (final String dataset : datasetNames) {
if (!container.getDatasets().contains(dataset)) {
logger.error("Container does not contain dataset '{}' in '{}'. Stopping.", dataset, containerPath);
return null;
}
}
// -d 'Puck_180602_20,Puck_180602_17'
final boolean skipDisplayResults = this.skipDisplayResults;
final boolean useQuality = !ignoreQuality;
final double lambda = this.lambda;
final double maxAllowedError = this.maxAllowedError;
final int maxIterations = this.maxIterations;
final int maxPlateauWidth = this.minIterations;
final double relativeThreshold = this.relativeThreshold;
final double absoluteThreshold = this.absoluteThreshold;
final boolean doICP = !skipICP;
final int icpIterations = this.icpIterations;
final double icpErrorFraction = this.icpErrorFraction;
final double maxAllowedErrorICP = this.maxAllowedErrorICP;
final int maxIterationsICP = this.maxIterationsICP;
final int maxPlateauWidthICP = this.minIterationsICP;
GlobalOptSIFT.globalOpt(
container,
datasetNames,
useQuality,
lambda,
maxAllowedError,
maxIterations,
maxPlateauWidth,
relativeThreshold,
absoluteThreshold,
doICP,
icpIterations,
icpErrorFraction,
maxAllowedErrorICP,
maxIterationsICP,
maxPlateauWidthICP,
Threads.numThreads(),
skipDisplayResults,
smoothnessFactor,
gene );
service.shutdown();
return null;
}
public static void main(final String... args) {
final CommandLine cmd = new CommandLine(new GlobalOpt());
cmd.execute(args);
}
}