Search in sources :

Example 6 with ProbeSet

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

the class RunningWindowProbeGenerator method designPerProbe.

private ProbeSet designPerProbe() {
    Chromosome[] chromosomes = collection.genome().getAllChromosomes();
    ProbeList activeList;
    if (limitRegionBox.getSelectedItem().equals("Active Probe List")) {
        activeList = collection.probeSet().getActiveList();
    } else {
        // We're just analysing a single probe over the current region
        existingListName = "Currently visible region";
        Probe p = new Probe(DisplayPreferences.getInstance().getCurrentChromosome(), DisplayPreferences.getInstance().getCurrentLocation());
        activeList = new ProbeSet("Current Region", 1);
        activeList.addProbe(p, 0f);
    }
    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[] probes = activeList.getProbesForChromosome(chromosomes[c]);
        for (int p = 0; p < probes.length; p++) {
            int pos = probes[p].start();
            while (pos < probes[p].end() - (probeSize - 1)) {
                // See if we need to quit
                if (cancel) {
                    generationCancelled();
                }
                int end = pos + (probeSize - 1);
                if (end > chromosomes[c].length())
                    end = chromosomes[c].length();
                Probe pr = new Probe(chromosomes[c], pos, end, probes[p].strand());
                newProbes.add(pr);
                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) ProbeList(uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) Vector(java.util.Vector)

Example 7 with ProbeSet

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

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

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

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

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