Search in sources :

Example 1 with SmoothedVarianceDataset

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset in project SeqMonk by s-andrews.

the class VarianceIntensityDifferenceFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
protected void generateProbeList() {
    applyMultipleTestingCorrection = optionsPanel.multipleTestingBox.isSelected();
    int varianceType = optionsPanel.getVarianceMeasure();
    Probe[] probes = startingList.getAllProbes();
    // We'll pull the number of probes to sample from the preferences if they've changed it
    Integer updatedProbesPerSet = optionsPanel.probesPerSet();
    if (updatedProbesPerSet != null)
        probesPerSet = updatedProbesPerSet;
    ProbeList newList = new ProbeList(startingList, "Filtered Probes", "", "Diff p-value");
    // We'll build up a set of p-values as we go along
    float[] lowestPValues = new float[probes.length];
    for (int p = 0; p < lowestPValues.length; p++) {
        lowestPValues[p] = 1;
    }
    // Put something in the progress whilst we're ordering the probe values to make
    // the comparison.
    progressUpdated("Generating background model", 0, 1);
    for (int r = 0; r < repSetsToUse.length; r++) {
        SmoothedVarianceDataset var = new SmoothedVarianceDataset(repSetsToUse[r], probes, varianceType, probesPerSet);
        progressUpdated("Processing " + repSetsToUse[r].name(), r, repSetsToUse.length);
        IndexTTestValue[] currentPValues = new IndexTTestValue[probes.length];
        for (int p = 0; p < probes.length; p++) {
            if (cancel) {
                cancel = false;
                progressCancelled();
                return;
            }
            if (p % 1000 == 0) {
                int progress = (p * 100) / probes.length;
                progress += 100 * r;
                progressUpdated("Made " + r + " out of " + repSetsToUse.length + " comparisons", progress, repSetsToUse.length * 100);
            }
            currentPValues[p] = new IndexTTestValue(p, var.getIntenstiyPValueForIndex(p, probesPerSet));
        }
        // We now need to correct the set of pValues
        if (applyMultipleTestingCorrection) {
            BenjHochFDR.calculateQValues(currentPValues);
        }
        // the combined set
        for (int i = 0; i < currentPValues.length; i++) {
            if (!optionsPanel.wantHighVariation()) {
                if (var.getDifferenceForIndex(currentPValues[i].index) > 0)
                    continue;
            }
            if (!optionsPanel.wantLowVariation()) {
                if (var.getDifferenceForIndex(currentPValues[i].index) < 0)
                    continue;
            }
            if (applyMultipleTestingCorrection) {
                if (currentPValues[i].q < lowestPValues[currentPValues[i].index]) {
                    lowestPValues[currentPValues[i].index] = (float) currentPValues[i].q;
                }
            } else {
                if (currentPValues[i].p < lowestPValues[currentPValues[i].index]) {
                    lowestPValues[currentPValues[i].index] = (float) currentPValues[i].p;
                }
            }
        }
    }
    // pass the filter.
    for (int i = 0; i < lowestPValues.length; i++) {
        if (lowestPValues[i] < pValueLimit) {
            newList.addProbe(probes[i], lowestPValues[i]);
        }
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) SmoothedVarianceDataset(uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) IndexTTestValue(uk.ac.babraham.SeqMonk.Analysis.Statistics.IndexTTestValue)

Example 2 with SmoothedVarianceDataset

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset in project SeqMonk by s-andrews.

the class VarianceValuesFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    // System.out.println("Data store size="+stores.length+" lower="+lowerLimit+" upper="+upperLimit+" type="+limitType+" chosen="+chosenNumber);
    Probe[] probes = startingList.getAllProbes();
    ProbeList newList = new ProbeList(startingList, "Filtered Probes", "", null);
    locallyCorrect = optionsPanel.locallyCorrectBox.isSelected();
    // If we're correcting our variances by the local trend then we'll need to store
    // the smoothed values.
    SmoothedVarianceDataset[] smoothedVariances = new SmoothedVarianceDataset[stores.length];
    if (locallyCorrect) {
        for (int s = 0; s < stores.length; s++) {
            smoothedVariances[s] = new SmoothedVarianceDataset(stores[s], probes, varianceType, probes.length / 100);
        }
    }
    for (int p = 0; p < probes.length; p++) {
        progressUpdated(p, probes.length);
        if (cancel) {
            cancel = false;
            progressCancelled();
            return;
        }
        int count = 0;
        for (int s = 0; s < stores.length; s++) {
            float d = 0;
            if (!stores[s].hasValueForProbe(probes[p]))
                continue;
            try {
                d = getVarianceMeasure(stores[s], probes[p]);
                if (locallyCorrect) {
                    float localValue = smoothedVariances[s].getSmoothedValueForIndex(p);
                    // System.err.println("Raw value is "+d+" smoothed value is "+localValue);
                    d -= localValue;
                }
            } catch (SeqMonkException e) {
                e.printStackTrace();
                continue;
            }
            // NaN values always fail the filter.
            if (Float.isNaN(d))
                continue;
            // Now we have the value we need to know if it passes the test
            if (upperLimit != null)
                if (d > upperLimit)
                    continue;
            if (lowerLimit != null)
                if (d < lowerLimit)
                    continue;
            // This one passes, we can add it to the count
            ++count;
        }
        // probe to the probe set.
        switch(limitType) {
            case EXACTLY:
                if (count == chosenNumber)
                    newList.addProbe(probes[p], null);
                break;
            case AT_LEAST:
                if (count >= chosenNumber)
                    newList.addProbe(probes[p], null);
                break;
            case NO_MORE_THAN:
                if (count <= chosenNumber)
                    newList.addProbe(probes[p], null);
                break;
        }
    }
    newList.setName(optionsPanel.varianceTypesBox.getSelectedItem().toString() + " between " + lowerLimit + "-" + upperLimit);
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) SmoothedVarianceDataset(uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 3 with SmoothedVarianceDataset

use of uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset in project SeqMonk by s-andrews.

the class VariancePlotPanel method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    // We need to find the mix/max counts, and get a non-overlapping
    // set of probes
    Probe[] probes = probeList.getAllProbes();
    // We need to get rid of any probes which don't have a value associated with them (ie NaN values)
    Vector<Probe> validProbes = new Vector<Probe>();
    try {
        for (int p = 0; p < probes.length; p++) {
            if (!Float.isNaN(repSet.getValueForProbeExcludingUnmeasured(probes[p]))) {
                validProbes.add(probes[p]);
            }
        }
    } catch (SeqMonkException sme) {
        return;
    }
    probes = validProbes.toArray(new Probe[0]);
    // If there aren't any probes there's no point going any further
    if (probes.length == 0) {
        noData = true;
        repaint();
        return;
    }
    boolean someXValueSet = false;
    boolean someYValueSet = false;
    try {
        // We extract the data to allow the calculation of the smoothed values
        float[] xData = new float[probes.length];
        float[] yData = new float[probes.length];
        for (int p = 0; p < probes.length; p++) {
            xData[p] = repSet.getValueForProbeExcludingUnmeasured(probes[p]);
            yData[p] = getYValue(probes[p]);
            if (!someXValueSet && !(Float.isNaN(xData[p]) || Float.isInfinite(xData[p]))) {
                minValueX = xData[p];
                maxValueX = xData[p];
                someXValueSet = true;
            }
            if (!someYValueSet && !(Float.isNaN(yData[p]) || Float.isInfinite(yData[p]))) {
                minValueY = yData[p];
                maxValueY = yData[p];
                someYValueSet = true;
            }
            if (!(Float.isNaN(xData[p]) || Float.isInfinite(xData[p]))) {
                if (xData[p] < minValueX)
                    minValueX = xData[p];
                if (xData[p] > maxValueX)
                    maxValueX = xData[p];
            }
            if (!(Float.isNaN(yData[p]) || Float.isInfinite(yData[p]))) {
                if (yData[p] < minValueY)
                    minValueY = yData[p];
                if (yData[p] > maxValueY)
                    maxValueY = yData[p];
            }
        }
        // Do a sanity check that something has a non-NaN value in it
        boolean someRealData = false;
        for (int i = 0; i < xData.length; i++) {
            if (!Float.isNaN(xData[i])) {
                someRealData = true;
                break;
            }
        }
        if (!someRealData) {
            // There's no point doing anything else
            return;
        }
        // Calculate the smoothed values
        smoothedTrend = new SmoothedVarianceDataset(repSet, probes, varianceMeasure, xData.length / 100);
    } catch (SeqMonkException e) {
        e.printStackTrace();
    }
    readyToDraw = true;
    repaint();
}
Also used : SmoothedVarianceDataset(uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Aggregations

SmoothedVarianceDataset (uk.ac.babraham.SeqMonk.Analysis.Statistics.SmoothedVarianceDataset)3 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)3 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)2 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)2 Vector (java.util.Vector)1 IndexTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.IndexTTestValue)1