Search in sources :

Example 1 with ProbeSet

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

the class EvenCoverageProbeGenerator 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);
        // We'll merge together the reads for all of the selected DataStores and
        // compute a single set of probes which covers all of them.
        ReadsWithCounts[] v = new ReadsWithCounts[selectedStores.length];
        for (int s = 0; s < selectedStores.length; s++) {
            v[s] = selectedStores[s].getReadsForChromosome(chromosomes[c]);
        }
        ReadsWithCounts reads = new ReadsWithCounts(v);
        v = null;
        if (reads.totalCount() == 0) {
            // System.err.println("Skipping strand "+strandsToTry[strand]+" on chr "+chromosomes[c]);
            continue;
        }
        int strandForNewProbes = Location.UNKNOWN;
        int start = SequenceRead.start(reads.reads[0]);
        int end = SequenceRead.end(reads.reads[0]);
        int count = reads.counts[0];
        for (int r = 1; r < reads.reads.length; r++) {
            // See if we need to quit
            if (cancel) {
                generationCancelled();
                return;
            }
            if (count > 0 && ((maxSize > 0 && (SequenceRead.end(reads.reads[r]) - start) + 1 > maxSize)) || (count + reads.counts[r] > targetReadCount)) {
                // Make a probe out of what we have and start a new one with the
                // read we're currently looking at
                Probe p = new Probe(chromosomes[c], start, end, strandForNewProbes);
                newProbes.add(p);
                start = end + 1;
                end = Math.max(end + 2, SequenceRead.end(reads.reads[r]));
                count = SequenceRead.end(reads.counts[r]);
            } else {
                count += reads.counts[r];
                if (SequenceRead.end(reads.reads[r]) > end) {
                    end = SequenceRead.end(reads.reads[r]);
                }
            }
        }
        if (count > 0) {
            Probe p = new Probe(chromosomes[c], start, end, strandForNewProbes);
            newProbes.add(p);
        }
    }
    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) ReadsWithCounts(uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 2 with ProbeSet

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

the class RandomProbeGenerator method designPerChromosome.

private ProbeSet designPerChromosome() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    long[] offsets = new long[chromosomes.length];
    offsets[0] = chromosomes[0].length();
    for (int i = 1; i < chromosomes.length; i++) {
        offsets[i] = offsets[i - 1] + chromosomes[i].length();
    }
    // Now make up the probes
    Vector<Probe> newProbes = new Vector<Probe>();
    Random rand = new Random();
    while (newProbes.size() < numberToGenerate) {
        if (cancel) {
            return null;
        }
        if (newProbes.size() % 1000 == 0) {
            updateGenerationProgress("Designed " + newProbes.size() + " probes", newProbes.size(), numberToGenerate);
        }
        // Select a random position in the genome
        long random = (long) (collection.genome().getTotalGenomeLength() * rand.nextDouble());
        Chromosome chromosome = null;
        int start = 0;
        int end = 0;
        // Find out which chromosome this comes from
        for (int o = 0; o < offsets.length; o++) {
            if (random < offsets[o]) {
                chromosome = chromosomes[o];
                if (o > 0) {
                    start = (int) (random - offsets[o - 1]) + 1;
                } else {
                    start = (int) random + 1;
                }
                end = start + (windowSize - 1);
                break;
            }
        }
        if (end > chromosome.length()) {
            // Try again
            continue;
        }
        // Make a probe
        newProbes.add(new Probe(chromosome, start, end));
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    return finalSet;
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Random(java.util.Random) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 3 with ProbeSet

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

the class RandomProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    ProbeSet finalSet;
    if (designWithinExisting) {
        finalSet = designPerProbe();
    } else {
        finalSet = designPerChromosome();
    }
    if (finalSet == null) {
        generationCancelled();
        return;
    }
    generationComplete(finalSet);
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet)

Example 4 with ProbeSet

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

the class RandomProbeGenerator method designPerProbe.

private ProbeSet designPerProbe() {
    Probe[] probes = collection.probeSet().getActiveList().getAllProbes();
    // TODO: We could remove all probes which are smaller than the windows we're going to
    // generate?
    long[] offsets = new long[probes.length];
    offsets[0] = probes[0].length();
    for (int i = 1; i < probes.length; i++) {
        offsets[i] = offsets[i - 1] + probes[i].length();
    }
    long totalLength = offsets[offsets.length - 1];
    // Now make up the probes
    Vector<Probe> newProbes = new Vector<Probe>();
    Random rand = new Random();
    RANDLOOP: while (newProbes.size() < numberToGenerate) {
        if (cancel) {
            return null;
        }
        if (newProbes.size() % 1000 == 0) {
            updateGenerationProgress("Designed " + newProbes.size() + " probes", newProbes.size(), numberToGenerate);
        }
        // Select a random position in the genome
        long random = (long) (totalLength * rand.nextDouble());
        Chromosome chromosome = null;
        int start = 0;
        int end = 0;
        // Find out which chromosome this comes from
        for (int o = 0; o < offsets.length; o++) {
            if (random < offsets[o]) {
                chromosome = probes[o].chromosome();
                if (o > 0) {
                    start = (int) (random - offsets[o - 1]) + probes[o].start();
                } else {
                    start = (int) random + probes[o].start();
                }
                end = start + (windowSize - 1);
                // Check that this is valid
                if (end > probes[o].end()) {
                    // Try again
                    continue RANDLOOP;
                }
                break;
            }
        }
        // Make a probe
        newProbes.add(new Probe(chromosome, start, end));
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    return finalSet;
}
Also used : ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) Random(java.util.Random) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 5 with ProbeSet

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

the class RunningWindowProbeGenerator method designPerChromosome.

private ProbeSet designPerChromosome() {
    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);
        int pos = 1;
        while (pos < chromosomes[c].length()) {
            // See if we need to quit
            if (cancel) {
                generationCancelled();
            }
            int end = pos + (probeSize - 1);
            if (end > chromosomes[c].length())
                end = chromosomes[c].length();
            Probe p = new Probe(chromosomes[c], pos, end);
            newProbes.add(p);
            pos += stepSize;
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    return 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)

Aggregations

ProbeSet (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet)30 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)26 Vector (java.util.Vector)22 Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)22 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)9 Location (uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)5 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)5 QuantitationStrandType (uk.ac.babraham.SeqMonk.DataTypes.Sequence.QuantitationStrandType)5 SplitLocation (uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)4 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)4 LongVector (uk.ac.babraham.SeqMonk.Utilities.LongVector)4 BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)3 ArrayList (java.util.ArrayList)2 Hashtable (java.util.Hashtable)2 Random (java.util.Random)2 ProbeTTestValue (uk.ac.babraham.SeqMonk.Analysis.Statistics.ProbeTTestValue)2 ReadsWithCounts (uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1