Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MDM Lab
Wiki
Merge requests
!161
List system ms
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
List system ms
list-system-ms
into
main
Overview
0
Commits
4
Pipelines
2
Changes
5
Merged
Remi PLANEL
requested to merge
list-system-ms
into
main
1 year ago
Overview
0
Commits
4
Pipelines
2
Changes
5
Expand
0
0
Merge request reports
Viewing commit
ac32dcc0
Prev
Next
Show latest version
5 files
+
121
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
ac32dcc0
df-wiki-cli: can create a systems index in meilisearch
· ac32dcc0
Remi PLANEL
authored
1 year ago
packages/df-wiki-cli/df_wiki_cli/content/main.py
+
80
−
0
Options
import
typer
import
sys
import
re
import
json
import
pandas
as
pd
from
pandas.errors
import
InvalidIndexError
import
shutil
from
typing_extensions
import
Annotated
from
typing
import
Optional
,
List
@@ -111,3 +114,80 @@ def structure(
systemDir
=
output
/
system
systemDir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
shutil
.
copy2
(
f
,
systemDir
)
@app.command
()
def
systems
(
dir
:
Annotated
[
Path
,
typer
.
Option
(
exists
=
False
,
file_okay
=
False
,
readable
=
True
,
dir_okay
=
True
),
],
pfam
:
Annotated
[
Path
,
typer
.
Option
(
exists
=
False
,
file_okay
=
True
,
writable
=
True
,
),
],
output
:
Annotated
[
Path
,
typer
.
Option
(
file_okay
=
True
,
dir_okay
=
False
,
writable
=
True
,
resolve_path
=
True
,
),
],
):
with
open
(
pfam
,
"
r
"
)
as
pf
:
pfam_df
=
pd
.
read_csv
(
pf
,
index_col
=
"
AC
"
,
keep_default_na
=
False
)
systems
=
[]
with
open
(
output
,
"
a
"
)
as
ty
:
for
file
in
dir
.
iterdir
():
if
file
.
suffix
==
"
.md
"
:
console
.
rule
(
f
"
[bold blue]
{
file
.
name
}
"
,
style
=
"
blue
"
)
with
open
(
file
)
as
f
:
metadata
,
_
=
frontmatter
.
parse
(
f
.
read
())
del
metadata
[
"
layout
"
]
if
"
tableColumns
"
in
metadata
:
table_data
=
metadata
[
"
tableColumns
"
]
if
"
PFAM
"
in
table_data
:
# print(table_data["PFAM"])
pfams_list
=
[
pfam
.
strip
()
for
pfam
in
table_data
[
"
PFAM
"
].
split
(
"
,
"
)
]
pfam_metadata
=
list
()
for
pfam
in
pfams_list
:
try
:
pfam_obj
=
pfam_df
.
loc
[[
pfam
]]
# print(pfam_obj)
pfam_to_dict
=
pfam_obj
.
to_dict
(
orient
=
"
index
"
)
pfam_to_dict
[
pfam
][
"
AC
"
]
=
pfam
flatten_value
=
pfam_to_dict
[
pfam
]
pfam_metadata
.
append
(
flatten_value
)
except
KeyError
as
err
:
console
.
print
(
f
"
[bold red]
{
err
}
"
,
style
=
"
red
"
)
console
.
print
(
f
"
[bold red]No pfam entry or
{
pfam
}
"
,
style
=
"
red
"
,
)
continue
del
metadata
[
"
tableColumns
"
]
if
"
article
"
in
table_data
:
metadata
[
"
doi
"
]
=
table_data
[
"
article
"
][
"
doi
"
]
if
"
abstract
"
in
table_data
[
"
article
"
]:
metadata
[
"
abstract
"
]
=
table_data
[
"
article
"
][
"
abstract
"
]
del
table_data
[
"
article
"
]
sanitizedMetadata
=
{
**
metadata
,
**
table_data
}
sanitizedMetadata
[
"
PFAM
"
]
=
pfam_metadata
systems
.
append
(
sanitizedMetadata
)
json_object
=
json
.
dumps
(
systems
,
indent
=
2
)
ty
.
write
(
json_object
)
Loading