Skip to content

Commit

Permalink
feat: configure file manifest summary (#888) (#3591)
Browse files Browse the repository at this point in the history
Co-authored-by: Fran McDade <[email protected]>
  • Loading branch information
frano-m and Fran McDade authored Aug 2, 2023
1 parent 535cf15 commit 688b575
Show file tree
Hide file tree
Showing 19 changed files with 859 additions and 342 deletions.
24 changes: 24 additions & 0 deletions explorer/app/apis/azul/anvil-cmg/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export interface ActivityEntityResponse {
activities: ActivityEntity[];
}

/**
* Model of activity type returned from the /index/summary API endpoint.
*/
export interface ActivityType {
count: number;
type: string;
}

/**
* Model of core biosample value returned from the /index/biosamples API endpoint.
*/
Expand Down Expand Up @@ -67,6 +75,14 @@ export interface DonorEntityResponse {
donors: DonorEntity[];
}

/**
* Model of donor species returned from the /index/summary API endpoint.
*/
export interface DonorSpecies {
count: number;
species: null; // TODO - when species type is known (currently returns null value).
}

/**
* Model of core file value returned from the /index/files API endpoint.
*/
Expand Down Expand Up @@ -98,6 +114,14 @@ export interface LibraryEntity {
prep_material_name: string;
}

/**
* Model of file format returned from the /index/summary API endpoint.
*/
export interface FileFormat {
count: number;
format: string;
}

/**
* Model of singleton array containing core library value returned from the /index/libraries API endpoint.
*/
Expand Down
19 changes: 19 additions & 0 deletions explorer/app/apis/azul/anvil-cmg/common/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {
} from "./aggregatedEntities";
import {
ActivityEntityResponse,
ActivityType,
BioSampleEntityResponse,
DatasetEntityResponse,
DonorEntityResponse,
DonorSpecies,
FileEntityResponse,
FileFormat,
LibraryEntityResponse,
} from "./entities";

Expand Down Expand Up @@ -83,3 +86,19 @@ export type LibrariesResponse = AzulHit &
AggregatedDatasetResponse &
AggregatedDonorResponse &
AggregatedFileResponse;

/**
* Model of response returned from /index/summary API endpoint.
*/
export type SummaryResponse = {
activityCount: number;
activityTypes: ActivityType[];
biosampleCount: number;
datasetCount: number;
donorCount: number;
donorDiagnosisDiseases: unknown[]; // TODO - when type is known.
donorDiagnosisPhenotypes: unknown[]; // TODO - when type is known.
donorSpecies: DonorSpecies[];
fileCount: number;
fileFormats: FileFormat[];
};
27 changes: 27 additions & 0 deletions explorer/app/apis/azul/hca-dcp/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ export interface AccessionResponse {
namespace: string;
}

/**
* Model of cell count summary from index/summary API endpoints.
*/
export interface CellCountSummary {
countOfDocsWithOrganType: number;
organType: string[];
totalCellCountByOrgan: number;
}

/**
* Model of contributor value in the response from index/projects API endpoint.
*/
Expand Down Expand Up @@ -44,6 +53,16 @@ export interface FileResponse {
version: string;
}

/**
* Model of file type summary from index/summary API endpoints.
*/
export interface FileTypeSummary {
count: number;
format: string;
matrixCellCount: number;
totalSize: number;
}

/**
* Model of file "leaf" values in matrix tree response from Azul.
*/
Expand Down Expand Up @@ -89,6 +108,14 @@ export interface ProjectsEntityResponse {
projects: ProjectResponse[];
}

/**
* Model of project summary in the response from /index/summary API endpoint.
*/
export interface ProjectSummary {
cellSuspensions: { totalCells: number };
projects: { estimatedCellCount: number };
}

/**
* Model of publication value in the response from index/projects API endpoint.
*/
Expand Down
20 changes: 20 additions & 0 deletions explorer/app/apis/azul/hca-dcp/common/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import {
AggregatedSpecimensResponse,
} from "./aggregatedEntities";
import {
CellCountSummary,
FilesEntityResponse,
FileTypeSummary,
ProjectsEntityResponse,
ProjectSummary,
SamplesEntityResponse,
} from "./entities";

Expand Down Expand Up @@ -54,3 +57,20 @@ export type SamplesResponse = AzulHit &
AggregatedProjectsResponse &
AggregatedProtocolsResponse &
AggregatedSpecimensResponse;

/**
* Model of response returned from /index/summary API endpoint.
*/
export type SummaryResponse = {
cellCountSummaries: CellCountSummary[];
donorCount: number;
fileCount: number;
fileTypeSummaries: FileTypeSummary[];
labCount: number;
organTypes: string[];
projectCount: number;
projects: ProjectSummary[];
speciesCount: number;
specimenCount: number;
totalFileSize: number | string;
};
15 changes: 11 additions & 4 deletions explorer/app/components/Index/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { AzulSummaryResponse } from "@clevercanary/data-explorer-ui/lib/apis/azul/common/entities";
import { FileFormat } from "../../../apis/azul/anvil-cmg/common/entities";
import { ProjectSummary } from "../../../apis/azul/hca-dcp/common/entities";

/**
* Calculates the summary file format count using count values returned for each file format in the summary response.
* TODO review configuration of summary response model and use of this method to calculate file formats.
* @param summaryResponse - Response model return from summary API.
* @returns count of file formats.
*/
export function calculateSummaryFileFormatsCount(
summaryResponse: AzulSummaryResponse
): number {
return (summaryResponse.fileFormats ?? []).reduce((accum, { count }) => {
return accum + count;
}, 0);
return ((summaryResponse.fileFormats as FileFormat[]) ?? []).reduce(
(accum, { count }) => {
return accum + count;
},
0 as number
);
}

/**
* Calculates the summary total cell count using the estimatedCellCount and totalCells values fom the summary response.
* TODO review configuration of summary response model and use of this method to calculate total cell count.
* @param summaryResponse - Response model return from summary API.
* @returns count of total cell count.
*/
export function calculateSummaryTotalCellCount(
summaryResponse: AzulSummaryResponse
): number {
return (summaryResponse.projects ?? []).reduce(
return ((summaryResponse.projects as ProjectSummary[]) ?? []).reduce(
(accum, { cellSuspensions, projects }) => {
if (
projects &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ interface AccessStatusBadgeProps {
accessible: boolean;
}

export const AccessStatusBadge = styled(Chip)<AccessStatusBadgeProps>`
export const AccessStatusBadge = styled(Chip, {
shouldForwardProp: (prop) => prop !== "accessible",
})<AccessStatusBadgeProps>`
background-color: ${({ accessible, theme }) =>
accessible ? theme.palette.success.light : theme.palette.warning.light};
color: ${({ accessible, theme }) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { LABEL } from "@clevercanary/data-explorer-ui/lib/apis/azul/common/entities";
import { stringifyValues } from "@clevercanary/data-explorer-ui/lib/common/utils";
import { Value } from "@clevercanary/data-explorer-ui/lib/components/common/KeyValuePairs/keyValuePairs";
import {
displaySummaryTerms,
listSelectedTermsOfFacet,
} from "@clevercanary/data-explorer-ui/lib/components/Export/components/ExportSummary/common/utils";
import { ANCHOR_TARGET } from "@clevercanary/data-explorer-ui/lib/components/Links/common/entities";
import { Links } from "@clevercanary/data-explorer-ui/lib/components/Links/links";
import { getConfig } from "@clevercanary/data-explorer-ui/lib/config/config";
import { FileManifest } from "@clevercanary/data-explorer-ui/lib/hooks/useFileManifest/common/entities";
import { formatCountSize } from "@clevercanary/data-explorer-ui/lib/utils/formatCountSize";
import { formatFileSize } from "@clevercanary/data-explorer-ui/lib/utils/formatFileSize";
import {
HCA_DCP_CATEGORY_KEY,
HCA_DCP_CATEGORY_LABEL,
} from "../../../../../../site-config/hca-dcp/category";
import { HCA_DCP_CATEGORY_KEY } from "../../../../../../site-config/hca-dcp/category";
import {
processAggregatedBooleanOrArrayValue,
processAggregatedNumberEntityValue,
Expand Down Expand Up @@ -226,87 +217,3 @@ export function mapProjectDataSummary(
details.set(DATA_SUMMARY.DONOR_COUNT, formatCountSize(donorCount)); // Donor Count
return details;
}

/**
* Maps export summary related information, included formatted display text from the given file manifest.
* @param fileManifest - File manifest.
* @returns summaries key-value pairs of data summary and corresponding value.
*/
export function mapExportSummary(
fileManifest: FileManifest
): Map<DATA_SUMMARY | string, string> {
const { filesFacets, fileSummary } = fileManifest;
// Grab summary values.
const donorCount = fileSummary.donorCount;
const donorDisease = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.DONOR_DISEASE
);
const fileCount = fileSummary.fileCount;
const genusSpecies = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.GENUS_SPECIES
);
const libraryConstructionApproach = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.LIBRARY_CONSTRUCTION_METHOD
);
const organ = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.ORGAN
);
const organPart = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.ORGAN_PART
);
const pairedEnd = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.PAIRED_END
);
const projectCount = fileSummary.projectCount;
const specimenCount = fileSummary.specimenCount;
const specimenDisease = listSelectedTermsOfFacet(
filesFacets,
HCA_DCP_CATEGORY_KEY.SPECIMEN_DISEASE
);
const totalCellCount = fileSummary.totalCellCount;
const totalFileSize = fileSummary.totalFileSize;

// Map summary by summary key or display text.
const summaryBySummaryKey = new Map<DATA_SUMMARY | string, string>();
summaryBySummaryKey.set("Estimated Cells", formatCountSize(totalCellCount));
summaryBySummaryKey.set(
HCA_DCP_CATEGORY_LABEL.FILE_SIZE,
formatFileSize(totalFileSize)
);
summaryBySummaryKey.set("Files", formatCountSize(fileCount));
summaryBySummaryKey.set("Projects", formatCountSize(projectCount));
summaryBySummaryKey.set(
DATA_SUMMARY.GENUS_SPECIES,
displaySummaryTerms(genusSpecies)
);
summaryBySummaryKey.set("Donors", formatCountSize(donorCount));
summaryBySummaryKey.set(
DATA_SUMMARY.DONOR_DISEASE,
displaySummaryTerms(donorDisease)
); // Disease Status (Donor)
summaryBySummaryKey.set("Specimens", formatCountSize(specimenCount));
summaryBySummaryKey.set(
DATA_SUMMARY.DISEASE,
displaySummaryTerms(specimenDisease)
); // Disease Status (Specimen)
summaryBySummaryKey.set(DATA_SUMMARY.ORGAN, displaySummaryTerms(organ)); // Anatomical Entity
summaryBySummaryKey.set(
DATA_SUMMARY.ORGAN_PART,
displaySummaryTerms(organPart)
);
summaryBySummaryKey.set(
DATA_SUMMARY.LIBRARY_CONSTRUCTION_APPROACH,
displaySummaryTerms(libraryConstructionApproach)
); // Library Construction Method
summaryBySummaryKey.set(
DATA_SUMMARY.PAIRED_END,
displaySummaryTerms(pairedEnd)
); // Paired End
return summaryBySummaryKey;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { HCA_DCP_CATEGORY_LABEL } from "../../../../../../site-config/hca-dcp/category";
import { FileSummary, SUMMARY } from "./entities";

export const DEFAULT_SUMMARY: FileSummary = {
donorCount: 0,
fileCount: 0,
fileTypeSummaries: [],
organTypes: [],
projectCount: 0,
specimenCount: 0,
totalCellCount: 0,
totalFileSize: 0,
};

/**
* Display text for summaries.
*/
export const SUMMARY_DISPLAY_TEXT = {
[SUMMARY.DONOR_COUNT]: "Donors",
[SUMMARY.DONOR_DISEASE]: "Disease Status (Donor)",
[SUMMARY.FILE_COUNT]: "Files",
[SUMMARY.GENUS_SPECIES]: "Species",
[SUMMARY.LIBRARY_CONSTRUCTION_APPROACH]:
HCA_DCP_CATEGORY_LABEL.LIBRARY_CONSTRUCTION_METHOD,
[SUMMARY.ORGAN]: HCA_DCP_CATEGORY_LABEL.ANATOMICAL_ENTITY, // anatomical entity
[SUMMARY.ORGAN_PART]: HCA_DCP_CATEGORY_LABEL.ORGAN_PART,
[SUMMARY.PAIRED_END]: HCA_DCP_CATEGORY_LABEL.PAIRED_END,
[SUMMARY.PROJECT_COUNT]: "Projects",
[SUMMARY.SPECIMEN_COUNT]: "Specimens",
[SUMMARY.SPECIMEN_DISEASE]: "Disease Status (Specimen)",
[SUMMARY.TOTAL_CELL_COUNT]: "Estimated Cells",
[SUMMARY.TOTAL_FILE_SIZE]: HCA_DCP_CATEGORY_LABEL.FILE_SIZE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Model of file summary.
*/
export interface FileSummary {
donorCount: number;
fileCount: number;
fileTypeSummaries: FileTypeSummary[];
organTypes: string[];
projectCount: number;
specimenCount: number;
totalCellCount: number;
totalFileSize: number;
}

/**
* Model of file type summary.
*/
export interface FileTypeSummary {
count: number;
fileType: string;
matrixCellCount: number;
totalSize: number;
}

/**
* Possible set of summaries.
*/
export const enum SUMMARY {
DONOR_COUNT = "DONOR_COUNT",
DONOR_DISEASE = "DONOR_DISEASE",
FILE_COUNT = "FILE_COUNT",
GENUS_SPECIES = "GENUS_SPECIES",
LIBRARY_CONSTRUCTION_APPROACH = "LIBRARY_CONSTRUCTION_APPROACH",
ORGAN = "ORGAN",
ORGAN_PART = "ORGAN_PART",
PAIRED_END = "PAIRED_END",
PROJECT_COUNT = "PROJECT_COUNT",
SPECIMEN_COUNT = "SPECIMEN_COUNT",
SPECIMEN_DISEASE = "SPECIMEN_DISEASE",
TOTAL_CELL_COUNT = "TOTAL_CELL_COUNT",
TOTAL_FILE_SIZE = "TOTAL_FILE_SIZE",
}
Loading

0 comments on commit 688b575

Please sign in to comment.