Skip to content

Commit

Permalink
Additional work
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbaumes committed Aug 14, 2023
1 parent 6d2c9d1 commit d07d31a
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 116 deletions.
257 changes: 213 additions & 44 deletions nmdc_server/api.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nmdc_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Settings(BaseSettings):
# Several different database urls are configured for different
# environments. In production, only database_uri and ingest_database_uri
# are used.
database_uri: str = "postgresql:///nmdc"
database_uri: str = "postgresql:///nmdc_testing"
ingest_database_uri: str = "postgresql:///nmdc_testing"
testing_database_uri: str = "postgresql:///nmdc_testing"

Expand Down
2 changes: 1 addition & 1 deletion nmdc_server/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def compare(self) -> ClauseElement:
# A special condition type on multiomics bitstrings
class MultiomicsConditionSchema(BaseConditionSchema):
table: Table
value: int
value: Union[int, List[str]]
field: Literal["multiomics"]
op: Literal["has"]

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"authlib==0.15.5",
"celery[redis]",
"click",
"cryptography<3.4", # https://github.com/pyca/cryptography/issues/5771
# "cryptography<3.4", # https://github.com/pyca/cryptography/issues/5771
"cryptography",
"fastapi==0.71.0",
"factory-boy==3.2.1",
"httpx<=0.18.2",
Expand Down
16 changes: 9 additions & 7 deletions web/src/components/ClusterMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ export default defineComponent({
const values: any[] = [];
data.forEach((cluster, index) => {
for (let i = 0; i < cluster.count; i += 1) {
values.push({
...cluster,
key: `${index}_${i}`,
latLng: L.latLng(cluster.latitude, cluster.longitude),
});
if (cluster.latitude !== undefined && cluster.longitude !== undefined) {
values.push({
...cluster,
key: `${index}_${i}`,
latLng: L.latLng(cluster.latitude, cluster.longitude),
});
}
}
});
mapData.value = values;
Expand All @@ -108,7 +110,7 @@ export default defineComponent({
if (bounds) {
emit('selected', [
{
field: 'latitude',
field: 'lat_lon.latitude',
op: 'between',
value: [
// @ts-ignore
Expand All @@ -117,7 +119,7 @@ export default defineComponent({
table: 'biosample',
},
{
field: 'longitude',
field: 'lat_lon.longitude',
op: 'between',
value: [
// @ts-ignore
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/DataObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ export default defineComponent({
const items = computed(() => flattenDeep(
flattenDeep(props.biosample.omics_processing.filter((o) => o.omics_type.has_raw_value === props.omicsType).map(
(omicsProcessing) => props.biosample.analysis.filter(
(analysis) => analysis.was_informed_by === omicsProcessing.id,
(omicsProcessing) => props.biosample.activity.filter(
(activity) => activity.was_informed_by === omicsProcessing.id,
),
)).map(
(analysis) => analysis.has_output.map(
(activity) => activity.has_output.map(
(dataObjectId) => props.biosample.data_object.find(
(dataObject) => dataObject.id === dataObjectId,
),
).map((dataObject, index) => ({
...dataObject,
analysis,
activity,
/* TODO Hack to replace metagenome with omics type name */
group_name: analysis.name ? analysis.name.replace('Metagenome', props.omicsType) : '',
group_name: activity.name ? activity.name.replace('Metagenome', props.omicsType) : '',
newgroup: index === 0,
})),
),
Expand Down
3 changes: 1 addition & 2 deletions web/src/components/Presentation/ConditionChips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Vue from 'vue';
import { groupBy } from 'lodash';
import { opMap } from '@/data/api';
import { fieldDisplayName } from '@/util';
import { makeSetsFromBitmask } from '@/encoding';
export default Vue.extend({
props: {
Expand Down Expand Up @@ -45,7 +44,7 @@ export default Vue.extend({
valueTransform(val, field, type) {
// Special handling for multiomics
if (field === 'multiomics' && type === 'biosample') {
return Array.from(makeSetsFromBitmask(val)).join(', ');
return val.join(', ');
}
// If it's not primitive
if (val && typeof val === 'object') {
Expand Down
14 changes: 5 additions & 9 deletions web/src/components/Presentation/UpSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { defineComponent, watchEffect, ref } from '@vue/composition-api';
import { select } from 'd3-selection';
import { scaleBand, scaleLinear } from 'd3-scale';
import { MultiomicsValue } from '@/encoding';
import { multiomicsAbbreviations } from '@/encoding';
export default defineComponent({
props: {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default defineComponent({
};
const fontSize = 12;
const setOrder = ['MG', 'MT', 'MP', 'MB', 'NOM'];
const setOrder = ['Metagenome', 'Metatranscriptome', 'Proteomics', 'Metabolomics', 'Organic Matter Characterization'];
const Samples = 'Samples';
const Studies = 'Studies';
const seriesTitles = [Samples, Studies];
Expand Down Expand Up @@ -103,7 +103,7 @@ export default defineComponent({
.attr('y', -4)
.attr('text-anchor', 'middle')
.attr('font-size', fontSize)
.text((d) => d)
.text((d) => multiomicsAbbreviations[d])
.attr('fill', 'black')
.append('svg:title')
.text((s) => props.tooltips[s]);
Expand Down Expand Up @@ -153,16 +153,12 @@ export default defineComponent({
.attr('height', y.bandwidth())
.attr('fill', root.$vuetify.theme.currentTheme.blue)
.classed('upset-bar-clickable', true)
.on('click', (event, values) => {
const value = values.sets.reduce((prev, cur) => {
const next = prev | MultiomicsValue[cur]; //eslint-disable-line no-bitwise
return next;
}, 0);
.on('click', (_event, values) => {
const conditions = [{
field: 'multiomics',
table: 'biosample',
op: 'has',
value,
value: values.sets,
}];
emit('select', { conditions });
});
Expand Down
6 changes: 3 additions & 3 deletions web/src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export interface BiosampleSearchResult extends BaseSearchResult {
}
emsl_biosample_identifiers: string[];
omics_processing: OmicsProcessingResult[];
analysis: AnalysisResult[];
activity: AnalysisResult[];
data_object: DataObjectSearchResult[];
}

Expand Down Expand Up @@ -472,7 +472,7 @@ async function getDatabaseStats() {
async function getEnvironmentGeospatialAggregation(
conditions: Condition[],
): Promise<EnvironmentGeospatialEntity[]> {
const { data } = await client.post<EnvironmentGeospatialEntity[]>('environment/geospatial', {
const { data } = await client.post<EnvironmentGeospatialEntity[]>('environment/mongo_geospatial', {
conditions,
});
return data;
Expand Down Expand Up @@ -521,7 +521,7 @@ async function getEnvoTrees() {
* Bulk Download API
*/
async function getBulkDownloadSummary(conditions: Condition[]) {
const { data } = await client.post<BulkDownloadSummary>('data_object/workflow_summary', {
const { data } = await client.post<BulkDownloadSummary>('data_object/mongo_workflow_summary', {
conditions,
});
return data;
Expand Down
38 changes: 7 additions & 31 deletions web/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,6 @@ function stringIsKegg(v: string) {
return Object.values(KeggPrefix).find((item) => v.match(item.pattern));
}

function makeSetsFromBitmask(mask_str: string) {
const mask = parseInt(mask_str, 10); // the bitmask comes in as a string
const sets = [];

/* eslint-disable no-bitwise */
if (1 & mask) {
sets.push('NOM');
}
if ((1 << 4) & mask) {
sets.push('MB');
}
if ((1 << 2) & mask) {
sets.push('MP');
}
if ((1 << 1) & mask) {
sets.push('MT');
}
if ((1 << 3) & mask) {
sets.push('MG');
}
return sets;
}

const types: Record<entityType, EntityData> = {
study: {
icon: 'mdi-book',
Expand Down Expand Up @@ -411,20 +388,19 @@ function getField(name: string, table?: entityType): FieldsData {
return {};
}

const MultiomicsValue = {
MB: 0b10000,
MG: 0b01000,
MP: 0b00100,
MT: 0b00010,
NOM: 0b00001,
const multiomicsAbbreviations = {
Metagenome: 'MG',
Metatranscriptome: 'MT',
Proteomics: 'MP',
Metabolomics: 'MB',
'Organic Matter Characterization': 'NOM',
};

export {
types,
ecosystems,
MultiomicsValue,
multiomicsAbbreviations,
getField,
keggEncode,
stringIsKegg,
makeSetsFromBitmask,
};
1 change: 1 addition & 0 deletions web/src/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function parseQuery(q: string) {
const u8a = new Uint8Array(atob(b64).split('').map((c) => c.charCodeAt(0)));
const msg = QueryParams.decode(u8a);
const obj = QueryParams.toObject(msg, { enums: String });
obj.conditions = obj.conditions ?? [];
obj.conditions.forEach((c: Condition) => {
// @ts-ignore
// eslint-disable-next-line no-param-reassign
Expand Down
9 changes: 4 additions & 5 deletions web/src/views/Search/BiosampleVisGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
toggleConditions, removeConditions, setUniqueCondition,
} from '@/store';
import { api, Condition, FacetSummaryResponse } from '@/data/api';
import { makeSetsFromBitmask } from '@/encoding';
const helpBarchart = 'Displays the number of omics processing runs for each data type available. Click on a bar to filter by data type.';
const helpMap = 'Displays geographical location (latitude, longitude) of sample collection sites. Click on a cluster to zoom in. Click "Search this regon" to limit search to the current map bounds.';
Expand Down Expand Up @@ -62,27 +61,27 @@ export default defineComponent({
const upsetData = computed(() => {
const multiomicsObj: Record<string, { counts: any, sets: any }> = {};
sampleFacetSummary.value.forEach(({ facet, count }) => {
if (parseInt(facet, 10) === 0) {
if (facet.length === 0) {
return;
}
multiomicsObj[facet] = {
counts: {
Samples: count,
Studies: 0,
},
sets: makeSetsFromBitmask(facet),
sets: facet.split(';'),
};
});
studyFacetSummary.value.forEach(({ facet, count }) => {
if (parseInt(facet, 10) === 0) {
if (facet.length === 0) {
return;
}
if (!multiomicsObj[facet]) {
multiomicsObj[facet] = {
counts: {
Samples: 0,
},
sets: makeSetsFromBitmask(facet),
sets: facet.split(';'),
};
}
multiomicsObj[facet].counts.Studies = count;
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/Search/SearchLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ export default defineComponent({
<template #subtitle="props">
<span class="pr-2">Study ID:</span>
<router-link
:to="{name: 'Study', params: { id: props.result.study_id }}"
:to="{name: 'Study', params: { id: props.result.part_of[0] }}"
class="pr-2 grey--text text--darken-2"
v-text="props.result.study_id"
v-text="props.result.part_of[0]"
/>
<template
v-if="(props.result.alternative_identifiers && props.result.alternative_identifiers.length) ||
Expand Down
13 changes: 8 additions & 5 deletions web/src/views/Search/SearchSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ const FunctionSearchFacets: SearchFacet[] = [
},
/** ENVO */
{
field: 'env_broad_scale',
field: 'env_broad_scale.has_raw_value',
table: 'biosample',
group: 'ENVO',
},
{
field: 'env_local_scale',
field: 'env_local_scale.has_raw_value',
table: 'biosample',
group: 'ENVO',
},
{
field: 'env_medium',
field: 'env_medium.has_raw_value',
table: 'biosample',
group: 'ENVO',
},
/** GOLD */
{
Expand All @@ -52,12 +55,12 @@ const FunctionSearchFacets: SearchFacet[] = [
group: 'Sample',
},
{
field: 'latitude',
field: 'lat_lon.latitude',
table: 'biosample',
group: 'Sample',
},
{
field: 'longitude',
field: 'lat_lon.longitude',
table: 'biosample',
group: 'Sample',
},
Expand Down

0 comments on commit d07d31a

Please sign in to comment.