UNPKG

@rcsb/rcsb-saguaro-app

Version:
46 lines 1.41 kB
import { Assertions } from "../Helpers/Assertions"; var assertElementListDefined = Assertions.assertElementListDefined; var assertDefined = Assertions.assertDefined; export class Logo { constructor(logo) { this.symbols = Object(); this.n = 0; assertElementListDefined(logo); logo.forEach(s => { assertDefined(s.symbol); assertDefined(s.value); this.symbols[s.symbol] = s.value; this.n += s.value; }); } aaTypes() { return Object.keys(this.symbols); } /*add(aa: T): void{ this.symbols[aa] ++; this.n ++; }*/ get(aa) { const n = this.symbols[aa]; assertDefined(n); return n; } total() { return this.n; } forEach(callback) { this.aaTypes().forEach((aa, n) => { callback(aa, n); }); } mode() { return this.aaTypes().sort((a, b) => (this.symbols[b] - this.symbols[a]))[0]; } frequency() { return this.aaTypes().sort((a, b) => (this.symbols[b] - this.symbols[a])).map(a => ({ symbol: a, value: this.get(a) / this.n })); } entropy() { return -this.aaTypes().map(aa => (this.get(aa) != 0 ? (this.get(aa) / this.n) * (Math.log(this.get(aa) / this.n) / Math.log(this.aaTypes().length)) : 0)).reduce((p, v) => (p + v)); } } //# sourceMappingURL=Logo.js.map