use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.
the class CisTransScatterPlotPanel method getFilteredProbes.
/**
* Gets the filtered probes.
*
* @param probeset the probeset
* @return the filtered probes
*/
public ProbeList getFilteredProbes(ProbeSet probeset) {
double minDiff = Math.min(diffStart, diffEnd);
double maxDiff = Math.max(diffStart, diffEnd);
ProbeList list = new ProbeList(probeList, "Difference between " + df.format(minDiff) + " and " + df.format(maxDiff), "Cis/Trans difference in " + store.name() + " between " + df.format(minDiff) + " and " + df.format(maxDiff), null);
if (madeSelection) {
Probe[] probes = probeList.getAllProbes();
Arrays.sort(probes);
for (int p = 0; p < probes.length; p++) {
double diff = xData[p] - yData[p];
if (diff < minDiff)
continue;
if (diff > maxDiff)
continue;
list.addProbe(probes[p], null);
}
}
return list;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.
the class CodonBiasPanel method run.
public void run() {
// First we need to know the length of the feature we'll be analysing. This isn't the
// full length in the genome but the sum length of the exons. We'll also make up an
// array of offsets so that we can convert genomic positions into positions within the
// feature easily.
Location[] subLocations;
if (feature.location() instanceof SplitLocation) {
subLocations = ((SplitLocation) (feature.location())).subLocations();
} else {
subLocations = new Location[] { feature.location() };
}
System.err.println("Working with " + feature.name());
System.err.println("There are " + subLocations.length + " sublocations");
// First work out the total transcript length so we can make an appropriate data structure
int totalLength = 0;
for (int e = 0; e < subLocations.length; e++) {
totalLength += subLocations[e].length();
}
System.err.println("Total exon length is " + totalLength);
int[] abundance = new int[totalLength];
// Now work out the exon boundary positions within the feature
// We can also work out a mapping between relative genomic position and
// feature position.
int[] exonBoundaries = new int[subLocations.length];
int[] genomeToFeatureMap = new int[1 + feature.location().end() - feature.location().start()];
for (int j = 0; j < genomeToFeatureMap.length; j++) {
genomeToFeatureMap[j] = -1;
}
System.err.println("Genome to feature map length is " + genomeToFeatureMap.length);
if (feature.location().strand() == Location.FORWARD) {
System.err.println("Feature is forward strand");
int length = 0;
int positionInFeature = 0;
for (int i = 0; i < subLocations.length; i++) {
System.err.println("Looking at sublocation " + i + " from " + subLocations[i].start() + " to " + subLocations[i].end());
exonBoundaries[i] = length;
System.err.println("Added exon boundary at " + exonBoundaries[i]);
length += subLocations[i].length();
for (int x = 0; x < subLocations[i].length(); x++) {
int genomePostion = subLocations[i].start() + x;
int relativeGenomePosition = genomePostion - feature.location().start();
System.err.println("Sublocation Pos=" + x + " Genome Pos=" + genomePostion + " Rel Genome Pos=" + relativeGenomePosition + " Feature pos=" + positionInFeature);
genomeToFeatureMap[relativeGenomePosition] = positionInFeature;
positionInFeature++;
}
}
} else if (feature.location().strand() == Location.REVERSE) {
int length = 0;
int positionInFeature = 0;
for (int i = subLocations.length - 1; i >= 0; i--) {
exonBoundaries[i] = length;
length += subLocations[i].length();
for (int x = 0; x < subLocations[i].length(); x++) {
genomeToFeatureMap[subLocations[i].end() - x] = positionInFeature;
positionInFeature++;
}
}
}
// Now we can get all of the reads and position them within the read.
long[] reads = store.getReadsForProbe(new Probe(SeqMonkApplication.getInstance().dataCollection().genome().getExactChromsomeNameMatch(feature.chromosomeName()), feature.location().packedPosition()));
for (int r = 0; r < reads.length; r++) {
// We need to work out the position of this read in the feature. This will depend
// on whether the feature is forward or reverse strand, and whether we're reversing
// the direction of reads.
System.err.println("Looking at read " + SequenceRead.toString(reads[r]));
int genomicPosition = 0;
if (feature.location().strand() == Location.FORWARD) {
System.err.println("It's a forward feature");
if (reverse) {
System.err.println("We're a same strand library");
if (SequenceRead.strand(reads[r]) != Location.REVERSE)
continue;
genomicPosition = SequenceRead.end(reads[r]);
} else {
System.err.println("We're an opposing strand library");
if (SequenceRead.strand(reads[r]) != Location.FORWARD)
continue;
genomicPosition = SequenceRead.start(reads[r]);
}
System.err.println("Raw genomic position is " + genomicPosition);
genomicPosition = genomicPosition - feature.location().start();
System.err.println("Corrected genomic position is " + genomicPosition);
} else if (feature.location().strand() == Location.REVERSE) {
if (reverse) {
if (SequenceRead.strand(reads[r]) != Location.REVERSE)
continue;
genomicPosition = SequenceRead.start(reads[r]);
} else {
if (SequenceRead.strand(reads[r]) != Location.FORWARD)
continue;
genomicPosition = SequenceRead.end(reads[r]);
}
genomicPosition = feature.location().end() - genomicPosition;
}
System.err.println("Final genomic position is " + genomicPosition);
if (genomicPosition < 0 || genomicPosition >= genomeToFeatureMap.length)
continue;
System.err.println("Position in feature is " + genomeToFeatureMap[genomicPosition]);
if (genomeToFeatureMap[genomicPosition] != -1) {
abundance[genomeToFeatureMap[genomicPosition]]++;
}
}
this.abundance = abundance;
this.exonBoundaries = exonBoundaries;
calculated = true;
repaint();
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.
the class ProbeListViewer method mouseClicked.
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent me) {
// We're only interested in double clicks
if (me.getClickCount() != 2)
return;
// This is only linked from the report JTable
JTable t = (JTable) me.getSource();
int r = t.getSelectedRow();
Probe p = (Probe) t.getValueAt(r, 0);
DisplayPreferences.getInstance().setLocation(p.chromosome(), p.packedPosition());
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.
the class FeaturePositionSelectorPanel method makeProbe.
/**
* Makes an individual probe
*
* @param name The name for the probe
* @param c The Chromosome
* @param start Start position
* @param end End position
* @return The newly generated probe
*/
private Probe makeProbe(String name, Chromosome c, int start, int end, int strand) {
if (end > c.length())
end = c.length();
if (start < 1)
start = 1;
if (end < start)
return null;
Probe p = new Probe(c, start, end, strand);
p.setName(name);
return p;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe in project SeqMonk by s-andrews.
the class FeaturePositionSelectorPanel method getProbes.
/**
* Gets the set of probes with appropriate context for the options
* currently set.
* @return
*/
public Probe[] getProbes() {
Chromosome[] chromosomes = collection.genome().getAllChromosomes();
Vector<Probe> newProbes = new Vector<Probe>();
for (int c = 0; c < chromosomes.length; c++) {
Vector<Feature> allFeatures = new Vector<Feature>();
String[] selectedFeatureTypes = selectedFeatureTypes();
for (int f = 0; f < selectedFeatureTypes.length; f++) {
Feature[] features = collection.genome().annotationCollection().getFeaturesForType(chromosomes[c], selectedFeatureTypes[f]);
for (int i = 0; i < features.length; i++) {
allFeatures.add(features[i]);
}
}
Feature[] features = allFeatures.toArray(new Feature[0]);
for (int f = 0; f < features.length; f++) {
if (useSubFeatures()) {
// We need to split this up so get the sub-features
if (features[f].location() instanceof SplitLocation) {
SplitLocation location = (SplitLocation) features[f].location();
Location[] subLocations = location.subLocations();
if (useExonSubfeatures()) {
// System.err.println("Making exon probes");
for (int s = 0; s < subLocations.length; s++) {
makeProbes(features[f], chromosomes[c], subLocations[s], newProbes, false);
}
} else {
// We're making introns
for (int s = 1; s < subLocations.length; s++) {
makeProbes(features[f], chromosomes[c], new Location(subLocations[s - 1].end() + 1, subLocations[s].start() - 1, features[f].location().strand()), newProbes, false);
}
}
} else {
if (useExonSubfeatures()) {
// We can still make a single probe
makeProbes(features[f], chromosomes[c], features[f].location(), newProbes, false);
}
// If we're making introns then we're stuffed and we give up.
}
} else {
makeProbes(features[f], chromosomes[c], features[f].location(), newProbes, false);
}
}
}
Probe[] finalList = newProbes.toArray(new Probe[0]);
if (removeDuplicates()) {
finalList = removeDuplicates(finalList);
}
return finalList;
}
Aggregations