Search in sources :

Example 11 with ReplicateSet

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

the class ReplicateSetEditor method valueChanged.

/* (non-Javadoc)
	 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
	 */
public void valueChanged(ListSelectionEvent ae) {
    // Check for a new set being selected
    if (ae.getSource() == replicateSetList) {
        // Move all samples back to the available list
        DataStore[] o = usedModel.getStores();
        availableModel.addElements(o);
        usedList.setSelectedIndices(new int[0]);
        availableList.setSelectedIndices(new int[0]);
        usedModel.removeAllElements();
        if (replicateSetList.getSelectedValues().length == 1) {
            renameButton.setEnabled(true);
            deleteButton.setEnabled(true);
            ReplicateSet s = (ReplicateSet) replicateSetList.getSelectedValue();
            DataStore[] st = s.dataStores();
            usedModel.addElements(st);
            availableModel.removeElements(st);
            usedList.setSelectedIndices(new int[0]);
            availableList.setSelectedIndices(new int[0]);
        } else if (replicateSetList.getSelectedValues().length > 1) {
            deleteButton.setEnabled(true);
        } else {
            deleteButton.setEnabled(false);
        }
    }
    // Check to see if we can add anything...
    if (availableList.getSelectedIndices().length > 0 && replicateSetList.getSelectedIndices().length == 1) {
        addButton.setEnabled(true);
    } else {
        addButton.setEnabled(false);
    }
    // Or remove anything
    if (usedList.getSelectedIndices().length > 0 && replicateSetList.getSelectedIndices().length == 1) {
        removeButton.setEnabled(true);
    } else {
        removeButton.setEnabled(false);
    }
}
Also used : DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)

Example 12 with ReplicateSet

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

the class ChromosomeViewer method tracksUpdated.

/**
 * This is quite a heavyweight call to make.  It forces the recalculation
 * of the layout of all tracks.  In many cases it is sufficient to call
 * repaint on the chromosome viewer which will update existing information
 * (name changes, selection changes etc).  Only use this when the actual
 * data has changed.
 */
public void tracksUpdated() {
    if (featurePanel == null)
        return;
    String[] featureTypes = application.drawnFeatureTypes();
    featureTracks.removeAllElements();
    for (int i = 0; i < featureTypes.length; i++) {
        ChromosomeFeatureTrack t = new ChromosomeFeatureTrack(this, featureTypes[i], application.dataCollection().genome().annotationCollection().getFeaturesForType(chromosome, featureTypes[i]));
        featureTracks.add(t);
    }
    DataStore[] dataStores = application.drawnDataStores();
    dataTracks.removeAllElements();
    for (int i = 0; i < dataStores.length; i++) {
        if (dataStores[i] instanceof ReplicateSet && DisplayPreferences.getInstance().getReplicateSetExpansion() == DisplayPreferences.REPLICATE_SETS_EXPANDED) {
            DataStore[] localStores = ((ReplicateSet) dataStores[i]).dataStores();
            for (int j = 0; j < localStores.length; j++) {
                ChromosomeDataTrack t = new ChromosomeDataTrack(this, application.dataCollection(), localStores[j]);
                t.setEnclosingReplicateSet((ReplicateSet) dataStores[i]);
                dataTracks.add(t);
            }
        } else {
            if (dataStores[i] == application.dataCollection().getActiveDataStore()) {
                ChromosomeDataTrack t = new MinSizeDataTrack(this, application.dataCollection(), dataStores[i]);
                dataTracks.add(t);
            } else {
                ChromosomeDataTrack t = new ChromosomeDataTrack(this, application.dataCollection(), dataStores[i]);
                dataTracks.add(t);
            }
        }
    }
    featurePanel.removeAll();
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 0.001;
    Enumeration<ChromosomeFeatureTrack> e = featureTracks.elements();
    while (e.hasMoreElements()) {
        featurePanel.add(e.nextElement(), c);
        c.gridy++;
    }
    // We weight the data tracks way more heavily than the feature tracks since the feature tracks
    // have a preferred size which we don't need to exceed but the data tracks should take up whatever
    // is left.
    c.weighty = 0.6;
    Enumeration<ChromosomeDataTrack> e2 = dataTracks.elements();
    while (e2.hasMoreElements()) {
        featurePanel.add(e2.nextElement(), c);
        c.gridy++;
    }
    // Finally add a scale track, which we weigh very lightly
    c.weighty = 0.00001;
    featurePanel.add(new ChromosomeScaleTrack(this), c);
    c.gridy++;
    featurePanel.validate();
    featurePanel.repaint();
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore)

Example 13 with ReplicateSet

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

the class DataViewer method mousePressed.

/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
public void mousePressed(MouseEvent me) {
    JTree tree = (JTree) me.getSource();
    tree.setSelectionRow(tree.getRowForLocation(me.getX(), me.getY()));
    // Check if they right-clicked
    if ((me.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
        // I'm not sure if this is a timing issue, but we can get the selection path being null
        if (tree.getSelectionPath() == null)
            return;
        Object clickedItem = tree.getSelectionPath().getLastPathComponent();
        if (clickedItem instanceof DataSet) {
            new DataPopupMenu((DataSet) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof DataGroup) {
            new GroupPopupMenu((DataGroup) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof ReplicateSet) {
            new ReplicatePopupMenu((ReplicateSet) clickedItem).show(dataTree, me.getX(), me.getY());
        } else if (clickedItem instanceof ProbeList) {
            new ProbePopupMenu((ProbeList) clickedItem).show(probeSetTree, me.getX(), me.getY());
        } else if (clickedItem instanceof AnnotationSet) {
            new AnnotationPopupMenu((AnnotationSet) clickedItem).show(dataTree, me.getX(), me.getY());
        }
    } else // Check if they double clicked
    if (me.getClickCount() == 2) {
        // I'm not sure if this is a timing issue, but we can get the selection path being null
        if (tree.getSelectionPath() == null)
            return;
        Object clickedItem = tree.getSelectionPath().getLastPathComponent();
        if (clickedItem instanceof DataSet) {
            new DataPopupMenu((DataSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof DataGroup) {
            new GroupPopupMenu((DataGroup) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof ReplicateSet) {
            new ReplicatePopupMenu((ReplicateSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        } else if (clickedItem instanceof ProbeList) {
            new ProbePopupMenu((ProbeList) clickedItem).actionPerformed(new ActionEvent(this, 0, "view"));
        } else if (clickedItem instanceof AnnotationSet) {
            new AnnotationPopupMenu((AnnotationSet) clickedItem).actionPerformed(new ActionEvent(this, 0, "properties"));
        }
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) AnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet) CoreAnnotationSet(uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet) JTree(javax.swing.JTree)

Example 14 with ReplicateSet

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

the class DataTrackSelector method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
public void actionPerformed(ActionEvent ae) {
    String c = ae.getActionCommand();
    if (c.equals("add")) {
        Object[] addObj = availableGroupList.getSelectedValues();
        DataStore[] adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableGroupModel.removeElements(adds);
        usedList.setSelectedIndices(new int[0]);
        availableGroupList.setSelectedIndices(new int[0]);
        addObj = availableSetList.getSelectedValues();
        adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableSetModel.removeElements(adds);
        availableSetList.setSelectedIndices(new int[0]);
        addObj = availableReplicateList.getSelectedValues();
        adds = new DataStore[addObj.length];
        for (int i = 0; i < adds.length; i++) {
            adds[i] = (DataStore) addObj[i];
        }
        usedModel.addElements(adds);
        availableReplicatesModel.removeElements(adds);
        availableReplicateList.setSelectedIndices(new int[0]);
    } else if (c.equals("remove")) {
        Object[] removeObj = usedList.getSelectedValues();
        DataStore[] removes = new DataStore[removeObj.length];
        for (int i = 0; i < removes.length; i++) {
            removes[i] = (DataStore) removeObj[i];
        }
        usedModel.removeElements(removes);
        usedList.setSelectedIndices(new int[0]);
        Vector<DataStore> removeSets = new Vector<DataStore>();
        Vector<DataStore> removeGroups = new Vector<DataStore>();
        Vector<DataStore> removeReps = new Vector<DataStore>();
        for (int i = 0; i < removes.length; i++) {
            if (removes[i] instanceof DataSet) {
                removeSets.add(removes[i]);
            } else if (removes[i] instanceof ReplicateSet) {
                removeReps.add(removes[i]);
            } else if (removes[i] instanceof DataGroup) {
                removeGroups.add(removes[i]);
            } else {
                throw new IllegalStateException("Unknown type of removed store " + removes[i]);
            }
        }
        availableSetModel.addElements(removeSets.toArray(new DataStore[0]));
        availableGroupModel.addElements(removeGroups.toArray(new DataStore[0]));
        availableReplicatesModel.addElements(removeReps.toArray(new DataStore[0]));
        availableSetList.setSelectedIndices(new int[0]);
        availableGroupList.setSelectedIndices(new int[0]);
        availableReplicateList.setSelectedIndices(new int[0]);
    } else if (c.equals("up")) {
        // Collect the list of selected indices
        int[] s = usedList.getSelectedIndices();
        Arrays.sort(s);
        // Get the set of objects associated with the selected indices
        DataStore[] current = new DataStore[s.length];
        for (int i = 0; i < s.length; i++) {
            current[i] = usedModel.elementAt(s[i]);
        }
        // Get the object above, which is going to move below
        DataStore above = usedModel.elementAt(s[0] - 1);
        // Move all the selected indices up one
        for (int i = 0; i < s.length; i++) {
            usedModel.setElementAt(current[i], s[i] - 1);
        }
        // Move the above object below the selected ones
        usedModel.setElementAt(above, s[s.length - 1]);
        // Decrease the set of selected indices and select them again
        for (int i = 0; i < s.length; i++) {
            s[i]--;
        }
        usedList.setSelectedIndices(s);
    } else if (c.equals("down")) {
        // Collect the list of selected indices
        int[] s = usedList.getSelectedIndices();
        Arrays.sort(s);
        // Get the set of objects associated with the selected indices
        DataStore[] current = new DataStore[s.length];
        for (int i = 0; i < s.length; i++) {
            current[i] = usedModel.elementAt(s[i]);
        }
        // Get the object below, which is going to move below
        DataStore below = usedModel.elementAt(s[s.length - 1] + 1);
        // Move all the selected indices down one
        for (int i = 0; i < s.length; i++) {
            usedModel.setElementAt(current[i], s[i] + 1);
        }
        // Move the below object above the selected ones
        usedModel.setElementAt(below, s[0]);
        // Increase the set of selected indices and select them again
        for (int i = 0; i < s.length; i++) {
            s[i]++;
        }
        usedList.setSelectedIndices(s);
    } else if (c.equals("cancel")) {
        setVisible(false);
        dispose();
    } else if (c.equals("ok")) {
        DataStore[] s = usedModel.getStores();
        application.setDrawnDataStores(s);
        setVisible(false);
        dispose();
    }
}
Also used : DataGroup(uk.ac.babraham.SeqMonk.DataTypes.DataGroup) DataSet(uk.ac.babraham.SeqMonk.DataTypes.DataSet) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) Vector(java.util.Vector)

Example 15 with ReplicateSet

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

the class WindowedReplicateStatsFilter method generateProbeList.

/* (non-Javadoc)
	 * @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
	 */
@Override
protected void generateProbeList() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    Vector<ProbeGroupTTestValue> newListProbesVector = new Vector<ProbeGroupTTestValue>();
    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(optionsPanel.featureTypeBox.getSelectedItem().toString()));
        }
        while (true) {
            if (cancel) {
                cancel = false;
                progressCancelled();
                return;
            }
            Probe[] theseProbes = gen.nextSet();
            if (theseProbes == null) {
                // System.err.println("List of probes was null");
                break;
            }
            // We need at least 3 probes in a set to calculate a p-value
            if (theseProbes.length < 3) {
                // System.err.println("Only "+theseProbes.length+" probes in the set");
                continue;
            }
            double[][] values = new double[stores.length][];
            for (int j = 0; j < stores.length; j++) {
                if (splitReplicateSets & stores[j] instanceof ReplicateSet) {
                    values[j] = new double[theseProbes.length * ((ReplicateSet) stores[j]).dataStores().length];
                } else {
                    values[j] = new double[theseProbes.length];
                }
            }
            for (int j = 0; j < stores.length; j++) {
                int index = 0;
                for (int i = 0; i < theseProbes.length; i++) {
                    try {
                        if (splitReplicateSets & stores[j] instanceof ReplicateSet) {
                            DataStore[] localStores = ((ReplicateSet) stores[j]).dataStores();
                            for (int l = 0; l < localStores.length; l++) {
                                values[j][index] = localStores[l].getValueForProbe(theseProbes[i]);
                                index++;
                            }
                        } else {
                            values[j][index] = stores[j].getValueForProbe(theseProbes[i]);
                            index++;
                        }
                    } catch (SeqMonkException e) {
                    }
                }
                if (index != values[j].length) {
                    throw new IllegalStateException("Didn't fill all values total=" + values[j].length + " index=" + index);
                }
            }
            double pValue = 0;
            try {
                if (stores.length == 1) {
                    pValue = TTest.calculatePValue(values[0], 0);
                } else if (stores.length == 2) {
                    pValue = TTest.calculatePValue(values[0], values[1]);
                } else {
                    pValue = AnovaTest.calculatePValue(values);
                }
            } catch (SeqMonkException e) {
                throw new IllegalStateException(e);
            }
            newListProbesVector.add(new ProbeGroupTTestValue(theseProbes, pValue));
        }
    }
    ProbeGroupTTestValue[] newListProbes = newListProbesVector.toArray(new ProbeGroupTTestValue[0]);
    // Do the multi-testing correction if necessary
    if (multiTest) {
        BenjHochFDR.calculateQValues(newListProbes);
    }
    ProbeList newList;
    // We need to handle duplicate hits internally since probe lists can't do
    // this themselves any more.
    Hashtable<Probe, Float> newListTemp = new Hashtable<Probe, Float>();
    if (multiTest) {
        newList = new ProbeList(startingList, "", "", "Q-value");
        for (int i = 0; i < newListProbes.length; i++) {
            if (newListProbes[i].q <= cutoff) {
                Probe[] passedProbes = newListProbes[i].probes;
                for (int p = 0; p < passedProbes.length; p++) {
                    if (newListTemp.containsKey(passedProbes[p])) {
                        // We always give a probe the lowest possible q-value
                        if (newListTemp.get(passedProbes[p]) <= newListProbes[i].q) {
                            continue;
                        }
                    }
                    newListTemp.put(passedProbes[p], (float) newListProbes[i].q);
                }
            }
        }
    } else {
        newList = new ProbeList(startingList, "", "", "P-value");
        for (int i = 0; i < newListProbes.length; i++) {
            if (newListProbes[i].p <= cutoff) {
                Probe[] passedProbes = newListProbes[i].probes;
                for (int p = 0; p < passedProbes.length; p++) {
                    if (newListTemp.containsKey(passedProbes[p])) {
                        // We always give a probe the lowest possible p-value
                        if (newListTemp.get(passedProbes[p]) <= newListProbes[i].p) {
                            continue;
                        }
                    }
                    newListTemp.put(passedProbes[p], (float) newListProbes[i].p);
                }
            }
        }
    }
    // Add the cached hits to the new list
    Enumeration<Probe> en = newListTemp.keys();
    while (en.hasMoreElements()) {
        Probe p = en.nextElement();
        newList.addProbe(p, newListTemp.get(p));
    }
    filterFinished(newList);
}
Also used : ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) ProbeWindowGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ProbeWindowGenerator) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) FeatureProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.FeatureProbeGroupGenerator) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Vector(java.util.Vector) ProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ProbeGroupGenerator) FeatureProbeGroupGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.FeatureProbeGroupGenerator) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Hashtable(java.util.Hashtable) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) ProbeGroupTTestValue(uk.ac.babraham.SeqMonk.Analysis.Statistics.ProbeGroupTTestValue) ConsecutiveProbeGenerator(uk.ac.babraham.SeqMonk.Filters.ProbeGroupGenerator.ConsecutiveProbeGenerator)

Aggregations

ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)15 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)10 Vector (java.util.Vector)5 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)5 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)5 ActionEvent (java.awt.event.ActionEvent)4 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)4 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 AnnotationSet (uk.ac.babraham.SeqMonk.DataTypes.Genome.AnnotationSet)3 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)3 BorderLayout (java.awt.BorderLayout)2 GridBagConstraints (java.awt.GridBagConstraints)2 ActionListener (java.awt.event.ActionListener)2 Hashtable (java.util.Hashtable)2 JButton (javax.swing.JButton)2 JList (javax.swing.JList)2 JScrollPane (javax.swing.JScrollPane)2 CoreAnnotationSet (uk.ac.babraham.SeqMonk.DataTypes.Genome.CoreAnnotationSet)2 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)2