Skip to content

Commit

Permalink
finish drafting all supported tracks; browser events API
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 6efe242 commit 2fd541c
Showing 1 changed file with 97 additions and 9 deletions.
106 changes: 97 additions & 9 deletions js/igv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,41 @@ declare class Opaque<N extends string> {
private readonly __opaque_brand: N;
}

export type TrackType = "annotation" | "alignment" | "variant" | "seg" | "cnvpytor" | "wig" | "merged" | "gwas" | "mut";
export type TrackType =
"annotation" | "wig" | "alignment" | "variant" | "mut" | "seg" |
"gwas" | "interact" | "qtl" | "junction" | "cnvpytor" | "merged" | "arc";

export type TrackLoad<T extends TrackType> =
Tracks.TrackCommonOptions &
(T extends "annotation" ? (Tracks.AnnotationTrackOptions & Tracks.TypeFormatPair<'annotation', Tracks.AnnotationFormat>) :
T extends "wig" ? (Tracks.WigTrackOptions & Tracks.TypeFormatPair<'wig', Tracks.WigFormat>) :
T extends "merged" ? (Tracks.WigMergedTrackOptions & { type: 'merged' }) :
T extends "alignment" ? (Tracks.AlignmentTrackOptions & Tracks.TypeFormatPair<'alignment', Tracks.AlignmentFormat>) :
T extends "variabt" ? (Tracks.VariantTrackOptions & Tracks.TypeFormatPair<'variant', Tracks.VariantFormat>) :
T extends "variant" ? (Tracks.VariantTrackOptions & Tracks.TypeFormatPair<'variant', Tracks.VariantFormat>) :
T extends "mut" ? (Tracks.MutationTrackOptions & Tracks.TypeFormatPair<'mut', Tracks.MutationFormat>) :
T extends "seg" ? (Tracks.SegTrackOptions & Tracks.TypeFormatPair<'seg', Tracks.SegFormat>) :
T extends "cnvpytor" ? (Tracks.CnvPyTorTrackOptions & Tracks.TypeFormatPair<'cnvpytor', Tracks.CnvPyTorFormat>) :
T extends "gwas" ? (Tracks.GWASTrackOptions<Tracks.GWASFormat> & Tracks.TypeFormatPair<'gwas', Tracks.GWASFormat>) :
T extends "mut" ? (Tracks.MutationTrackOptions & Tracks.TypeFormatPair<'mut', Tracks.MutationFormat>) :
T extends "interact" ? (Tracks.InteractTrackOptions & Tracks.TypeFormatPair<'interact', Tracks.InteractFormat>) :
T extends "qtl" ? (Tracks.QTLTrackOptions & Tracks.TypeFormatPair<'qtl', Tracks.QTLFormat>) :
T extends "junction" ? (Tracks.JunctionTrackOptions & Tracks.TypeFormatPair<'junction', Tracks.JunctionFormat>) :
T extends "cnvpytor" ? (Tracks.CnvPyTorTrackOptions & Tracks.TypeFormatPair<'cnvpytor', Tracks.CnvPyTorFormat>) :
T extends "merged" ? (Tracks.WigMergedTrackOptions & { type: 'merged' }) :
T extends "arc" ? (Tracks.ArcTrackOptions & Tracks.TypeFormatPair<'arc', Tracks.ArcFormat>) :
never);

export type TrackOf<T extends TrackType> =
T extends "annotation" ? Tracks.Track :
T extends "wig" ? Tracks.Track :
T extends "alignment" ? Tracks.AlignmentTrack :
T extends "variant" ? Tracks.Track :
T extends "mut" ? Tracks.Track :
T extends "seg" ? Tracks.Track :
T extends "gwas" ? Tracks.Track :
T extends "interact" ? Tracks.Track :
T extends "qtl" ? Tracks.Track :
T extends "junction" ? Tracks.Track :
T extends "cnvpytor" ? Tracks.Track :
T extends "wig" ? Tracks.Track :
T extends "merged" ? Tracks.Track :
T extends "gwas" ? Tracks.Track :
T extends "mut" ? Tracks.Track :
T extends "arc" ? Tracks.Track :
never;


Expand Down Expand Up @@ -391,6 +401,59 @@ export namespace Tracks {
attribute: string;
});
}

export type InteractFormat = "interact" | "bedpe" | "bigInteract";

export type InteractTrackOptions = {
arcType?: "nested" | "proportional" | "inView" | "partialInView";
arcOrientation?: "UP" | "DOWN";
alpha?: number;
thickness?: number;
}

export type QTLFormat = "qtl";

export type QTLTrackOptions = {
min?: number;
max?: number;
autoscalePercentile?: number;
}

export type JunctionFormat = "bed";

export type JunctionTrackFilteringOptions = {
minUniquelyMappedReads?: number;
minTotalReads?: number;
maxFractionMultiMappedReads?: number;
minSplicedAlignmentOverhang?: number;
hideStrand?: "+" | "-";
hideAnnotatedJunctions?: boolean;
hideUnannotatedJunctions?: boolean;
hideMotifs?: string[];
}

export type JunctionTrackOptions = ({
colorBy?: "numUniqueReads" | "numReads";
colorByNumReadsThreshold: number;
} | {
colorBy: "isAnnotatedJunction" | "strand" | "motif";
colorByNumReadsThreshold?: never;
}) & {
thicknessBasedOn?: "numUniqueReads" | "numReads" | "isAnnotatedJunction";
bounceHeightBasedOn?: "random" | "distance" | "thickness";
labelUniqueReadCount?: boolean;
labelMultiMappedReadCount?: boolean;
labelTotalReadCount?: boolean;
labelMotif?: boolean;
labelAnnotatedJunction?: string | null;
minSplicedAlignmentOverhang?: number;
} & JunctionTrackFilteringOptions;

export type ArcFormat = "bp";

export type ArcTrackOptions = {
arcOrientation?: "UP" | "DOWN";
}
}

type Nucleotide = 'A' | 'C' | 'G' | 'T' | 'N';
Expand Down Expand Up @@ -542,6 +605,29 @@ interface CreateOptExtras {
tracks: TrackLoad<TrackType>[];
}

export namespace BrowserEvents {
export type EventType = "trackremoved" | "trackdrag" | "trackdragend" | "locuschange" | "trackclick" | "trackorderchanged";

export type EventPayload<T extends EventType> =
T extends "trackremoved" ? Tracks.Track[] :
T extends "locusChange" ? {
chr: string;
start: number;
end: number;
getLocusString: () => string;
}[] :
T extends "trackclick" ? {
name: string;
value: string;
} :
T extends "trackorderchanged" ? string[] :
never;

export type EventReturn<T extends EventType> =
T extends "trackclick" ? boolean :
void;
}

export type CreateOpt = GenomeOpt & CreateOptExtras;

declare class ROISet {
Expand All @@ -566,7 +652,6 @@ declare class _Browser {
loadGenome(genome: string | ReferenceGenome): Promise<void>;
loadSessionObject(session: Opaque<'igv.js session JSON'>): void;
loadSession(session: string): void;
// TODO: check the return type
loadTrack<T extends TrackType>(track: TrackLoad<T>): Promise<TrackOf<T>>;
loadSampleInfo({ url: string }): void;
findTracks(func: (track: Tracks.Track) => boolean): Tracks.Track[];
Expand All @@ -589,6 +674,9 @@ declare class _Browser {
end: number,
interpolant: number,
}) => void): void;

on<T extends BrowserEvents.EventType>(event: T, handler: (payload: BrowserEvents.EventPayload<T>) => BrowserEvents.EventReturn<T>): void;
off(event: BrowserEvents.EventType): void;
}

export type Browser = _Browser;
Expand Down

0 comments on commit 2fd541c

Please sign in to comment.