Search in sources :

Example 1 with Probe

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

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

the class FeaturePositionSelectorPanel method getDownstreamProbes.

/**
 * Gets the set of additional downstream context regions for each feature given
 * the current options.  If the current options don't allow for any downstream
 * context then this returns null.
 * @return
 */
public Probe[] getDownstreamProbes() {
    // This is horribly inefficient since we make the core list
    // multiple times
    Probe[] coreProbes = getCoreProbes();
    if (positionType().equals("Over feature") && endOffset() > 0) {
        Vector<Probe> downstreamProbes = new Vector<Probe>();
        for (int p = 0; p < coreProbes.length; p++) {
            if (coreProbes[p].strand() == Probe.REVERSE) {
                int start = coreProbes[p].start() - endOffset();
                int end = coreProbes[p].start() - 1;
                if (start < 1 || end > coreProbes[p].chromosome().length())
                    continue;
                downstreamProbes.add(new Probe(coreProbes[p].chromosome(), start, end, coreProbes[p].strand()));
            } else {
                int start = coreProbes[p].end() + 1;
                int end = coreProbes[p].end() + endOffset();
                if (start < 1 || end > coreProbes[p].chromosome().length())
                    continue;
                downstreamProbes.add(new Probe(coreProbes[p].chromosome(), start, end, coreProbes[p].strand()));
            }
        }
        return downstreamProbes.toArray(new Probe[0]);
    } else {
        return null;
    }
}
Also used : Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 3 with Probe

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

the class FeaturePositionSelectorPanel method getCoreProbes.

/**
 * Gets the set of locations for the core of each feature.  This wouldn't
 * include additional context added by the options, but would have subtracted
 * context removed by the options.
 *
 * @return
 */
public Probe[] getCoreProbes() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    Vector<Probe> newProbes = new Vector<Probe>();
    for (int c = 0; c < chromosomes.length; c++) {
        Vector<Feature> allFeatures = new Vector<Feature>();
        String[] selectedFeatureTypes = selectedFeatureTypes();
        for (int f = 0; f < selectedFeatureTypes.length; f++) {
            Feature[] features = collection.genome().annotationCollection().getFeaturesForType(chromosomes[c], selectedFeatureTypes[f]);
            for (int i = 0; i < features.length; i++) {
                allFeatures.add(features[i]);
            }
        }
        Feature[] features = allFeatures.toArray(new Feature[0]);
        for (int f = 0; f < features.length; f++) {
            if (useSubFeatures()) {
                // We need to split this up so get the sub-features
                if (features[f].location() instanceof SplitLocation) {
                    SplitLocation location = (SplitLocation) features[f].location();
                    Location[] subLocations = location.subLocations();
                    if (useExonSubfeatures()) {
                        for (int s = 0; s < subLocations.length; s++) {
                            makeProbes(features[f], chromosomes[c], subLocations[s], newProbes, true);
                        }
                    } else {
                        // We're making introns
                        for (int s = 1; s < subLocations.length; s++) {
                            makeProbes(features[f], chromosomes[c], new Location(subLocations[s - 1].end() + 1, subLocations[s].start() - 1, features[f].location().strand()), newProbes, true);
                        }
                    }
                } else {
                    if (useExonSubfeatures()) {
                        // We can still make a single probe
                        makeProbes(features[f], chromosomes[c], features[f].location(), newProbes, true);
                    }
                // If we're making introns then we're stuffed and we give up.
                }
            } else {
                makeProbes(features[f], chromosomes[c], features[f].location(), newProbes, true);
            }
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    if (removeDuplicates()) {
        finalList = removeDuplicates(finalList);
    }
    return finalList;
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature) SplitLocation(uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation) Vector(java.util.Vector) Location(uk.ac.babraham.SeqMonk.DataTypes.Genome.Location) SplitLocation(uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)

Example 4 with Probe

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

the class InteractionReportTableDialog method mouseClicked.

/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
public void mouseClicked(MouseEvent me) {
    // We're only interested in double clicks
    if (me.getClickCount() != 2)
        return;
    // This is only linked from the report JTable
    JTable t = (JTable) me.getSource();
    int r = t.getSelectedRow();
    int c = t.getSelectedColumn();
    Object clickedOn = t.getModel().getValueAt(r, c);
    if (clickedOn == null)
        return;
    if (clickedOn instanceof Probe) {
        Probe p = (Probe) clickedOn;
        DisplayPreferences.getInstance().setLocation(p.chromosome(), p.packedPosition());
    }
    if (clickedOn instanceof Feature) {
        Feature f = (Feature) clickedOn;
        DisplayPreferences.getInstance().setLocation(application.dataCollection().genome().getChromosome(f.chromosomeName()).chromosome(), f.location().packedPosition());
    }
}
Also used : JTable(javax.swing.JTable) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)

Example 5 with Probe

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

the class SmallRNAQCCalcualtor method run.

public void run() {
    SmallRNAQCResult[] results = new SmallRNAQCResult[stores.length];
    for (int s = 0; s < stores.length; s++) {
        results[s] = new SmallRNAQCResult(stores[s], minLength, maxLength, features);
    }
    for (int f = 0; f < features.length; f++) {
        for (int d = 0; d < stores.length; d++) {
            updateProgress("Quantitating " + features[f] + " for " + stores[d], (stores.length * f) + d, stores.length * features.length);
            int[] lengthCounts = new int[(maxLength - minLength) + 1];
            String lastChr = "";
            Chromosome lastChrObject = null;
            Feature[] theseFeatures = collection.genome().annotationCollection().getFeaturesForType(features[f]);
            Arrays.sort(theseFeatures);
            for (int i = 0; i < theseFeatures.length; i++) {
                if (theseFeatures[i].chromosomeName() != lastChr) {
                    lastChr = theseFeatures[i].chromosomeName();
                    lastChrObject = collection.genome().getExactChromsomeNameMatch(lastChr);
                }
                long[] reads = stores[d].getReadsForProbe(new Probe(lastChrObject, theseFeatures[i].location().packedPosition()));
                for (int r = 0; r < reads.length; r++) {
                    int length = SequenceRead.length(reads[r]);
                    if (length >= minLength && length <= maxLength) {
                        lengthCounts[length - minLength]++;
                        if (cancel) {
                            progressCancelled();
                            return;
                        }
                    }
                }
                // End each read
                results[d].addCountsForFeatureIndex(f, lengthCounts);
            }
        // End each feature instance
        }
    // End each data store
    }
    // End each feature
    // Finally we make up the data sets we're going to pass back.
    progressComplete(results);
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)

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