Search in sources :

Example 26 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class KmerEncodingHelperTest method partialSequenceBasesDifferent_should_allow_seq_out_of_ref_bounds_start.

@Test
public void partialSequenceBasesDifferent_should_allow_seq_out_of_ref_bounds_start() {
    int k = 4;
    LongArrayList ref = KPN(k, "AAAACAAA", 1, 1, true).pathKmers();
    LongArrayList seq = KPN(k, "TATAACAA", 1, 1, true).pathKmers();
    assertEquals(1, KmerEncodingHelper.partialSequenceBasesDifferent(k, ref, seq, -1, false));
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Test(org.junit.Test)

Example 27 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class MisassemblyFixer method createContigTransitionOffsetLookup.

private static NavigableMap<Integer, ImmutableTriple<Integer, LongList, LongList>> createContigTransitionOffsetLookup(List<KmerPathSubnode> contig) {
    NavigableMap<Integer, ImmutableTriple<Integer, LongList, LongList>> lookup = new TreeMap<Integer, ImmutableTriple<Integer, LongList, LongList>>();
    int snoffset = 0;
    for (int i = 0; i < contig.size() - 1; i++) {
        KmerPathSubnode sn = contig.get(i);
        LongArrayList snendkmers = new LongArrayList();
        snendkmers.add(sn.lastKmer());
        for (int j = 0; j < sn.node().collapsedKmerOffsets().size(); j++) {
            int offset = sn.node().collapsedKmerOffsets().getInt(j);
            if (offset == sn.length() - 1) {
                snendkmers.add(sn.node().collapsedKmers().getLong(j));
            }
        }
        KmerPathSubnode snext = contig.get(i + 1);
        LongArrayList snextstartkmers = new LongArrayList();
        snextstartkmers.add(snext.firstKmer());
        for (int j = 0; j < snext.node().collapsedKmerOffsets().size(); j++) {
            int offset = snext.node().collapsedKmerOffsets().getInt(j);
            if (offset == 0) {
                snextstartkmers.add(snext.node().collapsedKmers().getLong(j));
            }
        }
        lookup.put(snoffset + sn.length() - 1, new ImmutableTriple<Integer, LongList, LongList>(i, snendkmers, snextstartkmers));
        snoffset += sn.length();
    }
    return lookup;
}
Also used : ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongList(it.unimi.dsi.fastutil.longs.LongList) TreeMap(java.util.TreeMap)

Example 28 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class EvidenceTracker method matchesExpected.

public boolean matchesExpected(KmerPathSubnode pn) {
    for (int i = 0; i < pn.length(); i++) {
        LongArrayList kmers = new LongArrayList();
        kmers.add(pn.kmer(i));
        for (int j = 0; j < pn.node().collapsedKmerOffsets().size(); j++) {
            if (pn.node().collapsedKmerOffsets().getInt(j) == i) {
                kmers.add(pn.node().collapsedKmers().getLong(j));
            }
        }
        if (!matchesExpected(pn.weight(i) * pn.width(), kmers, pn.firstStart() + i, pn.firstEnd() + i)) {
            return false;
        }
    }
    return true;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList)

Example 29 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class KmerPathNode method splitAtStartPosition.

/**
 * Splits at the given internal start position
 *
 * @param internalStart start position to split at
 * @return new node ending immediately before the given position
 */
public KmerPathNode splitAtStartPosition(int newStartPosition) {
    assert (newStartPosition > start);
    assert (newStartPosition <= end);
    KmerPathNode split = new KmerPathNode(kmers, start, newStartPosition - 1, reference, totalWeight, weight);
    this.start = newStartPosition;
    if (nextList != null) {
        ArrayList<KmerPathNode> newNextThis = new ArrayList<KmerPathNode>(nextList.size());
        ArrayList<KmerPathNode> newNextSplit = new ArrayList<KmerPathNode>(nextList.size());
        for (KmerPathNode adj : nextList) {
            if (IntervalUtil.overlapsClosed(this.lastStart() + 1, this.lastEnd() + 1, adj.firstStart(), adj.firstEnd())) {
                newNextThis.add(adj);
                // start position of this has changed so that might have invalidated the sort order of the neighbour
                adj.edgesSorted = false;
            } else {
                boolean removed = CollectionUtil.removeByReference(adj.prevList, this);
                assert (removed);
            }
            if (IntervalUtil.overlapsClosed(split.lastStart() + 1, split.lastEnd() + 1, adj.firstStart(), adj.firstEnd())) {
                newNextSplit.add(adj);
                adj.prevList.add(split);
                adj.edgesSorted = false;
            }
        }
        this.nextList = newNextThis;
        split.nextList = newNextSplit;
    }
    if (prevList != null) {
        ArrayList<KmerPathNode> newPrevThis = new ArrayList<KmerPathNode>(prevList.size());
        ArrayList<KmerPathNode> newPrevSplit = new ArrayList<KmerPathNode>(prevList.size());
        for (KmerPathNode adj : prevList) {
            if (IntervalUtil.overlapsClosed(adj.lastStart() + 1, adj.lastEnd() + 1, this.firstStart(), this.firstEnd())) {
                newPrevThis.add(adj);
                // start position of this has changed so that might have invalidated the sort order of the neighbour
                adj.edgesSorted = false;
            } else {
                boolean removed = CollectionUtil.removeByReference(adj.nextList, this);
                assert (removed);
            }
            if (IntervalUtil.overlapsClosed(adj.lastStart() + 1, adj.lastEnd() + 1, split.firstStart(), split.firstEnd())) {
                newPrevSplit.add(adj);
                adj.nextList.add(split);
                adj.edgesSorted = false;
            }
        }
        this.prevList = newPrevThis;
        split.prevList = newPrevSplit;
    }
    // edge list order retained
    split.edgesSorted = this.edgesSorted;
    if (this.additionalKmers != null) {
        split.additionalKmers = new LongArrayList(this.additionalKmers);
        split.additionalKmerOffsets = new IntArrayList(this.additionalKmerOffsets);
    }
    if (Defaults.SANITY_CHECK_DE_BRUIJN) {
        this.sanityCheck();
        split.sanityCheck();
    }
    return split;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 30 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class KmerPathNode method splitAtLength.

/**
 * Splits out a the node by creating a new node containing the first given number of bases
 *
 * Note: PositionalDeBruijnGraphPathNodeGraphSimplifier relies on the fact that the node
 * is truncated at the start, not the end.
 *
 * @param length length of node to split out
 * @return new predecessor node
 */
public KmerPathNode splitAtLength(int firstNodeLength) {
    if (firstNodeLength == 0 || firstNodeLength == length())
        return this;
    assert (firstNodeLength > 0);
    assert (firstNodeLength < length());
    // copy our new kmers and weights
    LongArrayList kmerSecond = new LongArrayList(kmers.subList(firstNodeLength, length()));
    IntArrayList weightSecond = new IntArrayList(weight.subList(firstNodeLength, length()));
    // let split own our current arrays
    this.kmers.removeElements(firstNodeLength, this.kmers.size());
    this.weight.removeElements(firstNodeLength, this.weight.size());
    KmerPathNode split = new KmerPathNode(this.kmers, start, end, reference, this.weight);
    // Update incoming edges to split
    split.prevList = this.prevList;
    // edge sorting remains unchanged for all nodes
    split.edgesSorted = this.edgesSorted;
    this.prevList = null;
    if (split.prevList != null) {
        for (KmerPathNode n : split.prevList) {
            replaceFirst(n.nextList, this, split);
        }
    }
    // outgoing edges remain unchanged since our end kmer is unchanged
    this.kmers = kmerSecond;
    this.weight = weightSecond;
    this.totalWeight -= split.weight();
    this.start += firstNodeLength;
    this.end += firstNodeLength;
    addEdgeImpl(split, this);
    if (this.additionalKmers != null) {
        LongArrayList nodeKmers = new LongArrayList();
        IntArrayList nodeOffsets = new IntArrayList();
        LongArrayList splitKmers = new LongArrayList();
        IntArrayList splitOffsets = new IntArrayList();
        for (int i = 0; i < additionalKmerOffsets.size(); i++) {
            if (additionalKmerOffsets.getInt(i) < firstNodeLength) {
                splitKmers.add(additionalKmers.getLong(i));
                splitOffsets.add(additionalKmerOffsets.getInt(i));
            } else {
                nodeKmers.add(additionalKmers.getLong(i));
                nodeOffsets.add(additionalKmerOffsets.getInt(i) - firstNodeLength);
            }
        }
        this.additionalKmers = nodeKmers;
        this.additionalKmerOffsets = nodeOffsets;
        split.additionalKmers = splitKmers;
        split.additionalKmerOffsets = splitOffsets;
    }
    if (Defaults.SANITY_CHECK_DE_BRUIJN) {
        this.sanityCheck();
        split.sanityCheck();
    }
    return split;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Aggregations

LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)37 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)3 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)3 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)3 LongList (it.unimi.dsi.fastutil.longs.LongList)3 LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)3 IOException (java.io.IOException)3 List (java.util.List)3 Block (com.facebook.presto.spi.block.Block)2 Type (com.facebook.presto.spi.type.Type)2 Supplier (com.google.common.base.Supplier)2 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)2 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)1