Skip to content

Commit

Permalink
Updated metadata queries for hubmap and sennet
Browse files Browse the repository at this point in the history
  • Loading branch information
bherr2 committed Sep 13, 2024
1 parent 2cf2189 commit ba4486a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/hubmap/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export class Downloader extends XConsortiaDownloader {
async getMetadataLookup(ids) {
const organMetadata = await OrganMetadataCollection.load(this.config);
const metadata = await getMetadata(ids, this.searchUrl, this.token, ID_KEYWORD, METADATA_FIELDS);
return metadataToLookup(metadata, organMetadata);
return await metadataToLookup(metadata, organMetadata);
}
}
6 changes: 3 additions & 3 deletions src/hubmap/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getSampleBlockId, getSampleSectionId, ORGAN_MAPPING } from '../xconsort
*/

const HUBMAP_ENTITY_ENDPOINT = 'https://entity.api.hubmapconsortium.org/entities/';
const HUBMAP_ANCESTORS_ENDPOINT = 'https://entity.api.hubmapconsortium.org/ancestors/';
const HUBMAP_PORTAL_ENDPOINT = 'https://portal.hubmapconsortium.org/browse/dataset/';
export const ID_KEYWORD = 'hubmap_id';
export const METADATA_FIELDS = [
Expand All @@ -32,7 +33,6 @@ export const METADATA_FIELDS = [
'donor.mapped_metadata.sex',
'donor.mapped_metadata.age_value',
'donor.mapped_metadata.body_mass_index_value',
'ancestors',
'donor.uuid',
];

Expand All @@ -42,7 +42,7 @@ export const METADATA_FIELDS = [
* @param {object} result Raw metadata
* @param {OrganMetadataCollection} organMetadata Organ metadata
*/
export function metadataToLookup(result, organMetadata) {
export async function metadataToLookup(result, organMetadata) {
/** @type {Map<string, HubmapMetadata>} */
const lookup = new Map();
for (const hit of result.hits.hits) {
Expand All @@ -64,9 +64,9 @@ export function metadataToLookup(result, organMetadata) {
} = {},
uuid: donor_uuid,
},
ancestors,
},
} = hit;
const ancestors = await fetch(`${HUBMAP_ANCESTORS_ENDPOINT}${uuid}`).then((r) => r.json());
const mapped_organ = organMetadata.resolve(ORGAN_MAPPING[organ.toUpperCase()]?.organ_id ?? '');
const { block_id, rui_location } = getSampleBlockId(ancestors, HUBMAP_ENTITY_ENDPOINT);
lookup.set(hubmap_id, {
Expand Down
2 changes: 1 addition & 1 deletion src/sennet/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export class Downloader extends XConsortiaDownloader {
async getMetadataLookup(ids) {
const organMetadata = await OrganMetadataCollection.load(this.config);
const metadata = await getMetadata(ids, this.searchUrl, this.token, ID_KEYWORD, METADATA_FIELDS);
return toLookup(metadata, organMetadata);
return await toLookup(metadata, organMetadata);
}
}
4 changes: 2 additions & 2 deletions src/sennet/listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export class Listing extends XConsortiaListing {
},
{
term: {
'files.rel_path.keyword': 'expr.h5ad',
'ingest_metadata.files.rel_path.keyword': 'expr.h5ad',
},
},
{
term: {
'source.source_type.keyword': 'Human',
'sources.source_type.keyword': 'Human',
},
},
],
Expand Down
33 changes: 15 additions & 18 deletions src/sennet/metadata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OrganMetadataCollection } from '../organ/metadata.js';
import { getMetadata, getSampleBlockId, getSampleSectionId, ORGAN_MAPPING } from '../xconsortia/metadata.js';
import { getSampleBlockId, getSampleSectionId, ORGAN_MAPPING } from '../xconsortia/metadata.js';

/**
* @typedef {object} SennetMetadata
Expand All @@ -20,6 +20,7 @@ import { getMetadata, getSampleBlockId, getSampleSectionId, ORGAN_MAPPING } from
*/

const SENNET_ENTITY_ENDPOINT = 'https://entity.api.sennetconsortium.org/entities/';
const SENNET_ANCESTORS_ENDPOINT = 'https://entity.api.sennetconsortium.org/ancestors/';
const SENNET_PORTAL_ENDPOINT = 'https://data.sennetconsortium.org/dataset';
export const ID_KEYWORD = 'sennet_id';
export const METADATA_FIELDS = [
Expand All @@ -29,12 +30,7 @@ export const METADATA_FIELDS = [
'dataset_info',
'group_name',
'group_uuid',
'source.source_mapped_metadata.race',
'source.source_mapped_metadata.sex',
'source.source_mapped_metadata.age_value',
'source.source_mapped_metadata.body_mass_index_value',
'ancestors',
'source.uuid',
'sources.uuid',
];

/**
Expand All @@ -43,7 +39,7 @@ export const METADATA_FIELDS = [
* @param {object} result Raw metadata
* @param {OrganMetadataCollection} organMetadata Organ metadata
*/
export function toLookup(result, organMetadata) {
export async function toLookup(result, organMetadata) {
/** @type {Map<string, SennetMetadata>} */
const lookup = new Map();
for (const hit of result.hits.hits) {
Expand All @@ -55,18 +51,19 @@ export function toLookup(result, organMetadata) {
dataset_info,
group_name,
group_uuid,
source: {
source_mapped_metadata: {
age_value: [donor_age] = [''],
race: [donor_race] = [''],
sex: [donor_sex] = [''],
body_mass_index_value: [donor_bmi] = [''],
} = {},
uuid: donor_uuid,
},
ancestors,
sources: [{ uuid: donor_uuid }],
},
} = hit;
const source = await fetch(`${SENNET_ENTITY_ENDPOINT}${donor_uuid}`).then((r) => r.json());
const {
source_mapped_metadata: {
age: { value: [donor_age] = [''] },
race: { value: [donor_race] = [''] },
sex: { value: [donor_sex] = [''] },
body_mass_index: { value: [donor_bmi] = [''] },
},
} = source;
const ancestors = await fetch(`${SENNET_ANCESTORS_ENDPOINT}${uuid}`).then((r) => r.json());
const mapped_organ = organMetadata.resolve(ORGAN_MAPPING[organ.toUpperCase()]?.organ_id ?? '');

const { block_id, rui_location } = getSampleBlockId(ancestors, SENNET_ENTITY_ENDPOINT);
Expand Down
5 changes: 4 additions & 1 deletion src/xconsortia/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ export function getSampleBlockId(ancestors, url_prefix) {

export function getSampleSectionId(ancestors, url_prefix) {
for (const ancestor of ancestors) {
if (ancestor['entity_type'].toLowerCase() == 'sample' && ancestor['sample_category'].toLowerCase() == 'section') {
if (
ancestor['entity_type'].toLowerCase() == 'sample' &&
ancestor['sample_category'].toLowerCase().replace('suspension', 'section') == 'section'
) {
return `${url_prefix}${ancestor['uuid']}`;
}
}
Expand Down

0 comments on commit ba4486a

Please sign in to comment.