Search in sources :

Example 1 with ClusterPair

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

the class HierarchicalClusterDialog method progressComplete.

public void progressComplete(String command, Object result) {
    clusterPanelGroup = new JPanel();
    clusterPanelGroup.setLayout(new BorderLayout());
    ColourGradient gradient = (ColourGradient) gradients.getSelectedItem();
    if (invertGradient.isSelected()) {
        gradient = new InvertedGradient(gradient);
    }
    if (negativeScale) {
        scaleBar = new GradientScaleBar(gradient, -2, 2);
    } else {
        scaleBar = new GradientScaleBar(gradient, 0, 2);
    }
    JPanel topBottomSplit = new JPanel();
    topBottomSplit.setLayout(new GridLayout(2, 1));
    topBottomSplit.add(new JPanel());
    topBottomSplit.add(scaleBar);
    clusterPanel = new HierarchicalClusterPanel(probes, stores, (ClusterPair) result, normalise, (ColourGradient) gradients.getSelectedItem());
    clusterPanelGroup.add(clusterPanel, BorderLayout.CENTER);
    clusterPanelGroup.add(topBottomSplit, BorderLayout.EAST);
    getContentPane().add(clusterPanelGroup, BorderLayout.CENTER);
    setLocationRelativeTo(SeqMonkApplication.getInstance());
    stateChanged(new ChangeEvent(clusterSlider));
    setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) GradientScaleBar(uk.ac.babraham.SeqMonk.Displays.GradientScaleBar.GradientScaleBar) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) InvertedGradient(uk.ac.babraham.SeqMonk.Gradients.InvertedGradient) ClusterPair(uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient)

Example 2 with ClusterPair

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

the class HierarchicalClusterPanel method saveClusters.

public ProbeList saveClusters(int minClusterSize) {
    ProbeList allClusterList = new ProbeList(probeList, "Hierarchical Clusters", "Hierarchical Clusters with R > " + rValue, null);
    // Now we need to work our way through the connected clusters
    // to make the appropriate sub-lists
    ClusterPair[] connectedClusters = clusters.getConnectedClusters((float) rValue);
    int runningCount = 0;
    for (int subListIndex = 0; subListIndex < connectedClusters.length; subListIndex++) {
        Integer[] indices = connectedClusters[subListIndex].getAllIndices();
        // System.err.println("Looking at index "+subListIndex+" which has "+indices.length+" probes");
        runningCount += indices.length;
        // If we're starting before the currently visible set then we can skip
        if (runningCount - indices.length < currentYStartIndex) {
            // System.err.println("Skipping index "+(runningCount-indices.length)+" which is less than "+currentYStartIndex);
            continue;
        }
        // If we're after the end of the current visible set we can stop all together
        if (runningCount > (currentYEndIndex + 1)) {
            // System.err.println("Stopping because "+runningCount+" is bigger than "+currentYEndIndex);
            break;
        }
        // We may get rid of the list later if there are duplicates in it.
        if (indices.length < minClusterSize)
            continue;
        Probe[] theseProbes = new Probe[indices.length];
        for (int i = 0; i < theseProbes.length; i++) {
            theseProbes[i] = probes[indices[i]];
        }
        // We used to sort and deduplicate these clusters so that we could be sure
        // the number of probes is correct.  We're now going to leave this alone
        // (probe lists deduplicate internally) and annotate on the index rather
        // than the r-value of the specific cluster.
        ProbeList thisList = new ProbeList(allClusterList, "Cluster " + (subListIndex + 1), "HiC cluster list number " + (subListIndex + 1), "Index");
        thisList.addProbe(theseProbes[0], (float) 0);
        allClusterList.addProbe(theseProbes[0], null);
        for (int i = 1; i < theseProbes.length; i++) {
            if (theseProbes[i] == theseProbes[i - 1])
                continue;
            thisList.addProbe(theseProbes[i], (float) i);
            allClusterList.addProbe(theseProbes[i], null);
        }
    }
    return allClusterList;
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) ClusterPair(uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 3 with ClusterPair

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

the class DataStoreTreeDialog method progressComplete.

public void progressComplete(String command, Object result) {
    getContentPane().setLayout(new BorderLayout());
    clusterPanel = new DataStoreClusterPanel((ClusterPair) result, stores, listName);
    getContentPane().add(clusterPanel, BorderLayout.CENTER);
    rValueSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000, 0);
    rValueSlider.setPaintTicks(true);
    getContentPane().add(rValueSlider, BorderLayout.NORTH);
    rValueSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            clusterPanel.setRProportion(rValueSlider.getValue() / 1000f);
        }
    });
    JPanel buttonPanel = new JPanel();
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
        }
    });
    buttonPanel.add(closeButton);
    JButton saveImageButton = new JButton("Save Image");
    saveImageButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ImageSaver.saveImage(clusterPanel);
        }
    });
    buttonPanel.add(saveImageButton);
    JButton createRepSetsButton = new JButton("Split data stores");
    createRepSetsButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            for (int s = 0; s < stores.length; s++) {
                if (stores[s] instanceof ReplicateSet) {
                    JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "One of the stores you plotted is already a replicate set so you can't make a new set with it in.", "Can't split stores", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            // TODO: Ask for min count per store
            DataStore[][] splitStores = clusterPanel.getSplitStores(2);
            for (int s = 0; s < splitStores.length; s++) {
                SeqMonkApplication.getInstance().dataCollection().addReplicateSet(new ReplicateSet("Cluster Group " + (s + 1), splitStores[s]));
            }
            JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "Created " + splitStores.length + " new replicate sets", "Splitting Complete", JOptionPane.INFORMATION_MESSAGE);
        }
    });
    buttonPanel.add(createRepSetsButton);
    JButton reorderStoresButton = new JButton("Reorder stores");
    reorderStoresButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            DataStore[] orderedStores = clusterPanel.getOrderedStores();
            SeqMonkApplication.getInstance().setDrawnDataStores(orderedStores);
        }
    });
    buttonPanel.add(reorderStoresButton);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    setSize(800, 800);
    setLocationRelativeTo(SeqMonkApplication.getInstance());
    setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ReplicateSet(uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) JButton(javax.swing.JButton) ClusterPair(uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 4 with ClusterPair

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

the class HeatmapMatrix method createProbeListsFromClusters.

public ProbeList createProbeListsFromClusters(int minClusterSize, int startIndex, int endIndex) {
    if (cluster == null)
        return null;
    ClusterPair[] connectedClusters = cluster.getConnectedClusters(currentClusterRValue);
    ProbeList commonList = findCommonProbeListParent();
    ProbeList allClusterList = new ProbeList(commonList, "HiC Clusters", "HiC Clusters with R > " + commonList, null);
    HashSet<Probe> allClusterProbes = new HashSet<Probe>();
    // Now we need to work our way through the connected clusters
    // to make the appropriate sub-lists
    // Make up the same initial list of probes as before
    Vector<Probe> originallyOrderedProbes = new Vector<Probe>();
    for (int l = 0; l < probeLists.length; l++) {
        Probe[] theseProbes = probeLists[l].getAllProbes();
        for (int p = 0; p < theseProbes.length; p++) {
            originallyOrderedProbes.add(theseProbes[p]);
        }
    }
    int currentPosition = 0;
    for (int subListIndex = 0; subListIndex < connectedClusters.length; subListIndex++) {
        Integer[] indices = connectedClusters[subListIndex].getAllIndices();
        currentPosition += indices.length;
        if (currentPosition - indices.length < startIndex)
            continue;
        if (currentPosition > endIndex)
            break;
        // We may get rid of the list later if there are duplicates in it.
        if (indices.length < minClusterSize)
            continue;
        Probe[] theseProbes = new Probe[indices.length];
        for (int i = 0; i < theseProbes.length; i++) {
            theseProbes[i] = originallyOrderedProbes.elementAt(indices[i]);
        }
        Arrays.sort(theseProbes);
        // Now find the non-redundant count
        int nonRedCount = 1;
        for (int i = 1; i < theseProbes.length; i++) {
            if (theseProbes[i] != theseProbes[i - 1]) {
                nonRedCount++;
            }
        }
        // There aren't enough different probes to keep this set.
        if (nonRedCount < minClusterSize)
            continue;
        ProbeList thisList = new ProbeList(allClusterList, "Cluster " + (subListIndex + 1), "HiC cluster list number " + (subListIndex + 1), "R-value");
        float rValue = connectedClusters[subListIndex].rValue();
        thisList.addProbe(theseProbes[0], rValue);
        if (!allClusterProbes.contains(theseProbes[0])) {
            allClusterList.addProbe(theseProbes[0], null);
            allClusterProbes.add(theseProbes[0]);
        }
        for (int i = 1; i < theseProbes.length; i++) {
            if (theseProbes[i] == theseProbes[i - 1])
                continue;
            thisList.addProbe(theseProbes[i], rValue);
            if (allClusterProbes.contains(theseProbes[i])) {
                continue;
            }
            allClusterList.addProbe(theseProbes[i], null);
            allClusterProbes.add(theseProbes[i]);
        }
    }
    return allClusterList;
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) ClusterPair(uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector) HashSet(java.util.HashSet)

Aggregations

ClusterPair (uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair)4 BorderLayout (java.awt.BorderLayout)2 JPanel (javax.swing.JPanel)2 ChangeEvent (javax.swing.event.ChangeEvent)2 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)2 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)2 GridLayout (java.awt.GridLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 HashSet (java.util.HashSet)1 Vector (java.util.Vector)1 JButton (javax.swing.JButton)1 JSlider (javax.swing.JSlider)1 ChangeListener (javax.swing.event.ChangeListener)1 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)1 ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)1 GradientScaleBar (uk.ac.babraham.SeqMonk.Displays.GradientScaleBar.GradientScaleBar)1 ColourGradient (uk.ac.babraham.SeqMonk.Gradients.ColourGradient)1 InvertedGradient (uk.ac.babraham.SeqMonk.Gradients.InvertedGradient)1