Search in sources :

Example 1 with DataStore

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

the class HeatmapProbeListPanel method paint.

public void paint(Graphics g) {
    super.paint(g);
    if (drawnPixels.length != getWidth() || drawnPixels[0].length != getHeight()) {
        drawnPixels = new boolean[getWidth()][getHeight()];
    } else {
        for (int i = 0; i < getWidth(); i++) {
            for (int j = 0; j < getHeight(); j++) {
                drawnPixels[i][j] = false;
            }
        }
    }
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLACK);
    // Add a label at the top to signify current filters
    StringBuffer topLabel = new StringBuffer();
    // Now append any current limits
    if (matrix.currentMinStrength() > 0) {
        topLabel.append("Strength > ");
        topLabel.append(df.format(matrix.currentMinStrength()));
        topLabel.append(" ");
    }
    if (matrix.minDifference() > 0) {
        topLabel.append("Difference > ");
        topLabel.append(df.format(matrix.minDifference()));
        topLabel.append(" ");
    }
    if (matrix.currentMaxSignficance() < 1) {
        topLabel.append("P-value < ");
        topLabel.append(df.format(matrix.currentMaxSignficance()));
        topLabel.append(" ");
    }
    if (topLabel.length() == 0) {
        topLabel.append("No filters");
    }
    g.drawString(topLabel.toString(), getWidth() / 2 - (g.getFontMetrics().stringWidth(topLabel.toString()) / 2), 15 + (g.getFontMetrics().getAscent() / 2));
    // Find the max height and width of the probe list names in this genome
    if (maxNameWidth == 0) {
        nameHeight = g.getFontMetrics().getHeight();
        maxNameWidth = 0;
        long runningBaseOffset = 0;
        for (int l = 0; l < probeLists.length; l++) {
            probeListIndexOffsets.put(probeLists[l], runningBaseOffset);
            int thisWidth = g.getFontMetrics().stringWidth(probeLists[l].name());
            if (thisWidth > maxNameWidth)
                maxNameWidth = thisWidth;
            runningBaseOffset += probeLists[l].getAllProbes().length;
        }
        // Give both the width and height a bit of breathing space
        nameHeight += 6;
        maxNameWidth += 6;
    }
    // Make the background of the plot black
    g.setColor(Color.WHITE);
    g.fillRect(maxNameWidth, 30, getWidth() - (maxNameWidth + 10), getHeight() - (nameHeight + 30));
    // Draw the actual data
    InteractionProbePair[] interactions = matrix.filteredInteractions();
    // Cache some values for use with the quantitation colouring
    double minQuantitatedValue;
    double maxQuantitatedValue;
    if (DisplayPreferences.getInstance().getScaleType() == DisplayPreferences.SCALE_TYPE_POSITIVE) {
        minQuantitatedValue = 0;
        maxQuantitatedValue = DisplayPreferences.getInstance().getMaxDataValue();
    } else {
        maxQuantitatedValue = DisplayPreferences.getInstance().getMaxDataValue();
        minQuantitatedValue = 0 - maxQuantitatedValue;
    }
    for (int i = 0; i < interactions.length; i++) {
        for (int forRev = 0; forRev <= 1; forRev++) {
            int probe1Index;
            int probe2Index;
            if (forRev == 0) {
                probe1Index = interactions[i].probe1Index();
                probe2Index = interactions[i].probe2Index();
            } else {
                probe2Index = interactions[i].probe1Index();
                probe1Index = interactions[i].probe2Index();
            }
            int xIndex = probe1Index;
            if (probeSortingOrder != null) {
                xIndex = probeSortingOrder[xIndex];
            }
            if (xIndex < currentXStartIndex)
                continue;
            if (xIndex > currentXEndIndex)
                continue;
            int xStart = getXForPosition(xIndex);
            if (xStart < maxNameWidth)
                continue;
            int xEnd = getXForPosition(xIndex + 1);
            if (xEnd > getWidth() - 10)
                continue;
            int yIndex = probe2Index;
            if (probeSortingOrder != null) {
                yIndex = probeSortingOrder[yIndex];
            }
            if (yIndex < currentYStartIndex)
                continue;
            if (yIndex > currentYEndIndex)
                continue;
            int yStart = getYForPosition(yIndex);
            if (yStart > getHeight() - nameHeight)
                continue;
            int yEnd = getYForPosition(yIndex + 1);
            if (yEnd < 30)
                continue;
            if (xEnd - xStart < 3) {
                xEnd += 1;
                xStart -= 1;
            }
            if (yEnd - yStart < 3) {
                yEnd -= 1;
                yStart += 1;
            }
            // See if we can skip drawing this because something else is already there
            if (drawnPixels[xStart][yEnd] && drawnPixels[xEnd][yStart]) {
                continue;
            }
            switch(matrix.currentColourSetting()) {
                case HeatmapMatrix.COLOUR_BY_OBS_EXP:
                    g.setColor(matrix.colourGradient().getColor(Math.log10(interactions[i].strength() - matrix.initialMinStrength()), Math.log10(matrix.initialMinStrength()), Math.log10(matrix.maxValue() - matrix.initialMinStrength())));
                    break;
                case HeatmapMatrix.COLOUR_BY_INTERACTIONS:
                    g.setColor(matrix.colourGradient().getColor(interactions[i].absolute(), matrix.initialMinAbsolute(), 50));
                    break;
                case HeatmapMatrix.COLOUR_BY_P_VALUE:
                    g.setColor(matrix.colourGradient().getColor(Math.log10(interactions[i].signficance()) * -10, Math.log10(matrix.initialMaxSignificance()) * -10, 50));
                    break;
                case HeatmapMatrix.COLOUR_BY_QUANTITATION:
                    Probe probeForQuantitation;
                    if (forRev == 0) {
                        probeForQuantitation = interactions[i].lowestProbe();
                    } else {
                        probeForQuantitation = interactions[i].highestProbe();
                    }
                    try {
                        g.setColor(matrix.colourGradient().getColor(((DataStore) dataSet).getValueForProbe(probeForQuantitation), minQuantitatedValue, maxQuantitatedValue));
                    } catch (SeqMonkException e) {
                    }
                    break;
            }
            g.fillRect(xStart, yEnd, xEnd - xStart, yStart - yEnd);
            // them again
            for (int x = Math.min(xStart, xEnd); x <= Math.min(xStart, xEnd) + Math.abs(xStart - xEnd); x++) {
                for (int y = Math.min(yStart, yEnd); y <= Math.min(yStart, yEnd) + Math.abs(yStart - yEnd); y++) {
                    drawnPixels[x][y] = true;
                }
            }
        }
    }
    // System.err.println("Skipped "+skipped+" interactions");
    // Draw the probe list lines
    g.setColor(Color.GRAY);
    // lines but we will bracket around related groups.
    if (currentCluster == null) {
        // Draw Probe List Lines on X axis
        int runningGenomeLength = 0;
        for (int l = 0; l < probeLists.length; l++) {
            int startPos = getXForPosition(runningGenomeLength);
            int endPos = getXForPosition(runningGenomeLength + probeLists[l].getAllProbes().length);
            if (l > 0) {
                if (startPos >= maxNameWidth && startPos <= getWidth() - 10) {
                    g.drawLine(startPos, 30, startPos, getHeight() - nameHeight);
                }
            }
            if (l + 1 == probeLists.length) {
                if (endPos >= maxNameWidth && endPos <= getWidth() - 10) {
                    g.drawLine(endPos, 30, endPos, getHeight() - nameHeight);
                }
            }
            int nameWidth = g.getFontMetrics().stringWidth(probeLists[l].name());
            g.drawString(probeLists[l].name(), (startPos + ((endPos - startPos) / 2)) - (nameWidth / 2), getHeight() - 3);
            runningGenomeLength += probeLists[l].getAllProbes().length;
        }
        // Draw Chr Lines on Y axis
        runningGenomeLength = 0;
        for (int l = 0; l < probeLists.length; l++) {
            int startPos = getYForPosition(runningGenomeLength);
            int endPos = getYForPosition(runningGenomeLength + probeLists[l].getAllProbes().length);
            if (l > 0) {
                if (startPos <= getHeight() - nameHeight && startPos >= 30) {
                    g.drawLine(maxNameWidth, startPos, getWidth() - 10, startPos);
                }
            }
            if (l + 1 == probeLists.length) {
                if (endPos <= getHeight() - nameHeight && endPos >= 30) {
                    g.drawLine(maxNameWidth, endPos, getWidth() - 10, endPos);
                }
            }
            int nameWidth = g.getFontMetrics().stringWidth(probeLists[l].name());
            g.drawString(probeLists[l].name(), (maxNameWidth / 2) - (nameWidth / 2), (endPos + ((startPos - endPos) / 2)) + (g.getFontMetrics().getAscent() / 2));
            runningGenomeLength += probeLists[l].getAllProbes().length;
        }
    } else // If we are clustered then we draw bracketed sets around the current R value cutoff
    {
        // Draw Cluster Lines on X axis
        int runningListPosition = 0;
        for (int l = 0; l < clusterIntervals.length; l++) {
            runningListPosition += clusterIntervals[l];
            if (runningListPosition < currentXStartIndex)
                continue;
            if (runningListPosition > currentXEndIndex)
                break;
            int pos = getXForPosition(runningListPosition);
            g.drawLine(pos, 30, pos, getHeight() - nameHeight);
        }
        // Draw Cluster Lines on Y axis
        runningListPosition = 0;
        for (int l = 0; l < clusterIntervals.length; l++) {
            runningListPosition += clusterIntervals[l];
            if (runningListPosition < currentYStartIndex)
                continue;
            if (runningListPosition > currentYEndIndex)
                break;
            int pos = getYForPosition(runningListPosition);
            g.drawLine(maxNameWidth, pos, getWidth() - 10, pos);
        }
    }
    // Draw the axes
    g.drawLine(maxNameWidth, getHeight() - nameHeight, getWidth() - 10, getHeight() - nameHeight);
    g.drawLine(maxNameWidth, getHeight() - nameHeight, maxNameWidth, 30);
    // Draw a selection if we're making one
    if (makingSelection) {
        g.setColor(ColourScheme.DRAGGED_SELECTION);
        g.drawRect(Math.min(selectionEndX, selectionStartX), Math.min(selectionEndY, selectionStartY), Math.abs(selectionEndX - selectionStartX), Math.abs(selectionEndY - selectionStartY));
    }
}
Also used : InteractionProbePair(uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionProbePair) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) HiCDataStore(uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 2 with DataStore

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

the class MAPlotDialog 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")) {
        DataStore xStore = (DataStore) xStores.getSelectedItem();
        DataStore yStore = (DataStore) yStores.getSelectedItem();
        getContentPane().remove(maPlotPanel);
        // 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 if (!yStore.isQuantitated()) {
            JOptionPane.showMessageDialog(this, yStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
        } else {
            maPlotPanel = new MAPlotPanel(xStore, yStore, probeList, subLists, commonScaleBox.isSelected(), dotSizeSlider.getValue());
            getContentPane().add(maPlotPanel, BorderLayout.CENTER);
        }
        validate();
    } else if (ae.getActionCommand().equals("save_probe_list")) {
        if (maPlotPanel instanceof MAPlotPanel) {
            ProbeList list = ((MAPlotPanel) maPlotPanel).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(maPlotPanel);
    } else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) ActionEvent(java.awt.event.ActionEvent) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) OrderedListSelector(uk.ac.babraham.SeqMonk.Dialogs.OrderedListSelector)

Example 3 with DataStore

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

the class ChromosomeDisplay method paintComponent.

/* (non-Javadoc)
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    xOffset = getWidth() / 80;
    if (xOffset > 10)
        xOffset = 10;
    if (xOffset < 1)
        xOffset = 1;
    int yOffset = getHeight() / 10;
    if (yOffset > 10)
        yOffset = 10;
    if (yOffset < 2)
        yOffset = 2;
    int width = getWidth() - (2 * xOffset);
    int height = getHeight() - (2 * yOffset);
    chrWidth = scaleX(width, chromosome.length(), maxLen);
    lastProbeXEnd = 0;
    lastProbeXMid = 0;
    lastProbeY = 0;
    lastProbeValue = -10000000;
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, getWidth(), getHeight());
    if (activeStore != null && activeStore.isQuantitated() && probes != null) {
        g.setColor(ColourScheme.DATA_BACKGROUND_ODD);
        g.fillRoundRect(xOffset, yOffset, scaleX(width, chromosome.length(), maxLen), height, 2, 2);
        // Draw a box over the selected region if there is one
        if (showView) {
            g.setColor(Color.BLACK);
            // Limit how small the box can get so we can always see it
            int boxWidth = scaleX(width, viewEnd - viewStart, maxLen);
            if (boxWidth < 4) {
                boxWidth = 4;
            }
            g.fillRoundRect(xOffset + scaleX(width, viewStart, maxLen), 0, boxWidth, getHeight(), 2, 2);
        }
        // Draw as many probes as we have space for
        showNegative = DisplayPreferences.getInstance().getScaleType() == DisplayPreferences.SCALE_TYPE_POSITIVE_AND_NEGATIVE;
        Color fixedColour = null;
        if (DisplayPreferences.getInstance().getColourType() == DisplayPreferences.COLOUR_TYPE_INDEXED) {
            DataStore[] drawnStores = SeqMonkApplication.getInstance().drawnDataStores();
            for (int d = 0; d < drawnStores.length; d++) {
                if (drawnStores[d] == activeStore) {
                    fixedColour = ColourIndexSet.getColour(d);
                    break;
                }
            }
            if (fixedColour == null)
                fixedColour = Color.DARK_GRAY;
        }
        maxValue = DisplayPreferences.getInstance().getMaxDataValue();
        if (showNegative) {
            minValue = 0 - maxValue;
        } else {
            minValue = 0;
        }
        // the origin
        if (showNegative) {
            g.setColor(Color.LIGHT_GRAY);
            g.drawLine(xOffset, getHeight() / 2, xOffset + scaleX(width, chromosome.length(), maxLen), getHeight() / 2);
        }
        // Now go through all the probes figuring out whether they
        // need to be displayed
        // Reset the values used to optimise drawing
        lastProbeXEnd = 0;
        lastProbeValue = 0;
        for (int i = 0; i < probes.length; i++) {
            drawProbe(probes[i], g, width, maxLen, yOffset, xOffset, height, fixedColour);
        }
        if (showView) {
            g.setColor(ColourScheme.GENOME_SELECTED_CHROMOSOME);
        } else {
            g.setColor(ColourScheme.GENOME_CHROMOSOME);
        }
        g.drawRoundRect(xOffset, yOffset, scaleX(width, chromosome.length(), maxLen), height, 2, 2);
        // Draw a box over the selected region if there is one
        if (showView) {
            g.setColor(Color.BLACK);
            // Limit how small the box can get so we can always see it
            int boxWidth = scaleX(width, viewEnd - viewStart, maxLen);
            if (boxWidth < 4) {
                boxWidth = 4;
            }
            g.drawRoundRect(xOffset + scaleX(width, viewStart, maxLen), 0, boxWidth, getHeight(), 2, 2);
        }
    } else {
        // There's no quantitation to draw so fall back to the old methods
        g.setColor(ColourScheme.GENOME_CHROMOSOME);
        g.fillRoundRect(xOffset, yOffset, scaleX(width, chromosome.length(), maxLen), height, 2, 2);
        // Draw a box over the selected region if there is one
        if (showView) {
            g.setColor(ColourScheme.GENOME_SELECTED);
            // Limit how small the box can get so we can always see it
            int boxWidth = scaleX(width, viewEnd - viewStart, maxLen);
            if (boxWidth < 4) {
                boxWidth = 4;
            }
            g.fillRoundRect(xOffset + scaleX(width, viewStart, maxLen), 1, boxWidth, getHeight() - 2, 2, 2);
        }
    }
    // Finally draw a selection if there is one
    if (isSelecting) {
        g.setColor(ColourScheme.DRAGGED_SELECTION);
        g.fillRect(Math.min(selectionEnd, selectionStart), yOffset, Math.abs(selectionEnd - selectionStart), height);
    }
}
Also used : Color(java.awt.Color) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore)

Example 4 with DataStore

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

the class ScatterPlotDialog 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")) {
        DataStore xStore = (DataStore) xStores.getSelectedItem();
        DataStore yStore = (DataStore) yStores.getSelectedItem();
        getContentPane().remove(scatterPlotPanel);
        // 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 if (!yStore.isQuantitated()) {
            JOptionPane.showMessageDialog(this, yStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
        } else {
            scatterPlotPanel = new ScatterPlotPanel(xStore, yStore, probeList, subLists, commonScaleBox.isSelected(), dotSizeSlider.getValue());
            getContentPane().add(scatterPlotPanel, BorderLayout.CENTER);
        }
        validate();
    } else if (ae.getActionCommand().equals("save_probe_list")) {
        if (scatterPlotPanel instanceof ScatterPlotPanel) {
            ProbeList list = ((ScatterPlotPanel) scatterPlotPanel).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(scatterPlotPanel);
    } else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) ActionEvent(java.awt.event.ActionEvent) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) OrderedListSelector(uk.ac.babraham.SeqMonk.Dialogs.OrderedListSelector)

Example 5 with DataStore

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

the class HiCPCADomainQuantitation method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    // We're going to go through the probes one chromosome at a time so we
    // can reduce the complexity we have to deal with
    Chromosome[] chromosomes = application.dataCollection().genome().getAllChromosomes();
    for (int c = 0; c < chromosomes.length; c++) {
        if (cancel) {
            progressCancelled();
            return;
        }
        currentChromosome = chromosomes[c];
        Probe[] probes = application.dataCollection().probeSet().getProbesForChromosome(chromosomes[c]);
        if (probes.length < 5) {
            progressWarningReceived(new SeqMonkException("Too few probes on chromosome " + currentChromosome.name() + " - assigning zero to everything"));
            // It's not worth trying to find domains
            for (int d = 0; d < data.length; d++) {
                for (int p = 0; p < probes.length; p++) {
                    ((DataStore) data[d]).setValueForProbe(probes[p], 0f);
                }
            }
            continue;
        }
        ProbeList thisChrProbes = new ProbeList(application.dataCollection().probeSet(), chromosomes[c].name(), "", null);
        for (int p = 0; p < probes.length; p++) {
            thisChrProbes.addProbe(probes[p], 0f);
        }
        for (int d = 0; d < data.length; d++) {
            if (cancel) {
                progressCancelled();
                return;
            }
            currentStore = data[d];
            current = (d * chromosomes.length) + c;
            total = chromosomes.length * data.length;
            progressUpdated("Processing chromosome " + chromosomes[c].name() + " for " + data[d].name(), current, total);
            HeatmapMatrix matrix = new HeatmapMatrix(data[d], new ProbeList[] { thisChrProbes }, application.dataCollection().genome(), optionsPanel.minDistance(), optionsPanel.maxDistance(), optionsPanel.minStrength(), optionsPanel.maxSignificance(), optionsPanel.minAbsolute(), optionsPanel.correctLinkage());
            matrix.addProgressListener(this);
            wait = true;
            matrix.startCalculating();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            if (cancel) {
                progressCancelled();
                return;
            }
            if (matrix.filteredInteractions().length < 10) {
                progressWarningReceived(new SeqMonkException("Too few interactions on chromosome " + currentChromosome.name() + " for " + data[d].name() + " - assigning zero to everything"));
                // not going to get a sensible answer anyway.
                for (int p = 0; p < probes.length; p++) {
                    ((DataStore) data[d]).setValueForProbe(probes[p], 0f);
                }
                continue;
            }
            InteractionClusterMatrix clusterMatrix = new InteractionClusterMatrix(matrix.filteredInteractions(), probes.length);
            clusterMatrix.addListener(this);
            wait = true;
            clusterMatrix.startCorrelating();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            float[][] correlationMatrix = clusterMatrix.correlationMatix();
            // Annoyingly the PCA needs a double [][]
            double[][] correlationMatrixDouble = new double[correlationMatrix.length][];
            for (int i = 0; i < correlationMatrix.length; i++) {
                double[] db = new double[correlationMatrix[i].length];
                for (int j = 0; j < db.length; j++) {
                    db[j] = correlationMatrix[i][j];
                }
                correlationMatrixDouble[i] = db;
            }
            // Now we can calculate the PCA values from the correlation matrix
            PCA pca = new PCA(correlationMatrixDouble);
            pca.addProgressListener(this);
            wait = true;
            pca.startCalculating();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            double[] extractedEigenValues = pca.extractedEigenValues();
            // for these probes
            for (int p = 0; p < probes.length; p++) {
                ((DataStore) data[d]).setValueForProbe(probes[p], (float) extractedEigenValues[p]);
            }
        }
        thisChrProbes.delete();
    }
    quantitatonComplete();
}
Also used : ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) InteractionClusterMatrix(uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) HeatmapMatrix(uk.ac.babraham.SeqMonk.DataTypes.Interaction.HeatmapMatrix) PCA(uk.ac.babraham.SeqMonk.Analysis.Statistics.PCA) DataStore(uk.ac.babraham.SeqMonk.DataTypes.DataStore) HiCDataStore(uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException)

Aggregations

DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)46 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)21 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)19 Vector (java.util.Vector)15 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)15 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)11 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)11 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)11 JPanel (javax.swing.JPanel)10 ReplicateSet (uk.ac.babraham.SeqMonk.DataTypes.ReplicateSet)10 GridBagConstraints (java.awt.GridBagConstraints)9 JLabel (javax.swing.JLabel)9 GridBagLayout (java.awt.GridBagLayout)8 File (java.io.File)8 ActionEvent (java.awt.event.ActionEvent)7 BufferedReader (java.io.BufferedReader)7 FileReader (java.io.FileReader)7 JComboBox (javax.swing.JComboBox)7 JScrollPane (javax.swing.JScrollPane)7 HiCDataStore (uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)7