Skip to content

Commit

Permalink
feat: add and run script to get cellxgene collections linked to hca p…
Browse files Browse the repository at this point in the history
…rojects (#2364) (#2365)

* feat: add and run script to get cellxgene collections linked to hca projects (#2364)

* fix: project url regexp (#2364)
  • Loading branch information
hunterckx authored Feb 2, 2024
1 parent 88a04dc commit 0a493a6
Show file tree
Hide file tree
Showing 3 changed files with 394 additions and 1 deletion.
3 changes: 2 additions & 1 deletion next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"format": "prettier --write .",
"postbuild": "next-sitemap --config next-sitemap.config.mjs",
"prepare": "cd .. && husky install next/.husky",
"complete-biccn-publications": "esrun ./scripts/complete-biccn-publications.ts"
"complete-biccn-publications": "esrun ./scripts/complete-biccn-publications.ts",
"get-cellxgene-projects": "esrun ./scripts/get-cellxgene-projects.ts"
},
"dependencies": {
"@clevercanary/data-explorer-ui": "64.0.0",
Expand Down
42 changes: 42 additions & 0 deletions next/scripts/get-cellxgene-projects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fsp from "fs/promises";
import got from "got";

interface CellxGeneCollection {
collection_id: string;
links: { link_url: string }[];
}

interface CellxGeneProjectMapping {
cellxgeneId: string;
hcaProjectId: string;
}

const cellxgeneProjectsFilePath = "./scripts/out/cellxgene-projects.json";

getCellxGeneProjects();

async function getCellxGeneProjects(): Promise<void> {
const collections = JSON.parse(
(await got("https://api.cellxgene.cziscience.com/curation/v1/collections"))
.body
) as CellxGeneCollection[];
const cellxgeneProjects: CellxGeneProjectMapping[] = [];
for (const collection of collections) {
for (const { link_url } of collection.links) {
const match =
/^https:\/\/(?:explore\.)?data\.humancellatlas\.org(?:\/explore)?\/projects\/([^/?#]+)/.exec(
link_url
);
if (match)
cellxgeneProjects.push({
cellxgeneId: collection.collection_id,
hcaProjectId: match[1],
});
}
}
await fsp.writeFile(
cellxgeneProjectsFilePath,
JSON.stringify(cellxgeneProjects, undefined, 2)
);
console.log(`Saved to ${cellxgeneProjectsFilePath}`);
}
Loading

0 comments on commit 0a493a6

Please sign in to comment.