Skip to content

Commit

Permalink
chore: working on compiler for axis-independent scales
Browse files Browse the repository at this point in the history
  • Loading branch information
sehilyi committed Aug 24, 2021
1 parent 8ab7ee9 commit 890e0b5
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 101 deletions.
3 changes: 3 additions & 0 deletions schema/gosling.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
"items": {
"additionalProperties": false,
"properties": {
"assembly": {
"$ref": "#/definitions/Assembly"
},
"chromosomeField": {
"type": "string"
},
Expand Down
111 changes: 62 additions & 49 deletions src/core/example/hg-view-config-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const example = {
options: {
layout: 'linear',
innerRadius: null,
width: 400,
width: 1000,
height: 44,
theme: {
base: 'light',
Expand Down Expand Up @@ -286,7 +286,7 @@ const example = {
contents: [
{
type: 'gosling-track',
width: 400,
width: 1000,
height: 14,
options: {
showMousePosition: true,
Expand All @@ -313,10 +313,10 @@ const example = {
x: {
field: 'chromStart',
type: 'genomic',
domain: {
chromosome: '17',
interval: [20000000, 50000000]
},
// domain: {
// chromosome: '17',
// interval: [20000000, 50000000]
// },
linkingId: 'top',
axis: 'top'
},
Expand All @@ -325,7 +325,7 @@ const example = {
size: { value: 14 },
stroke: { value: 'black' },
strokeWidth: { value: 0.5 },
width: 400,
width: 1000,
height: 44,
overlay: [
{
Expand Down Expand Up @@ -631,8 +631,8 @@ const example = {
gallery: [],
whole: []
},
initialXDomain: [2510780562, 2540780562],
initialYDomain: [2510780562, 2540780562],
initialXDomain: [0, 3088269832],
initialYDomain: [0, 3088269832],
zoomFixed: false,
zoomLimits: [1, null],
uid: 'view-1',
Expand All @@ -653,13 +653,30 @@ const example = {
center: [
{
type: 'combined',
width: 399,
height: 400,
width: 999,
height: 430,
contents: [
{
type: 'gosling-2d-track',
width: 400,
height: 400,
width: 1000,
height: 430,
data: {
url:
'https://s3.amazonaws.com/gosling-lang.org/data/ideogram.js/homo_sapiens-mus_musculus-synteny-v73-adjusted.tsv',
type: 'csv',
genomicFieldsToConvert: [
{
chromosomeField: 'Chromosome_spec1',
genomicFields: ['Start_spec1', 'End_spec1']
},
{
chromosomeField: 'Chromosome_spec2',
genomicFields: ['Start_spec2', 'End_spec2']
}
],
separator: '\t',
assembly: 'hg38'
},
options: {
showMousePosition: true,
mousePositionColor: '#000000',
Expand All @@ -676,7 +693,7 @@ const example = {
backgroundColor: 'transparent',
spec: {
layout: 'linear',
xDomain: { chromosome: '1' },
// xDomain: { chromosome: '1' },
assembly: 'hg38',
orientation: 'horizontal',
static: false,
Expand All @@ -686,32 +703,39 @@ const example = {
style: { outlineWidth: 0 },
data: {
url:
'https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt',
'https://s3.amazonaws.com/gosling-lang.org/data/ideogram.js/homo_sapiens-mus_musculus-synteny-v73-adjusted.tsv',
type: 'csv',
headerNames: ['id', 'chr', 'p1', 'p2'],
chromosomePrefix: 'hs',
chromosomeField: 'chr',
genomicFields: ['p1', 'p2'],
separator: ' ',
longToWideId: 'id'
genomicFieldsToConvert: [
{
chromosomeField: 'Chromosome_spec1',
genomicFields: ['Start_spec1', 'End_spec1']
},
{
chromosomeField: 'Chromosome_spec2',
genomicFields: ['Start_spec2', 'End_spec2']
}
],
separator: '\t',
assembly: 'hg38'
},
mark: 'betweenLink',
x: {
field: 'p1',
field: 'Start_spec1',
type: 'genomic',
axis: 'none',
linkingId: 'top',
domain: { chromosome: '1' }
linkingId: 'top'
// domain: { chromosome: '1' }
},
xe: { field: 'p2', type: 'genomic' },
xe: { field: 'End_spec1', type: 'genomic' },
x1: {
field: 'p1_2',
field: 'Start_spec2',
type: 'genomic',
linkingId: 'bottom'
},
x1e: { field: 'p2_2', type: 'genomic' },
stroke: {
field: 'chr',
x1e: { field: 'End_spec2', type: 'genomic' },
strokeWidth: { value: 0 },
color: {
field: 'Chromosome_spec1',
type: 'nominal',
domain: [
'chr1',
Expand Down Expand Up @@ -741,8 +765,8 @@ const example = {
]
},
opacity: { value: 0.5 },
width: 400,
height: 400,
width: 1000,
height: 430,
overlayOnPreviousTrack: false
},
theme: {
Expand Down Expand Up @@ -986,17 +1010,6 @@ const example = {
quantitativeSizeRange: [2, 6]
}
}
},
data: {
url: 'https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt',
type: 'csv',
headerNames: ['id', 'chr', 'p1', 'p2'],
chromosomePrefix: 'hs',
chromosomeField: 'chr',
genomicFields: ['p1', 'p2'],
separator: ' ',
longToWideId: 'id',
assembly: 'hg38'
}
}
]
Expand All @@ -1007,7 +1020,7 @@ const example = {
gallery: [],
whole: []
},
initialXDomain: [1, 248956422],
initialXDomain: [1, 3088269832],
initialYDomain: [0, 3088269832],
zoomFixed: false,
zoomLimits: [1, null],
Expand All @@ -1029,12 +1042,12 @@ const example = {
center: [
{
type: 'combined',
width: 399,
width: 999,
height: 14,
contents: [
{
type: 'gosling-track',
width: 400,
width: 1000,
height: 14,
options: {
showMousePosition: true,
Expand Down Expand Up @@ -1062,15 +1075,15 @@ const example = {
field: 'chromStart',
type: 'genomic',
axis: 'bottom',
domain: { chromosome: '3' },
// domain: { chromosome: '3' },
linkingId: 'bottom'
},
xe: { field: 'chromEnd', type: 'genomic' },
color: { value: 'white' },
size: { value: 14 },
stroke: { value: 'black' },
strokeWidth: { value: 0.5 },
width: 400,
width: 1000,
height: 44,
overlay: [
{
Expand Down Expand Up @@ -1640,8 +1653,8 @@ const example = {
gallery: [],
whole: []
},
initialXDomain: [491149952, 689445510],
initialYDomain: [491149952, 689445510],
initialXDomain: [0, 3088269832],
initialYDomain: [0, 3088269832],
zoomFixed: false,
zoomLimits: [1, null],
uid: 'view-3'
Expand Down
6 changes: 5 additions & 1 deletion src/core/gosling-to-higlass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ export function goslingToHiGlass(
.adjustDomain(gosTrack.orientation, width, height)
.setMainTrack(hgTrack)
.addTrackSourceServers(server)
.setZoomFixed(firstResolvedSpec.static === true)
.setZoomFixed(
Is2DTrack(firstResolvedSpec) && firstResolvedSpec.mark === 'betweenLink'
? true
: firstResolvedSpec.static === true
)
.setLayout(layout);
}

Expand Down
18 changes: 18 additions & 0 deletions src/core/gosling.schema.guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ export function Is2DTrack(track: Track) {
);
}

/**
* Is this a between link view with two independent axes?
* TODO: should we include orthorgonal view that use both x and y for genomics fields?
*/
export function IsConnectorView(track: Track) {
return (
IsSingleTrack(track) &&
track.mark === 'betweenLink' &&
IsChannelDeep(track['x']) &&
track['x'].type === 'genomic' &&
IsChannelDeep(track['x1']) &&
track['x1'].type === 'genomic' &&
track['x'].linkingId &&
track['x1'].linkingId &&
track['x'].linkingId !== track['x1'].linkingId
);
}

export function IsChannelValue(
channel: ChannelDeep | ChannelValue | ChannelBind | undefined | 'none'
): channel is ChannelValue {
Expand Down
1 change: 1 addition & 0 deletions src/core/gosling.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export interface CSVData {
genomicFieldsToConvert?: {
chromosomeField: string;
genomicFields: string[];
assembly?: Assembly;
}[];
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/higlass.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface GenericLocks {
}

export interface LocksByViewUid {
[k: string]: string;
[k: string]: any; // string | { [k: string]: { lock: string, axis: string } };
}

export interface ValueScaleLocks {
Expand Down
58 changes: 41 additions & 17 deletions src/core/layout/higlass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ export function renderHiGlass(
theme: CompleteThemeDeep
) {
if (trackInfos.length === 0) {
// no tracks to render
// no tracks to render, so no point to render HiGlass.
return;
}

// HiGlass model
/* Generate/update the HiGlass model by iterating tracks */
const hgModel = new HiGlassModel();

/* Update the HiGlass model by iterating tracks */
trackInfos.forEach(tb => {
const { track, boundingBox: bb, layout } = tb;
goslingToHiGlass(hgModel, track, bb, layout, theme);
Expand All @@ -29,8 +27,7 @@ export function renderHiGlass(
/* Add linking information to the HiGlass model */
const linkingInfos = getLinkingInfo(hgModel);

// Brushing
// (between a view with `brush` and a view having the same linking name)
/* Linking between a brush and a view */
linkingInfos
.filter(d => d.isBrush)
.forEach(info => {
Expand All @@ -43,33 +40,60 @@ export function renderHiGlass(
);
});

// location/zoom lock information
// fill `locksByViewUid`
/*
* Linking zoom levels between views
*/

// Set `locksByViewUid`
linkingInfos
.filter(d => !d.isBrush)
.forEach(d => {
hgModel.spec().zoomLocks.locksByViewUid[d.viewId] = d.linkId;
hgModel.spec().locationLocks.locksByViewUid[d.viewId] = d.linkId;
hgModel.spec().zoomLocks.locksByViewUid[d.viewId] = d.zoomLinkingId;
});

// fill `locksDict`
const uniqueLinkIds = Array.from(new Set(linkingInfos.map(d => d.linkId)));
// Set `locksDict`
const uniqueZoomLinkIds = Array.from(new Set(linkingInfos.map(d => d.zoomLinkingId)));
uniqueZoomLinkIds.forEach(zoomLinkingId => {
hgModel.spec().zoomLocks.locksDict[zoomLinkingId] = { uid: zoomLinkingId };
linkingInfos
.filter(d => !d.isBrush)
.filter(d => d.zoomLinkingId === zoomLinkingId)
.forEach(d => {
hgModel.spec().zoomLocks.locksDict[zoomLinkingId][d.viewId] = [124625310.5, 124625310.5, 249250.621];
});
});

/*
* Linking locations between views
*/

uniqueLinkIds.forEach(linkId => {
hgModel.spec().zoomLocks.locksDict[linkId] = { uid: linkId };
hgModel.spec().locationLocks.locksDict[linkId] = { uid: linkId };
// Set `locksByViewUid`
linkingInfos
.filter(d => !d.isBrush)
.forEach(d => {
if (!hgModel.spec().locationLocks.locksByViewUid[d.viewId]) {
hgModel.spec().locationLocks.locksByViewUid[d.viewId] = {};
}
hgModel.spec().locationLocks.locksByViewUid[d.viewId][d.channel === 'x' ? 'x' : 'y'] = {
lock: d.linkId,
axis: d.viewId === 'view-3' ? 'y' : 'x'
};
});

// Set `locksDict`
const uniqueLocationLinkIds = Array.from(new Set(linkingInfos.map(d => d.linkId)));
uniqueLocationLinkIds.forEach(linkId => {
hgModel.spec().locationLocks.locksDict[linkId] = { uid: linkId };
linkingInfos
.filter(d => !d.isBrush)
.filter(d => d.linkId === linkId)
.forEach(d => {
hgModel.spec().zoomLocks.locksDict[linkId][d.viewId] = [124625310.5, 124625310.5, 249250.621];
hgModel.spec().locationLocks.locksDict[linkId][d.viewId] = [124625310.5, 124625310.5, 249250.621];
});
});

// !! Uncomment the following code to test with specific HiGlass viewConfig
hgModel.setExampleHiglassViewConfig();
// hgModel.setExampleHiglassViewConfig();

setHg(hgModel.spec(), getBoundingBox(trackInfos));
}
Loading

0 comments on commit 890e0b5

Please sign in to comment.