-
Notifications
You must be signed in to change notification settings - Fork 239
/
BioRadReader.java
1137 lines (1012 loc) · 40.2 KB
/
BioRadReader.java
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* #%L
* OME Bio-Formats package for reading and converting biological file formats.
* %%
* Copyright (C) 2005 - 2014 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
package loci.formats.in;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Vector;
import loci.common.Location;
import loci.common.RandomAccessInputStream;
import loci.common.xml.BaseHandler;
import loci.common.xml.XMLTools;
import loci.formats.CoreMetadata;
import loci.formats.FilePattern;
import loci.formats.FormatException;
import loci.formats.FormatReader;
import loci.formats.FormatTools;
import loci.formats.MetadataTools;
import loci.formats.meta.IMinMaxStore;
import loci.formats.meta.MetadataStore;
import ome.xml.model.primitives.PositiveFloat;
import ome.xml.model.primitives.Timestamp;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
/**
* BioRadReader is the file format reader for Bio-Rad PIC files.
*
* <dl><dt><b>Source code:</b></dt>
* <dd><a href="http://trac.openmicroscopy.org.uk/ome/browser/bioformats.git/components/bio-formats/src/loci/formats/in/BioRadReader.java">Trac</a>,
* <a href="http://git.openmicroscopy.org/?p=bioformats.git;a=blob;f=components/bio-formats/src/loci/formats/in/BioRadReader.java;hb=HEAD">Gitweb</a></dd></dl>
*
* @author Curtis Rueden ctrueden at wisc.edu
* @author Melissa Linkert melissa at glencoesoftware.com
*/
public class BioRadReader extends FormatReader {
// -- Constants --
/** Numerical ID of a valid Bio-Rad PIC file. */
private static final int PIC_FILE_ID = 12345;
/** Always little endian. */
private static final boolean LITTLE_ENDIAN = true;
/** List of merge types. */
private static final String[] MERGE_NAMES = {
"MERGE_OFF", "MERGE_16", "MERGE_ALTERNATE", "MERGE_COLUMN", "MERGE_ROW",
"MERGE_MAXIMUM", "MERGE_OPT12", "MERGE_OPT12_V2"
};
/** List of note types. */
public static final String[] NOTE_NAMES = {
"0", "LIVE", "FILE1", "NUMBER", "USER", "LINE", "COLLECT", "FILE2",
"SCALEBAR", "MERGE", "THRUVIEW", "ARROW", "12", "13", "14", "15",
"16", "17", "18", "19", "VARIABLE", "STRUCTURE", "4D SERIES"
};
public static final int NOTE_TYPE_LIVE = 1;
public static final int NOTE_TYPE_FILE1 = 2;
public static final int NOTE_TYPE_NUMBER = 3;
public static final int NOTE_TYPE_USER = 4;
public static final int NOTE_TYPE_LINE = 5;
public static final int NOTE_TYPE_COLLECT = 6;
public static final int NOTE_TYPE_FILE2 = 7;
public static final int NOTE_TYPE_SCALEBAR = 8;
public static final int NOTE_TYPE_MERGE = 9;
public static final int NOTE_TYPE_THRUVIEW = 10;
public static final int NOTE_TYPE_ARROW = 11;
public static final int NOTE_TYPE_VARIABLE = 20;
public static final int NOTE_TYPE_STRUCTURE = 21;
public static final int NOTE_TYPE_4D_SERIES = 22;
/** Structure labels. */
public static final String[] STRUCTURE_LABELS_1 = {
"Scan Channel", "Both mode", "Speed", "Filter", "Factor", "Number of scans",
"Photon counting mode (channel 1)", "Photon counting detector (channel 1)",
"Photon counting mode (channel 2)", "Photon counting detector (channel 2)",
"Photon mode", "Objective magnification", "Zoom factor", "Motor on",
"Z Step Size"
};
public static final String[] STRUCTURE_LABELS_2 = {
"Z Start", "Z Stop", "Scan area X coordinate", "Scan area Y coordinate",
"Scan area width", "Scan area height"
};
public static final String[] STRUCTURE_LABELS_3 = {
"Iris for PMT", "Gain for PMT", "Black level for PMT",
"Emission filter for PMT", "Multiplier for channel"
};
public static final String[] STRUCTURE_LABELS_4 = {
"enhanced", "PMT 1 percentage", "PMT 2 percentage",
"Transmission 1 percentage", "Transmission 2 percentage",
"Transmission 3 percentage"
};
public static final String[] STRUCTURE_LABELS_5 = {
"laser ", "excitation filter for laser ", "ND filter for laser ",
"emission filter for laser "
};
public static final String[] STRUCTURE_LABELS_6 = {
"Part number for laser 3", "Part number for excitation filter for laser 3",
"Part number for ND filter for laser 3",
"Part number for emission filter for laser 3",
"Part number for filter block 1", "Part number for filter block 2"
};
public static final String[] PIC_SUFFIX = {"pic"};
public static final int LUT_LENGTH = 256;
// -- Fields --
private Vector<String> used;
private String[] picFiles;
private byte[][][] lut;
private int lastChannel = 0;
private boolean brokenNotes = false;
private Vector<Note> noteStrings;
private Vector<Double> offset, gain;
// -- Constructor --
/** Constructs a new BioRadReader. */
public BioRadReader() {
super("Bio-Rad PIC", new String[] {"pic", "xml", "raw"});
domains = new String[] {FormatTools.LM_DOMAIN};
hasCompanionFiles = true;
datasetDescription = "One or more .pic files and an optional lse.xml file";
}
// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#getOptimalTileHeight() */
public int getOptimalTileHeight() {
FormatTools.assertId(currentId, true, 1);
return getSizeY();
}
/* @see loci.formats.IFormatReader#isSingleFile(String) */
public boolean isSingleFile(String id) throws FormatException, IOException {
return false;
}
/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
public boolean isThisType(String name, boolean open) {
if (checkSuffix(name, PIC_SUFFIX)) return true;
String fname = new File(name.toLowerCase()).getName();
return fname.equals("lse.xml") || fname.equals("data.raw");
}
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
final int blockLen = 56;
if (!FormatTools.validStream(stream, blockLen, LITTLE_ENDIAN)) {
return false;
}
String c = stream.readString(blockLen);
stream.seek(54);
return stream.readShort() == PIC_FILE_ID || c.startsWith("[Input Sources]");
}
/* @see loci.formats.IFormatReader#fileGroupOption(String) */
public int fileGroupOption(String id) throws FormatException, IOException {
Location thisFile = new Location(id).getAbsoluteFile();
Location parent = thisFile.getParentFile();
String[] list = parent.list(true);
for (String f : list) {
if (checkSuffix(f, "raw") || checkSuffix(f, "xml")) {
return FormatTools.MUST_GROUP;
}
}
return FormatTools.CAN_GROUP;
}
/* @see loci.formats.IFormatReader#get8BitLookupTable() */
public byte[][] get8BitLookupTable() {
FormatTools.assertId(currentId, true, 1);
return lut == null ? null : lut[lastChannel];
}
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
public String[] getSeriesUsedFiles(boolean noPixels) {
FormatTools.assertId(currentId, true, 1);
if (noPixels) {
Vector<String> files = new Vector<String>();
for (String f : used) {
if (!checkSuffix(f, PIC_SUFFIX)) files.add(f);
}
return files.toArray(new String[files.size()]);
}
return used.toArray(new String[used.size()]);
}
/**
* @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
*/
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
throws FormatException, IOException
{
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
lastChannel = getZCTCoords(no)[1];
if (picFiles != null) {
int file = no % picFiles.length;
RandomAccessInputStream ras = new RandomAccessInputStream(picFiles[file]);
long offset = (no / picFiles.length) * FormatTools.getPlaneSize(this);
ras.seek(offset + 76);
readPlane(ras, x, y, w, h, buf);
ras.close();
}
else {
in.seek(no * FormatTools.getPlaneSize(this) + 76);
readPlane(in, x, y, w, h, buf);
}
return buf;
}
/* @see loci.formats.IFormatReader#close(boolean) */
public void close(boolean fileOnly) throws IOException {
super.close(fileOnly);
if (!fileOnly) {
used = null;
picFiles = null;
lut = null;
lastChannel = 0;
noteStrings = null;
offset = gain = null;
brokenNotes = false;
}
}
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
// always initialize a PIC file, even if we were given something else
if (!checkSuffix(id, PIC_SUFFIX)) {
Location dir = new Location(id).getAbsoluteFile().getParentFile();
String[] list = dir.list(true);
for (int i=0; i<list.length; i++) {
if (checkSuffix(list[i], PIC_SUFFIX)) {
id = new Location(dir.getAbsolutePath(), list[i]).getAbsolutePath();
}
}
if (!checkSuffix(id, PIC_SUFFIX)) {
throw new FormatException("No .pic files found - invalid dataset.");
}
}
super.initFile(id);
in = new RandomAccessInputStream(id);
in.order(true);
offset = new Vector<Double>();
gain = new Vector<Double>();
used = new Vector<String>();
used.add(currentId);
LOGGER.info("Reading image dimensions");
noteStrings = new Vector<Note>();
// read header
CoreMetadata m = core.get(0);
m.sizeX = in.readShort();
m.sizeY = in.readShort();
int npic = in.readShort();
m.imageCount = npic;
int ramp1min = in.readShort();
int ramp1max = in.readShort();
boolean notes = in.readInt() != 0;
m.pixelType =
in.readShort() == 0 ? FormatTools.UINT16 : FormatTools.UINT8;
int imageNumber = in.readShort();
String name = in.readString(32);
for (int i=0; i<name.length(); i++) {
if (name.charAt(i) == 0) {
name = name.substring(0, i);
break;
}
}
float magFactor = 1f;
int lens = 0;
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
int merged = in.readShort();
int color1 = in.readShort();
int fileId = in.readShort();
int ramp2min = in.readShort();
int ramp2max = in.readShort();
int color2 = in.readShort();
int edited = in.readShort();
lens = in.readShort();
magFactor = in.readFloat();
// check validity of header
if (fileId != PIC_FILE_ID) {
throw new FormatException("Invalid file header : " + fileId);
}
// populate metadata fields
addGlobalMeta("nx", getSizeX());
addGlobalMeta("ny", getSizeY());
addGlobalMeta("npic", getImageCount());
addGlobalMeta("ramp1_min", ramp1min);
addGlobalMeta("ramp1_max", ramp1max);
addGlobalMeta("notes", notes);
addGlobalMeta("image_number", imageNumber);
addGlobalMeta("name", name);
addGlobalMeta("merged", MERGE_NAMES[merged]);
addGlobalMeta("color1", color1);
addGlobalMeta("file_id", fileId);
addGlobalMeta("ramp2_min", ramp2min);
addGlobalMeta("ramp2_max", ramp2max);
addGlobalMeta("color2", color2);
addGlobalMeta("edited", edited);
addGlobalMeta("lens", lens);
addGlobalMeta("mag_factor", magFactor);
}
else in.skipBytes(20);
// skip image data
int imageLen = getSizeX() * getSizeY();
int bpp = FormatTools.getBytesPerPixel(getPixelType());
in.skipBytes(bpp * getImageCount() * imageLen + 6);
m.sizeZ = getImageCount();
m.sizeC = 1;
m.sizeT = 1;
m.orderCertain = false;
m.rgb = false;
m.interleaved = false;
m.littleEndian = LITTLE_ENDIAN;
m.metadataComplete = true;
m.falseColor = true;
LOGGER.info("Reading notes");
String zoom = null, zstart = null, zstop = null, mag = null;
String gain1 = null, gain2 = null, gain3 = null;
String offset1 = null;
String ex1 = null, ex2 = null, ex3 = null;
String em1 = null, em2 = null, em3 = null;
MetadataStore store = makeFilterMetadata();
// read notes
readNotes(in, true);
LOGGER.info("Populating metadata");
// look for companion metadata files
Vector<String> pics = new Vector<String>();
if (isGroupFiles()) {
Location parent =
new Location(currentId).getAbsoluteFile().getParentFile();
String parentPath = parent.getAbsolutePath();
String[] list = parent.list(true);
Arrays.sort(list);
for (int i=0; i<list.length; i++) {
if (list[i].endsWith("lse.xml")) {
String path = new Location(parentPath, list[i]).getAbsolutePath();
used.add(path);
DefaultHandler handler = new BioRadHandler();
RandomAccessInputStream xml = new RandomAccessInputStream(path);
XMLTools.parseXML(xml, handler);
xml.close();
used.remove(currentId);
for (int q=0; q<list.length; q++) {
if (checkSuffix(list[q], PIC_SUFFIX)) {
path = new Location(parentPath, list[q]).getAbsolutePath();
pics.add(path);
if (!used.contains(path)) used.add(path);
}
}
}
else if (list[i].endsWith("data.raw")) {
used.add(new Location(parentPath, list[i]).getAbsolutePath());
}
}
}
// populate Pixels
m.dimensionOrder = "XYCTZ";
boolean multipleFiles = parseNotes(store);
if (multipleFiles && isGroupFiles() && pics.size() == 0) {
// do file grouping
used.remove(currentId);
long length = new Location(currentId).length();
FilePattern pattern = new FilePattern(new Location(id).getAbsoluteFile());
String[] patternFiles = pattern.getFiles();
for (String file : patternFiles) {
Location f = new Location(file);
if (f.length() == length) {
pics.add(file);
used.add(file);
}
}
if (pics.size() == 1) m.sizeC = 1;
}
picFiles = pics.toArray(new String[pics.size()]);
Arrays.sort(picFiles);
if (picFiles.length > 0) {
if (getSizeC() == 0) m.sizeC = 1;
m.imageCount = npic * picFiles.length;
if (multipleFiles) {
m.sizeT = getImageCount() / (getSizeZ() * getSizeC());
}
else m.sizeC = getImageCount() / (getSizeZ() * getSizeT());
}
else picFiles = null;
if (getEffectiveSizeC() != getSizeC() && !isRGB()) {
m.sizeC = 1;
}
LOGGER.info("Reading lookup tables");
lut = new byte[getEffectiveSizeC()][][];
for (int channel=0; channel<lut.length; channel++) {
int plane = getIndex(0, channel, 0);
String file =
picFiles == null ? currentId : picFiles[plane % picFiles.length];
LOGGER.trace("reading table for C = {} from {}", channel, file);
RandomAccessInputStream s = new RandomAccessInputStream(file);
s.order(true);
readLookupTables(s);
s.close();
if (lut == null) break;
}
m.indexed = lut != null;
MetadataTools.populatePixels(store, this);
store.setImageName(name, 0);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
// link Instrument and Image
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
store.setImageInstrumentRef(instrumentID, 0);
// link Objective to Image using ObjectiveSettings
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
store.setObjectiveSettingsID(objectiveID, 0);
store.setObjectiveLensNA(new Double(lens), 0, 0);
store.setObjectiveNominalMagnification(new Double(magFactor), 0, 0);
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
// link Detector to Image
for (int i=0; i<getEffectiveSizeC(); i++) {
Double detectorOffset = i < offset.size() ? offset.get(i) : null;
Double detectorGain = i < gain.size() ? gain.get(i) : null;
if (detectorOffset != null || detectorGain != null) {
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorSettingsID(detectorID, 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorType(getDetectorType("Other"), 0, i);
}
if (detectorOffset != null) {
store.setDetectorSettingsOffset(detectorOffset, 0, i);
}
if (detectorGain != null) {
store.setDetectorSettingsGain(detectorGain, 0, i);
}
}
}
}
// -- Helper methods --
/**
* Read all of the note strings from the given file. If the 'add' flag is
* set, the notes will be added to the 'noteStrings' list.
*/
private void readNotes(RandomAccessInputStream s, boolean add)
throws IOException
{
s.seek(70);
int imageLen = getSizeX() * getSizeY();
if (picFiles == null) imageLen *= getImageCount();
else {
imageLen *= (getImageCount() / picFiles.length);
}
int bpp = FormatTools.getBytesPerPixel(getPixelType());
s.skipBytes(bpp * imageLen + 6);
boolean notes = true;
while (notes) {
// read in note
if (s.getFilePointer() >= s.length()) {
brokenNotes = true;
break;
}
Note n = new Note();
n.level = s.readShort();
notes = s.readInt() != 0;
n.num = s.readShort();
n.status = s.readShort();
n.type = s.readShort();
n.x = s.readShort();
n.y = s.readShort();
n.p = s.readString(80);
if (n.type < 0 || n.type >= NOTE_NAMES.length) {
notes = false;
brokenNotes = true;
break;
}
if (!add) continue;
// be sure to remove binary data from the note text
int ndx = n.p.length();
for (int i=0; i<n.p.length(); i++) {
if (n.p.charAt(i) == 0) {
ndx = i;
break;
}
}
n.p = n.p.substring(0, ndx).trim();
String value = n.p.replaceAll("=", "");
Vector<String> v = new Vector<String>();
StringTokenizer t = new StringTokenizer(value, " ");
while (t.hasMoreTokens()) {
String token = t.nextToken().trim();
if (token.length() > 0) v.add(token);
}
String[] tokens = v.toArray(new String[v.size()]);
try {
if (tokens.length > 1) {
int noteType = Integer.parseInt(tokens[1]);
if (noteType == 2 && value.indexOf("AXIS_4") != -1) {
CoreMetadata m = core.get(0);
m.sizeZ = 1;
m.sizeT = getImageCount();
m.orderCertain = true;
}
}
}
catch (NumberFormatException e) { }
// add note to list
noteStrings.add(n);
}
}
private boolean parseNotes(MetadataStore store) throws FormatException {
boolean multipleFiles = false;
int nextDetector = 0, nLasers = 0;
for (Note n : noteStrings) {
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
switch (n.type) {
case NOTE_TYPE_USER:
// TODO : this should be an overlay
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_SCALEBAR:
// TODO : this should be an overlay
// the format of the text is:
// SCALEBAR = <length> <angle>
// where <length> is the length of the scalebar in microns,
// and <angle> is the angle in degrees
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_ARROW:
// TODO : this should be an overlay
// the format of the text is:
// ARROW = <lx> <ly> <angle> <fill>
// where <lx> and <ly> define the arrow's bounding box,
// <angle> is the angle in degrees and <fill> is either "Fill" or
// "Outline"
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_VARIABLE:
if (n.p.indexOf("=") >= 0) {
String key = n.p.substring(0, n.p.indexOf("=")).trim();
String value = n.p.substring(n.p.indexOf("=") + 1).trim();
addGlobalMeta(key, value);
if (key.equals("INFO_OBJECTIVE_NAME")) {
store.setObjectiveModel(value, 0, 0);
}
else if (key.equals("INFO_OBJECTIVE_MAGNIFICATION")) {
Double mag = Double.parseDouble(value);
store.setObjectiveNominalMagnification(mag, 0, 0);
}
else if (key.equals("LENS_MAGNIFICATION")) {
Double magnification = Double.parseDouble(value);
store.setObjectiveNominalMagnification(magnification, 0, 0);
}
else if (key.startsWith("SETTING")) {
if (key.indexOf("_DET_") != -1) {
int index = key.indexOf("_DET_") + 5;
if (key.lastIndexOf("_") > index) {
String detectorID =
MetadataTools.createLSID("Detector", 0, nextDetector);
store.setDetectorID(detectorID, 0, nextDetector);
store.setDetectorType(
getDetectorType("Other"), 0, nextDetector);
if (key.endsWith("OFFSET")) {
if (nextDetector < offset.size()) {
offset.setElementAt(new Double(value), nextDetector);
}
else {
while (nextDetector > offset.size()) {
offset.add(null);
}
offset.add(new Double(value));
}
}
else if (key.endsWith("GAIN")) {
if (nextDetector < gain.size()) {
gain.setElementAt(new Double(value), nextDetector);
}
else {
while (nextDetector > gain.size()) {
gain.add(null);
}
gain.add(new Double(value));
}
}
nextDetector++;
}
}
}
else {
String[] values = value.split(" ");
if (values.length > 1) {
try {
int type = Integer.parseInt(values[0]);
if (type == 257 && values.length >= 3) {
// found length of axis in um
Double pixelSize = new Double(values[2]);
if (key.equals("AXIS_2")) {
PositiveFloat size =
FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
}
else if (key.equals("AXIS_3")) {
PositiveFloat size =
FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
}
}
}
catch (NumberFormatException e) { }
}
}
}
else if (n.p.startsWith("AXIS_2")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
PositiveFloat size = FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
}
else if (n.p.startsWith("AXIS_3")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
PositiveFloat size = FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
}
else {
addGlobalMetaList("Note", n.toString());
}
break;
case NOTE_TYPE_STRUCTURE:
int structureType = (n.x & 0xff00) >> 8;
int version = (n.x & 0xff);
String[] values = n.p.split(" ");
if (structureType == 1) {
switch (n.y) {
case 1:
for (int i=0; i<STRUCTURE_LABELS_1.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_1[i], values[i]);
}
Double mag = Double.parseDouble(values[11]);
store.setObjectiveNominalMagnification(mag, 0, 0);
Double sizeZ = new Double(values[14]);
PositiveFloat size = FormatTools.getPhysicalSizeZ(sizeZ);
if (size != null) {
store.setPixelsPhysicalSizeZ(size, 0);
}
break;
case 2:
for (int i=0; i<STRUCTURE_LABELS_2.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_2[i], values[i]);
}
double x1 = Double.parseDouble(values[2]);
double x2 = Double.parseDouble(values[4]);
double width = x2 - x1;
width /= getSizeX();
double y1 = Double.parseDouble(values[3]);
double y2 = Double.parseDouble(values[5]);
double height = y2 - y1;
height /= getSizeY();
PositiveFloat sizeX = FormatTools.getPhysicalSizeX(width);
PositiveFloat sizeY = FormatTools.getPhysicalSizeY(height);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
break;
case 3:
for (int i=0; i<3; i++) {
for (int j=0; j<STRUCTURE_LABELS_3.length; j++) {
String v = j == STRUCTURE_LABELS_3.length - 1 ?
values[12 + i] : values[i * 4 + j];
addGlobalMetaList(STRUCTURE_LABELS_3[j], v);
}
}
break;
case 4:
nLasers = Integer.parseInt(values[0]);
addGlobalMeta("Number of lasers", values[0]);
addGlobalMeta("Number of transmission detectors", values[1]);
addGlobalMeta("Number of PMTs", values[2]);
for (int i=1; i<=3; i++) {
int idx = (i + 1) * 3;
addGlobalMetaList("Shutter present for laser", values[i + 2]);
addGlobalMetaList("Neutral density filter for laser",
values[idx]);
addGlobalMetaList("Excitation filter for laser",
values[idx + 1]);
addGlobalMetaList("Use laser", values[idx + 2]);
}
for (int i=0; i<nLasers; i++) {
addGlobalMetaList("Neutral density filter name - laser",
values[15 + i]);
}
break;
case 5:
String prefix = "Excitation filter name - laser";
for (int i=0; i<nLasers; i++) {
addGlobalMetaList(prefix, values[i]);
}
break;
case 6:
prefix = "Emission filter name - laser";
for (int i=0; i<nLasers; i++) {
addGlobalMeta(prefix, values[i]);
}
break;
case 7:
for (int i=0; i<2; i++) {
prefix = "Mixer " + i + " - ";
for (int j=0; j<STRUCTURE_LABELS_4.length; j++) {
addGlobalMeta(prefix + STRUCTURE_LABELS_4[j],
values[i * 7 + j]);
}
}
addGlobalMeta("Mixer 0 - low signal on", values[14]);
addGlobalMeta("Mixer 1 - low signal on", values[15]);
break;
case 8:
case 9:
case 10:
addGlobalMeta("Laser name - laser " + (n.y - 7), values[0]);
break;
case 11:
for (int i=0; i<3; i++) {
prefix = "Transmission detector " + (i + 1) + " - ";
addGlobalMeta(prefix + "offset", values[i * 3]);
addGlobalMeta(prefix + "gain", values[i * 3 + 1]);
addGlobalMeta(prefix + "black level", values[i * 3 + 2]);
String detectorID =
MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorOffset(new Double(values[i * 3]), 0, i);
store.setDetectorGain(new Double(values[i * 3 + 1]), 0, i);
store.setDetectorType(getDetectorType("Other"), 0, i);
}
break;
case 12:
for (int i=0; i<2; i++) {
prefix = "Part number for ";
for (int j=0; j<STRUCTURE_LABELS_5.length; j++) {
addGlobalMetaList(prefix + STRUCTURE_LABELS_5[j],
values[i * 4 + j]);
}
}
break;
case 13:
for (int i=0; i<STRUCTURE_LABELS_6.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_6[i], values[i]);
}
break;
case 14:
prefix = "Filter Block Name - filter block ";
addGlobalMetaList(prefix, values[0]);
addGlobalMetaList(prefix, values[1]);
break;
case 15:
for (int i=0; i<5; i++) {
addGlobalMetaList("Image bands status - band", values[i*3]);
addGlobalMetaList("Image bands min - band", values[i*3 + 1]);
addGlobalMetaList("Image bands max - band", values[i*3 + 2]);
if (store instanceof IMinMaxStore) {
((IMinMaxStore) store).setChannelGlobalMinMax(i,
Double.parseDouble(values[i*3 + 1]),
Double.parseDouble(values[i*3 + 2]), 0);
}
}
break;
case 17:
int year = Integer.parseInt(values[5]) + 1900;
for (int i=0; i<5; i++) {
if (values[i].length() == 1) values[i] = "0" + values[i];
}
// date is in yyyy-MM-dd'T'HH:mm:ss
String date = year + "-" + values[4] + "-" + values[3] + "T" +
values[2] + ":" + values[1] + ":" + values[0];
addGlobalMeta("Acquisition date", date);
try {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
catch (Exception e) {
LOGGER.debug("Failed to parse acquisition date", e);
}
break;
case 18:
addGlobalMeta("Mixer 3 - enhanced", values[0]);
for (int i=1; i<=3; i++) {
addGlobalMetaList("Mixer 3 - PMT percentage", values[i]);
addGlobalMetaList("Mixer 3 - Transmission percentage",
values[i + 3]);
addGlobalMetaList("Mixer 3 - photon counting",
values[i + 7]);
}
addGlobalMeta("Mixer 3 - low signal on", values[7]);
addGlobalMeta("Mixer 3 - mode", values[11]);
break;
case 19:
for (int i=1; i<=2; i++) {
prefix = "Mixer " + i + " - ";
String photon = prefix + "photon counting ";
addGlobalMetaList(photon, values[i * 4 - 4]);
addGlobalMetaList(photon, values[i * 4 - 3]);
addGlobalMetaList(photon, values[i * 4 - 2]);
addGlobalMeta(prefix + "mode", values[i * 4 - 1]);
}
break;
case 20:
addGlobalMeta("Display mode", values[0]);
addGlobalMeta("Course", values[1]);
addGlobalMeta("Time Course - experiment type", values[2]);
addGlobalMeta("Time Course - kd factor", values[3]);
String experimentID =
MetadataTools.createLSID("Experiment", 0);
store.setExperimentID(experimentID, 0);
store.setExperimentType(getExperimentType(values[2]), 0);
break;
case 21:
addGlobalMeta("Time Course - ion name", values[0]);
break;
case 22:
addGlobalMeta("PIC file generated on Isoscan (lite)",
values[0]);
for (int i=1; i<=3; i++) {
addGlobalMetaList("Photon counting used - PMT", values[i]);
addGlobalMetaList("Hot spot filter used - PMT",
values[i + 3]);
addGlobalMetaList("Tx Selector used - TX", values[i + 6]);
}
break;
}
}
break;
default:
// notes for display only
addGlobalMetaList("Note", n.toString());
}
}
// if the text of the note contains "AXIS", parse the text
// more thoroughly (see pg. 21 of the BioRad specs)
if (n.p.indexOf("AXIS") != -1) {
n.p = n.p.replaceAll("=", "");
Vector<String> v = new Vector<String>();
StringTokenizer tokens = new StringTokenizer(n.p, " ");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (token.length() > 0) v.add(token);
}
String[] values = v.toArray(new String[v.size()]);
String key = values[0];
String noteType = values[1];
int axisType = Integer.parseInt(noteType);
if (axisType == 11 && values.length > 2) {
addGlobalMeta(key + " RGB type (X)", values[2]);
addGlobalMeta(key + " RGB type (Y)", values[3]);
CoreMetadata m = core.get(0);
if (key.equals("AXIS_4")) {
// this is a single section multi-channel dataset
m.sizeC = getImageCount();
m.sizeZ = 1;
m.sizeT = 1;
}
else if (key.equals("AXIS_9")) {
multipleFiles = true;
m.sizeC = (int) Double.parseDouble(values[3]);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM &&
values.length > 2)
{
switch (axisType) {
case 1:
addGlobalMeta(key + " distance (X) in microns", values[2]);
addGlobalMeta(key + " distance (Y) in microns", values[3]);
break;
case 3:
addGlobalMeta(key + " angle (X) in degrees", values[2]);