Search in sources :

Example 1 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project ProPPR by TeamCohen.

the class LightweightStateGraph method setOutlinks.

public void setOutlinks(State u, List<Outlink> outlinks) {
    // wwc: why are we saving these outlinks as a trove thing? space?
    int ui = this.nodeTab.getId(u);
    if (near.containsKey(ui)) {
        log.warn("Overwriting previous outlinks for state " + u);
        edgeCount -= near.get(ui).size();
    }
    TIntArrayList nearui = new TIntArrayList(outlinks.size());
    near.put(ui, nearui);
    TIntObjectHashMap<TIntDoubleHashMap> fui = new TIntObjectHashMap<TIntDoubleHashMap>();
    edgeFeatureDict.put(ui, fui);
    for (Outlink o : outlinks) {
        int vi = this.nodeTab.getId(o.child);
        nearui.add(vi);
        edgeCount++;
        TIntDoubleHashMap fvui = new TIntDoubleHashMap(o.fd.size());
        for (Map.Entry<Feature, Double> e : o.fd.entrySet()) {
            fvui.put(this.featureTab.getId(e.getKey()), e.getValue());
        }
        fui.put(vi, fvui);
    }
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) Map(java.util.Map) Feature(edu.cmu.ml.proppr.prove.wam.Feature) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method getCoordinates.

private TIntObjectHashMap<IdPeakResult[]> getCoordinates(List<PeakResult> list) {
    final TIntObjectHashMap<IdPeakResult[]> coords = new TIntObjectHashMap<IdPeakResult[]>();
    if (list.size() > 0) {
        // Do not use HashMap directly to build the coords object since there 
        // will be many calls to getEntry(). Instead sort the results and use 
        // a new list for each time point
        Collections.sort(list);
        int last = -1;
        int id = 0;
        int uniqueId = 0;
        ArrayList<PeakResult> tmp = new ArrayList<PeakResult>();
        // Add the results to the lists
        for (PeakResult p : list) {
            if (last != p.getFrame()) {
                if (!tmp.isEmpty()) {
                    coords.put(last, tmp.toArray(new IdPeakResult[tmp.size()]));
                }
                id = 0;
                tmp.clear();
            }
            last = p.getFrame();
            tmp.add(new IdPeakResult(id++, uniqueId++, p));
        }
        if (!tmp.isEmpty()) {
            coords.put(last, tmp.toArray(new IdPeakResult[tmp.size()]));
        }
    }
    return coords;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ArrayList(java.util.ArrayList) PeakResult(gdsc.smlm.results.PeakResult) BasePreprocessedPeakResult(gdsc.smlm.results.filter.BasePreprocessedPeakResult) PreprocessedPeakResult(gdsc.smlm.results.filter.PreprocessedPeakResult)

Example 3 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.

the class BenchmarkSpotFilter method run.

private BenchmarkFilterResult run(FitEngineConfiguration config, boolean relativeDistances, boolean batchSummary) {
    if (Utils.isInterrupted())
        return null;
    MaximaSpotFilter spotFilter = config.createSpotFilter(relativeDistances);
    // Extract all the results in memory into a list per frame. This can be cached
    if (// || lastRelativeDistances != relativeDistances)
    lastId != simulationParameters.id) {
        // Always use float coordinates.
        // The Worker adds a pixel offset for the spot coordinates.
        TIntObjectHashMap<ArrayList<Coordinate>> coordinates = ResultsMatchCalculator.getCoordinates(results.getResults(), false);
        actualCoordinates = new TIntObjectHashMap<PSFSpot[]>();
        lastId = simulationParameters.id;
        //lastRelativeDistances = relativeDistances;
        // Store these so we can reset them
        final int total = totalProgress;
        final String prefix = progressPrefix;
        // Spot PSFs may overlap so we must determine the amount of signal overlap and amplitude effect 
        // for each spot...
        IJ.showStatus("Computing PSF overlap ...");
        final int nThreads = Prefs.getThreads();
        final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
        List<OverlapWorker> workers = new LinkedList<OverlapWorker>();
        List<Thread> threads = new LinkedList<Thread>();
        for (int i = 0; i < nThreads; i++) {
            OverlapWorker worker = new OverlapWorker(jobs, coordinates);
            Thread t = new Thread(worker);
            workers.add(worker);
            threads.add(t);
            t.start();
        }
        // Process the frames
        totalProgress = coordinates.size();
        stepProgress = Utils.getProgressInterval(totalProgress);
        progress = 0;
        coordinates.forEachKey(new TIntProcedure() {

            public boolean execute(int value) {
                put(jobs, value);
                return true;
            }
        });
        // Finish all the worker threads by passing in a null job
        for (int i = 0; i < threads.size(); i++) {
            put(jobs, -1);
        }
        // Wait for all to finish
        for (int i = 0; i < threads.size(); i++) {
            try {
                threads.get(i).join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            actualCoordinates.putAll(workers.get(i).coordinates);
        }
        threads.clear();
        IJ.showProgress(-1);
        IJ.showStatus("");
        setupProgress(total, prefix);
    }
    if (!batchMode)
        IJ.showStatus("Computing results ...");
    final ImageStack stack = imp.getImageStack();
    float background = 0;
    if (spotFilter.isAbsoluteIntensity()) {
        // To allow the signal factor to be computed we need to lower the image by the background so 
        // that the intensities correspond to the results amplitude.
        // Just assume the background is uniform.
        double sum = 0;
        for (PeakResult r : results) sum += r.getBackground();
        background = (float) (sum / results.size());
    }
    // Create a pool of workers
    final int nThreads = Prefs.getThreads();
    BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
    List<Worker> workers = new LinkedList<Worker>();
    List<Thread> threads = new LinkedList<Thread>();
    for (int i = 0; i < nThreads; i++) {
        Worker worker = new Worker(jobs, stack, spotFilter, background);
        Thread t = new Thread(worker);
        workers.add(worker);
        threads.add(t);
        t.start();
    }
    // Fit the frames
    for (int i = 1; i <= stack.getSize(); i++) {
        put(jobs, i);
    }
    // Finish all the worker threads by passing in a null job
    for (int i = 0; i < threads.size(); i++) {
        put(jobs, -1);
    }
    // Wait for all to finish
    for (int i = 0; i < threads.size(); i++) {
        try {
            threads.get(i).join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    threads.clear();
    if (Utils.isInterrupted())
        return null;
    if (!batchMode) {
        IJ.showProgress(-1);
        IJ.showStatus("Collecting results ...");
    }
    TIntObjectHashMap<FilterResult> filterResults = new TIntObjectHashMap<FilterResult>();
    time = 0;
    for (Worker w : workers) {
        time += w.time;
        filterResults.putAll(w.results);
    }
    // Show a table of the results
    BenchmarkFilterResult filterResult = summariseResults(filterResults, config, spotFilter, relativeDistances, batchSummary);
    if (!batchMode)
        IJ.showStatus("");
    return filterResult;
}
Also used : TIntProcedure(gnu.trove.procedure.TIntProcedure) ArrayList(java.util.ArrayList) PeakResult(gdsc.smlm.results.PeakResult) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) ImageStack(ij.ImageStack) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint) LinkedList(java.util.LinkedList) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap)

Example 4 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project mixcr by milaboratory.

the class FullSeqAssembler method calculateRawData.

public RawVariantsData calculateRawData(Supplier<OutputPort<VDJCAlignments>> alignments) {
    if (!sequenceToVariantId.isEmpty())
        throw new IllegalStateException();
    for (byte letter = 0; letter < NucleotideSequence.ALPHABET.basicSize(); letter++) {
        NucleotideSequence seq = new NucleotideSequence(new byte[] { letter });
        sequenceToVariantId.put(seq, letter);
        variantIdToSequence.put(letter, seq);
    }
    sequenceToVariantId.put(NucleotideSequence.EMPTY, NucleotideSequence.ALPHABET.basicSize());
    variantIdToSequence.put(NucleotideSequence.ALPHABET.basicSize(), NucleotideSequence.EMPTY);
    TIntIntHashMap coverage = new TIntIntHashMap();
    TIntObjectHashMap<TIntObjectHashMap<VariantAggregator>> variants = new TIntObjectHashMap<>();
    int nAlignments = 0;
    for (VDJCAlignments al : CUtils.it(alignments.get())) {
        ++nAlignments;
        for (PointSequence point : toPointSequences(al)) {
            int seqIndex = getVariantIndex(point.sequence.getSequence());
            coverage.adjustOrPutValue(point.point, 1, 1);
            TIntObjectHashMap<VariantAggregator> map = variants.get(point.point);
            if (map == null)
                variants.put(point.point, map = new TIntObjectHashMap<>());
            VariantAggregator var = map.get(seqIndex);
            if (var == null)
                map.put(point.point, var = new VariantAggregator());
            var.count += 1;
            var.sumQuality += 0x7F & point.quality;
        }
    }
    assert nAlignments > 0;
    long[] forSort = new long[coverage.size()];
    TIntIntIterator iterator = coverage.iterator();
    int i = 0;
    while (iterator.hasNext()) {
        iterator.advance();
        forSort[i++] = -((((long) iterator.value()) << 32) | iterator.key());
    }
    Arrays.sort(forSort);
    int[] pointsArray = Arrays.stream(forSort).mapToInt(l -> (int) (-l)).toArray();
    TIntIntHashMap revIndex = new TIntIntHashMap();
    for (int j = 0; j < pointsArray.length; j++) revIndex.put(pointsArray[j], j);
    int[] coverageArray = Arrays.stream(forSort).mapToInt(l -> (int) ((-l) >> 32)).toArray();
    int[][] packedData = new int[pointsArray.length][nAlignments];
    for (int[] aPackedData : packedData) Arrays.fill(aPackedData, -1);
    i = 0;
    for (VDJCAlignments al : CUtils.it(alignments.get())) {
        for (PointSequence point : toPointSequences(al)) {
            int pointIndex = revIndex.get(point.point);
            packedData[pointIndex][i] = (sequenceToVariantId.get(point.sequence.getSequence()) << 8) | (0xFF & point.quality);
        }
        i++;
    }
    return new RawVariantsData(nAlignments, pointsArray, coverageArray) {

        @Override
        OutputPort<int[]> createPort() {
            return CUtils.asOutputPort(Arrays.asList(packedData));
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) VDJCPartitionedSequence(com.milaboratory.mixcr.basictypes.VDJCPartitionedSequence) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) java.util(java.util) TObjectFloatHashMap(gnu.trove.map.hash.TObjectFloatHashMap) Clone(com.milaboratory.mixcr.basictypes.Clone) Supplier(java.util.function.Supplier) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) com.milaboratory.core.alignment(com.milaboratory.core.alignment) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) CloneFactory(com.milaboratory.mixcr.assembler.CloneFactory) MutationsBuilder(com.milaboratory.core.mutations.MutationsBuilder) Constants(gnu.trove.impl.Constants) io.repseq.core(io.repseq.core) Range(com.milaboratory.core.Range) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) CUtils(cc.redberry.pipe.CUtils) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) OutputPort(cc.redberry.pipe.OutputPort) Collectors(java.util.stream.Collectors) com.milaboratory.core.sequence(com.milaboratory.core.sequence) TIntHashSet(gnu.trove.set.hash.TIntHashSet) Joining(io.repseq.core.GeneType.Joining) Stream(java.util.stream.Stream) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit) VDJCGenes(io.repseq.gen.VDJCGenes) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) Variable(io.repseq.core.GeneType.Variable) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 5 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project Random-Things by lumien231.

the class PortKeyMesh method getModelLocation.

@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
    NBTTagCompound camo = stack.getSubCompound("camo");
    if (camo != null) {
        ItemStack camoStack = new ItemStack(camo.getCompoundTag("stack"));
        Item item = camoStack.getItem();
        int meta = camoStack.getItemDamage();
        Map<IRegistryDelegate<Item>, TIntObjectHashMap<ModelResourceLocation>> modelMap = ReflectionUtil.getModelMap();
        if (modelMap != null && modelMap.containsKey(item.delegate)) {
            TIntObjectHashMap<ModelResourceLocation> metaMap = modelMap.get(item.delegate);
            if (metaMap.contains(meta)) {
                return metaMap.get(meta);
            }
        }
    }
    return new ModelResourceLocation("randomthings:portkey");
}
Also used : Item(net.minecraft.item.Item) IRegistryDelegate(net.minecraftforge.registries.IRegistryDelegate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)42 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)12 List (java.util.List)11 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)10 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)9 TIntHashSet (gnu.trove.set.hash.TIntHashSet)8 IJ (ij.IJ)8 Prefs (ij.Prefs)8 PlugIn (ij.plugin.PlugIn)8 TextWindow (ij.text.TextWindow)8 Arrays (java.util.Arrays)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)8 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)8 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)8 TIntProcedure (gnu.trove.procedure.TIntProcedure)7