Search in sources :

Example 26 with Chromosome

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

the class ShuffleListProbeGenerator method run.

/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    Vector<Probe> newProbes = new Vector<Probe>();
    String description = collection.probeSet().description() + " then shuffled " + selectedList.name() + " into random positions.";
    if (keepChromosomalDistributionBox.isSelected()) {
        description += " Chromosomal distribution was maintained.";
    }
    if (limitEndsBox.isSelected()) {
        description += " Positions were constrained within the limits of the existing probeset.";
    }
    Probe[] probes = selectedList.getAllProbes();
    long totalGenomeLength = collection.genome().getTotalGenomeLength();
    // If we're constraining within the limits of the probes then
    // we need to work out where the ends are.
    HashMap<Chromosome, int[]> chromosomeLimits = new HashMap<Chromosome, int[]>();
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    for (int c = 0; c < chromosomes.length; c++) {
        Probe[] thisChrProbes = selectedList.getProbesForChromosome(chromosomes[c]);
        for (int p = 0; p < thisChrProbes.length; p++) {
            if (!chromosomeLimits.containsKey(chromosomes[c])) {
                chromosomeLimits.put(chromosomes[c], new int[] { probes[p].start(), probes[p].end() });
                continue;
            }
            if (thisChrProbes[p].start() < chromosomeLimits.get(chromosomes[c])[0]) {
                if (probes[p].start() < 0) {
                    System.err.println("Probe " + thisChrProbes[p].name() + " started at " + thisChrProbes[p].start());
                }
                chromosomeLimits.get(chromosomes[c])[0] = thisChrProbes[p].start();
            }
            if (thisChrProbes[p].end() > chromosomeLimits.get(chromosomes[c])[1]) {
                if (thisChrProbes[p].end() > chromosomes[c].length()) {
                    System.err.println("Probe " + thisChrProbes[p].name() + " ended at " + thisChrProbes[p].end() + " which is beyond " + chromosomes[c].length() + " for chr " + chromosomes[c].name());
                }
                chromosomeLimits.get(chromosomes[c])[1] = thisChrProbes[p].end();
            }
        }
    }
    if (limitEndsBox.isSelected()) {
        totalGenomeLength = 0;
        for (int c = 0; c < chromosomes.length; c++) {
            if (chromosomeLimits.containsKey(chromosomes[c])) {
                int length = (chromosomeLimits.get(chromosomes[c])[1] - chromosomeLimits.get(chromosomes[c])[0]) + 1;
                // System.err.println("Length of "+chromosomes[c].name()+" is "+length+" from "+chromosomeLimits.get(chromosomes[c])[1]+" and "+chromosomeLimits.get(chromosomes[c])[0]+" compared to "+chromosomes[c].length());
                totalGenomeLength += length;
            }
        }
    } else {
        for (int c = 0; c < chromosomes.length; c++) {
            chromosomeLimits.put(chromosomes[c], new int[] { 1, chromosomes[c].length() });
        }
    }
    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);
        }
        Chromosome chromosomeToUse = probes[p].chromosome();
        if (!keepChromosomalDistributionBox.isSelected()) {
            chromosomeToUse = selectRandomChromosome(totalGenomeLength, chromosomeLimits, probes[p].length());
        }
        // Now we need to select a random position within that chromosome.  We need it to start within
        // the range of viable positions.
        int validStart = chromosomeLimits.get(chromosomeToUse)[0];
        int validEnd = chromosomeLimits.get(chromosomeToUse)[1] - probes[p].length();
        int actualStart = validStart + (int) (Math.random() * (validEnd - validStart));
        int actualEnd = actualStart + (probes[p].length() - 1);
        // We leave probes of unknown strand as unknown, but we randomly shuffle known ones
        int strand = Location.UNKNOWN;
        if (probes[p].strand() != Location.UNKNOWN) {
            if (Math.random() >= 0.5) {
                strand = Location.FORWARD;
            } else {
                strand = Location.REVERSE;
            }
        }
        newProbes.add(new Probe(chromosomeToUse, actualStart, actualEnd, strand, 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) HashMap(java.util.HashMap) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 27 with Chromosome

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

the class FeaturePercentileProbeGenerator 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);
        Feature[] features = collection.genome().annotationCollection().getFeaturesForType(chromosomes[c], featureType);
        for (int f = 0; f < features.length; f++) {
            // See if we need to quit
            if (cancel) {
                generationCancelled();
                return;
            }
            if (useSubfeatures && (features[f].location() instanceof SplitLocation)) {
                SplitLocation location = (SplitLocation) features[f].location();
                Location[] subLocations = location.subLocations();
                for (int s = 0; s < subLocations.length; s++) {
                    makeProbes(features[f], chromosomes[c], subLocations[s], newProbes);
                }
            } else {
                makeProbes(features[f], chromosomes[c], features[f].location(), newProbes);
            }
        }
    }
    Probe[] finalList = newProbes.toArray(new Probe[0]);
    ProbeSet finalSet = new ProbeSet(getDescription(), finalList);
    generationComplete(finalSet);
}
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) ProbeSet(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet) 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 28 with Chromosome

use of uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome 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 29 with Chromosome

use of uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome 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 30 with Chromosome

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

Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)78 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)47 Vector (java.util.Vector)36 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)23 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)23 ProbeSet (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet)22 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)12 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)11 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)8 ReadsWithCounts (uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)8 Location (uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)7 SplitLocation (uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)7 ProgressListener (uk.ac.babraham.SeqMonk.DataTypes.ProgressListener)7 HiCHitCollection (uk.ac.babraham.SeqMonk.DataTypes.Sequence.HiCHitCollection)7 IOException (java.io.IOException)6 File (java.io.File)5 Hashtable (java.util.Hashtable)5 HiCDataStore (uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)5 QuantitationStrandType (uk.ac.babraham.SeqMonk.DataTypes.Sequence.QuantitationStrandType)5 PairedDataSet (uk.ac.babraham.SeqMonk.DataTypes.PairedDataSet)4