-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77c4e8c
commit 7fa64ff
Showing
16 changed files
with
438 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,27 @@ | ||
import { execFile as callbackExecFile } from 'node:child_process'; | ||
import { promisify } from 'node:util'; | ||
import { getSrcFilePath } from '../util/paths.js'; | ||
import { Config } from '../util/config.js'; | ||
import { FORCE } from '../util/constants.js'; | ||
import { downloadFile } from '../util/fs.js'; | ||
import { IDownloader } from '../util/handler.js'; | ||
import { getMetadataLookup } from './metadata.js'; | ||
import { XConsortiaDownloader } from '../xconsortia/downloader.js'; | ||
import { getMetadata } from '../xconsortia/metadata.js'; | ||
import { ID_KEYWORD, METADATA_FIELDS, metadataToLookup } from './metadata.js'; | ||
|
||
const HUBMAP_TOKEN = 'HUBMAP_TOKEN'; | ||
const HUBMAP_SEARCH_URL = 'HUBMAP_SEARCH_URL'; | ||
const HUBMAP_ASSETS_URL = 'HUBMAP_ASSETS_URL'; | ||
const DEFAULT_HUBMAP_SEARCH_URL = | ||
'https://search.api.hubmapconsortium.org/v3/portal/search'; | ||
const DEFAULT_HUBMAP_SEARCH_URL = 'https://search.api.hubmapconsortium.org/v3/portal/search'; | ||
const DEFAULT_HUBMAP_ASSETS_URL = 'https://assets.hubmapconsortium.org/'; | ||
|
||
const execFile = promisify(callbackExecFile); | ||
|
||
/** @implements {IDownloader} */ | ||
export class Downloader { | ||
export class Downloader extends XConsortiaDownloader { | ||
constructor(config) { | ||
/** @type {Config} */ | ||
this.config = config; | ||
/** @type {string} */ | ||
this.token = config.get(HUBMAP_TOKEN); | ||
/** @type {string} */ | ||
this.searchUrl = config.get(HUBMAP_SEARCH_URL, DEFAULT_HUBMAP_SEARCH_URL); | ||
/** @type {string} */ | ||
this.assetsUrl = config.get(HUBMAP_ASSETS_URL, DEFAULT_HUBMAP_ASSETS_URL); | ||
this.exprAdjustScript = 'expr_h5ad_adjust.py'; | ||
/** @type {string} */ | ||
this.exprAdjustScriptFilePath = getSrcFilePath( | ||
super( | ||
config, | ||
'hubmap', | ||
this.exprAdjustScript | ||
config.get(HUBMAP_TOKEN), | ||
config.get(HUBMAP_SEARCH_URL, DEFAULT_HUBMAP_SEARCH_URL), | ||
config.get(HUBMAP_ASSETS_URL, DEFAULT_HUBMAP_ASSETS_URL) | ||
); | ||
} | ||
|
||
async prepareDownload(datasets) { | ||
const ids = datasets.map((dataset) => dataset.id); | ||
const lookup = await getMetadataLookup(ids, this.searchUrl, this.token); | ||
for (const dataset of datasets) { | ||
const metadata = lookup.get(dataset.id); | ||
Object.assign(dataset, metadata); | ||
} | ||
} | ||
|
||
async download(dataset) { | ||
if (!dataset.uuid) { | ||
throw new Error('Missing uuid - Dataset might have been deleted'); | ||
} | ||
|
||
const url = new URL(`${dataset.uuid}/expr.h5ad`, this.assetsUrl); | ||
url.searchParams.set('token', this.token); | ||
await downloadFile(dataset.dataFilePath, url, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
overwrite: this.config.get(FORCE, false), | ||
}); | ||
|
||
const { stdout } = await execFile('python3', [ | ||
this.exprAdjustScriptFilePath, | ||
dataset.dataFilePath, | ||
'--assay', | ||
dataset.assay_type, | ||
'--output', | ||
dataset.dataFilePath, | ||
]); | ||
async getMetadataLookup(ids) { | ||
const metadata = await getMetadata(ids, this.searchUrl, this.token, ID_KEYWORD, METADATA_FIELDS); | ||
return metadataToLookup(metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.