Search in sources :

Example 26 with ProbeList

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

the class VariancePlotDialog method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("close")) {
        setVisible(false);
        dispose();
    } else if (ae.getActionCommand().equals("sublists")) {
        // Select a set of sublists from the current probe list to highlight
        // in the plot
        OrderedListSelector selector = new OrderedListSelector(this, probeList, subLists);
        // It's modal so by the time we get here the selection has been made
        subLists = selector.getOrderedLists();
        // try to highlight anything.
        if (subLists != null && subLists.length == 0) {
            subLists = null;
        }
        selector.dispose();
        actionPerformed(new ActionEvent(this, 1, "plot"));
    } else if (ae.getActionCommand().equals("plot")) {
        ReplicateSet xStore = (ReplicateSet) stores.getSelectedItem();
        getContentPane().remove(variancePlotPanel);
        // Check if these stores are quantitated
        if (!xStore.isQuantitated()) {
            JOptionPane.showMessageDialog(this, xStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
        } else {
            int varianceMeasure = VariancePlotPanel.VARIANCE_COEF;
            if (varianceMeasures.getSelectedItem().equals("StDev")) {
                varianceMeasure = VariancePlotPanel.VARIANCE_STDEV;
            } else if (varianceMeasures.getSelectedItem().equals("SEM")) {
                varianceMeasure = VariancePlotPanel.VARIANCE_SEM;
            } else if (varianceMeasures.getSelectedItem().equals("QuartDisp")) {
                varianceMeasure = VariancePlotPanel.VARIANCE_QUARTILE_DISP;
            } else if (varianceMeasures.getSelectedItem().equals("Unmeasured")) {
                varianceMeasure = VariancePlotPanel.VARIANCE_NUMBER_UNMEASURED;
            }
            variancePlotPanel = new VariancePlotPanel(xStore, varianceMeasure, probeList, subLists, dotSizeSlider.getValue());
            getContentPane().add(variancePlotPanel, BorderLayout.CENTER);
        }
        validate();
    } else if (ae.getActionCommand().equals("save_probe_list")) {
        if (variancePlotPanel instanceof VariancePlotPanel) {
            ProbeList list = ((VariancePlotPanel) variancePlotPanel).getFilteredProbes(collection.probeSet());
            if (list.getAllProbes().length == 0) {
                JOptionPane.showMessageDialog(this, "No probes were selected", "No probes", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            // Ask for a name for the list
            String groupName = null;
            while (true) {
                groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + list.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, list.name());
                if (groupName == null) {
                    // Remove the list which will have been created by this stage
                    list.delete();
                    // They cancelled
                    return;
                }
                if (groupName.length() == 0)
                    // Try again
                    continue;
                break;
            }
            list.setName(groupName);
        }
    } else if (ae.getActionCommand().equals("save_image")) {
        ImageSaver.saveImage(variancePlotPanel);
    } else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) OrderedListSelector(uk.ac.babraham.SeqMonk.Dialogs.OrderedListSelector)

Example 27 with ProbeList

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

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

use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList 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)

Example 30 with ProbeList

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

the class ProbeNameFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    queries = optionsPanel.queriesArea.getText().split("\n");
    stripSuffixes = optionsPanel.stripSuffixesBox.isSelected();
    stripTranscript = optionsPanel.stripTranscriptBox.isSelected();
    caseInsensitive = optionsPanel.caseInsensitiveBox.isSelected();
    ProbeList passedProbes = new ProbeList(startingList, "", "", startingList.getValueName());
    // We start by building a list of query strings we're going to
    // check against.
    HashSet<String> queryStrings = new HashSet<String>();
    for (int q = 0; q < queries.length; q++) {
        String query = queries[q].trim();
        if (caseInsensitive) {
            query = query.toLowerCase();
        }
        if (stripSuffixes) {
            query = query.replaceFirst("_upstream$", "").replaceAll("_downstream$", "").replaceAll("_gene$", "");
        }
        if (stripTranscript) {
            query = query.replaceAll("-\\d\\d\\d$", "");
        }
        // System.err.println("Adding query term "+query);
        queryStrings.add(query);
    }
    Probe[] probes = startingList.getAllProbes();
    // 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 (p % 100 == 0) {
            progressUpdated("Filtering probes", p, probes.length);
        }
        if (cancel) {
            cancel = false;
            progressCancelled();
            return;
        }
        String name = probes[p].name();
        if (caseInsensitive) {
            name = name.toLowerCase();
        }
        if (stripSuffixes) {
            name = name.replaceFirst("_upstream$", "").replaceAll("_downstream$", "").replaceAll("_gene$", "");
        }
        if (stripTranscript) {
            name = name.replaceAll("-\\d\\d\\d$", "");
        }
        if (queryStrings.contains(name)) {
            passedProbes.addProbe(probes[p], startingList.getValueForProbe(probes[p]));
        } else {
        // System.err.println("No match for "+name);
        }
    }
    filterFinished(passedProbes);
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) HashSet(java.util.HashSet)

Aggregations

ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)79 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)54 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)32 Vector (java.util.Vector)16 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)15 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)12 HashSet (java.util.HashSet)10 JLabel (javax.swing.JLabel)8 ProbeTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.ProbeTTestValue)8 GridBagConstraints (java.awt.GridBagConstraints)7 GridBagLayout (java.awt.GridBagLayout)7 File (java.io.File)7 JComboBox (javax.swing.JComboBox)7 JPanel (javax.swing.JPanel)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 PrintWriter (java.io.PrintWriter)6 JCheckBox (javax.swing.JCheckBox)6 ProgressRecordDialog (uk.ac.babraham.SeqMonk.Dialogs.ProgressRecordDialog)6 RProgressListener (uk.ac.babraham.SeqMonk.R.RProgressListener)6