Skip to content

Commit

Permalink
chore: inputs from users
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Havlik committed Apr 5, 2024
1 parent 071963f commit bd04753
Show file tree
Hide file tree
Showing 18 changed files with 2,976 additions and 1,325 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dnarchive

Human Genome Database

## Getting Started
Expand All @@ -9,4 +10,4 @@ First, run the development server:
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
6 changes: 4 additions & 2 deletions components/analysis/AnalysisContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AnalysisContainer = () => {
),
],
analysis: "g4",
name: "",
});

return (
Expand Down Expand Up @@ -57,13 +58,14 @@ const AnalysisContainer = () => {
>
<ChromosomeSelector formData={formData} setFormData={setFormData} />
<Button
variant="outlined"
variant="contained"
color="success"
fullWidth
onClick={() =>
router.push({ pathname: "/analysis/data/", query: formData })
}
>
Save filter
START ANALYSIS
</Button>
</Stack>
</Grid>
Expand Down
50 changes: 48 additions & 2 deletions components/analysis/AnalysisDataContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BrowseListQueryData } from "@components/types";
import DownloadIcon from "@mui/icons-material/Download";
import { Button } from "@mui/material";
import Paper from "@mui/material/Paper";
import Stack from "@mui/material/Stack";
import Table from "@mui/material/Table";
Expand All @@ -9,6 +11,7 @@ import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Typography from "@mui/material/Typography";
import MaterialReactTable, { MRT_ColumnDef } from "material-react-table";
import { useRouter } from "next/router";
import React, { useMemo } from "react";

type Props = {
Expand All @@ -24,6 +27,8 @@ type Props = {
};

const AnalysisContainer = ({ items, settings, isLoading, isError }: Props) => {
const router = useRouter();
const { query } = router;
const g4Columns = useMemo<MRT_ColumnDef<BrowseListQueryData[0]>[]>(
() => [
{
Expand Down Expand Up @@ -66,6 +71,29 @@ const AnalysisContainer = ({ items, settings, isLoading, isError }: Props) => {
[]
);

// Function to convert array of objects to CSV string
const convertToCSV = (array: any) => {
const header = Object.keys(array[0]).join(",") + "\n";
const body = array
.map((obj: { [s: string]: unknown } | ArrayLike<unknown>) =>
Object.values(obj).join(",")
)
.join("\n");
return header + body;
};

const handleDownloadClick = () => {
const csvString = convertToCSV(items ?? []);
const blob = new Blob([csvString], { type: "text/csv;charset=utf-8;" });
const link = document.createElement("a");
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", "dnarchive_table_data.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};

return (
<Stack direction="column" spacing={2}>
<Typography variant="h6">G4Hunter</Typography>
Expand All @@ -81,18 +109,36 @@ const AnalysisContainer = ({ items, settings, isLoading, isError }: Props) => {
<TableBody>
<TableRow>
<TableCell component="th" scope="row">
Window size: {settings.window_size}
Window size: {settings.window_size} | Threshold:{" "}
{settings.threshold} | Gene: {query?.name}
</TableCell>
<TableCell>
Frequency: {settings.freq_per_1k?.toFixed(2)} / 1000 bp
</TableCell>
</TableRow>
<TableRow>
<TableCell component="th" scope="row">
Threshold: {settings.threshold}
Analysis area: {query.start} - {query.end}
</TableCell>
<TableCell>Total: {settings.total}</TableCell>
</TableRow>
<TableRow>
<TableCell component="th" scope="row">
Chromosomes:{" "}
{Array.isArray(query?.chromosome)
? query?.chromosome.join(", ")
: query?.chromosome}
</TableCell>
<TableCell>
<Button
startIcon={<DownloadIcon />}
onClick={handleDownloadClick}
style={{ textTransform: "none" }}
>
Download results
</Button>
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
Expand Down
6 changes: 4 additions & 2 deletions components/analysis/cards/GeneCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ const GeneCard = ({ formData, setFormData }: Props) => {

const handleSetGeneWindow = (
_: any,
value: { chromosome: any; start: any; end: any }
value: { chromosome: any; start: any; end: any; name: string }
) => {
if (!value) {
return;
}
console.log(data);

const { chromosome, start, end } = value;
const { chromosome, start, end, name } = value;

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

Expand Down
1 change: 1 addition & 0 deletions components/analysis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type FormData = {
end: number;
chromosome: string[];
analysis: string;
name: string;
};
2 changes: 1 addition & 1 deletion components/browse/BrowseContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function BrowseContainer({ data = [], isLoading, isError }: Props) {
columns={columns}
data={data ?? []}
rowNumberMode="original"
enableTopToolbar
enableTopToolbar={false}
enableColumnActions={false}
enablePagination={false}
muiTableBodyRowProps={{ hover: true }}
Expand Down
28 changes: 17 additions & 11 deletions components/browse/BrowseTableActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import InfoIcon from "@mui/icons-material/Info";
import TroubleshootIcon from "@mui/icons-material/Troubleshoot";
import { Box, IconButton, Tooltip } from "@mui/material";
import { useRouter } from "next/router";
import React, { useMemo } from "react";
Expand All @@ -17,24 +17,30 @@ export function BrowseTableActions({ chromosome, length }: Props) {
const router = useRouter();

const actions: Action[] = useMemo(
() => [{ icon: <InfoIcon />, placement: "bottom" }],
() => [{ icon: <TroubleshootIcon />, placement: "bottom" }],
[]
);

return (
<Box sx={{ display: "flex" }}>
{actions.map(({ icon, placement }, index) => (
<IconButton
<Tooltip
key={index}
onClick={() =>
router.push({
pathname: "/sequence",
query: { chromosome, length },
})
}
title={`Analyze ${chromosome}`}
placement={placement || "top"}
>
{icon}
</IconButton>
<IconButton
key={index}
onClick={() =>
router.push({
pathname: "/sequence",
query: { chromosome, length },
})
}
>
{icon}
</IconButton>
</Tooltip>
))}
</Box>
);
Expand Down
2 changes: 1 addition & 1 deletion components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
};

function Layout({ children }: Props) {
const [drawerOpen, setDrawerOpen] = useState(false);
const [drawerOpen, setDrawerOpen] = useState(true);

return (
<Box sx={{ display: "flex" }}>
Expand Down
16 changes: 9 additions & 7 deletions components/layout/menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
ThemeProvider,
} from "@mui/material/styles";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import Image from "next/image";

import { MENU_ITEMS } from "./items";
import Logo from "./logo.png";
import MenuItem from "./MenuItem";

const darkTheme = createTheme({
Expand Down Expand Up @@ -79,12 +80,13 @@ export default function Menu({ open, onDrawerOpen }: Props) {
>
<MenuIcon />
</IconButton>
<Typography
variant="button"
sx={{ ...(!open && { display: "none" }) }}
>
Logo
</Typography>
<Image
src={Logo}
alt="Logo"
width={80}
height={(80 * 358) / 647}
style={{ marginLeft: "15px", ...(!open && { display: "none" }) }}
/>
</Toolbar>
<List>
{MENU_ITEMS.map(({ label, icon, path }) => (
Expand Down
8 changes: 4 additions & 4 deletions components/layout/menu/items.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import AccountTreeIcon from "@mui/icons-material/AccountTree";
import BarChartIcon from "@mui/icons-material/BarChart";
import ContactsIcon from "@mui/icons-material/Contacts";
import EditIcon from "@mui/icons-material/Edit";
import TableChartIcon from "@mui/icons-material/TableChart";
import TroubleshootIcon from "@mui/icons-material/Troubleshoot";

export const MENU_ITEMS = [
{ label: "Browser", icon: <TableChartIcon />, path: "/" },
{ label: "Analysis", icon: <EditIcon />, path: "/analysis" },
{ label: "Browser", icon: <AccountTreeIcon />, path: "/" },
{ label: "Analysis", icon: <TroubleshootIcon />, path: "/analysis" },
{ label: "Statistics", icon: <BarChartIcon />, path: "/statistics" },
{ label: "Contact", icon: <ContactsIcon />, path: "/contact" },
];
Binary file added components/layout/menu/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added components/layout/menu/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 31 additions & 6 deletions components/statistics/StatisticsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { StatisticsQueryData } from "@components/types";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Paper from "@mui/material/Paper";
import Stack from "@mui/material/Stack";
Expand All @@ -10,6 +9,7 @@ import {
Bar,
BarChart,
CartesianGrid,
Label,
Legend,
Rectangle,
Tooltip,
Expand Down Expand Up @@ -60,7 +60,7 @@ export function StatisticsContainer({ data = [] }: Props) {
})
}
>
Show analysis
Analyze
</Button>
</Stack>

Expand All @@ -79,8 +79,20 @@ export function StatisticsContainer({ data = [] }: Props) {
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<XAxis dataKey="name">
<Label
value={"G4 Threshold"}
position="insideBottomRight"
offset={-10}
/>
</XAxis>
<YAxis
label={{
value: "PQS frequency",
angle: -90,
position: "insideLeft",
}}
/>
<Tooltip />
<Legend />
<Bar
Expand All @@ -107,8 +119,21 @@ export function StatisticsContainer({ data = [] }: Props) {
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<XAxis dataKey="name">
<Label
value={"G4 Threshold"}
position="insideBottomRight"
offset={-10}
/>
</XAxis>
<YAxis
label={{
value: "PQS threshold",
angle: -90,
position: "insideLeft",
offset: -12,
}}
/>
<Tooltip />
<Legend />
<Bar
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@zodios/core": "^10.9.6",
"lodash": "^4.17.21",
"material-react-table": "^1.14.0",
"next": "13.0.5",
"next": "^13.5.6",
"next-axiom": "^0.15.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
Loading

0 comments on commit bd04753

Please sign in to comment.