Skip to content
Snippets Groups Projects
Commit 86ec5c81 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

WIP: Normalize with number total assembly

parent 7d3ba931
No related branches found
No related tags found
1 merge request!222Refseq no sys
Pipeline #122107 waiting for manual action with stages
in 5 minutes and 46 seconds
<script setup lang="ts"> <script setup lang="ts">
import * as d3 from "d3";
import * as Plot from "@observablehq/plot"; import * as Plot from "@observablehq/plot";
import PlotFigure from "~/components/PlotFigure"; import PlotFigure from "~/components/PlotFigure";
import { useDisplay } from "vuetify"; import { useDisplay } from "vuetify";
...@@ -149,10 +151,7 @@ const allHits: Ref<Record<string, any> | undefined> = ref(undefined) ...@@ -149,10 +151,7 @@ const allHits: Ref<Record<string, any> | undefined> = ref(undefined)
const pendingAllHits = ref(false) const pendingAllHits = ref(false)
async function getAllHits(params: { index: string, params: Record<string, any>, query: string }) { async function getAllHits(params: { index: string, params: Record<string, any>, query: string }) {
console.log(params.index)
if (params.index === toValue(dbName)) { if (params.index === toValue(dbName)) {
console.log("get all hits in function ")
console.log(params)
pendingAllHits.value = true pendingAllHits.value = true
try { try {
const { data, error } = await useAsyncMeiliSearch(params) const { data, error } = await useAsyncMeiliSearch(params)
...@@ -205,6 +204,8 @@ const computedSystemDistribution = computed(() => { ...@@ -205,6 +204,8 @@ const computedSystemDistribution = computed(() => {
}) })
const computedDistriSystemOptions = computed(() => { const computedDistriSystemOptions = computed(() => {
const toValNormalizePerAssembly = toValue(normalizePerAssembly)
return { return {
...defaultBarPlotOptions.value, ...defaultBarPlotOptions.value,
marginBottom: 100, marginBottom: 100,
...@@ -214,11 +215,13 @@ const computedDistriSystemOptions = computed(() => { ...@@ -214,11 +215,13 @@ const computedDistriSystemOptions = computed(() => {
marks: [ marks: [
// Plot.frame(), // Plot.frame(),
Plot.barY( Plot.barY(
toValue(computedSystemDistribution), toValNormalizePerAssembly,
{ Plot.groupX({ y: "sum" }, {
y: "count", x: 'type', tip: true, x: 'system', tip: true,
sort: { x: "-y" }, sort: { x: "-y" },
}, },
)
// toValue(computedSystemDistribution),
), ),
], ],
...@@ -228,7 +231,8 @@ const computedDistriSystemOptions = computed(() => { ...@@ -228,7 +231,8 @@ const computedDistriSystemOptions = computed(() => {
// Taxo distri // Taxo distri
const computedTaxonomyDistribution = computed(() => { 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 Object.entries(toValue(msResult).facetDistribution[selectedTaxoRank.value]).map(([key, value]) => {
return { return {
[selectedTaxoRank.value]: key, [selectedTaxoRank.value]: key,
...@@ -248,6 +252,7 @@ const computedDistriTaxoOptions = computed(() => { ...@@ -248,6 +252,7 @@ const computedDistriTaxoOptions = computed(() => {
width: computedWidth.value, width: computedWidth.value,
marks: [ marks: [
Plot.barY( Plot.barY(
toValue(computedTaxonomyDistribution), toValue(computedTaxonomyDistribution),
{ {
y: "count", y: "count",
...@@ -291,7 +296,8 @@ const binPlotOptions = ref({ ...@@ -291,7 +296,8 @@ const binPlotOptions = ref({
const binPlotDataOptions = computed(() => { const binPlotDataOptions = computed(() => {
const toValueAllHits = toValue(allHits) const toValueAllHits = toValue(allHits)
return toValueAllHits?.hits?.length > 0 ? { const toValNormalizePerAssembly = toValue(normalizePerAssembly)
return toValNormalizePerAssembly?.length > 0 ? {
...binPlotOptions.value, ...binPlotOptions.value,
width: width.value, width: width.value,
...@@ -302,12 +308,81 @@ const binPlotDataOptions = computed(() => { ...@@ -302,12 +308,81 @@ const binPlotDataOptions = computed(() => {
ticks: scaleType.value === 'symlog' ? 3 : 5, ticks: scaleType.value === 'symlog' ? 3 : 5,
}, },
marks: [ 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 } : 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 scaleType = ref("linear")
const systemsDistributionPlot = ref<ComponentPublicInstance | null>(null) const systemsDistributionPlot = ref<ComponentPublicInstance | null>(null)
const taxonomicDistributionPlot = ref<ComponentPublicInstance | null>(null) const taxonomicDistributionPlot = ref<ComponentPublicInstance | null>(null)
...@@ -466,7 +541,6 @@ async function downloadPng(component: ComponentPublicInstance | null, filename: ...@@ -466,7 +541,6 @@ async function downloadPng(component: ComponentPublicInstance | null, filename:
</v-expansion-panel-text> </v-expansion-panel-text>
</v-expansion-panel> </v-expansion-panel>
</v-expansion-panels> </v-expansion-panels>
<ServerDbTable title="RefSeq" :sortBy="sortBy" <ServerDbTable title="RefSeq" :sortBy="sortBy"
:autocomplete-meili-facets-props="computedAutocompleteMeiliFacetsProps" :autocomplete-meili-facets-props="computedAutocompleteMeiliFacetsProps"
:data-table-server-props="dataTableServerProps" @refresh:search="(params) => getAllHits(params)"> :data-table-server-props="dataTableServerProps" @refresh:search="(params) => getAllHits(params)">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment