Search in sources :

Example 6 with LongVector

use of uk.ac.babraham.SeqMonk.Utilities.LongVector in project SeqMonk by s-andrews.

the class ContigProbeGenerator method getNonRedundantReads.

/**
 * Gets the non redundant reads.
 *
 * @param reads the reads
 * @return the non redundant reads
 */
private ReadsWithCounts getNonRedundantReads(ReadsWithCounts reads, int limitToStrand) {
    boolean limitStrand = false;
    if (limitToStrand == Location.FORWARD || limitToStrand == Location.REVERSE || limitToStrand == Location.UNKNOWN) {
        limitStrand = true;
    }
    if (!limitStrand) {
        // It's already done.
        return reads;
    }
    LongVector keptReads = new LongVector();
    IntVector keptCounts = new IntVector();
    for (int r = 0; r < reads.reads.length; r++) {
        if (!readStrandType.useRead(reads.reads[r])) {
            continue;
        }
        if (limitStrand && (SequenceRead.strand(reads.reads[r]) != limitToStrand))
            continue;
        keptReads.add(reads.reads[r]);
        keptCounts.add(reads.counts[r]);
    }
    return new ReadsWithCounts(keptReads.toArray(), keptCounts.toArray());
}
Also used : LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector) IntVector(uk.ac.babraham.SeqMonk.Utilities.IntVector) ReadsWithCounts(uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)

Example 7 with LongVector

use of uk.ac.babraham.SeqMonk.Utilities.LongVector in project SeqMonk by s-andrews.

the class MacsPeakCaller method deduplicateReads.

private long[] deduplicateReads(long[] reads, int threshold) {
    if (skipDeduplicationBox.isSelected())
        return reads;
    // System.err.println("Threshold is "+threshold);
    LongVector passed = new LongVector();
    int lastReadCount = 0;
    if (reads.length > 0) {
        lastReadCount = 1;
    }
    for (int r = 1; r < reads.length; r++) {
        if (reads[r] == reads[r - 1]) {
            ++lastReadCount;
        } else {
            for (int i = 0; i < Math.min(lastReadCount, threshold); i++) {
                passed.add(reads[r - 1]);
            }
            lastReadCount = 1;
        }
    }
    for (int i = 0; i < Math.min(lastReadCount, threshold); i++) {
        passed.add(reads[reads.length - 1]);
    }
    return passed.toArray();
}
Also used : LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector)

Example 8 with LongVector

use of uk.ac.babraham.SeqMonk.Utilities.LongVector in project SeqMonk by s-andrews.

the class IntronFeatureGroup method getSubLocations.

public Location[] getSubLocations() {
    if (features.size() == 1) {
        Location loc = features.elementAt(0).location();
        if (loc instanceof SplitLocation) {
            Location[] subLocs = ((SplitLocation) loc).subLocations();
            Location[] interLocs = new Location[subLocs.length - 1];
            for (int i = 0; i < subLocs.length - 1; i++) {
                interLocs[i] = new Location(subLocs[i].end() + 1, subLocs[i + 1].start() - 1, subLocs[i].strand());
            }
            return interLocs;
        } else {
            return new Location[0];
        }
    }
    LongVector allLocs = new LongVector();
    Enumeration<Feature> en = features.elements();
    while (en.hasMoreElements()) {
        Location loc = en.nextElement().location();
        if (loc instanceof SplitLocation) {
            Location[] subLocs = ((SplitLocation) loc).subLocations();
            for (int s = 0; s < subLocs.length; s++) {
                allLocs.add(subLocs[s].packedPosition());
            }
        } else {
            allLocs.add(loc.packedPosition());
        }
    }
    long[] locs = allLocs.toArray();
    SequenceRead.sort(locs);
    Vector<Location> mergedLocs = new Vector<Location>();
    long current = locs[0];
    for (int i = 1; i < locs.length; i++) {
        // if (debug) {System.err.println("Looking at "+SequenceRead.start(locs[i])+"-"+SequenceRead.end(locs[i])+" current is "+SequenceRead.start(current)+"-"+SequenceRead.end(current));}
        if (SequenceRead.overlaps(current, locs[i]) && SequenceRead.end(locs[i]) > SequenceRead.end(current)) {
            // if (debug) {System.err.println("They overlap, extending...");}
            current = SequenceRead.packPosition(SequenceRead.start(current), SequenceRead.end(locs[i]), SequenceRead.strand(current));
        } else if (SequenceRead.end(locs[i]) <= SequenceRead.end(current)) {
            // if (debug) {System.err.println("This is a subset, ignoring it");}
            continue;
        } else {
            // if (debug) {System.err.println("They don't overlap, moving on...");}
            mergedLocs.add(new Location(current));
            current = locs[i];
        }
    }
    mergedLocs.add(new Location(current));
    Location[] interLocs = new Location[mergedLocs.size() - 1];
    for (int i = 0; i < mergedLocs.size() - 1; i++) {
        interLocs[i] = new Location(mergedLocs.elementAt(i).end() + 1, mergedLocs.elementAt(i + 1).start() - 1, mergedLocs.elementAt(i).strand());
    }
    return interLocs;
}
Also used : LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector) SplitLocation(uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation) Feature(uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature) Vector(java.util.Vector) LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector) SplitLocation(uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation) Location(uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)

Example 9 with LongVector

use of uk.ac.babraham.SeqMonk.Utilities.LongVector in project SeqMonk by s-andrews.

the class HiCHitCollection method addHit.

public void addHit(String hitChromsome, long sourcePosition, long hitPosition) {
    if (!hits.containsKey(hitChromsome)) {
        hits.put(hitChromsome, new LongVector[] { new LongVector(), new LongVector() });
    }
    hits.get(hitChromsome)[0].add(sourcePosition);
    hits.get(hitChromsome)[1].add(hitPosition);
}
Also used : LongVector(uk.ac.babraham.SeqMonk.Utilities.LongVector)

Aggregations

LongVector (uk.ac.babraham.SeqMonk.Utilities.LongVector)9 Vector (java.util.Vector)3 Location (uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)3 SplitLocation (uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)3 ReadsWithCounts (uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)3 IntVector (uk.ac.babraham.SeqMonk.Utilities.IntVector)3 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)2