use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.
the class KmerPathNode method prepend.
/**
* Adds the given node to the front of this one
* @param node
*/
public void prepend(KmerPathNode node) {
assert (firstStart() == node.lastStart() + 1);
assert (firstEnd() == node.lastEnd() + 1);
assert (isReference() == node.isReference());
assert (node.nextList != null);
assert (node.nextList.size() == 1);
assert (node.nextList.get(0) == this);
assert (prevList != null);
assert (prevList.size() == 1);
assert (prevList.get(0) == node);
int nodeLength = node.length();
node.kmers.addAll(kmers);
kmers = node.kmers;
node.weight.addAll(weight);
weight = node.weight;
totalWeight += node.totalWeight;
reference |= node.reference;
if (additionalKmerOffsets != null) {
// shift over the additional kmers offsets to their new values
for (int i = 0; i < additionalKmerOffsets.size(); i++) {
additionalKmerOffsets.set(i, additionalKmerOffsets.getInt(i) + nodeLength);
}
}
if (node.additionalKmers != null) {
if (additionalKmers == null) {
additionalKmers = new LongArrayList(node.additionalKmers.size());
additionalKmerOffsets = new IntArrayList(node.additionalKmers.size());
}
additionalKmers.addAll(node.additionalKmers);
additionalKmerOffsets.addAll(node.additionalKmerOffsets);
}
prevList = node.prevList;
edgesSorted &= node.edgesSorted;
if (prevList != null) {
for (KmerPathNode n : prevList) {
replaceFirst(n.nextList, node, this);
n.edgesSorted = false;
}
}
start = node.start;
end = node.end;
node.prevList = null;
node.nextList = null;
node.invalidate();
if (Defaults.SANITY_CHECK_DE_BRUIJN) {
sanityCheck();
}
}
use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.
the class LeafBubbleCollapseIterator method partialSequenceBasesDifferent.
private int partialSequenceBasesDifferent(LongArrayList toCollapsePathKmers, TraversalNode tn, boolean traversalForward) {
LongArrayList nodeKmers = tn.node.node().pathKmers();
int basesDifference;
if (traversalForward) {
basesDifference = KmerEncodingHelper.partialSequenceBasesDifferent(k, toCollapsePathKmers, nodeKmers, tn.pathLength - tn.node.length(), true);
} else {
basesDifference = KmerEncodingHelper.partialSequenceBasesDifferent(k, toCollapsePathKmers, nodeKmers, toCollapsePathKmers.size() - tn.pathLength, false);
}
return basesDifference;
}
use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.
the class LeafBubbleCollapseIterator method memoizedCollapse.
/**
* Use a memoized breadth first search to find a similar path
* @param collapseNodes lookup of collapse path
* @param toCollapse path to attempt to collapse
* @param traversalForward traversal direction
* @param terminalNode node our path must finish on, null if collapsing leaf
* @return true if the path was collapsed, false otherwise
*/
private boolean memoizedCollapse(Set<KmerPathNode> collapseNodes, TraversalNode toCollapse, boolean traversalForward, KmerPathNode terminalNode) {
LongArrayList toCollapsePathKmers = new LongArrayList(toCollapse.pathLength);
for (KmerPathSubnode sn : traversalForward ? toCollapse.toSubnodeNextPath() : toCollapse.toSubnodePrevPath()) {
toCollapsePathKmers.addAll(sn.node().pathKmers());
}
assert (toCollapsePathKmers.size() == toCollapse.pathLength);
if (terminalNode != null) {
collapseNodes.remove(terminalNode);
}
SortedMap<KmerPathSubnode, List<MemoizedPath>> frontier = new TreeMap<KmerPathSubnode, List<MemoizedPath>>(KmerNodeUtil.ByFirstStartKmer);
KmerPathSubnode root = traversalForward ? toCollapse.toSubnodeNextPath().getFirst() : toCollapse.toSubnodePrevPath().getLast();
// set up frontier
for (TraversalNode tn : successors(collapseNodes, new TraversalNode(root, 0), traversalForward)) {
MemoizedPath mp = new MemoizedPath(tn, partialSequenceBasesDifferent(toCollapsePathKmers, tn, traversalForward));
if (frontierProcess(frontier, mp, toCollapse, traversalForward, terminalNode))
return true;
}
while (!frontier.isEmpty()) {
for (MemoizedPath mp : frontierPop(frontier)) {
for (TraversalNode tn : successors(collapseNodes, mp.path, traversalForward)) {
int basesDifferent = mp.basesDifferent + partialSequenceBasesDifferent(toCollapsePathKmers, tn, traversalForward);
MemoizedPath mpnext = new MemoizedPath(tn, basesDifferent);
if (frontierProcess(frontier, mpnext, toCollapse, traversalForward, terminalNode))
return true;
}
}
}
if (terminalNode != null) {
collapseNodes.add(terminalNode);
}
return false;
}
use of it.unimi.dsi.fastutil.longs.LongArrayList in project presto by prestodb.
the class TestColumnIndexFilter method assertAllRows.
private static void assertAllRows(RowRanges ranges, long rowCount) {
LongList actualList = new LongArrayList();
ranges.iterator().forEachRemaining((long value) -> actualList.add(value));
LongList expectedList = new LongArrayList();
LongStream.range(0, rowCount).forEach(expectedList::add);
assertArrayEquals(expectedList + " != " + actualList, expectedList.toLongArray(), actualList.toLongArray());
}
use of it.unimi.dsi.fastutil.longs.LongArrayList in project symja_android_library by axkr.
the class InstantColumn method lag.
@Override
public InstantColumn lag(int n) {
int srcPos = n >= 0 ? 0 : 0 - n;
long[] dest = new long[size()];
int destPos = n <= 0 ? 0 : n;
int length = n >= 0 ? size() - n : size() + n;
for (int i = 0; i < size(); i++) {
dest[i] = InstantColumnType.missingValueIndicator();
}
System.arraycopy(data.toLongArray(), srcPos, dest, destPos, length);
InstantColumn copy = emptyCopy(size());
copy.data = new LongArrayList(dest);
copy.setName(name() + " lag(" + n + ")");
return copy;
}
Aggregations