dvdkouril / chromospace

🧬🚀 visualizing chromatin in space
https://chromospace.org/
MIT License
1 stars 0 forks source link

Better ergonomics for top-level library API #1

Closed dvdkouril closed 5 months ago

dvdkouril commented 8 months ago

Using the library in computational notebook context makes me really think differently about the API: Before:

const urlTan2018 = "https://datapath";
const fileTan2018 = await fetchTsv(urlTan2018);
const tab2018Model = parse3dg(fileTan2018 , { center: true, normalize: true }); 

//~ create a scene
let chromatinScene = {
    chunks: [],
    models: [],
};

const renderer = new ChromatinBasicRenderer();
renderer.addScene(chromatinScene);
renderer.startDrawing();
const canvas = renderer.getCanvasElement();
return canvas;

Better:

const urlTan2018 = "https://datapath";
const fileTan2018 = await fetchTsv(urlTan2018);
const tab2018Model = parse3dg(fileTan2018 , { center: true, normalize: true }); 

//~ create a scene
let chromatinScene = {
    chunks: [],
    models: [tab2018Model],
};

//~ This will go somewhere in the library
const display = (scene: ChromatinScene) => {
    const renderer = new ChromatinBasicRenderer();
    renderer.addScene(chromatinScene);
    renderer.startDrawing();
    const canvas = renderer.getCanvasElement();
    return canvas;
};

return display(chromatinScene);

Better (gosling-ready):

const config = {
    scenes: [
        {
            chunks: [
                {
                    url: "https://chunkurl",
                    representation: "balls",
                    ...
                },
            ],
            models: [
                {
                    url: "https://modelpath",
                    representation: "balls-and-stick",
                    ...
                }
            ]
        },
    ],
    camera: {...},
    cuttingPlanes: {...},
};
return displayView(config);
dvdkouril commented 5 months ago

Some aspects of this have been addressed, some don't make sense anymore.