Skip to content

Commit

Permalink
35254 Add metagenomic workflow
Browse files Browse the repository at this point in the history
- Implemented Index Assignment Assign by grid that works with metagenomics batch item
- Can select index, save, and load
  • Loading branch information
johnphan96 committed Nov 29, 2024
1 parent dad62c3 commit ed9f60e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "./useMetagenomicsIndexAssignmentAPI";

interface MetagenomicsIndexAssignmentRow {
materialSample?: MaterialSampleSummary;
materialSampleSummary?: MaterialSampleSummary;
metagenomicsIndexAssignmentResource?: MetagenomicsIndexAssignmentResource;
pcrBatchItem?: PcrBatchItem;
}
Expand All @@ -41,7 +41,7 @@ export function MetagenomicsIndexAssignmentTable(
setPerformSave,
loading,
metagenomicsIndexAssignmentResources,
materialSamples,
materialSampleSummaries,
ngsIndexes,
onSubmitTable
} = props;
Expand Down Expand Up @@ -153,13 +153,13 @@ export function MetagenomicsIndexAssignmentTable(
? metagenomicsIndexAssignmentResources.map<MetagenomicsIndexAssignmentRow>(
(prep) => ({
metagenomicsIndexAssignmentResource: prep,
materialSample: materialSamples?.find(
materialSampleSummary: materialSampleSummaries?.find(
(samp) => samp.id === prep?.materialSampleSummary?.id
)
})
)
: [],
[metagenomicsIndexAssignmentResources, materialSamples]
[metagenomicsIndexAssignmentResources, materialSampleSummaries]
);

const initialValues = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { LibraryPrep } from "../../../../types/seqdb-api";
import { ColumnDef } from "@tanstack/react-table";
import { useSeqdbIntl } from "packages/dina-ui/intl/seqdb-intl";
import { MetagenomicsIndexAssignmentStepProps } from "../../metagenomics-workflow/MetagenomicsIndexAssignmentStep";
import { UseMetagenomicsIndexAssignmentReturn } from "../useMetagenomicsIndexAssignmentAPI";
import {
MetagenomicsIndexAssignmentResource,
UseMetagenomicsIndexAssignmentReturn
} from "../useMetagenomicsIndexAssignmentAPI";

interface CellData {
row: number;
Expand All @@ -23,19 +26,20 @@ interface MetagenomicsIndexGridProps
export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) {
const {
pcrBatch,
metagenomicsBatch,
editMode,
performSave,
setPerformSave,
loading: libraryPrepsLoading,
metagenomicsIndexAssignmentResources: libraryPreps,
materialSamples,
loading,
metagenomicsIndexAssignmentResources,
materialSampleSummaries,
ngsIndexes,
storageUnitType,
onSubmitGrid
} = props;

const { formatMessage } = useSeqdbIntl();
const { indexSet } = pcrBatch;
const { indexSet } = metagenomicsBatch;

// Hidden button bar is used to submit the page from the button bar in a parent component.
const hiddenButtonBar = (
Expand All @@ -46,7 +50,7 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) {
/>
);

if (libraryPrepsLoading) {
if (loading) {
return <LoadingSpinner loading={true} />;
}

Expand All @@ -58,26 +62,28 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) {
);
}

if (libraryPreps) {
const libraryPrepsWithCoords = libraryPreps.filter(
(prep) =>
prep.storageUnitUsage?.wellRow && prep.storageUnitUsage?.wellColumn
);
if (metagenomicsIndexAssignmentResources) {
const indexAssignmentResourcesWithCoords =
metagenomicsIndexAssignmentResources.filter(
(indexAssignmentResource) =>
indexAssignmentResource.storageUnitUsage?.wellRow &&
indexAssignmentResource.storageUnitUsage?.wellColumn
);

// Display an error if no coordinates have been selected yet, nothing to edit.
if (libraryPrepsWithCoords.length === 0) {
if (indexAssignmentResourcesWithCoords.length === 0) {
return (
<div className="alert alert-warning mt-2">
{formatMessage("missingSelectedCoordinatesForAssignment")}
</div>
);
}

const cellGrid: { [key: string]: LibraryPrep } = {};
for (const prep of libraryPrepsWithCoords) {
const cellGrid: { [key: string]: MetagenomicsIndexAssignmentResource } = {};
for (const resource of indexAssignmentResourcesWithCoords) {
cellGrid[
`${prep.storageUnitUsage?.wellRow}_${prep.storageUnitUsage?.wellColumn}`
] = prep;
`${resource.storageUnitUsage?.wellRow}_${resource.storageUnitUsage?.wellColumn}`
] = resource;
}

const columns: ColumnDef<CellData>[] = [];
Expand Down Expand Up @@ -134,26 +140,29 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) {
cell: ({ row: { original } }) => {
const rowLabel = String.fromCharCode(original.row + 65);
const coords = `${rowLabel}_${columnLabel}`;
const prep = cellGrid[coords];
const indexAssignmentResource: MetagenomicsIndexAssignmentResource =
cellGrid[coords];

return prep ? (
return indexAssignmentResource ? (
<div className="h-100 w-100 list-group-item">
<div>
{materialSamples?.find(
(sample) => sample.id === prep?.materialSample?.id
{materialSampleSummaries?.find(
(sample) =>
sample.id ===
indexAssignmentResource?.materialSampleSummary?.id
)?.materialSampleName ?? ""}
</div>
<div>
{prep.indexI5 && (
{indexAssignmentResource.indexI5 && (
<div>
<strong>i5: </strong>
{prep.indexI5.name}
{indexAssignmentResource.indexI5.name}
</div>
)}
{prep.indexI7 && (
{indexAssignmentResource.indexI7 && (
<div>
<strong>i7: </strong>
{prep.indexI7.name}
{indexAssignmentResource.indexI7.name}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { MetagenomicsBatchItem } from "packages/dina-ui/types/seqdb-api/resource
export interface UseMetagenomicsIndexAssignmentReturn {
loading: boolean;
metagenomicsIndexAssignmentResources?: MetagenomicsIndexAssignmentResource[];
materialSamples?: MaterialSampleSummary[];
materialSampleSummaries?: MaterialSampleSummary[];
ngsIndexes?: NgsIndex[];
storageUnitType?: StorageUnitType;
protocol?: Protocol;
Expand Down Expand Up @@ -62,7 +62,7 @@ export function useMetagenomicsIndexAssignmentAPI({
metagenomicsIndexAssignmentResources,
setMetagenomicsIndexAssignmentResources
] = useState<MetagenomicsIndexAssignmentResource[]>([]);
const [materialSamples, setMaterialSamples] =
const [materialSampleSummaries, setMaterialSamples] =
useState<MaterialSampleSummary[]>();
const [ngsIndexes, setNgsIndexes] = useState<NgsIndex[]>();
const [protocol, setProtocol] = useState<Protocol>();
Expand Down Expand Up @@ -274,8 +274,8 @@ export function useMetagenomicsIndexAssignmentAPI({
}

const saveOps: SaveArgs[] = toPairs(edits).map(([id, prepEdit]) => ({
resource: { id, type: "library-prep", ...prepEdit },
type: "library-prep"
resource: { id, type: "metagenomics-batch-item", ...prepEdit },
type: "metagenomics-batch-item"
}));

await save(saveOps, { apiBaseUrl: "/seqdb-api" });
Expand Down Expand Up @@ -354,7 +354,7 @@ export function useMetagenomicsIndexAssignmentAPI({
return {
loading,
metagenomicsIndexAssignmentResources,
materialSamples,
materialSampleSummaries,
ngsIndexes,
storageUnitType,
protocol,
Expand Down

0 comments on commit ed9f60e

Please sign in to comment.