use of gnu.trove.map.hash.TObjectLongHashMap in project spf4j by zolyfarkas.
the class GCUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder gcUsage = RecorderFactory.createDirectRecorder("gc-time", "ms", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private final TObjectLongMap lastValues = new TObjectLongHashMap();
@Override
public void doRun() {
synchronized (lastValues) {
gcUsage.record(getGCTimeDiff(MBEANS, lastValues));
}
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("GC usage sampling already started " + samplingFuture);
}
}
use of gnu.trove.map.hash.TObjectLongHashMap in project mixcr by milaboratory.
the class AlignedTarget method orderTargets.
public static List<AlignedTarget> orderTargets(List<AlignedTarget> targets) {
// Selecting best gene by total score
final EnumMap<GeneType, VDJCGene> bestGenes = new EnumMap<>(GeneType.class);
for (GeneType geneType : GeneType.VDJC_REFERENCE) {
TObjectLongMap<VDJCGene> scores = new TObjectLongHashMap<>();
for (AlignedTarget target : targets) {
for (VDJCHit hit : target.getAlignments().getHits(geneType)) {
Alignment<NucleotideSequence> alignment = hit.getAlignment(target.getTargetId());
if (alignment != null)
scores.adjustOrPutValue(hit.getGene(), (long) alignment.getScore(), (long) alignment.getScore());
}
}
VDJCGene bestGene = null;
long bestScore = Long.MIN_VALUE;
TObjectLongIterator<VDJCGene> it = scores.iterator();
while (it.hasNext()) {
it.advance();
if (bestScore < it.value()) {
bestScore = it.value();
bestGene = it.key();
}
}
if (bestGene != null)
bestGenes.put(geneType, bestGene);
}
// Class to facilitate comparison between targets
final class Wrapper implements Comparable<Wrapper> {
final AlignedTarget target;
final EnumMap<GeneType, Alignment<NucleotideSequence>> alignments = new EnumMap<>(GeneType.class);
Wrapper(AlignedTarget target) {
this.target = target;
for (VDJCGene gene : bestGenes.values()) for (VDJCHit hit : target.getAlignments().getHits(gene.getGeneType())) if (hit.getGene() == gene) {
Alignment<NucleotideSequence> alignment = hit.getAlignment(target.targetId);
if (alignment != null) {
alignments.put(gene.getGeneType(), alignment);
break;
}
}
}
GeneType firstAlignedGeneType() {
for (GeneType geneType : GeneType.VDJC_REFERENCE) if (alignments.containsKey(geneType))
return geneType;
return null;
}
@Override
public int compareTo(Wrapper o) {
GeneType thisFirstGene = firstAlignedGeneType();
GeneType otherFirstGene = o.firstAlignedGeneType();
int cmp = Byte.compare(thisFirstGene.getOrder(), otherFirstGene.getOrder());
return cmp != 0 ? cmp : Integer.compare(alignments.get(thisFirstGene).getSequence1Range().getLower(), o.alignments.get(thisFirstGene).getSequence1Range().getLower());
}
}
// Creating wrappers and sorting list
List<Wrapper> wrappers = new ArrayList<>(targets.size());
for (AlignedTarget target : targets) {
Wrapper wrapper = new Wrapper(target);
if (wrapper.firstAlignedGeneType() == null)
continue;
wrappers.add(wrapper);
}
Collections.sort(wrappers);
// Creating result
List<AlignedTarget> result = new ArrayList<>(wrappers.size());
for (Wrapper wrapper : wrappers) result.add(wrapper.target);
return result;
}
Aggregations