Search in sources :

Example 46 with Probe

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.

the class FeatureNameFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    annotationType = optionsPanel.annotationTypeBox.getSelectedItem().toString();
    stripSuffixes = optionsPanel.stripSuffixesBox.isSelected();
    stripTranscriptSuffixes = optionsPanel.stripTranscriptSuffixesBox.isSelected();
    ProbeList passedProbes = new ProbeList(startingList, "", "", startingList.getValueName());
    // Since we're going to be making the annotations on the
    // basis of position we should go through all probes one
    // chromosome at a time.  We therefore make a stipulation that
    // not only do the feature names have to match, so do the
    // chromosomes.
    Chromosome[] chrs = collection.genome().getAllChromosomes();
    for (int c = 0; c < chrs.length; c++) {
        // We start by building a list of the feature names we're going to
        // check against.
        HashSet<String> featureNames = new HashSet<String>();
        progressUpdated("Processing features on Chr " + chrs[c].name(), c, chrs.length);
        Probe[] probes = startingList.getProbesForChromosome(chrs[c]);
        Feature[] features = collection.genome().annotationCollection().getFeaturesForType(chrs[c], annotationType);
        for (int f = 0; f < features.length; f++) {
            String name = features[f].name();
            if (stripSuffixes) {
                name = name.replaceFirst("_upstream$", "").replaceAll("_downstream$", "").replaceAll("_gene$", "");
            }
            if (stripTranscriptSuffixes) {
                name = name.replaceAll("-\\d\\d\\d$", "");
            }
            featureNames.add(name);
        }
        // We can now step through the probes looking for a match to the stored feature names
        for (int p = 0; p < probes.length; p++) {
            if (cancel) {
                cancel = false;
                progressCancelled();
                return;
            }
            String name = probes[p].name();
            if (stripSuffixes) {
                name = name.replaceFirst("_upstream$", "").replaceAll("_downstream$", "").replaceAll("_gene$", "");
            }
            if (stripTranscriptSuffixes) {
                name = name.replaceAll("-\\d\\d\\d$", "");
            }
            if (featureNames.contains(name)) {
                passedProbes.addProbe(probes[p], startingList.getValueForProbe(probes[p]));
            }
        }
    }
    filterFinished(passedProbes);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature) HashSet(java.util.HashSet)

Example 47 with Probe

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.

the class GeneSetDisplay method valueChanged.

public void valueChanged(ListSelectionEvent ae) {
    int viewRow = table.getSelectedRow();
    if (viewRow >= 0) {
        int modelRow = table.convertRowIndexToModel(viewRow);
        ProbeList tempProbeList = new ProbeList(startingProbeList, filterResultsPVals[modelRow].mappedGeneSet.name(), "temp list", "z score");
        Probe[] tempProbes = filterResultsPVals[modelRow].mappedGeneSet.getProbes();
        for (int j = 0; j < tempProbes.length; j++) {
            tempProbeList.addProbe(tempProbes[j], (float) 0);
        }
        if (currentSelectedProbeList != null) {
            currentSelectedProbeList[0].delete();
        }
        currentSelectedProbeList = new ProbeList[1];
        currentSelectedProbeList[0] = tempProbeList;
    } else {
        if (currentSelectedProbeList != null) {
            currentSelectedProbeList[0].delete();
        }
        currentSelectedProbeList = null;
    }
    if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
        System.err.println("trying to update the scatter plot");
        plotPanel.remove((GeneSetScatterPlotPanel) scatterPlotPanel);
        // plotPanel.repaint();
        scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList, currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues, simpleRegression);
        // here
        plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
        plotPanel.revalidate();
        plotPanel.repaint();
    } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
        ((ZScoreScatterPlotPanel) scatterPlotPanel).setSubLists(currentSelectedProbeList);
    }
// Check to see if we can add anything...
// if (availableList.getSelectedIndices().length>0) {
// System.out.println("Selected index = " + availableList.getSelectedIndices().toString());
// }
}
Also used : GeneSetScatterPlotPanel(uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetScatterPlotPanel) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 48 with Probe

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe 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 49 with Probe

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe 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 50 with Probe

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.

the class WindowedDifferencesFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    // We need to check that we don't add any probes more than once
    // so we need to keep a hash of the probes we've added to the
    // filtered list.
    Hashtable<Probe, Float> goingToAdd = new Hashtable<Probe, Float>();
    ProbeList newList = new ProbeList(startingList, "Filtered Probes", "", "Difference");
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    for (int c = 0; c < chromosomes.length; c++) {
        progressUpdated("Processing windows on Chr" + chromosomes[c].name(), c, chromosomes.length);
        Probe[] probes = startingList.getProbesForChromosome(chromosomes[c]);
        ProbeGroupGenerator gen = null;
        if (windowType == DISTANCE_WINDOW) {
            gen = new ProbeWindowGenerator(probes, windowSize);
        } else if (windowType == CONSECUTIVE_WINDOW) {
            gen = new ConsecutiveProbeGenerator(probes, windowSize);
        } else if (windowType == FEATURE_WINDOW) {
            gen = new FeatureProbeGroupGenerator(probes, collection.genome().annotationCollection().getFeaturesForType(optionPanel.featureTypeBox.getSelectedItem().toString()));
        }
        while (true) {
            if (cancel) {
                cancel = false;
                progressCancelled();
                return;
            }
            Probe[] theseProbes = gen.nextSet();
            if (theseProbes == null) {
                break;
            }
            int count = 0;
            float d = 0;
            for (int s1 = 0; s1 < fromStores.length; s1++) {
                for (int s2 = 0; s2 < toStores.length; s2++) {
                    switch(combineType) {
                        case DifferencesFilter.AVERAGE:
                            d += getDifferenceValue(toStores[s2], fromStores[s1], theseProbes);
                            count++;
                            break;
                        case DifferencesFilter.MAXIMUM:
                            float dt1 = getDifferenceValue(toStores[s2], fromStores[s1], theseProbes);
                            if (count == 0 || dt1 > d)
                                d = dt1;
                            count++;
                            break;
                        case DifferencesFilter.MINIMUM:
                            float dt2 = getDifferenceValue(toStores[s2], fromStores[s1], theseProbes);
                            if (count == 0 || dt2 < d)
                                d = dt2;
                            count++;
                            break;
                    }
                }
            }
            if (combineType == DifferencesFilter.AVERAGE) {
                d /= count;
            }
            // Now we have the value we need to know if it passes the test
            if (upperLimit != null)
                if (d > upperLimit.doubleValue())
                    continue;
            if (lowerLimit != null)
                if (d < lowerLimit.doubleValue())
                    continue;
            for (int i = 0; i < theseProbes.length; i++) {
                if (goingToAdd.containsKey(theseProbes[i])) {
                    // Don't do anything if this probe is already there with a bigger difference
                    continue;
                // if (Math.abs(goingToAdd.get(theseProbes[i])) > Math.abs(d)) continue;
                }
                goingToAdd.put(theseProbes[i], d);
            }
        }
    }
    // Finally add all of the cached probes to the actual probe list
    Enumeration<Probe> en = goingToAdd.keys();
    while (en.hasMoreElements()) {
        Probe p = en.nextElement();
        newList.addProbe(p, goingToAdd.get(p));
    }
    filterFinished(newList);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Hashtable(java.util.Hashtable) ProbeWindowGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ProbeWindowGenerator) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) FeatureProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.FeatureProbeGroupGenerator) ConsecutiveProbeGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ConsecutiveProbeGenerator) ProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ProbeGroupGenerator) FeatureProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.FeatureProbeGroupGenerator)

Aggregations

Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)125 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)54 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)52 Vector (java.util.Vector)48 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)47 ProbeSet (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet)26 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)21 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)20 HashSet (java.util.HashSet)9 Location (uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)9 File (java.io.File)8 PrintWriter (java.io.PrintWriter)8 ProbeTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.ProbeTTestValue)8 SplitLocation (uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)7 HiCDataStore (uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 Hashtable (java.util.Hashtable)6 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)6 HiCHitCollection (uk.ac.babraham.SeqMonk.DataTypes.Sequence.HiCHitCollection)6