Search in sources :

Example 31 with Probe

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

the class InterstitialProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    makeEndProbes = makeEndProbesBox.isSelected();
    Vector<Probe> newProbes = new Vector<Probe>();
    try {
        for (int c = 0; c < chromosomes.length; c++) {
            // Time for an update
            updateGenerationProgress("Processed " + c + " chromosomes", c, chromosomes.length);
            Probe[] startingProbes = initialList.getProbesForChromosome(chromosomes[c]);
            // on the chromsoome.
            if (makeEndProbes) {
                if (startingProbes.length > 0) {
                    if (startingProbes[0].start() > 1) {
                        Probe p = makeProbe(chromosomes[c], 1, startingProbes[0].start() - 1, Probe.UNKNOWN);
                        if (p != null) {
                            newProbes.add(p);
                        }
                    }
                } else {
                    Probe p = makeProbe(chromosomes[c], 1, chromosomes[c].length(), Probe.UNKNOWN);
                    if (p != null) {
                        newProbes.add(p);
                    }
                }
            }
            int lastEnd = 1;
            int lastStrand = Probe.UNKNOWN;
            if (startingProbes.length > 0) {
                lastEnd = startingProbes[0].end() + 1;
                lastStrand = startingProbes[0].strand();
            }
            // Now we can make the actual interstitial probes
            for (int i = 0; i < startingProbes.length - 1; i++) {
                if (cancel) {
                    generationCancelled();
                    return;
                }
                if (startingProbes[i].end() + 1 > lastEnd) {
                    lastEnd = startingProbes[i].end() + 1;
                    lastStrand = startingProbes[i].strand();
                }
                if (startingProbes[i + 1].end() <= lastEnd) {
                    continue;
                }
                int strandToUse = Probe.UNKNOWN;
                if (startingProbes[i + 1].strand() == lastStrand) {
                    strandToUse = lastStrand;
                }
                Probe p = makeProbe(chromosomes[c], lastEnd, startingProbes[i + 1].start() - 1, strandToUse);
                if (p != null) {
                    newProbes.add(p);
                }
            }
            // Finally we can make an end probe if we need to
            if (makeEndProbes) {
                if (startingProbes.length > 0) {
                    if (startingProbes[startingProbes.length - 1].end() < chromosomes[c].length()) {
                        Probe p = makeProbe(chromosomes[c], startingProbes[startingProbes.length - 1].end() + 1, chromosomes[c].length(), Probe.UNKNOWN);
                        if (p != null) {
                            newProbes.add(p);
                        }
                    }
                }
            }
        }
    } catch (SeqMonkException e) {
        generationExceptionReceived(e);
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    generationComplete(finalSet);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 32 with Probe

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

the class MergeConsecutiveProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    Vector<Probe> newProbes = new Vector<Probe>();
    for (int c = 0; c < chromosomes.length; c++) {
        // Time for an update
        updateGenerationProgress("Processed " + c + " chromosomes", c, chromosomes.length);
        Probe[] startingProbes = collection.probeSet().getProbesForChromosome(chromosomes[c]);
        Arrays.sort(startingProbes);
        // Now we can make the actual probes
        int index = 0;
        while (index < startingProbes.length - 1) {
            int start = 0;
            int end = 0;
            int strand = 0;
            for (int i = index; i < startingProbes.length && i < index + numberToMerge; i++) {
                if (cancel) {
                    generationCancelled();
                    return;
                }
                if (i == index || startingProbes[i].start() < start) {
                    start = startingProbes[i].start();
                }
                if (i == index || startingProbes[i].end() > end) {
                    end = startingProbes[i].end();
                }
                if (i == index) {
                    strand = startingProbes[i].strand();
                } else {
                    if (startingProbes[i].strand() != strand) {
                        strand = Probe.UNKNOWN;
                    }
                }
            }
            newProbes.add(new Probe(chromosomes[c], start, end, strand));
            index += stepSize;
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    generationComplete(finalSet);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 33 with Probe

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

the class WigglePipeline method startPipeline.

protected void startPipeline() {
    // We first need to generate probes over all of the features listed in
    // the feature types.  The probes should cover the whole area of the
    // feature regardless of where it splices.
    boolean logTransform = optionsPanel.logTransform();
    boolean correctTotal = optionsPanel.correctTotal();
    int probeSize = optionsPanel.probeSize();
    int stepSize = optionsPanel.stepSize();
    super.progressUpdated("Making probes", 0, 1);
    Probe[] probes = null;
    String region = optionsPanel.getRegion();
    try {
        if (region.equals("Whole Genome")) {
            probes = makeGenomeProbes(probeSize, stepSize);
        } else if (region.equals("Current Chromosome")) {
            probes = makeChromosomeProbes(DisplayPreferences.getInstance().getCurrentChromosome(), probeSize, stepSize);
        } else if (region.equals("Currently Visible Region")) {
            probes = makeVisibleProbes(DisplayPreferences.getInstance().getCurrentChromosome(), SequenceRead.start(DisplayPreferences.getInstance().getCurrentLocation()), SequenceRead.end(DisplayPreferences.getInstance().getCurrentLocation()), probeSize, stepSize);
        }
    } catch (SeqMonkException sme) {
        progressExceptionReceived(sme);
        return;
    }
    collection().setProbeSet(new ProbeSet("Wiggle probes", probes));
    // method from inside the pipeline rather than doing this again ourselves.
    if (cancel) {
        progressCancelled();
        return;
    }
    bpq = new BasePairQuantitation(application);
    bpq.addProgressListener(this);
    bpq.quantitate(collection(), data, QuantitationStrandType.getTypeOptions()[0], correctTotal, false, false, false, logTransform, false);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) BasePairQuantitation(uk.ac.babraham.SeqMonk.Quantitation.BasePairQuantitation) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)

Example 34 with Probe

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

the class ProbeListProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    Vector<Probe> newProbes = new Vector<Probe>();
    boolean reverse = reverseDirectionBox.isSelected();
    String description = collection.probeSet().description() + " then took subset of probes in " + selectedList.name();
    if (reverse) {
        description = description + " and reversed all probe directions";
    }
    Probe[] probes = selectedList.getAllProbes();
    for (int p = 0; p < probes.length; p++) {
        // See if we need to quit
        if (cancel) {
            generationCancelled();
            return;
        }
        if (p % 10000 == 0) {
            // Time for an update
            updateGenerationProgress("Processed " + p + " probes", p, probes.length);
        }
        if (reverse) {
            // We reverse the existing strand.  We don't do anything to
            // probes with unknown strand.
            int strand = probes[p].strand();
            if (strand == Location.FORWARD) {
                strand = Location.REVERSE;
            } else if (strand == Location.REVERSE) {
                strand = Location.FORWARD;
            }
            newProbes.add(new Probe(probes[p].chromosome(), probes[p].start(), probes[p].end(), strand, probes[p].name()));
        } else {
            newProbes.add(new Probe(probes[p].chromosome(), probes[p].packedPosition(), probes[p].name()));
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(description, finalList);
    generationComplete(finalSet);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 35 with Probe

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

the class ReadPositionProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    if (limitWithinRegion) {
        chromosomes = new Chromosome[] { DisplayPreferences.getInstance().getCurrentChromosome() };
    }
    Vector<Probe> newProbes = new Vector<Probe>();
    for (int c = 0; c < chromosomes.length; c++) {
        // Time for an update
        updateGenerationProgress("Processed " + c + " chromosomes", c, chromosomes.length);
        // We'll merge together the reads for all of the selected DataStores and
        // compute a single set of probes which covers all of them.
        Probe[] regions = new Probe[0];
        if (limitWithinRegion) {
            if (limitRegionBox.getSelectedItem().toString().equals("Currently Visible Region")) {
                if (chromosomes[c] == DisplayPreferences.getInstance().getCurrentChromosome()) {
                    regions = new Probe[] { new Probe(chromosomes[c], DisplayPreferences.getInstance().getCurrentLocation()) };
                }
            } else if (limitRegionBox.getSelectedItem().toString().equals("Active Probe List")) {
                regions = collection.probeSet().getActiveList().getProbesForChromosome(chromosomes[c]);
            } else {
                throw new IllegalStateException("Don't know how to filter by " + limitRegionBox.getSelectedItem().toString());
            }
        } else {
            regions = new Probe[] { new Probe(chromosomes[c], 0, chromosomes[c].length()) };
        }
        for (int p = 0; p < regions.length; p++) {
            long[][] v = new long[selectedStores.length][];
            for (int s = 0; s < selectedStores.length; s++) {
                v[s] = selectedStores[s].getReadsForProbe(regions[p]);
            }
            long[] rawReads = getUsableRedundantReads(LongSetSorter.sortLongSets(v));
            v = null;
            int currentCount = 1;
            int currentStart = 0;
            int currentEnd = 0;
            int currentPositionCount = 0;
            for (int r = 1; r < rawReads.length; r++) {
                if (SequenceRead.start(rawReads[r]) == SequenceRead.start(rawReads[r - 1]) && SequenceRead.end(rawReads[r]) == SequenceRead.end(rawReads[r - 1]) && (ignoreStrand || SequenceRead.strand(rawReads[r]) == SequenceRead.strand(rawReads[r - 1]))) {
                    // It's the same
                    ++currentCount;
                } else {
                    // Check if we need to make a new probe
                    if (currentCount >= minCount) {
                        // Add this probe to the current set
                        if (currentPositionCount == 0) {
                            // Start a new position
                            currentStart = SequenceRead.start(rawReads[r - 1]);
                            currentEnd = SequenceRead.end(rawReads[r - 1]);
                        } else {
                            if (SequenceRead.end(rawReads[r - 1]) > currentEnd) {
                                currentEnd = SequenceRead.end(rawReads[r - 1]);
                            }
                        }
                        currentPositionCount++;
                        if (currentPositionCount == readsPerWindow) {
                            int strand = Probe.UNKNOWN;
                            if (!ignoreStrand) {
                                strand = SequenceRead.strand(rawReads[r - 1]);
                            }
                            newProbes.add(new Probe(chromosomes[c], currentStart, currentEnd, strand));
                            currentPositionCount = 0;
                        }
                    }
                    currentCount = 1;
                }
            }
            // See if we need to add the last read
            if (currentCount >= minCount && rawReads.length >= 1) {
                // Add this probe to the current set
                if (currentPositionCount == 0) {
                    // Start a new position
                    currentStart = SequenceRead.start(rawReads[rawReads.length - 1]);
                    currentEnd = SequenceRead.end(rawReads[rawReads.length - 1]);
                } else {
                    if (SequenceRead.end(rawReads[rawReads.length - 1]) > currentEnd) {
                        currentEnd = SequenceRead.end(rawReads[rawReads.length - 1]);
                    }
                }
                currentPositionCount++;
                // Make a probe with whatever we have left
                int strand = Probe.UNKNOWN;
                if (!ignoreStrand) {
                    strand = SequenceRead.strand(rawReads[rawReads.length - 1]);
                }
                newProbes.add(new Probe(chromosomes[c], currentStart, currentEnd, strand));
            }
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    newProbes.clear();
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    generationComplete(finalSet);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector) LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector)

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