Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
5d4534fa
Unverified
Commit
5d4534fa
authored
Jan 22, 2024
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rename_column
Added item_alias Rename columns in reconstruct
parent
f4506438
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
5 deletions
+79
-5
include/cif++/category.hpp
+3
-0
include/cif++/validate.hpp
+15
-1
src/category.cpp
+14
-0
src/dictionary_parser.cpp
+8
-1
src/pdb/reconstruct.cpp
+17
-3
src/validate.cpp
+22
-0
No files found.
include/cif++/category.hpp
View file @
5d4534fa
...
...
@@ -1041,6 +1041,9 @@ class category
*/
void
remove_column
(
std
::
string_view
column_name
);
/** @brief Rename column @a from_name to @a to_name */
void
rename_column
(
std
::
string_view
from_name
,
std
::
string_view
to_name
);
/// @brief Return whether a column with name @a name exists in this category
/// @param name The name of the column
/// @return True if the column exists
...
...
include/cif++/validate.hpp
View file @
5d4534fa
...
...
@@ -146,6 +146,16 @@ struct type_validator
int
compare
(
std
::
string_view
a
,
std
::
string_view
b
)
const
;
};
/** @brief Item alias, items can be renamed over time
*/
struct
item_alias
{
std
::
string
m_name
;
///< The alias_name
std
::
string
m_dict
;
///< The dictionary in which it was known
std
::
string
m_vers
;
///< The version of the dictionary
};
/**
* @brief An item_validator binds a type_validator to an item in
* a category along with other information found in the dictionary.
...
...
@@ -163,6 +173,7 @@ struct item_validator
cif
::
iset
m_enums
;
///< If filled, the set of allowed values
std
::
string
m_default
;
///< If filled, a default value for this item
category_validator
*
m_category
=
nullptr
;
///< The category_validator this item_validator belongs to
std
::
vector
<
item_alias
>
m_aliases
;
///< The aliases for this item
/// @brief Compare based on the name
bool
operator
<
(
const
item_validator
&
rhs
)
const
...
...
@@ -191,7 +202,7 @@ struct category_validator
{
std
::
string
m_name
;
///< The name of the category
std
::
vector
<
std
::
string
>
m_keys
;
///< The list of items that make up the key
cif
::
iset
m_groups
;
///< The category groups this category belongs to
cif
::
iset
m_groups
;
///< The category groups this category belongs to
cif
::
iset
m_mandatory_fields
;
///< The mandatory fields for this category
std
::
set
<
item_validator
>
m_item_validators
;
///< The item validators for the items in this category
...
...
@@ -206,6 +217,9 @@ struct category_validator
/// @brief Return the item_validator for item @a tag, may return nullptr
const
item_validator
*
get_validator_for_item
(
std
::
string_view
tag
)
const
;
/// @brief Return the item_validator for an item that has as alias name @a tag, may return nullptr
const
item_validator
*
get_validator_for_aliased_item
(
std
::
string_view
tag
)
const
;
};
/**
...
...
src/category.cpp
View file @
5d4534fa
...
...
@@ -614,6 +614,20 @@ void category::remove_column(std::string_view column_name)
}
}
void
category
::
rename_column
(
std
::
string_view
from_name
,
std
::
string_view
to_name
)
{
for
(
size_t
ix
=
0
;
ix
<
m_columns
.
size
();
++
ix
)
{
if
(
not
iequals
(
from_name
,
m_columns
[
ix
].
m_name
))
continue
;
m_columns
[
ix
].
m_name
=
to_name
;
m_columns
[
ix
].
m_validator
=
m_cat_validator
?
m_cat_validator
->
get_validator_for_item
(
to_name
)
:
nullptr
;
break
;
}
}
iset
category
::
get_columns
()
const
{
iset
result
;
...
...
src/dictionary_parser.cpp
View file @
5d4534fa
...
...
@@ -224,6 +224,13 @@ class dictionary_parser : public parser
// }
// }
std
::
vector
<
item_alias
>
aliases
;
for
(
const
auto
&
[
alias_name
,
dictionary
,
version
]
:
dict
[
"item_aliases"
].
rows
<
std
::
string
,
std
::
string
,
std
::
string
>
(
"alias_name"
,
"dictionary"
,
"version"
))
{
aliases
.
emplace_back
(
alias_name
,
dictionary
,
version
);
}
// collect the dict from our dataBlock and construct validators
for
(
auto
i
:
dict
[
"item"
])
{
...
...
@@ -245,7 +252,7 @@ class dictionary_parser : public parser
auto
vi
=
find
(
ivs
.
begin
(),
ivs
.
end
(),
item_validator
{
item_name
});
if
(
vi
==
ivs
.
end
())
ivs
.
push_back
(
item_validator
{
item_name
,
iequals
(
mandatory
,
"yes"
),
tv
,
ess
,
defaultValue
/*, defaultIsNull*/
});
ivs
.
push_back
(
item_validator
{
item_name
,
iequals
(
mandatory
,
"yes"
),
tv
,
ess
,
defaultValue
,
nullptr
,
std
::
move
(
aliases
)
});
else
{
// need to update the itemValidator?
...
...
src/pdb/reconstruct.cpp
View file @
5d4534fa
...
...
@@ -683,9 +683,6 @@ void comparePolySeqSchemes(datablock &db)
}
}
}
if
(
ndb_poly_seq_scheme
.
empty
())
db
.
erase
(
std
::
remove
(
db
.
begin
(),
db
.
end
(),
ndb_poly_seq_scheme
),
db
.
end
());
}
void
reconstruct_pdbx
(
file
&
file
,
std
::
string_view
dictionary
)
...
...
@@ -732,6 +729,23 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
auto
cv
=
validator
.
get_validator_for_category
(
cat
.
name
());
if
(
not
cv
)
continue
;
// Start by renaming columns that may have old names based on alias info
for
(
auto
tag
:
cat
.
get_columns
())
{
auto
iv
=
cv
->
get_validator_for_item
(
tag
);
if
(
iv
)
// know, must be OK then
continue
;
iv
=
cv
->
get_validator_for_aliased_item
(
tag
);
if
(
not
iv
)
continue
;
if
(
cif
::
VERBOSE
>
0
)
std
::
clog
<<
"Renaming "
<<
tag
<<
" to "
<<
iv
->
m_tag
<<
" in category "
<<
cat
.
name
()
<<
'\n'
;
cat
.
rename_column
(
tag
,
iv
->
m_tag
);
}
for
(
auto
link
:
validator
.
get_links_for_child
(
cat
.
name
()))
{
...
...
src/validate.cpp
View file @
5d4534fa
...
...
@@ -256,6 +256,28 @@ const item_validator *category_validator::get_validator_for_item(std::string_vie
return
result
;
}
const
item_validator
*
category_validator
::
get_validator_for_aliased_item
(
std
::
string_view
tag
)
const
{
const
item_validator
*
result
=
nullptr
;
for
(
auto
&
iv
:
m_item_validators
)
{
for
(
auto
&
ai
:
iv
.
m_aliases
)
{
const
auto
&
[
cat
,
name
]
=
split_tag_name
(
ai
.
m_name
);
if
(
name
==
tag
and
cat
==
m_name
)
{
result
=
&
iv
;
break
;
}
}
if
(
result
)
break
;
}
return
result
;
}
// --------------------------------------------------------------------
void
validator
::
add_type_validator
(
type_validator
&&
v
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment