Skip to content

Commit

Permalink
feat: implement genes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikkaura committed Dec 12, 2023
1 parent df9f4f2 commit 4d7e536
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 36 deletions.
6 changes: 5 additions & 1 deletion components/analysis/AnalysisContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import G4HunterFilterCard from "@components/analysis/cards/analysis-filter-cards/G4HunterFilterCard";
import AttributesCard from "@components/analysis/cards/AttributesCard";
import ChromosomeSelector from "@components/analysis/cards/ChromosomeSelector";
import GeneCard from "@components/analysis/cards/GeneCard";
import SortingCard from "@components/analysis/cards/sorting-card/SortingCard";
import type { FormData } from "@components/analysis/types";
import { CHROMOSOMES } from "@config";
Expand Down Expand Up @@ -40,7 +41,10 @@ const AnalysisContainer = () => {
<G4HunterFilterCard formData={formData} setFormData={setFormData} />
<SortingCard formData={formData} setFormData={setFormData} />
</Stack>
<AttributesCard formData={formData} setFormData={setFormData} />
<Stack direction="row" spacing={1}>
<AttributesCard formData={formData} setFormData={setFormData} />
<GeneCard formData={formData} setFormData={setFormData} />
</Stack>
</Stack>
</Grid>

Expand Down
96 changes: 70 additions & 26 deletions components/analysis/cards/GeneCard.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,86 @@
import AddIcon from "@mui/icons-material/Add";
import Button from "@mui/material/Button";
import Chip from "@mui/material/Chip";
import type { FormData } from "@components/analysis/types";
import Autocomplete from "@mui/material/Autocomplete";
import CircularProgress from "@mui/material/CircularProgress";
import Divider from "@mui/material/Divider";
import Stack from "@mui/material/Stack";
import TextField from "@mui/material/TextField";
import Typography from "@mui/material/Typography";
import { trpc } from "@utils/trpc";
import { useState } from "react";

import BaseCard from "./BaseCard";

const GeneCard = () => {
type Props = {
formData: FormData;
setFormData: (formData: FormData) => void;
};

const GeneCard = ({ formData, setFormData }: Props) => {
const { data, isLoading } = trpc.browse.getGenes.useQuery();
const [open, setOpen] = useState(false);

const handleSetGeneWindow = (
_: any,
value: { chromosome: any; start: any; end: any }
) => {
if (!value) {
return;
}

const { chromosome, start, end } = value;

setFormData({
...formData,
chromosome: [chromosome],
start,
end,
});
};

return (
<BaseCard minHeight={100}>
<Stack spacing={2}>
<Typography variant="h6">Genes</Typography>

<Divider />

<Button
sx={{ width: "120px" }}
variant="outlined"
size="small"
endIcon={<AddIcon />}
>
Gene
</Button>
<Stack direction="row" spacing={1}>
<Chip
label="DCDC 2"
variant="outlined"
onClick={() => {}}
onDelete={() => {}}
/>
<Chip
label="Clickable Deletable"
variant="outlined"
onClick={() => {}}
onDelete={() => {}}
/>
</Stack>
<Autocomplete
id="asynchronous-demo"
sx={{ width: 300 }}
open={open}
onOpen={() => {
setOpen(true);
}}
onClose={() => {
setOpen(false);
}}
isOptionEqualToValue={(chromosome, value) =>
chromosome.name === value.name
}
// @ts-expect-error fixme !!!
onChange={handleSetGeneWindow}
getOptionLabel={(chromosome) => chromosome.name}
options={data ?? []}
loading={isLoading}
renderInput={(params) => (
<TextField
{...params}
size="small"
label="Gene"
InputProps={{
...params.InputProps,
endAdornment: (
<>
{isLoading ? (
<CircularProgress color="inherit" size={20} />
) : null}
{params.InputProps.endAdornment}
</>
),
}}
/>
)}
/>
</Stack>
</BaseCard>
);
Expand Down
1 change: 1 addition & 0 deletions components/layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useMemo } from "react";
const SUB_ROUTE = [
{ route: "/", title: "All chromosomes" },
{ route: "/analysis", title: "Analysis" },
{ route: "/analysis/data", title: "Analysis data" },
{ route: "/statistics", title: "Statistics" },
{ route: "/contact", title: "Contact" },
];
Expand Down
1 change: 1 addition & 0 deletions server/api/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const browseApi = router({
.input(listSequenceInputSchema)
.query(({ input }) => BrowseManager.listSequence(input)),
getStatistics: baseProcedure.query(() => BrowseManager.getStatistics()),
getGenes: baseProcedure.query(() => BrowseManager.getGenes()),
});
4 changes: 4 additions & 0 deletions server/manager/BrowseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ export class BrowseManager {
static async getStatistics() {
return BrowseAdapter.getStatistics();
}

static async getGenes() {
return BrowseAdapter.getGenes();
}
}
6 changes: 5 additions & 1 deletion server/manager/adapter/BrowseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class BrowseAdapter {
const { analysis, sequence = "" } = items;

const mappedAnalysis = {
g4Hunter: analysis.map(({ sub_score, abs_score, ...rest }) => ({
g4Hunter: analysis[0].result.map(({ sub_score, abs_score, ...rest }) => ({
...rest,
absScore: abs_score,
subScore: sub_score,
Expand All @@ -61,4 +61,8 @@ export class BrowseAdapter {
static async getStatistics() {
return api.getStatistics();
}

static async getGenes() {
return api.getGenes();
}
}
40 changes: 32 additions & 8 deletions server/manager/adapter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ export const api = new Zodios(
response: z.object({
analysis: z.array(
z.object({
abs_score: z.number(),
chromosome: z.string(),
length: z.number(),
position: z.number(),
score: z.number(),
sequence: z.string(),
sub_score: z.number(),
threshold: z.number(),
result: z.array(
z.object({
abs_score: z.number(),
chromosome: z.string(),
length: z.number(),
position: z.number(),
score: z.number(),
sequence: z.string(),
sub_score: z.number(),
threshold: z.number(),
})
),
})
),
sequence: z.array(z.string()),
settings: z.object({
total: z.number(),
freq_per_1k: z.number(),
window_size: z.number(),
threshold: z.number(),
}),
}),
status: 200,
},
Expand Down Expand Up @@ -134,6 +144,20 @@ export const api = new Zodios(
),
status: 200,
},
{
method: "get",
path: "/genes",
alias: "getGenes",
response: z.array(
z.object({
name: z.string(),
start: z.number(),
end: z.number(),
chromosome: z.string(),
})
),
status: 200,
},
],
{ validate: false }
);

1 comment on commit 4d7e536

@vercel
Copy link

@vercel vercel bot commented on 4d7e536 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dnarchive – ./

dnarchive-git-main-jan-havlik.vercel.app
dnarchive.vercel.app
dnarchive-jan-havlik.vercel.app

Please sign in to comment.