Skip to content

Commit

Permalink
fix: FTU Explorer data source updates (#635)
Browse files Browse the repository at this point in the history
* Data source updates

* refactor(ftu-ui): ♻️ Reimplement cell types table data processing logic

* style(ftu-ui): 🔥 Remove commented out code

* fix(services): Readd ftu data mock service (used by stories)

* style(ftu-ui): Fix sonar cloud issues

* docs(state): 📝 Increase doc coverage

* test(state): ✅ Fix and update tests for data aggregation logic

* refactor(state): Update column keys & labels, sort columns alphabetically & update column layout

* refactor(ftu-ui): 💄 Style tweak

* test(state): ✅ Fix a cell-summary test

---------

Co-authored-by: Daniel Bolin <axbolin@iu.edu>
  • Loading branch information
bherr2 and axdanbol authored Aug 15, 2024
1 parent 53f45a8 commit 8b2c970
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 419 deletions.
14 changes: 7 additions & 7 deletions apps/ftu-ui/src/assets/TEMP/ftu-cell-summaries.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@graph": [
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/kidney-nephron",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-nephron",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -3746,7 +3746,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/kidney-renal-corpuscle",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-renal-corpuscle",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -6744,7 +6744,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/kidney-cortical-collecting-duct",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-cortical-collecting-duct",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -9756,7 +9756,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/kidney-ascending-thin-loop-of-henle",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-ascending-thin-loop-of-henle",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -11266,7 +11266,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/liver-liver-lobule",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_liver-liver-lobule",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -13485,7 +13485,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/lung-pulmonary-alveolus",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_lung-pulmonary-alveolus",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down Expand Up @@ -16399,7 +16399,7 @@
},
{
"@type": "CellSummary",
"cell_source": "https://purl.humanatlas.io/2d-ftu/lung-bronchial-submucosal-gland",
"cell_source": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_lung-bronchial-submucosal-gland",
"annotation_method": "Aggregation",
"biomarker_type": "gene",
"summary": [
Expand Down
14 changes: 7 additions & 7 deletions apps/ftu-ui/src/assets/TEMP/ftu-datasets.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-nephron",
"@type": "Dataset",
"label": "snRNA-seq of Three Healthy Human Kidney Tissue",
"link": "https://doi.org/10.1038/s41467-021-22368-w",
Expand All @@ -53,7 +53,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-renal-corpuscle",
"@type": "Dataset",
"label": "snRNA-seq of Three Healthy Human Kidney Tissue",
"link": "https://doi.org/10.1038/s41467-021-22368-w",
Expand All @@ -76,7 +76,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-cortical-collecting-duct",
"@type": "Dataset",
"label": "snRNA-seq of Three Healthy Human Kidney Tissue",
"link": "https://doi.org/10.1038/s41467-021-22368-w",
Expand All @@ -99,7 +99,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_kidney-ascending-thin-loop-of-henle",
"@type": "Dataset",
"label": "snRNA-seq of Three Healthy Human Kidney Tissue",
"link": "https://doi.org/10.1038/s41467-021-22368-w",
Expand All @@ -122,7 +122,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_lung-bronchial-submucosal-gland",
"@type": "Dataset",
"label": "scRNA Seq of Resected Human Lung Tissue",
"link": "https://doi.org/10.1038/s41591-019-0468-5",
Expand All @@ -149,7 +149,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_lung-pulmonary-alveolus",
"@type": "Dataset",
"label": "scRNA Seq of Resected Human Lung Tissue",
"link": "https://doi.org/10.1038/s41591-019-0468-5",
Expand All @@ -176,7 +176,7 @@
"@type": "FtuIllustration",
"data_sources": [
{
"@id": "https://cns-iu.github.io/hra-cell-type-populations-supporting-information/data/enriched_rui_locations.jsonld#36e76662-60b8-4193-8a70-1bfd4f6938d0_D088_Lung",
"@id": "https://doi.org/10.1038/s41467-021-22368-w#CellSummary_liver-liver-lobule",
"@type": "Dataset",
"label": "sc Bulk Transcriptomics of Liver Data",
"link": "https://doi.org/10.1038/s41598-021-98806-y",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
height: 100%;

&.small {
height: fit-content;
min-height: fit-content;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
:host {
display: block;

@media (min-height: 60.75rem) {
.table th {
height: 4.5rem !important;
}
.table th,
.table th div {
height: 6.5rem !important;
}

cdk-virtual-scroll-viewport {
Expand Down Expand Up @@ -104,10 +103,13 @@

.icon-header {
.header-column-text {
transform: rotate(-45deg);
// transform: rotate(-90deg);
writing-mode: vertical-rl;
transform: rotate(180deg);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 0.5rem auto;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class BiomarkerTableComponent<T extends DataCell> implements OnInit, OnCh
* @param changes object consisting of change in the Input
*/
ngOnChanges(changes: SimpleChanges): void {
this.checkDisplayedColumns();
this.checkDisplayedColumns('columns' in changes);
if ('data' in changes || 'illustrationIds' in changes) {
this.dataSource.data = this.sortTableData(this.data);
}
Expand All @@ -194,11 +194,11 @@ export class BiomarkerTableComponent<T extends DataCell> implements OnInit, OnCh
/**
* Checks to see if columns should be updated
*/
checkDisplayedColumns(): void {
checkDisplayedColumns(forceUpdate = false): void {
const scrollable = this.vscroll.scrollable;
const size = scrollable.measureViewportSize('horizontal');
const offset = scrollable.measureScrollOffset('start');
let shouldUpdate = false;
let shouldUpdate = forceUpdate;

if (size !== this.horizontalViewportSize) {
this.updateHorizontalViewportSize(size);
Expand Down
73 changes: 1 addition & 72 deletions libs/services/src/lib/ftu-data/ftu-data.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
RAW_CELL_SUMMARIES,
RAW_DATASETS,
RAW_ILLUSTRATIONS_JSONLD,
RawCellSummary,
RawDatasets,
RawIllustrationFile,
RawIllustrationsJsonld,
Expand Down Expand Up @@ -59,11 +58,6 @@ const EMPTY_TISSUE_LIBRARY: TissueLibrary = {
nodes: {},
};

/** Capitalizes the first character */
function capitalize(str: string): string {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}

/** Converts case to title case for organ name */
function titleCase(name: string) {
return name
Expand Down Expand Up @@ -139,10 +133,7 @@ export class FtuDataImplService extends FtuDataService {
@returns An Observable that emits an CellSummary array.
*/
override getCellSummaries(iri: Iri): Observable<CellSummary[]> {
return this.fetchData(iri, 'summaries', RAW_CELL_SUMMARIES).pipe(
map((data) => data?.['@graph']),
map((data) => (data ? this.constructCellSummaries(data) : [])),
);
return this.fetchData(iri, 'summaries', RAW_CELL_SUMMARIES).pipe(map((data) => data?.['@graph'] ?? []));
}

/**
Expand Down Expand Up @@ -289,68 +280,6 @@ export class FtuDataImplService extends FtuDataService {
return results;
}

/**
* constructCellSummaries : Formates Cell Summary after fetching the data
* @param data
* @returns
*/
private constructCellSummaries(data: RawCellSummary['@graph']): CellSummary[] {
type SummaryItem = RawCellSummary['@graph'][number]['summary'][number];
const cellSummaries: CellSummary[] = [];
const defaultBiomarkerLables = ['gene', 'protein', 'lipid'];
const biomarkersPresent = new Set(data.map((summary) => summary.biomarker_type.toLowerCase()));
const expandGenes = (summary: SummaryItem) =>
summary.genes.map((gene) => ({
...summary,
...gene,
}));

data.forEach((summaryGroup) => {
const nestedSummaries = summaryGroup.summary.map(expandGenes);
const summary = nestedSummaries.reduce((acc, items) => acc.concat(items), [] as (typeof nestedSummaries)[number]);

const cells = summary.map((entry) => ({
id: entry.cell_id as Iri,
label: entry.cell_label,
}));

const biomarkers = summary.map((entry) => ({
id: entry.gene_id as Iri,
label: entry.gene_label,
}));

const summaries = summary.map((entry) => ({
cell: entry.cell_id as Iri,
biomarker: entry.gene_id as Iri,
count: entry.count,
percentage: entry.percentage,
meanExpression: entry.mean_expression,
}));

cellSummaries.push({
label: `${capitalize(summaryGroup.biomarker_type)} Biomarkers`,
cellSource: summaryGroup.cell_source,
cells,
biomarkers,
summaries,
});
});

defaultBiomarkerLables.forEach((defaultLabel) => {
if (!biomarkersPresent.has(defaultLabel)) {
cellSummaries.push({
label: `${capitalize(defaultLabel)} Biomarkers`,
cellSource: '',
cells: [],
biomarkers: [],
summaries: [],
});
}
});

return cellSummaries;
}

/**
* Constructs tissue library ,forming parent and child nodes
* @param items
Expand Down
20 changes: 1 addition & 19 deletions libs/services/src/lib/ftu-data/ftu-data.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,25 +324,7 @@ const sourceReferences: SourceReference[] = [
/**
* Dummy data extract om Mock Data of tissue mock
*/
const CELL_SUMMARY_DATA: CellSummary[] = Object.values(MOCK_SUMMARIES).map((summary) => ({
label: summary.label,
cellSource: summary.cellSource,
cells: summary.entries.map((entry) => ({
id: entry.cell.id as Iri,
label: entry.cell.label,
})),
biomarkers: summary.entries.map((entry) => ({
id: entry.biomarker.id as Iri,
label: entry.biomarker.label,
})),
summaries: summary.entries.map((entry) => ({
cell: entry.cell.id as Iri,
biomarker: entry.biomarker.id as Iri,
count: entry.count,
percentage: entry.percentage,
meanExpression: entry.meanExpression,
})),
}));
const CELL_SUMMARY_DATA: CellSummary[] = [];

/**
This class represents a mock implementation of the FtuDataService class.
Expand Down
52 changes: 22 additions & 30 deletions libs/services/src/lib/ftu-data/ftu-data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export const CELL = z.object({

/** Zod Schema for a BIOMARKER */
export const BIOMARKER = z.object({
id: IRI,
id: z.string(),
label: z.string(),
});

/** Zod Schema for a CELL_SUMMARY_ROW */
export const CELL_SUMMARY_ROW = z.object({
cell: IRI,
biomarker: IRI,
biomarker: z.string(),
count: COUNT,
percentage: PERCENTAGE,
meanExpression: PERCENTAGE,
Expand All @@ -68,11 +68,25 @@ export const CELL_SUMMARY_ROW = z.object({

/** Zod Schema for a CELL_SUMMARY */
export const CELL_SUMMARY = z.object({
label: z.string(),
cellSource: z.string(),
cells: CELL.array(),
biomarkers: BIOMARKER.array(),
summaries: CELL_SUMMARY_ROW.array(),
cell_source: IRI,
biomarker_type: z.string(),
summary: z
.object({
cell_id: IRI,
cell_label: z.string(),
genes: z
.object({
gene_id: z.string(),
gene_label: z.string(),
ensemble_id: z.string(),
mean_expression: z.number(),
})
.array(),
count: z.number(),
percentage: z.number(),
dataset_count: z.number().optional(),
})
.array(),
});

/** Zod Schema for a DATA_FILE_REFERENCE */
Expand Down Expand Up @@ -155,29 +169,7 @@ export const RAW_DATASETS = z.object({

/** CELL_SUMMARIES zod object reflecting the format in the file*/
export const RAW_CELL_SUMMARIES = z.object({
'@graph': z
.object({
cell_source: IRI,
biomarker_type: z.string(),
summary: z
.object({
cell_id: z.string(),
cell_label: z.string(),
genes: z
.object({
'@type': z.string(),
gene_id: z.string(),
gene_label: z.string(),
mean_expression: z.number(),
})
.array(),
count: z.number(),
percentage: z.number(),
dataset_count: z.number().optional(),
})
.array(),
})
.array(),
'@graph': CELL_SUMMARY.array(),
});

// ---------------------------------------
Expand Down
Loading

0 comments on commit 8b2c970

Please sign in to comment.