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

feat: add entry point for using experimental plugin data fetchers #760

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions schema/gosling.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@
},
{
"$ref": "#/definitions/VCFData"
},
{
"$ref": "#/definitions/PluginData"
}
]
},
Expand Down Expand Up @@ -5562,6 +5565,30 @@
},
"type": "object"
},
"PluginData": {
"additionalProperties": false,
"description": "A data spec to use plugin data fetcher that are defined externally",
"properties": {
"name": {
"description": "The name of the plugin data that should match the `type` of a plugin data fetcher",
"type": "string"
},
"options": {
"description": "All custom options used in the plugin data fetcher",
"type": "object"
},
"type": {
"const": "experimentalPlugin",
"type": "string"
}
},
"required": [
"type",
"name",
"options"
],
"type": "object"
},
"PredefinedColors": {
"enum": [
"viridis",
Expand Down
33 changes: 15 additions & 18 deletions src/core/gosling-to-higlass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,21 @@ export function goslingToHiGlass(
}
};

if (
firstResolvedSpec.data &&
IsDataDeep(firstResolvedSpec.data) &&
(firstResolvedSpec.data.type === 'csv' ||
firstResolvedSpec.data.type === 'json' ||
firstResolvedSpec.data.type === 'bigwig' ||
firstResolvedSpec.data.type === 'bam' ||
firstResolvedSpec.data.type === 'vcf')
) {
// use gosling's custom data fetchers
hgTrack.data = {
...firstResolvedSpec.data,
// Additionally, add assembly, otherwise, a default genome build is used
assembly
// TODO: should look all sub tracks' `dataTransform` and apply OR operation.
// Add a data transformation spec so that the fetcher can properly sample datasets
// filter: (firstResolvedSpec as any).dataTransform?.filter((f: DataTransform) => f.type === 'filter')
};
if (firstResolvedSpec.data && IsDataDeep(firstResolvedSpec.data)) {
const dataType = firstResolvedSpec.data.type;
if (
dataType === 'csv' ||
dataType === 'json' ||
dataType === 'bigwig' ||
dataType === 'bam' ||
dataType === 'vcf'
) {
// This means we use data fetchers that are implemented in Gosling
hgTrack.data = { ...firstResolvedSpec.data, assembly };
} else if (dataType === 'experimentalPlugin') {
// This means we use an external data fetcher that a user implemented
hgTrack.data = { ...firstResolvedSpec.data.options, type: firstResolvedSpec.data.name, assembly };
}
}

// We use higlass 'heatmap' track instead of 'gosling-track' for rendering performance.
Expand Down
15 changes: 14 additions & 1 deletion src/core/gosling.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ export type DataDeep =
| VectorData
| MatrixData
| BAMData
| VCFData;
| VCFData
| PluginData;

/** Values in the form of JSON. */
export interface Datum {
Expand Down Expand Up @@ -1058,6 +1059,18 @@ export interface MatrixData {
binSize?: number;
}

/** A data spec to use plugin data fetcher that are defined externally */
export interface PluginData {
// TODO (7-Jul-2022): change to 'plugin' for official support
type: 'experimentalPlugin';

/** The name of the plugin data that should match the `type` of a plugin data fetcher */
name: string;

/** All custom options used in the plugin data fetcher */
options: Record<string, any>;
}

/* ----------------------------- DATA TRANSFORM ----------------------------- */

export type DataTransform =
Expand Down