@jbrowse/plugin-linear-genome-view
Version:
JBrowse 2 linear genome view
41 lines (40 loc) • 1.37 kB
JavaScript
import { getContainingView, getSession } from '@jbrowse/core/util';
import { getRpcSessionId } from '@jbrowse/core/util/tracks';
import { isAlive } from 'mobx-state-tree';
export function getDisplayStr(totalBytes) {
if (Math.floor(totalBytes / 1000000) > 0) {
return `${Number.parseFloat((totalBytes / 1000000).toPrecision(3))} Mb`;
}
else if (Math.floor(totalBytes / 1000) > 0) {
return `${Number.parseFloat((totalBytes / 1000).toPrecision(3))} Kb`;
}
else {
return `${Math.floor(totalBytes)} bytes`;
}
}
export function getId(id, index) {
const notJest = typeof jest === 'undefined';
return ['clip', notJest ? id : 'jest', index, notJest ? Math.random() : '']
.filter(f => !!f)
.join('-');
}
export async function getFeatureDensityStatsPre(self) {
const view = getContainingView(self);
const regions = view.staticBlocks.contentBlocks;
const { rpcManager } = getSession(self);
const { adapterConfig } = self;
if (!adapterConfig) {
return {};
}
const sessionId = getRpcSessionId(self);
return rpcManager.call(sessionId, 'CoreGetFeatureDensityStats', {
sessionId,
regions,
adapterConfig,
statusCallback: (message) => {
if (isAlive(self)) {
self.setMessage(message);
}
},
});
}