diff --git a/components/content/RefseqDb.vue b/components/content/RefseqDb.vue index be566e687f16804b034cc27459b1c48730ec8ffc..b292e394e9809830168d55d69d10ab88fa459220 100644 --- a/components/content/RefseqDb.vue +++ b/components/content/RefseqDb.vue @@ -1,4 +1,6 @@ <script setup lang="ts"> +import * as d3 from "d3"; + import * as Plot from "@observablehq/plot"; import PlotFigure from "~/components/PlotFigure"; import { useDisplay } from "vuetify"; @@ -149,10 +151,7 @@ const allHits: Ref<Record<string, any> | undefined> = ref(undefined) const pendingAllHits = ref(false) async function getAllHits(params: { index: string, params: Record<string, any>, query: string }) { - console.log(params.index) if (params.index === toValue(dbName)) { - console.log("get all hits in function ") - console.log(params) pendingAllHits.value = true try { const { data, error } = await useAsyncMeiliSearch(params) @@ -205,6 +204,8 @@ const computedSystemDistribution = computed(() => { }) const computedDistriSystemOptions = computed(() => { + const toValNormalizePerAssembly = toValue(normalizePerAssembly) + return { ...defaultBarPlotOptions.value, marginBottom: 100, @@ -214,11 +215,13 @@ const computedDistriSystemOptions = computed(() => { marks: [ // Plot.frame(), Plot.barY( - toValue(computedSystemDistribution), - { - y: "count", x: 'type', tip: true, + toValNormalizePerAssembly, + Plot.groupX({ y: "sum" }, { + x: 'system', tip: true, sort: { x: "-y" }, }, + ) + // toValue(computedSystemDistribution), ), ], @@ -228,7 +231,8 @@ const computedDistriSystemOptions = computed(() => { // Taxo distri const computedTaxonomyDistribution = computed(() => { - if (toValue(msResult)?.facetDistribution?.[selectedTaxoRank.value]) { + const toValNormalizePerAssembly = toValue(normalizePerAssembly) + if (toValNormalizePerAssembly?.length > 0) { return Object.entries(toValue(msResult).facetDistribution[selectedTaxoRank.value]).map(([key, value]) => { return { [selectedTaxoRank.value]: key, @@ -248,6 +252,7 @@ const computedDistriTaxoOptions = computed(() => { width: computedWidth.value, marks: [ Plot.barY( + toValue(computedTaxonomyDistribution), { y: "count", @@ -291,7 +296,8 @@ const binPlotOptions = ref({ const binPlotDataOptions = computed(() => { const toValueAllHits = toValue(allHits) - return toValueAllHits?.hits?.length > 0 ? { + const toValNormalizePerAssembly = toValue(normalizePerAssembly) + return toValNormalizePerAssembly?.length > 0 ? { ...binPlotOptions.value, width: width.value, @@ -302,12 +308,81 @@ const binPlotDataOptions = computed(() => { ticks: scaleType.value === 'symlog' ? 3 : 5, }, marks: [ - Plot.cell(toValueAllHits?.hits ?? [], Plot.group({ fill: "count" }, { x: "type", y: selectedTaxoRank.value, tip: true, inset: 0.5, sort: { y: "fill" } })), + Plot.cell( + toValNormalizePerAssembly ?? [], + Plot.group({ + fill: "count" + }, { + x: "system", + y: "rank", + tip: true, + inset: 0.5, + sort: { y: "fill" } + })), ] } : null }) + +const systemPerAssemblyPerRank = computed(() => { + const toValueAllHits = toValue(allHits) + console.log("all hits dans system per...") + console.log(toValueAllHits) + if (toValueAllHits && toValueAllHits?.hits?.length > 0) { + return d3.rollup(toValueAllHits.hits, D => D.length, d => d[toValue(selectedTaxoRank)], d => d.Assembly, d => d.type) + } +}) + +const assemblyPerRank = computed(() => { + const toValueAllHits = toValue(allHits) + + if (toValueAllHits && toValueAllHits?.hits?.length > 0) { + return d3.rollup(toValueAllHits.hits, D => D.length, d => d[toValue(selectedTaxoRank)], d => d.Assembly) + } +}) + +const ranks = computed(() => { + + const toValAssemblyPerRank = toValue(assemblyPerRank) + console.log("dans le ranks computed") + console.log(toValAssemblyPerRank) + if (toValAssemblyPerRank && toValAssemblyPerRank?.size > 0) { + console.log(toValAssemblyPerRank.keys()) + + return [...toValAssemblyPerRank.keys()] + } +}) + +const normalizePerAssembly = computed(() => { + const toValRanks = toValue(ranks) + const toValAssemblyPerRank = toValue(assemblyPerRank) + const toValSystemPerAssemblyPerRank = toValue(systemPerAssemblyPerRank) + const normalizedSystemCount = [] + + console.log("dans computed normalize per assembly") + console.log(toValRanks) + console.log(toValAssemblyPerRank) + console.log(toValSystemPerAssemblyPerRank) + if (toValRanks && toValAssemblyPerRank && toValSystemPerAssemblyPerRank) { + for (const rank of toValRanks) { + // get list assembly for this rank + console.log(rank) + const assemblies = [...toValAssemblyPerRank.get(rank).keys()] + for (const assembly of assemblies) { + // get list + const countAssemblyPerRank = toValAssemblyPerRank.get(rank).get(assembly) + const systems = toValSystemPerAssemblyPerRank.get(rank).get(assembly).keys() + for (const system of systems) { + const countSystem = toValSystemPerAssemblyPerRank.get(rank).get(assembly).get(system) + normalizedSystemCount.push({ rank, assembly, system, frequency: countSystem / countAssemblyPerRank }) + } + } + } + } + return normalizedSystemCount +}) + const scaleType = ref("linear") const systemsDistributionPlot = ref<ComponentPublicInstance | null>(null) const taxonomicDistributionPlot = ref<ComponentPublicInstance | null>(null) @@ -466,7 +541,6 @@ async function downloadPng(component: ComponentPublicInstance | null, filename: </v-expansion-panel-text> </v-expansion-panel> </v-expansion-panels> - <ServerDbTable title="RefSeq" :sortBy="sortBy" :autocomplete-meili-facets-props="computedAutocompleteMeiliFacetsProps" :data-table-server-props="dataTableServerProps" @refresh:search="(params) => getAllHits(params)">