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 32333d1601245e3c17bec85923cd043c05e5f621..bea0f2d4778a98e34d8da8a9b93dcef1f15fb67a 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 320115fc3a887382a669362e1118c0a5c2e4f373..236029026cd480779937ff757858d6cf7c8ad037 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"