Skip to content

Commit

Permalink
type inference helpers for converting options to tracks
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Sep 2, 2024
1 parent 3629e90 commit 1ff7e16
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions js/igv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ declare class Opaque<N extends string> {
private readonly __opaque_brand: N;
}

export type TrackLoad = Tracks.TrackCommonOptions &
export type TrackLoad =
Tracks.TrackCommonOptions &
((Tracks.AnnotationTrackOptions & Tracks.TypeFormatPair<'annotation', Tracks.AnnotationFormat>) |
(Tracks.WigTrackOptions & Tracks.TypeFormatPair<'wig', Tracks.WigFormat>) |
(Tracks.WigMergedTrackOptions & { type: 'merged' }) |
Expand All @@ -15,8 +16,20 @@ export type TrackLoad = Tracks.TrackCommonOptions &
(Tracks.SegTrackOptions & Tracks.TypeFormatPair<'seg', Tracks.SegTrackFormat>) |
(Tracks.CnvPyTorTrackOptions & Tracks.TypeFormatPair<'cnvpytor', Tracks.CnvPyTorFormat>));

export type TrackOf<T extends string> =
T extends "annotation" ? Tracks.Track :
T extends "alignment" ? Tracks.AlignmentTrack :
T extends "variant" ? Tracks.Track :
T extends "seg" ? Tracks.Track :
T extends "cnvpytor" ? Tracks.Track :
T extends "wig" ? Tracks.Track :
T extends "merged" ? Tracks.Track :
never;

export type TrackOfLoad<K extends TrackLoad> = K extends { type: infer T } ? T extends string ? TrackOf<T> : never : never;

export namespace Tracks {
export declare class Track { }; \
export class Track { }

export interface TypeFormatPair<K extends string, F extends string> {
type?: K;
Expand Down Expand Up @@ -314,7 +327,6 @@ export namespace Tracks {
"strand" | "firstOfPairStrand" | "pairOrientation" | "mateChr" | "chimeric" | "supplementary" | "readOrder" | AlignmentBy;
samplingWindowSize?: number;
samplingDepth?: number;
alignmentRowHeight?: number;
readGroup?: string;
sort: AlignmentSortOptions;
filter: {
Expand Down Expand Up @@ -347,17 +359,17 @@ export namespace Tracks {
)


export declare class AlignmentTrack extends Track {
class AlignmentTrack extends Track {
setHighlightedReads(readNames: string[], color: string): void;
sort(options: AlignmentSortOptions): void;
};
}
}

type Nucleotide = 'A' | 'C' | 'G' | 'T' | 'N';
type AnnotationFormat = 'bed' | 'gff3' | 'gtf' | 'genePred' | 'genePredExt' | 'peaks' | 'narrowPeak' | 'broadPeak' | 'bigBed' | 'bedpe';

interface GenomeNoRef {
genome: string;
genome: HostedGenomes | (string & {});
reference?: never;
}

Expand Down Expand Up @@ -520,17 +532,18 @@ interface DefineROI {
color: string;
}


declare class _Browser {
currentLoci(): string[] | string;
loadGenome(genome: string | ReferenceGenome): Promise<void>;
loadSessionObject(session: Opaque<'igv.js session JSON'>): void;
loadSession(session: string): void;
// TODO: check the return type
loadTrack(track: TrackLoad): Promise<any>;
loadTrack(track: TrackLoad): Promise<Tracks.Track>;
loadSampleInfo({ url: string }): void;
findTracks(func: (track: Track) => boolean): Track[];
findTracks(property: string, value: any): Track[];
removeTrack(track: Track): void;
findTracks(func: (track: Tracks.Track) => boolean): Tracks.Track[];
findTracks(property: string, value: any): Tracks.Track[];
removeTrack(track: Tracks.Track): void;
removeTrackByName(trackName: string): void;
loadROI(roi: DefineROI | DefineROI[]): void;
clearROIs(): void;
Expand Down

0 comments on commit 1ff7e16

Please sign in to comment.