Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entropy types #1915

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
34 changes: 27 additions & 7 deletions src/util/entropyCreateStateFromJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const entropyCreateState = (genomeAnnotations: JsonAnnotations) => {
};


function validColor(color:(string|undefined)) {
function validColor(color: string | undefined) {
if (!color) return false;
return color; // TODO XXX
}
Expand All @@ -184,7 +184,12 @@ function* nextColorGenerator() {
/**
* Returns a CDS object parsed from the provided JsonAnnotation block
*/
function cdsFromAnnotation(cdsName: string, annotation: JsonAnnotation, rangeGenome: RangeGenome, defaultColor: (string|void)): CDS {
function cdsFromAnnotation(
cdsName: string,
annotation: JsonAnnotation,
rangeGenome: RangeGenome,
defaultColor: string | void,
): CDS {
const invalidCds: CDS = {
name: '__INVALID__',
length: 0,
Expand Down Expand Up @@ -296,7 +301,13 @@ function cdsFromAnnotation(cdsName: string, annotation: JsonAnnotation, rangeGen
* positiveStrand: boolean
* Returns a number in the set {0, 1, 2}
*/
function _frame(start:number, end:number, phase: number, genomeLength:number, positiveStrand:boolean) {
function _frame(
start: number,
end: number,
phase: number,
genomeLength: number,
positiveStrand: boolean,
) {
return positiveStrand ?
(start+phase-1)%3 :
Math.abs((end-phase-genomeLength)%3);
Expand All @@ -309,7 +320,10 @@ function _frame(start:number, end:number, phase: number, genomeLength:number, po
* refers to this being a stacking problem.) The stack position starts at 1.
* Returns the maximum position observed.
*/
function calculateStackPosition(genes: Gene[], strand: (Strand|null) = null):number {
function calculateStackPosition(
genes: Gene[],
strand: Strand | null = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to a previous comment, null is probably not the right choice here (as it's a schema-valid strand). By the time this function is called we have already created cds objects (cdsFromAnnotation) and so restricted the strand to +/-, so in practice it doesn't mater. I'd suggest

  • (a) requiring the argument (and thus getting rid of the conditional if (strand) below)

and, potentially,

  • (b) using a more restricted type definition.

): number {
/* List of CDSs, sorted by their earliest occurrence in the genome (for any segment) */
let cdss = genes.reduce((acc: CDS[], gene) => [...acc, ...gene.cds], []);
if (strand) {
Expand Down Expand Up @@ -359,7 +373,7 @@ function calculateStackPosition(genes: Gene[], strand: (Strand|null) = null):num
* Given an array of sorted integers, if there are any spaces (starting with 1)
* then return the value which can fill that space. Returns 0 if no spaces.
*/
function _emptySlots(values: number[]):number {
function _emptySlots(values: number[]): number {
if ((values[0] || 0) > 1) return 1;
for (let i=1; i<values.length; i++) {
/* intermediate variables because of https://github.com/microsoft/TypeScript/issues/46253 */
Expand All @@ -374,7 +388,10 @@ function _emptySlots(values: number[]):number {
* between-segment space of an existing segment, then return the stackPosition
* of that existing CDS. Otherwise return 0;
*/
function _fitCdssTogether(existing: CDS[], newCds: CDS):number {
function _fitCdssTogether(
existing: CDS[],
newCds: CDS,
): number {
const a = Math.min(...newCds.segments.map((s) => s.rangeGenome[0]));
const b = Math.max(...newCds.segments.map((s) => s.rangeGenome[1]));
for (const cds of existing) {
Expand Down Expand Up @@ -409,7 +426,10 @@ function _fitCdssTogether(existing: CDS[], newCds: CDS):number {


/* Does a CDS wrap the origin? */
function _isCdsWrapping(strand: Strand, segments: CdsSegment[]): boolean {
function _isCdsWrapping(
strand: Strand,
segments: CdsSegment[],
): boolean {
const positive = strand==='+';
// segments ordered to guarantee rangeLocal will always be greater (than the previous segment)
let prevSegment;
Expand Down