-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenimadis_annotate.java
More file actions
196 lines (135 loc) · 5.72 KB
/
openimadis_annotate.java
File metadata and controls
196 lines (135 loc) · 5.72 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package plugins.perrine.openimadisutilities;
import com.strandgenomics.imaging.iclient.ImageSpace;
import com.strandgenomics.imaging.iclient.ImageSpaceObject;
import com.strandgenomics.imaging.iclient.PixelMetaData;
import com.strandgenomics.imaging.iclient.RecordBuilder;
import com.strandgenomics.imaging.icore.Dimension;
import com.strandgenomics.imaging.icore.ImageType;
import com.strandgenomics.imaging.icore.Site;
import com.strandgenomics.imaging.icore.SourceFormat;
import com.strandgenomics.imaging.icore.VODimension;
import com.strandgenomics.imaging.icore.image.PixelArray;
import com.strandgenomics.imaging.icore.image.PixelDepth;
import com.strandgenomics.imaging.icore.vo.Ellipse;
import com.strandgenomics.imaging.icore.vo.VisualObject;
import com.strandgenomics.imaging.iclient.Project;
import com.strandgenomics.imaging.icore.Channel;
import icy.gui.frame.progress.AnnounceFrame;
import icy.roi.ROI;
import icy.sequence.Sequence;
import icy.type.DataType;
import icy.type.point.Point5D;
import icy.system.thread.ThreadUtil;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import loci.formats.ome.OMEXMLMetadataImpl;
import plugins.adufour.blocks.lang.Block;
import plugins.adufour.blocks.util.VarList;
import plugins.adufour.ezplug.EzPlug;
import plugins.adufour.ezplug.EzVar;
import plugins.adufour.ezplug.EzVarEnum;
import plugins.adufour.ezplug.EzVarInteger;
import plugins.adufour.ezplug.EzVarSequence;
import plugins.adufour.ezplug.EzVarText;
import plugins.adufour.vars.lang.VarSequence;
import plugins.kernel.roi.descriptor.measure.ROIMassCenterDescriptorsPlugin;
/**
* From a sequence with Roi on it (like from spot detector with export to roi enabled):
* ask for an annotation name (number of roi will be called), ask for a parent guid,
* upload the number of roi as field /value annotations and add a circle around the position
* of the gravity center of the counted stuff.
* also in block
* @author Perrine
*
*/
public class openimadis_annotate extends EzPlug implements Block{
EzVarInteger mamaguid=new EzVarInteger( "GUID from which the sequence was created");
EzVarText annotationfield=new EzVarText("Name for the count of Rois");
VarSequence inputsequence=new VarSequence("sequence where to read ROI", null);
// for block processing
EzVarSequence inputvarsequence=new EzVarSequence("input sequence with Rois");
@Override
public void clean() {
// TODO Auto-generated method stub
}
@Override
protected void execute() {
// TODO Auto-generated method stub
if (!isHeadLess()){
uploadRoisandannotationstoSequence(mamaguid.getValue(),inputvarsequence.getValue());
}
else
{
uploadRoisandannotationstoSequence(mamaguid.getValue(),inputsequence.getValue());
}
new AnnounceFrame("Done.");
}
private void uploadRoisandannotationstoSequence(final Integer mamaguid, Sequence value2) {
// TODO Auto-generated method stub
// get list of Rois from sequence
ArrayList<ROI> listrois = value2.getROIs();
int count = listrois.size();
ImageSpace ispace = ImageSpaceObject.getConnectionManager();
com.strandgenomics.imaging.iclient.Record mamarecord = ispace.findRecordForGUID(mamaguid);
// clean the previous one if any
// we clean it first
Map<String, Object> annotations =mamarecord.getUserAnnotations();
Iterator<String> it = annotations.keySet().iterator();
while(it.hasNext())
{
String key = it.next();
if (key.compareTo(annotationfield.getValue())==0){
Object value = annotations.get(key);
mamarecord.removeUserAnnotation(annotationfield.getValue());
mamarecord.addCustomHistory("Annotation "+ annotationfield.getValue()+"=" + value+ "have been DELETED from the record by ICY client.");
}
}
mamarecord.addUserAnnotation(annotationfield.getValue(), count);
mamarecord.addCustomHistory("Automatic annotation "+ annotationfield.getValue()+"=" + count+ " have been added to the record by ICY client.");
// bonus track -> add the protocol as an attachment when headless
double width=10;
double length=10;
if (count>0) //at least one roi to add:
{
mamarecord.deleteVisualOverlays(0, annotationfield.getValue());
mamarecord.createVisualOverlays(0, annotationfield.getValue());
List<VisualObject> vObjects = new ArrayList<VisualObject>();//red on the center
for (int r=0;r<listrois.size(); r++) {
Point5D p3D = ROIMassCenterDescriptorsPlugin.computeMassCenter(listrois.get(r));
double upperleftx=p3D.getX()-width/2;
double upperlefty=p3D.getY()-length/2;
Ellipse position2 = new Ellipse(upperleftx,upperlefty,width,length);
position2.setPenColor(Color.RED);
position2.setPenWidth(2.0f);
vObjects.add(position2) ;
}
mamarecord.addVisualObjects(vObjects, annotationfield.getValue(), new VODimension(0,0,0));
}
}
@Override
protected void initialize() {
addEzComponent(mamaguid);
addEzComponent(inputvarsequence);
addEzComponent(annotationfield);
}
@Override
public void declareInput(VarList inputMap) {
// TODO Auto-generated method stub
inputMap.add("MAMAGUID", mamaguid.getVariable());
inputMap.add("SequenceToUpload", inputsequence);
inputMap.add("annotationname", annotationfield.getVariable());
}
@Override
public void declareOutput(VarList outputMap) {
}
}