Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Extended Microorganisms Taxonomy
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
A compter du 1er avril, attention à vos pipelines :
Nouvelles limitations de Docker Hub
Show more breadcrumbs
Omnicrobe
Extended Microorganisms Taxonomy
Commits
893a56ae
Commit
893a56ae
authored
11 months ago
by
Robert Bossy
Browse files
Options
Downloads
Patches
Plain Diff
refactored MeSH handling code
parent
55129836
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mesh.py
+47
-0
47 additions, 0 deletions
mesh.py
scripts/roots2mesh-tree.py
+9
-33
9 additions, 33 deletions
scripts/roots2mesh-tree.py
with
56 additions
and
33 deletions
mesh.py
0 → 100644
+
47
−
0
View file @
893a56ae
import
collections
import
re
_prop_pattern
=
re
.
compile
(
'
([1A-Z_ ]+) = (.*)
'
)
class
Values
(
list
):
def
__init__
(
self
):
super
().
__init__
()
def
__bool__
(
self
):
return
True
class
Record
(
collections
.
defaultdict
):
def
__init__
(
self
):
super
().
__init__
(
Values
)
def
__getattr__
(
self
,
item
):
return
self
[
item
]
@property
def
uid
(
self
):
return
self
.
UI
[
0
]
def
records
(
path
):
current
=
Record
()
with
open
(
path
)
as
f
:
for
line
in
f
:
line
=
line
.
strip
()
if
line
==
''
:
continue
if
line
==
'
*NEWRECORD
'
:
if
'
UI
'
in
current
:
yield
current
current
=
Record
()
continue
m
=
_prop_pattern
.
fullmatch
(
line
)
if
m
is
None
:
raise
RuntimeError
(
'
could not parse:
'
+
line
)
key
=
m
.
group
(
1
)
value
=
m
.
group
(
2
)
current
[
key
].
append
(
value
)
if
'
UI
'
in
current
:
yield
current
This diff is collapsed.
Click to expand it.
scripts/roots2mesh-tree.py
+
9
−
33
View file @
893a56ae
...
...
@@ -3,8 +3,7 @@
import
sys
import
yaml
import
re
import
collections
import
mesh
MESH_FILE
=
sys
.
argv
[
1
]
...
...
@@ -15,41 +14,18 @@ with open(ROOTS_FILE) as f:
ROOTS
=
dict
((
e
[
'
mesh-id
'
],
e
[
'
name
'
])
for
e
in
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
if
'
mesh-id
'
in
e
)
LINE
=
re
.
compile
(
'
([1A-Z_ ]+) = (.*)
'
)
SEEN
=
set
()
def
finish
(
rec
):
if
'
UI
'
not
in
rec
:
return
if
rec
[
'
UI
'
][
0
]
not
in
ROOTS
:
return
if
'
MN
'
not
in
rec
:
raise
RuntimeError
(
'
no tree for
'
+
rec
[
'
UI
'
][
0
])
for
mtree
in
rec
[
'
MN
'
]:
for
rec
in
mesh
.
records
(
MESH_FILE
):
mid
=
rec
.
uid
if
mid
not
in
ROOTS
:
continue
if
not
rec
.
MN
:
raise
RuntimeError
(
'
no tree for
'
+
mid
)
for
mtree
in
rec
.
MN
:
print
(
mtree
)
SEEN
.
add
(
rec
[
'
UI
'
][
0
])
current
=
collections
.
defaultdict
(
list
)
with
open
(
MESH_FILE
)
as
f
:
for
line
in
f
:
line
=
line
.
strip
()
if
line
==
''
:
continue
if
line
==
'
*NEWRECORD
'
:
finish
(
current
)
current
=
collections
.
defaultdict
(
list
)
continue
m
=
LINE
.
fullmatch
(
line
)
if
m
is
None
:
raise
RuntimeError
(
'
could not parse:
'
+
line
)
key
=
m
.
group
(
1
)
value
=
m
.
group
(
2
)
current
[
key
].
append
(
value
)
finish
(
current
)
SEEN
.
add
(
mid
)
for
meshid
,
name
in
ROOTS
.
items
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment