|
37 | 37 |
|
38 | 38 | import org.scijava.types.Nil; |
39 | 39 | import org.scijava.ops.image.AbstractColocalisationTest; |
| 40 | + |
| 41 | +import org.junit.jupiter.api.BeforeAll; |
40 | 42 | import org.junit.jupiter.api.Test; |
41 | 43 | import static org.junit.jupiter.api.Assertions.assertEquals; |
42 | 44 |
|
43 | 45 | /** |
44 | 46 | * Tests {@code coloc.saca} ops. |
| 47 | + * |
| 48 | + * @author Edward Evans |
45 | 49 | */ |
46 | 50 |
|
47 | 51 | public class SACATest extends AbstractColocalisationTest { |
48 | 52 |
|
49 | | - @Test |
50 | | - public void testSACAFramework() { |
51 | | - final int[] xPositions = { 30, 79, 77, 104, 7, 52, 164, 88, 119, 65 }; |
52 | | - final int[] yPositions = { 30, 36, 80, 79, 139, 102, 77, 41, 142, 118 }; |
53 | | - final double[] zscoreExpected = { 0.0, 6.117364936585281, 0.0, |
54 | | - -1.282447034877343, 0.0, 6.642396454955293, 0.0, -1.6567255788972388, 0.0, |
55 | | - 3.5385003044434877 }; |
56 | | - final double[] pvalueExpected = { 0.5, 0.9999999995243234, 0.5, |
57 | | - 0.09984293678613743, 0.5, 0.9999999999845688, 0.5, 0.04878748455758225, |
58 | | - 0.5, 0.9997987965912973 }; |
59 | | - final double[] sigExpected = { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, |
60 | | - 0.0 }; |
| 53 | + // XY positions to sample |
| 54 | + private final static int[] xPositions = { 30, 79, 77, 104, 7, 52, 164, 88, |
| 55 | + 119, 65 }; |
| 56 | + private final static int[] yPositions = { 30, 36, 80, 79, 139, 102, 77, 41, |
| 57 | + 142, 118 }; |
61 | 58 |
|
62 | | - // load sample colocalization data |
63 | | - Img<UnsignedByteType> green = getPositiveCorrelationImageCh1(); |
64 | | - Img<UnsignedByteType> red = getPositiveCorrelationImageCh2(); |
| 59 | + // green and red colocalization images |
| 60 | + private Img<UnsignedByteType> green; |
| 61 | + private Img<UnsignedByteType> red; |
65 | 62 |
|
66 | | - // get slice 15 from the green/red images |
67 | | - var gs = ops.op("transform.hyperSliceView").input(green, 2, 15).apply(); |
68 | | - var rs = ops.op("transform.hyperSliceView").input(red, 2, 15).apply(); |
| 63 | + // green and red data slices |
| 64 | + private Img<UnsignedByteType> gs; |
| 65 | + private Img<UnsignedByteType> rs; |
69 | 66 |
|
70 | | - // create image containers |
71 | | - Img<DoubleType> zscore = ops.op("create.img").input(gs, new DoubleType()) |
72 | | - .outType(new Nil<Img<DoubleType>>() |
| 67 | + // SACA heatmap z score and sig mask image containers |
| 68 | + private Img<DoubleType> zscore; |
| 69 | + private Img<BitType> sigMask; |
| 70 | + |
| 71 | + @BeforeAll |
| 72 | + public void setUpTest() { |
| 73 | + // load colocalization data (3D) |
| 74 | + green = getPositiveCorrelationImageCh1(); |
| 75 | + red = getPositiveCorrelationImageCh2(); |
| 76 | + |
| 77 | + // get slice 15 from colocalization data |
| 78 | + gs = ops.op("transform.hyperSliceView").input(green, 2, 15).outType( |
| 79 | + new Nil<Img<UnsignedByteType>>() |
73 | 80 | {}).apply(); |
74 | | - Img<DoubleType> pvalue = ops.op("create.img").input(gs, new DoubleType()) |
75 | | - .outType(new Nil<Img<DoubleType>>() |
| 81 | + rs = ops.op("transform.hyperSliceView").input(red, 2, 15).outType( |
| 82 | + new Nil<Img<UnsignedByteType>>() |
76 | 83 | {}).apply(); |
77 | | - Img<BitType> sigMask = ops.op("create.img").input(gs, new BitType()) |
78 | | - .outType(new Nil<Img<BitType>>() |
| 84 | + |
| 85 | + // create image containers |
| 86 | + zscore = ops.op("create.img").input(gs, new DoubleType()).outType( |
| 87 | + new Nil<Img<DoubleType>>() |
79 | 88 | {}).apply(); |
| 89 | + sigMask = ops.op("create.img").input(gs, new BitType()).outType( |
| 90 | + new Nil<Img<BitType>>() |
| 91 | + {}).apply(); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testSACAHeatmapZScore() { |
| 96 | + final double[] zscoreExpected = { 0.0, 6.117364936585281, 0.0, |
| 97 | + -1.282447034877343, 0.0, 6.642396454955293, 0.0, -1.6567255788972388, 0.0, |
| 98 | + 3.5385003044434877 }; |
80 | 99 |
|
81 | 100 | // run SACA heatmap Z score op |
82 | 101 | ops.op("coloc.saca.heatmapZScore").input(gs, rs).output(zscore).compute(); |
83 | 102 |
|
84 | | - // run stats.pnorm op |
85 | | - ops.op("stats.pnorm").input(zscore).output(pvalue).compute(); |
| 103 | + // get random access and assert results are equal |
| 104 | + final RandomAccess<DoubleType> zRA = zscore.randomAccess(); |
| 105 | + for (int i = 0; i < xPositions.length; i++) { |
| 106 | + zRA.setPosition(xPositions[i], 0); |
| 107 | + zRA.setPosition(yPositions[i], 1); |
| 108 | + assertEquals(zscoreExpected[i], zRA.get().getRealDouble()); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testSACASigMask() { |
| 114 | + final double[] sigExpected = { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, |
| 115 | + 0.0 }; |
86 | 116 |
|
87 | 117 | // run SACA significant pixel mask op |
88 | 118 | ops.op("coloc.saca.sigMask").input(zscore).output(sigMask).compute(); |
89 | 119 |
|
90 | | - // get random access and compare pixels |
91 | | - final RandomAccess<DoubleType> zRA = zscore.randomAccess(); |
92 | | - final RandomAccess<DoubleType> pRA = pvalue.randomAccess(); |
| 120 | + // get random access and assert results are equal |
93 | 121 | final RandomAccess<BitType> sRA = sigMask.randomAccess(); |
94 | | - |
95 | | - // assert results are equal |
96 | 122 | for (int i = 0; i < xPositions.length; i++) { |
97 | | - zRA.setPosition(xPositions[i], 0); |
98 | | - zRA.setPosition(yPositions[i], 1); |
99 | | - pRA.setPosition(xPositions[i], 0); |
100 | | - pRA.setPosition(yPositions[i], 1); |
101 | 123 | sRA.setPosition(xPositions[i], 0); |
102 | 124 | sRA.setPosition(yPositions[i], 1); |
103 | | - assertEquals(zscoreExpected[i], zRA.get().getRealDouble()); |
104 | | - assertEquals(pvalueExpected[i], pRA.get().getRealDouble()); |
105 | 125 | assertEquals(sigExpected[i], sRA.get().getRealDouble()); |
| 126 | + |
106 | 127 | } |
| 128 | + |
107 | 129 | } |
108 | 130 | } |
0 commit comments