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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations