Skip to content

Commit

Permalink
Add PValue op
Browse files Browse the repository at this point in the history
This op is based on a new statistical framework published in Wang et al
(2017) IEEE Signal Processing "Automated and Robust Quantification of
Colocalization in Dual-Color Fluorescence Microscopy: A Nonparametric
Statistical Approach". This routine repeatedly executes a colocalization
algorithm (coloc op), computing a p-value.
  • Loading branch information
etadobson authored and ctrueden committed Oct 25, 2017
1 parent 0a160b1 commit c0018a1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/main/java/net/imagej/ops/coloc/pValue/PValue.java
@@ -0,0 +1,64 @@

package net.imagej.ops.coloc.pValue;

import net.imagej.ops.Ops;
import net.imagej.ops.coloc.BlockShuffle;
import net.imagej.ops.special.function.AbstractBinaryFunctionOp;
import net.imagej.ops.special.function.BinaryFunctionOp;
import net.imglib2.img.Img;
import net.imglib2.type.numeric.RealType;

import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* This algorithm repeatedly executes a colocalization algorithm, computing a
* p-value. It is based on a new statistical framework published by Wang et al
* (2017) IEEE Signal Processing "Automated and Robust Quantification of
* Colocalization in Dual-Color Fluorescence Microscopy: A Nonparametric
* Statistical Approach".
*/
@Plugin(type = Ops.Coloc.PValue.class)
public class PValue<T extends RealType<T>, U extends RealType<U>> extends
AbstractBinaryFunctionOp<Img<T>, Iterable<U>, Double> implements
Ops.Coloc.PValue
{

@Parameter
private BinaryFunctionOp<Iterable<T>, Iterable<U>, Double> op;

@Parameter(required = false)
private final int nrRandomizations = 1000;

@Parameter(required = false)
private final long seed = 0x27372034;

@Override
public Double calculate(final Img<T> image1, final Iterable<U> image2) {

final BlockShuffle<T> shuffler = new BlockShuffle<>(image1, seed);
final double[] sampleDistribution = new double[nrRandomizations];

final double value = op.calculate(image1, image2);

for (int i = 0; i < nrRandomizations; i++) {
final Img<T> shuffledImage = shuffler.shuffleBlocks(image1.factory());
sampleDistribution[i] = op.calculate(shuffledImage, image2);
}

return calculatePvalue(value, sampleDistribution);
}

private double calculatePvalue(final double input,
final double[] distribution)
{
double count = 0;
for (int i = 0; i < distribution.length; i++) {
if (distribution[i] > input) {
count++;
}
}
final double pvalue = count / distribution.length;
return pvalue;
}
}
1 change: 1 addition & 0 deletions src/main/templates/net/imagej/ops/Ops.list
Expand Up @@ -30,6 +30,7 @@ namespaces = ```
[name: "manders", iface: "Manders"],
[name: "pearsons", iface: "Pearsons"],
[name: "pearsonsClassic", iface: "PearsonsClassic"],
[name: "pValue", iface: "PValue"],
[name: "threshold", iface: "Threshold"],
[name: "spearman", iface: "Spearman"],
]],
Expand Down

0 comments on commit c0018a1

Please sign in to comment.