Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
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
Show more breadcrumbs
Michal Malý
Molstar
Commits
a7119590
Commit
a7119590
authored
7 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
get types for all fields in mmcif dic
parent
29787be0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/reader/cif/schema/utils.ts
+72
-23
72 additions, 23 deletions
src/reader/cif/schema/utils.ts
src/script.ts
+1
-1
1 addition, 1 deletion
src/script.ts
with
73 additions
and
24 deletions
src/reader/cif/schema/utils.ts
+
72
−
23
View file @
a7119590
...
@@ -63,38 +63,87 @@ function getFieldType (type: string) {
...
@@ -63,38 +63,87 @@ function getFieldType (type: string) {
return
str
return
str
}
}
type
SafeFrameCategories
=
{
[
category
:
string
]:
Data
.
SafeFrame
}
type
SafeFrameLinks
=
{
[
k
:
string
]:
string
}
interface
SafeFrameData
{
categories
:
SafeFrameCategories
links
:
SafeFrameLinks
}
function
getCode
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
|
undefined
{
const
{
categories
,
links
}
=
ctx
const
item_type
=
d
.
categories
[
'
_item_type
'
]
if
(
item_type
)
{
const
code
=
item_type
.
getField
(
'
code
'
)
if
(
code
)
{
return
code
.
str
(
0
)
}
else
{
console
.
log
(
`item_type.code not found for '
${
d
.
header
}
'`
)
}
}
else
{
if
(
d
.
header
in
links
)
{
return
getCode
(
categories
[
links
[
d
.
header
]],
ctx
)
}
else
{
console
.
log
(
`no links found for '
${
d
.
header
}
'`
)
}
}
}
export
function
getSchema
(
dic
:
Data
.
Block
)
{
// todo Block needs to be specialized with safe frames as well
export
function
getSchema
(
dic
:
Data
.
Block
)
{
// todo Block needs to be specialized with safe frames as well
const
schema
:
{
[
category
:
string
]:
Category
.
Schema
}
=
{}
const
schema
:
{
[
category
:
string
]:
Category
.
Schema
}
=
{}
const
categories
:
SafeFrameCategories
=
{}
const
links
:
SafeFrameLinks
=
{}
dic
.
saveFrames
.
forEach
(
d
=>
{
dic
.
saveFrames
.
forEach
(
d
=>
{
if
(
d
.
header
[
0
]
!==
'
_
'
)
{
if
(
d
.
header
[
0
]
!==
'
_
'
)
return
schema
[
d
.
header
]
=
{}
categories
[
d
.
header
]
=
d
}
else
{
const
item_linked
=
d
.
categories
[
'
_item_linked
'
]
const
categoryName
=
d
.
header
.
substring
(
1
,
d
.
header
.
indexOf
(
'
.
'
))
if
(
item_linked
)
{
const
itemName
=
d
.
header
.
substring
(
d
.
header
.
indexOf
(
'
.
'
)
+
1
)
const
child_name
=
item_linked
.
getField
(
'
child_name
'
)
let
fields
const
parent_name
=
item_linked
.
getField
(
'
parent_name
'
)
if
(
categoryName
in
schema
)
{
if
(
child_name
&&
parent_name
)
{
fields
=
schema
[
categoryName
]
for
(
let
i
=
0
;
i
<
item_linked
.
rowCount
;
++
i
)
{
}
else
{
const
childName
=
child_name
.
str
(
i
)
fields
=
{}
const
parentName
=
parent_name
.
str
(
i
)
schema
[
categoryName
]
=
fields
if
(
childName
in
links
&&
links
[
childName
]
!==
parentName
)
{
}
console
.
log
(
`
${
childName
}
linked to
${
links
[
childName
]}
, ignoring link to
${
parentName
}
`
)
// console.log(util.inspect(d.categories, {showHidden: false, depth: 1}))
}
const
item_type
=
d
.
categories
[
'
_item_type
'
]
links
[
childName
]
=
parentName
if
(
item_type
)
{
const
code
=
item_type
.
getField
(
'
code
'
)
if
(
code
)
{
fields
[
itemName
]
=
getFieldType
(
code
.
str
(
0
))
}
else
{
console
.
log
(
`item_type.code not found for '
${
d
.
header
}
'`
)
}
}
}
else
{
// TODO check for _item_linked.parent_name and use its type
console
.
log
(
`item_type not found for '
${
d
.
header
}
'`
)
}
}
}
})
Object
.
keys
(
categories
).
forEach
(
categoryName
=>
{
const
d
=
categories
[
categoryName
]
const
itemName
=
d
.
header
.
substring
(
d
.
header
.
indexOf
(
'
.
'
)
+
1
)
let
fields
if
(
categoryName
in
schema
)
{
fields
=
schema
[
categoryName
]
}
else
{
fields
=
{}
schema
[
categoryName
]
=
fields
}
const
code
=
getCode
(
d
,
{
categories
,
links
})
if
(
code
)
{
fields
[
itemName
]
=
getFieldType
(
code
)
}
else
{
console
.
log
(
`could not determine code for '
${
d
.
header
}
'`
)
}
}
})
})
return
schema
return
schema
}
}
// TODO
// support controlled vocabulary as a specialization string type field
// in the example below the string type would be `Y|N`
// _item_type.code ucode
// loop_
// _item_enumeration.value
// _item_enumeration.detail
// Y 'Yes'
// N 'No'
This diff is collapsed.
Click to expand it.
src/script.ts
+
1
−
1
View file @
a7119590
...
@@ -156,7 +156,7 @@ async function runDic(input: string | Uint8Array) {
...
@@ -156,7 +156,7 @@ async function runDic(input: string | Uint8Array) {
}
}
export
function
_dic
()
{
export
function
_dic
()
{
let
path
=
'
.
./test
/mmcif_pdbx_v50.dic
'
let
path
=
'
.
/build/dics
/mmcif_pdbx_v50.dic
'
fs
.
readFile
(
path
,
'
utf8
'
,
function
(
err
,
input
)
{
fs
.
readFile
(
path
,
'
utf8
'
,
function
(
err
,
input
)
{
if
(
err
)
{
if
(
err
)
{
return
console
.
log
(
err
);
return
console
.
log
(
err
);
...
...
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