Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vega Charts (new Charting Library) #295

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,209 changes: 3,041 additions & 168 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@
"react-toastify": "^9.1.2",
"react-twitter-embed": "4.0.4",
"react-use": "^17.4.0",
"react-vega": "^7.6.0",
"ro-crate": "^3.2.1",
"textarea-sequence": "3.5.1",
"universal-cookie": "4.0.4",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"vega": "^5.25.0",
"vega-embed": "^6.22.1",
"vega-lite": "^5.13.0"
},
"devDependencies": {
"@cypress/code-coverage": "3.9.12",
Expand Down
16 changes: 14 additions & 2 deletions src/components/Analysis/Functional/GO/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const GOBarChart: React.FC<GOBarChartProps> = ({
color,
containerId,
}) => {
// Sort the data in descending order based on the series values
const sortedData = series
.map((value, index) => ({
category: categories[index],
value,
}))
.sort((a, b) => b.value - a.value); // Sort in descending order

const sortedCategories = sortedData.map((data) => data.category);
const sortedSeries = sortedData.map((data) => data.value);

Comment on lines +26 to +36
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not part of Vega.

Sorted the data for Highchart.js GO Bar Viz.

const chartComponentRef = useRef<HighchartsReact.RefObject>(null);
const options: Record<string, unknown> = {
chart: {
Expand All @@ -44,7 +55,7 @@ const GOBarChart: React.FC<GOBarChartProps> = ({
},
},
xAxis: {
categories,
categories: sortedCategories,
},
plotOptions: {
series: {
Expand All @@ -68,7 +79,7 @@ const GOBarChart: React.FC<GOBarChartProps> = ({
series: [
{
name: 'annotations',
data: series,
data: sortedSeries,
color,
},
],
Expand All @@ -82,4 +93,5 @@ const GOBarChart: React.FC<GOBarChartProps> = ({
/>
);
};

export default GOBarChart;
3 changes: 3 additions & 0 deletions src/components/Analysis/Functional/GO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FetchError from 'components/UI/FetchError';
import { MGnifyDatum } from 'hooks/data/useData';
import { TAXONOMY_COLOURS } from 'utils/taxon';
import useQueryParamState from 'hooks/queryParamState/useQueryParamState';
import GOBar from 'src/components/VegaCharts/GOBar';
import GOBarChart from './BarChart';
import GOPieChart from './PieChart';

Expand Down Expand Up @@ -104,6 +105,8 @@ const GO: React.FC = () => {
containerId="cellular-component-bar-chart"
/>
</div>

<GOBar />
</div>
)}
{chart === 'pie' && dataBundles && (
Expand Down
2 changes: 2 additions & 0 deletions src/components/Analysis/Functional/InterPro/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Loading from 'components/UI/Loading';
import FetchError from 'components/UI/FetchError';
import ExtLink from 'components/UI/ExtLink';
import useQueryParamState from 'hooks/queryParamState/useQueryParamState';
import InterProBar from 'src/components/VegaCharts/InterproBar';
import InterProMatchesChart from './InterProMatchesChart';
import InterProQCChart from './QCChart';

Expand Down Expand Up @@ -91,6 +92,7 @@ const InterPro: React.FC = () => {
<div className="vf-stack">
<div>
<InterProQCChart />
<InterProBar />
</div>
<h5>InterPro match summary</h5>
<div className="vf-grid mg-grid-30-70">
Expand Down
22 changes: 17 additions & 5 deletions src/components/Analysis/Functional/KO/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React from 'react';
import PfamTable from './Table';
import PfamBarChart from './BarChart';
import React, { useContext } from 'react';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';
import AnalysisContext from 'src/pages/Analysis/AnalysisContext';
import KOTable from './Table';
import KOBarChart from './BarChart';

const PfamTab: React.FC = () => {
const { overviewData } = useContext(AnalysisContext);
const accession = `analyses/${overviewData.id}/kegg-orthologs`;
return (
<div className="vf-stack">
<PfamBarChart />
<PfamTable />
<KOBarChart />

<VerticalBarChart
ChartTitle="Top KO Entries"
accession={accession}
tooltipKey1="KEGG Class"
tooltipVal1="description"
tooltipKey3="Count"
/>
<KOTable />
</div>
);
};
Expand Down
26 changes: 19 additions & 7 deletions src/components/Analysis/Functional/Pfam/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import React from 'react';
import KOTable from './Table';
import KOBarChart from './BarChart';
import React, { useContext } from 'react';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';
import AnalysisContext from 'src/pages/Analysis/AnalysisContext';
import PfamTable from './Table';
import BarChart from './BarChart';

const KOTab: React.FC = () => {
const PfamTab: React.FC = () => {
const { overviewData } = useContext(AnalysisContext);
const accession = `analyses/${overviewData.id}/pfam-entries`;
return (
<div className="vf-stack">
<KOBarChart />
<KOTable />
<BarChart />

<VerticalBarChart
ChartTitle="Top Pfam Entries"
accession={accession}
tooltipKey1="Pfam Entry"
tooltipVal1="description"
tooltipKey3="Count"
/>
<PfamTable />
</div>
);
};

export default KOTab;
export default PfamTab;
15 changes: 14 additions & 1 deletion src/components/Analysis/Pathways/AntiSMASH/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import React from 'react';
import React, { useContext } from 'react';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';
import AnalysisContext from 'src/pages/Analysis/AnalysisContext';
import AntiSMASHTable from './Table';
import AntiSMASHBarChart from './BarChart';

const KOTab: React.FC = () => {
const { overviewData } = useContext(AnalysisContext);
const accession = `analyses/${overviewData.id}/antismash-gene-clusters`;
return (
<div className="vf-stack">
<AntiSMASHBarChart />
<VerticalBarChart
ChartTitle="Top AntiSMASH gene clusters"
accession={accession}
tooltipKey1="AntiSMASH gene cluster"
tooltipVal1="description"
tooltipKey2="Count"
tooltipVal2="count"
lAngle={0}
/>
<AntiSMASHTable />
</div>
);
Expand Down
23 changes: 22 additions & 1 deletion src/components/Analysis/Pathways/KeggModule/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import React from 'react';
import React, { useContext } from 'react';
import AnalysisContext from 'src/pages/Analysis/AnalysisContext';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';
import KeggTable from './Table';
import KeggBarChart from './BarChart';

const KOTab: React.FC = () => {
const { overviewData } = useContext(AnalysisContext);
const accession = `analyses/${overviewData.id}/kegg-modules`;
return (
<div className="vf-stack">
<KeggBarChart />

<VerticalBarChart
ChartTitle="KEGG Module Categories"
accession={accession}
tooltipKey1="Class ID"
tooltipVal1="id"
tooltipKey2="KEGG Module"
tooltipVal2="description"
tooltipKey3="Completeness (%)"
y="completeness"
sliderValue={250}
maxSlider={250}
titleY="Completeness (%)"
lAngle={-75}
paddingLabel={30}
overlapLabels
/>
<KeggTable />
</div>
);
Expand Down
21 changes: 21 additions & 0 deletions src/components/Analysis/QualityControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import useMGnifyData from 'hooks/data/useMGnifyData';
import Loading from 'components/UI/Loading';
import { ResponseFormat } from 'hooks/data/useData';
import AnalysisContext from 'pages/Analysis/AnalysisContext';
import NucleotideHistogram from 'src/components/VegaCharts/NucleotidesHistogram';
import QCStdDevChart from 'src/components/VegaCharts/QCStdDevChart';
import QualityControlChart from './QCChart';
import ContigsHistogram from './ContigsHistogram';
import NucleotidesHistogram from './NucleotidesHistogram';
Expand All @@ -12,6 +14,7 @@ import SeqLengthChart from './SeqLengthChart';
import GCContentChart from './GCContentChart';

import './style.css';
import VegaQC from '../../VegaCharts/QCChart';

const QualityControl: React.FC = () => {
const { overviewData: analysisData } = useContext(AnalysisContext);
Expand Down Expand Up @@ -41,6 +44,8 @@ const QualityControl: React.FC = () => {
number given by ENA.
</p>
<QualityControlChart summaryData={summaryData} />
<h3>Vega</h3>
<VegaQC summaryData={summaryData} />
{summaryData && Number(analysisData.attributes['pipeline-version']) > 2 && (
<>
<p>
Expand All @@ -62,12 +67,28 @@ const QualityControl: React.FC = () => {
<GCContentChart summaryData={summaryData} />
</div>
</div>

<div className="vf-grid vf-grid__col-2">
<div className="vf-stack">
<QCStdDevChart
accession={`analyses/${accession}`}
type="seq-length"
/>
</div>
<div className="vf-stack">
<QCStdDevChart
accession={`analyses/${accession}`}
type="gc-distribution"
/>
</div>
</div>
<p>
The graph below show the relative abundance of nucletotides (A, C,
G, T, or ambiguous base &quot;N&quot;) at each position starting
from the beginning of each {unit} up to the first 500 base pairs.
</p>
<NucleotidesHistogram />
<NucleotideHistogram />
</>
)}
</div>
Expand Down
13 changes: 13 additions & 0 deletions src/components/Analysis/Taxonomy/PhylumCharts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FetchError from 'components/UI/FetchError';
import useMGnifyData from 'hooks/data/useMGnifyData';
import { MGnifyDatum } from 'hooks/data/useData';
import { TAXONOMY_COLOURS } from 'utils/taxon';
import TaxBar from 'src/components/VegaCharts/TaxBar';
import PhylumTable from '../PhylumTable';
import PhylumPie from './Pie';
import PhylumColumn from './Column';
Expand Down Expand Up @@ -156,6 +157,12 @@ const PhylumCharts: React.FC<PhylumChartsProps> = ({
title="Domain composition"
sequencesType={sequencesType}
/>
<TaxBar
ChartTitle="Domain composition"
clusteredData={clusteredDataTop}
sequencesType={sequencesType}
title="Domain"
/>
</div>
)}
{chartType === 'column' && (
Expand All @@ -167,6 +174,12 @@ const PhylumCharts: React.FC<PhylumChartsProps> = ({
sequencesType={sequencesType}
showTotal
/>
<TaxBar
ChartTitle="Phylum composition (top 10)"
clusteredData={clusteredData}
sequencesType={sequencesType}
title="Phylum"
/>
</div>
)}
{chartType === 'stacked-column' && (
Expand Down
13 changes: 12 additions & 1 deletion src/components/Genomes/COGAnalysis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MGnifyDatum, MGnifyResponseList } from 'hooks/data/useData';
import useURLAccession from 'hooks/useURLAccession';
import useDefaultGenomeConfig from 'hooks/genomes/useDefaultConfig';
import { TAXONOMY_COLOURS } from 'utils/taxon';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';

addExportMenu(Highcharts);

Expand All @@ -23,7 +24,7 @@ const COGAnalises: React.FC<{ includePangenomes?: boolean }> = ({
const { data, loading, error } = useMGnifyData(`genomes/${accession}/cogs`, {
page_size: 100,
});

const accession1 = `genomes/${accession}/cogs`;
if (loading) return <Loading size="large" />;
if (error) return <FetchError error={error} />;
if (!data) return <Loading />;
Expand Down Expand Up @@ -95,6 +96,16 @@ const COGAnalises: React.FC<{ includePangenomes?: boolean }> = ({
options={options}
ref={chartComponentRef}
/>
<VerticalBarChart
ChartTitle="Top COG categories"
accession={accession1}
y="genome-count"
x="name"
tooltipKey1="COG"
tooltipVal1="description"
tooltipKey3="Genome Count"
lAngle={null}
/>
<EMGTable
cols={columns}
data={data as MGnifyResponseList}
Expand Down
12 changes: 11 additions & 1 deletion src/components/Genomes/KEGGClassAnalysis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useURLAccession from 'hooks/useURLAccession';
import useDefaultGenomeConfig from 'hooks/genomes/useDefaultConfig';
import { TAXONOMY_COLOURS } from 'utils/taxon';
import useQueryParamState from 'hooks/queryParamState/useQueryParamState';
import VerticalBarChart from 'src/components/VegaCharts/VerticalBar';

addExportMenu(Highcharts);

Expand Down Expand Up @@ -40,7 +41,7 @@ const KEGGClassAnalises: React.FC<{ includePangenomes?: boolean }> = ({
page_size: keggPageSize,
}
);

const accession1 = `genomes/${accession}/kegg-class`;
if (loading) return <Loading size="large" />;
if (error) return <FetchError error={error} />;
if (!data) return <Loading />;
Expand Down Expand Up @@ -118,6 +119,15 @@ const KEGGClassAnalises: React.FC<{ includePangenomes?: boolean }> = ({
options={options}
ref={chartComponentRef}
/>
<VerticalBarChart
ChartTitle="Top KEGG brite categories"
accession={accession1}
y="genome-count"
x="class-id"
tooltipKey1="Description"
tooltipVal1="name"
tooltipKey3="Genome Count"
/>
<EMGTable
cols={columns}
data={data as MGnifyResponseList}
Expand Down
Loading