From ed999eae26b0b19bf32186edcc606d1d02ca401f Mon Sep 17 00:00:00 2001
From: Remi  PLANEL <rplanel@pasteur.fr>
Date: Tue, 19 Dec 2023 14:01:24 +0100
Subject: [PATCH] pae as image

---
 components/content/MolstarPdbePlugin.vue      | 125 +++++-----
 data/system-to-dir.yaml                       | 213 ++++++++++++++++++
 .../df-wiki-cli/df_wiki_cli/content/main.py   |  63 +++++-
 packages/df-wiki-cli/pyproject.toml           |   2 +-
 4 files changed, 330 insertions(+), 73 deletions(-)
 create mode 100644 data/system-to-dir.yaml

diff --git a/components/content/MolstarPdbePlugin.vue b/components/content/MolstarPdbePlugin.vue
index 79949bc6..bfb97d00 100644
--- a/components/content/MolstarPdbePlugin.vue
+++ b/components/content/MolstarPdbePlugin.vue
@@ -4,16 +4,18 @@ import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
 import { useRuntimeConfig, computed } from '#imports'
 import * as d3 from "d3";
 import * as Plot from "@observablehq/plot";
-
-
 import PlotFigure from "~/components/PlotFigure";
 
+import { useDisplay } from "vuetify";
+
 export interface Props {
     height?: number
     dataUrls?: string[]
     dataUrl?: string
     uniq?: boolean
 }
+
+const { mobile } = useDisplay()
 // const selectedPdb = ref('')
 const refinedDataUrls = computed(() => {
 
@@ -100,66 +102,63 @@ const pdbeMolstarComponent = ref(null)
 const selectedPdb: Ref<string | null> = ref(null)
 
 const selectedPaePath = computed(() => {
-    return selectedPdb.value ? `${selectedPdb.value.split(".").slice(0, -1).join('.')}.tsv` : null
+    return selectedPdb.value ? `${selectedPdb.value.split(".").slice(0, -1).join('.')}.png` : null
 })
 
-const paeData = ref([])
-watch(selectedPaePath, async (newPaePath) => {
-    if (newPaePath !== null) {
-        try {
-            const data = await d3.tsv(newPaePath);
-            console.log(data.length)
-            console.log(data[0][0])
-            console.log(data?.[0]?.[0] !== undefined)
-            if (data.length > 500) {
-                paeError.value = `The PAE is too large to be displayed (${data.length} residus)`
-                paeData.value = []
-            }
-            else if (data?.[0]?.[0] === undefined) {
-                paeError.value = "The PAE cannot be downloaded"
-                paeData.value = []
-            }
-            else {
-                paeData.value = data
-                paeError.value = null
-            }
-
-        }
-        catch (error) {
-            console.log(error)
-        }
-    } else {
-        paeData.value = []
-    }
-
-})
+// const paeData = ref([])
+// watch(selectedPaePath, async (newPaePath) => {
+//     if (newPaePath !== null) {
+//         try {
+//             const data = await d3.tsv(newPaePath);
+//             if (data.length > 500) {
+//                 paeError.value = `The PAE is too large to be displayed (${data.length} residus)`
+//                 paeData.value = []
+//             }
+//             else if (data?.[0]?.[0] === undefined) {
+//                 paeError.value = "The PAE cannot be downloaded"
+//                 paeData.value = []
+//             }
+//             else {
+//                 paeData.value = data
+//                 paeError.value = null
+//             }
+
+//         }
+//         catch (error) {
+//             console.log(error)
+//         }
+//     } else {
+//         paeData.value = []
+//     }
 
-const sanitizedPaeData = computed(() => {
-    return paeData.value.reduce((acc, curr, index) => {
-        const scoredResidue = index
-        // let newAcc = [...acc]
-        for (const [alignedResidue, value] of Object.entries(curr)) {
-            // console.log(value)
-            acc.push({ alignedResidue: parseInt(alignedResidue), scoredResidue: parseInt(scoredResidue), value: parseFloat(value) })
-            // newAcc = [...newAcc, ...[{ alignedResidue: parseInt(alignedResidue), scoredResidue: parseInt(scoredResidue), value: parseFloat(value) }]]
-        }
+// })
 
-        return acc
-    }, [])
-})
+// const sanitizedPaeData = computed(() => {
+//     return paeData.value.reduce((acc, curr, index) => {
+//         const scoredResidue = index
+//         // let newAcc = [...acc]
+//         for (const [alignedResidue, value] of Object.entries(curr)) {
+//             // console.log(value)
+//             acc.push({ alignedResidue: parseInt(alignedResidue), scoredResidue: parseInt(scoredResidue), value: parseFloat(value) })
+//             // newAcc = [...newAcc, ...[{ alignedResidue: parseInt(alignedResidue), scoredResidue: parseInt(scoredResidue), value: parseFloat(value) }]]
+//         }
+
+//         return acc
+//     }, [])
+// })
 
 
-const plotPaeOptions = computed(() => {
-    return {
-        width: 640,
-        height: 640,
-        color: { scheme: "Greens", legend: true, reverse: true, label: "Expected position error (Ångströms)" },
-        y: { reverse: true },
-        marks: [
-            Plot.dot(sanitizedPaeData.value, { x: "scoredResidue", y: "alignedResidue", stroke: "value" })
-        ]
-    }
-})
+// const plotPaeOptions = computed(() => {
+//     return {
+//         width: 640,
+//         height: 640,
+//         color: { scheme: "Greens", legend: true, reverse: true, label: "Expected position error (Ångströms)" },
+//         y: { reverse: true },
+//         marks: [
+//             Plot.dot(sanitizedPaeData.value, { x: "scoredResidue", y: "alignedResidue", stroke: "value" })
+//         ]
+//     }
+// })
 
 watch(selectedPdb, (newSelectedPdb, prevSelectPdb) => {
     viewPdb(newSelectedPdb)
@@ -171,10 +170,13 @@ function viewPdb(pdbPath: string | null) {
         dialog.value = true
         const format = toValue(pdbPath)?.split(".").slice(-1)[0]?.toLowerCase() ?? "pdb"
         moleculeFormat.value = format
+        
         if (pdbeMolstarComponent.value?.viewerInstance) {
+            console.log(pdbeMolstarComponent.value)
             const viewerInstance = pdbeMolstarComponent.value.viewerInstance
             const customData = { url: pdbPath, format: format, binary: false }
             viewerInstance.visual.update({ customData })
+            
         }
     }
 }
@@ -217,7 +219,7 @@ const moleculeFormat: Ref<string> = ref("pdb")
                 </v-toolbar>
                 <v-card-text>
                     <v-row>
-                        <v-col cols="auto">
+                        <v-col :cols="mobile ? 12 : 'auto'">
                             <v-sheet v-if="selectedPdb"
                                 class="d-flex align-center justify-center flex-wrap text-center mx-auto px-4 my-3"
                                 :height="computedHeight" :width="computedWidth" position="relative">
@@ -226,12 +228,13 @@ const moleculeFormat: Ref<string> = ref("pdb")
                                     :custom-data-format="moleculeFormat"></pdbe-molstar>
                             </v-sheet>
                         </v-col>
-                        <v-col>
-                            <PlotFigure v-if="sanitizedPaeData?.length > 0 && paeError === null" defer
+                        <v-col :cols="mobile ? 12 : undefined">
+                            <v-img :src="selectedPaePath"></v-img>
+
+                            <!-- <PlotFigure v-if="sanitizedPaeData?.length > 0 && paeError === null" defer
                                 :options="plotPaeOptions"></PlotFigure>
-                            <v-alert v-else type="warning" variant="tonal">{{ paeError }}</v-alert>
+                            <v-alert v-else type="warning" variant="tonal">{{ paeError }}</v-alert> -->
                             <v-card flat color="transparent">
-
                                 <v-card-title>Model Confidence</v-card-title>
                                 <v-card-text>
                                     AlphaFold produces a per-residue model
diff --git a/data/system-to-dir.yaml b/data/system-to-dir.yaml
new file mode 100644
index 00000000..11208a67
--- /dev/null
+++ b/data/system-to-dir.yaml
@@ -0,0 +1,213 @@
+AVAST_I: avs
+AVAST_II-0: avs
+AVAST_III: avs
+AVAST_IV-0: avs
+AVAST_V-0: avs
+AbiA_large-0: abia_large
+AbiA_small: abia_small
+AbiB-0: abib
+AbiC-0: abic
+AbiD-0: abid
+AbiE: abie
+AbiG: abig
+AbiH-0: abih
+AbiI-0: abii
+AbiJ-0: abij
+AbiK-0: abik
+AbiL: abil
+AbiN-0: abin
+AbiO-0: abio
+AbiP2-0: abip2
+AbiQ-0: abiq
+AbiR: abir
+AbiT: abit
+AbiU-0: abiu
+AbiV-0: abiv
+AbiZ-0: abiz
+Aditi: aditi
+Azaca: azaca
+BREX_I: brex
+BREX_II: brex
+BREX_III: brex
+BREX_IV: brex
+BREX_V: brex
+BREX_VI: brex
+Borvo-0: borvo
+BstA-0: bsta
+BstA-1: bsta
+BstA-2: bsta
+Bunzi: bunzi
+Butters_gp30_gp31-0: butters_gp30_gp31
+Butters_gp57r-0: butters_gp57r
+CBASS_I: cbass
+CBASS_II: cbass
+CBASS_III: cbass
+CBASS_IV: cbass
+CapRel-0: caprel
+Charlie_gp32-0: charlie_gp32
+DISARM_1: disarm
+DISARM_2: disarm
+DRT6-0: drt
+DRT7-0: drt
+DRT8-0: drt
+DRT9-0: drt
+DRT_1: drt
+DRT_2-0: drt
+DRT_3: drt
+DRT_4-0: drt
+DRT_5-0: drt
+DarTG: dartg
+Dazbog: dazbog
+DdmDE: ddmde
+Detocs-0: detocs
+Detocs_hydrolase-0: detocs
+Dnd_ABCDE: dnd
+Dnd_ABCDEFGH: dnd
+Dodola: dodola
+Dpd: dpd
+Druantia_I: druantia
+Druantia_II: druantia
+Druantia_III: druantia
+Dsr_I-0: dsr
+Dsr_II-0: dsr
+Eleos: eleos
+FS_GIY_YIG-0: fs_giy_yig
+FS_HEPN_TM-0: fs_hepn_tm
+FS_HP-0: fs_hp
+FS_HP_SDH_sah-0: fs_hp_sdh_sah
+FS_HsdR_like-0: fs_hsdr_like
+FS_Sma-0: fs_sma
+GAPS1-0: gaps1
+GAPS2-0: gaps2
+GAPS4-0: gaps4
+GAPS6-0: gaps6
+Gabija: gabija
+Gao_Ape-0: gao_ape
+Gao_Her_DUF: gao_her
+Gao_Her_SIR: gao_her
+Gao_Hhe-0: gao_hhe
+Gao_Iet: gao_iet
+Gao_Mza: gao_mza
+Gao_Ppl-0: gao_ppl
+Gao_Qat: gao_qat
+Gao_RL: gao_rl
+Gao_TerY: gao_tery
+Gao_Tmn-0: gao_tmn
+Gao_Upx-0: gao_upx
+GasderMIN-0: gasdermin
+GasderMIN-1: gasdermin
+Hachiman: hachiman
+Hna-0: hna
+ISG15-like: isg15-like
+JukAB-0: jukab
+Kiwa: kiwa
+Lamassu-Amidase: lamassu-fam
+Lamassu-Cap4_nuclease: lamassu-fam
+Lamassu-FMO: lamassu-fam
+Lamassu-Fam_Hydrolase_Protease: lamassu-fam
+Lamassu-Fam_Mrr: lamassu-fam
+Lamassu-Fam_PDDEXK: lamassu-fam
+Lamassu-Hypothetical: lamassu-fam
+Lamassu-Lipase: lamassu-fam
+Lamassu-Sir2: lamassu-fam
+Lit-0: lit
+MADS-0: mads
+MMB_gp29_gp30-0: mmb_gp29_gp30
+Menshen: menshen
+Mok_Hok_Sok-0: mok_hok_sok
+Mokosh_TypeI: mokosh
+Mokosh_TypeII-0: mokosh
+MqsRAC: mqsrac
+NLR_like_bNACHT01-0: nlr
+NLR_like_bNACHT09-0: nlr
+Nhi-0: nhi
+NixI-0: nixi
+Old_exonuclease-0: old_exonuclease
+Olokun: olokun
+PARIS_I: paris
+PARIS_II: paris
+PARIS_II_merge-0: paris
+PARIS_I_merge-0: paris
+PD-Lambda-1-0: pd-lambda-1
+PD-Lambda-2: pd-lambda-2
+PD-Lambda-3: pd-lambda-3
+PD-Lambda-4: pd-lambda-4
+PD-Lambda-5: pd-lambda-5
+PD-Lambda-6-0: pd-lambda-6
+PD-T4-1-0: pd-t4-1
+PD-T4-10: pd-t4-10
+PD-T4-2: pd-t4-2
+PD-T4-3-0: pd-t4-3
+PD-T4-4: pd-t4-4
+PD-T4-5-0: pd-t4-5
+PD-T4-6-0: pd-t4-6
+PD-T4-7-0: pd-t4-7
+PD-T4-8-0: pd-t4-8
+PD-T4-9: pd-t4-9
+PD-T7-1-0: pd-t7-1
+PD-T7-2: pd-t7-2
+PD-T7-3-0: pd-t7-3
+PD-T7-4-0: pd-t7-4
+PD-T7-5-0: pd-t7-5
+Panchino_gp28-0: panchino_gp28
+PfiAT: pfiat
+Pif: pif
+PrrC-0: prrc
+PsyrTA: psyrta
+Pycsar: pycsar
+RT_Ec67_SLATT: retron
+Retron_II: retron
+Retron_III: retron
+Retron_IV: retron
+Retron_IX: retron
+Retron_I_A: retron
+Retron_I_B: retron
+Retron_V: retron
+Retron_VI: retron
+Retron_VIII: retron
+Retron_VII_2: retron
+Retron_X: retron
+Retron_XIII: retron
+RexAB: rexab
+RloC-0: rloc
+RnlAB: rnlab
+RosmerTA: rosmerta
+Rst_2TM_1TM_TIR: rst_2tm_1tm_tir
+Rst_3HP: rst_3hp
+Rst_DUF4238-0: rst_duf4238
+Rst_HelicaseDUF2290: rst_helicaseduf2290
+Rst_Hydrolase-Tm: rst_hydrolase-tm
+Rst_RT-Tm: rst_rt-nitrilase-tm
+Rst_TIR-NLR-0: rst_tir-nlr
+Rst_gop_beta_cll: rst_gop_beta_cll
+SEFIR-0: sefir
+SanaTA: sanata
+Septu: septu
+Shango: shango
+Shedu-0: shedu
+ShosTA: shosta
+SoFic-0: sofic
+SpbK-0: spbk
+SspBCDE: sspbcde
+Stk2-0: stk2
+Thoeris_I: thoeris
+Thoeris_II: thoeris
+Tiamat-0: tiamat
+Uzume-0: uzume
+Viperin-0: viperin
+Wadjet_I: wadjet
+Wadjet_II: wadjet
+Wadjet_III: wadjet
+Zorya_TypeI: zorya
+Zorya_TypeII: zorya
+dCTPdeaminase-0: dctpdeaminase
+dGTPase-0: dgtpase
+gp29_gp30: gp29_gp30
+pAgo_LongA-0: pago
+pAgo_LongB-0: pago
+pAgo_S1A-0: pago
+pAgo_S1B-0: pago
+pAgo_S2B-0: pago
+pAgo_SPARTA-0: pago
+radar_I: radar
+radar_II: radar
diff --git a/packages/df-wiki-cli/df_wiki_cli/content/main.py b/packages/df-wiki-cli/df_wiki_cli/content/main.py
index 32333d16..bea0f2d4 100644
--- a/packages/df-wiki-cli/df_wiki_cli/content/main.py
+++ b/packages/df-wiki-cli/df_wiki_cli/content/main.py
@@ -2,6 +2,8 @@ import typer
 import sys
 import re
 import shutil
+import csv
+import yaml
 from typing_extensions import Annotated
 from typing import Optional, List
 from pathlib import Path
@@ -78,13 +80,35 @@ def lint(
 
 @app.command()
 def structure(
+    stat: Annotated[
+        Path,
+        typer.Option(
+            exists=True,
+            file_okay=True,
+            dir_okay=True,
+            writable=False,
+            readable=True,
+            resolve_path=True,
+        ),
+    ],
+    map: Annotated[
+        Path,
+        typer.Option(
+            exists=True,
+            file_okay=True,
+            dir_okay=True,
+            writable=False,
+            readable=True,
+            resolve_path=True,
+        ),
+    ],
     dir: Annotated[
         Path,
         typer.Option(
             exists=True,
             file_okay=False,
             dir_okay=True,
-            writable=False,
+            writable=True,
             readable=True,
             resolve_path=True,
         ),
@@ -101,13 +125,30 @@ def structure(
         ),
     ],
 ):
-    console.rule(f"[bold blue]{dir.name}", style="blue")
-    for f in dir.iterdir():
-        console.print(f"[green] {f.name}")
-        # get the system name
-        system = re.split("_|\.|-0", f.name)[0].lower()
-
-        console.print(system)
-        systemDir = output / system
-        systemDir.mkdir(parents=True, exist_ok=True)
-        shutil.copy2(f, systemDir)
+    with open(map, "r") as map_f:
+        system_to_dir = yaml.safe_load(map_f)
+
+    with open(stat, "r") as stat_f:
+        reader = csv.DictReader(stat_f)
+
+        for row in reader:
+            dir_name = system_to_dir[row["system"]]
+            # console.rule(f"[bold blue]{dir_name}", style="blue")
+            files = [
+                {"f": Path(row["pdb"]), "d": "PDB"},
+                {"f": Path(row["pae_table"]), "d": "PAE"},
+                {"f": Path(row["fasta_file"]), "d": "Fastas"},
+                {"f": Path(row["Foldseek_name"]), "d": "foldseek_monomers_html"},
+            ]
+            target_dir = output / dir_name
+            target_dir.mkdir(parents=True, exist_ok=True)
+            for f in files:
+                str_f = str(f["f"])
+                if str_f and str_f != "." and str_f != "" and str_f != "na":
+                    # console.print("--" + str(f["f"]) + "--")
+                    # console.print(f"[green] copy {f['f'].name} to {target_dir}")
+                    file_to_copy = dir / f["d"] / f["f"]
+                    if file_to_copy.exists():
+                        shutil.copy2(file_to_copy, target_dir)
+                    else:
+                        console.print(f"[red] file {str(file_to_copy.name)} does not exist")
diff --git a/packages/df-wiki-cli/pyproject.toml b/packages/df-wiki-cli/pyproject.toml
index 320115fc..23602902 100644
--- a/packages/df-wiki-cli/pyproject.toml
+++ b/packages/df-wiki-cli/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "df-wiki-cli"
-version = "0.1.2"
+version = "0.1.3"
 description = ""
 authors = ["Remi  PLANEL <rplanel@pasteur.fr>"]
 readme = "README.md"
-- 
GitLab