Skip to content

Commit 33d965e

Browse files
committed
Added xchem metadata transformation
1 parent 1eb37a6 commit 33d965e

7 files changed

Lines changed: 206 additions & 39 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ mmcif-gen make-mmcif pdbe --help
8888
# Using metadata configuration
8989
mmcif-gen make-mmcif --json dls_metadata.json --output-folder ./out --id I_1234 dls --dls-json metadata-from-isypb.json
9090
```
91+
92+
#### XChem
93+
Parameters required
94+
```
95+
$ mmcif-gen make-mmcif xchem --help
96+
usage: mmcif-gen make-mmcif xchem [-h] [--sqlite SQLITE] [--cif-type {model,investigation}]
97+
98+
options:
99+
-h, --help show this help message and exit
100+
--sqlite SQLITE Path to the .sqlite file for each data set
101+
--cif-type {model,investigation}
102+
Type of the CIF file that will be generated
103+
```
104+
105+
Example command:
106+
```
107+
mmcif-gen make-mmcif --id 001 --json mmcif_gen/operations/xchem/xchem_operations_metadata.json --output-folder pdbedeposit xchem --sqlite mmcif_gen/test/data/lb32633-1-soakDBDataFile.sqlite --cif-type model
108+
```
109+
91110
### Working with Investigation Files
92111

93112
Investigation files are a specialized type of mmCIF file that capture metadata across multiple experiments.

mmcif_gen/facilities/xchem.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99

1010
class InvestigationXChem(InvestigationEngine):
1111

12-
def __init__(self, sqlite_path: str, deposit_path: str, cif_files: str, investigation_id: str, output_path: str) -> None:
12+
def __init__(self, sqlite_path: str, investigation_id: str, output_path: str, json_path: str, cif_type: str) -> None:
1313
logging.info("Instantiating XChem Investigation subclass")
14-
self.sqlite_reader= SqliteReader(sqlite_path)
15-
self.pickle_reader = PickleReader(deposit_path).data
16-
self.reader = CIFReader()
17-
self.reader.read_files(cif_files)
18-
self.operation_file_json = "./operations/xchem_operations.json"
14+
self.reader = SqliteReader(sqlite_path)
15+
self.operation_file_json = json_path
1916
self.excluded_libraries = ["'Diffraction Test'","'Solvent'"]
17+
self.cif_type = cif_type
2018
super().__init__(investigation_id, output_path)
2119

2220
def pre_run(self) -> None:
2321
logging.info("Pre-running")
24-
libraries=["XChem_Libraries_2024-02-01.csv"]
25-
for library in libraries:
26-
self.load_library_csv(f"./external_data/{library}")
27-
self.create_experiment_table()
28-
self.find_missing_compound_information()
22+
if self.cif_type == "investigation":
23+
libraries=["XChem_Libraries_2024-02-01.csv"]
24+
for library in libraries:
25+
self.load_library_csv(f"./external_data/{library}")
26+
self.create_experiment_table()
27+
self.find_missing_compound_information()
2928
super().pre_run()
3029

3130
def find_missing_compound_information(self) -> None:
@@ -193,27 +192,19 @@ def xchem_subparser(subparsers, parent_parser):
193192
help="Path to the .sqlite file for each data set"
194193
)
195194
parser_xchem.add_argument(
196-
"--deposit",
197-
help="Path for the deposition process via XCE"
198-
)
199-
parser_xchem.add_argument(
200-
"--txt",
201-
help="Path to add additional information or overwrite in mmcifs"
195+
"--cif-type",
196+
help="Type of the CIF file that will be generated",
197+
default="model",
198+
choices=["model", "investigation"]
202199
)
203200

204-
def run(sqlite_path : str, deposit_path: str, txt_path: str, investigation_id: str, output_path: str) -> None:
205-
cif_files = []
206-
if txt_path:
207-
cif_files = get_cif_file_paths(txt_path)
208-
print("List of CIF file paths:")
209-
for file_path in cif_files:
210-
print(file_path)
211-
im = InvestigationXChem(sqlite_path, deposit_path, cif_files, investigation_id, output_path)
201+
def run(sqlite_path : str, investigation_id: str, output_path: str, json_path: str, cif_type: str) -> None:
202+
im = InvestigationXChem(sqlite_path, investigation_id, output_path, json_path, cif_type)
212203
im.pre_run()
213204
im.run()
214205

215206
def run_investigation_xchem(args):
216207
if not args.sqlite:
217208
logging.error("XChem facility requires path to --sqlite file")
218209
return 1
219-
run(args.sqlite, args.deposit, args.txt, args.id, args.output_folder)
210+
run(args.sqlite, args.id, args.output_folder, args.json, args.cif_type)

mmcif_gen/investigation_engine.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ def read_json_operations(self) -> None:
4646
self.investigation_storage.mmcif_order = json_data.get("mmcif_order", [])
4747

4848
def operation_factory(self, operation_type: str, operation_reader: str) -> operationBase:
49-
if not operation_reader:
49+
try:
50+
if not operation_reader:
51+
operation_reader = self.reader
52+
elif operation_reader == "sqlite":
53+
operation_reader = self.sqlite_reader
54+
elif operation_reader == "pickle":
55+
operation_reader = self.pickle_reader
56+
elif operation_reader == "cif":
57+
operation_reader = self.reader
58+
elif operation_reader == "json":
59+
operation_reader = self.json_reader
60+
except KeyError:
61+
logging.error(f"Resorting to default reader")
5062
operation_reader = self.reader
51-
elif operation_reader == "sqlite":
52-
operation_reader = self.sqlite_reader
53-
elif operation_reader == "pickle":
54-
operation_reader = self.pickle_reader
55-
elif operation_reader == "cif":
56-
operation_reader = self.reader
57-
elif operation_reader == "json":
58-
operation_reader = self.json_reader
59-
6063

6164
if operation_type == "distinct_union":
6265
return UnionDistinctOperation(self.investigation_storage, operation_reader)

mmcif_gen/operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def perform_operation(self, operation_data):
191191

192192
self.investigation_storage.add_category(target_category)
193193
data = self.investigation_storage.data[target_category]
194-
rows_to_write = max(self.get_number_of_rows_in_data(data), 1)
194+
rows_to_write = 1
195195

196196
for index, item in enumerate(target_items):
197197
if item not in data:

mmcif_gen/operations/fetched_list.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"operations/dls/dls_metadata.json"],
44
"maxiv" : [ "operations/maxiv/maxiv_investigation.json"],
55
"xchem" : ["operations/xchem/xchem_operations.json",
6-
"operations/xchem/xchem_operations_soakdb.json"],
6+
"operations/xchem/xchem_operations_soakdb.json",
7+
"operations/xchem/xchem_operations_metadata.json"],
78
"pdbe" : ["operations/pdbe/pdbe_operations.json"]
89
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"operations": [
3+
{
4+
"target_category": "_software",
5+
"target_items": [
6+
"pdbx_ordinal",
7+
"classification",
8+
"name",
9+
"version"
10+
],
11+
"operation": "static_value",
12+
"target_values": [
13+
"1",
14+
"refinement",
15+
"Refmac or Buster",
16+
"?"
17+
]
18+
},
19+
{
20+
"target_category": "_software",
21+
"target_items": [
22+
"pdbx_ordinal",
23+
"classification",
24+
"name",
25+
"version"
26+
],
27+
"operation": "static_value",
28+
"target_values": [
29+
"2",
30+
"data reduction",
31+
"XDS",
32+
"?"
33+
]
34+
},
35+
{
36+
"target_category": "_software",
37+
"target_items": [
38+
"pdbx_ordinal",
39+
"classification",
40+
"name",
41+
"version"
42+
],
43+
"operation": "static_value",
44+
"target_values": [
45+
"3",
46+
"data_integration_software",
47+
"XDS",
48+
""
49+
]
50+
},
51+
{
52+
"target_category": "_software",
53+
"target_items": [
54+
"pdbx_ordinal",
55+
"classification",
56+
"name",
57+
"version"
58+
],
59+
"operation": "static_value",
60+
"target_values": [
61+
"4",
62+
"phasing_software",
63+
"PHASER",
64+
"?"
65+
]
66+
},
67+
{
68+
"target_category": "_software",
69+
"target_items": [
70+
"pdbx_ordinal",
71+
"classification",
72+
"name",
73+
"version"
74+
],
75+
"operation": "static_value",
76+
"target_values": [
77+
"5",
78+
"",
79+
"AIMLESS",
80+
"?"
81+
]
82+
},
83+
{
84+
"target_category": "_refine",
85+
"target_items": [
86+
"pdbx_diffrn_id",
87+
"pdbx_method_to_determine_struct"
88+
],
89+
"operation": "static_value",
90+
"target_values": [
91+
"1",
92+
"MOLECULAR REPLACEMENT"
93+
]
94+
},
95+
{
96+
"target_category": "_pdbx_initial_refinement_model",
97+
"target_items": [
98+
"type",
99+
"source_name",
100+
"details"
101+
],
102+
"operation": "static_value",
103+
"target_values": [
104+
"experimental model",
105+
"PDB",
106+
"?"
107+
]
108+
},
109+
{
110+
"target_category": "_pdbx_initial_refinement_model",
111+
"target_item": "id",
112+
"operation": "auto_increment"
113+
},
114+
{
115+
"target_category": "_pdbx_initial_refinement_model",
116+
"target_items": [
117+
"accession_code"
118+
],
119+
"operation": "sql_query",
120+
"operation_parameters": {
121+
"query": "SELECT DISTINCT pdbx_starting_model FROM depositTable WHERE pdbx_starting_model IS NOT NULL AND pdbx_starting_model != '' GROUP BY pdbx_starting_model"
122+
}
123+
},
124+
{
125+
"target_category": "_exptl_crystal_grow",
126+
"target_items": [
127+
"crystal_id",
128+
"method",
129+
"temp",
130+
"pH",
131+
"pdbx_details"
132+
],
133+
"operation": "sql_query",
134+
"operation_parameters": {
135+
"query": "SELECT DISTINCT crystallization_id, crystallization_method, crystallization_temperature, crystallization_pH, crystallization_details FROM depositTable WHERE crystallization_method IS NOT NULL OR crystallization_temperature IS NOT NULL OR crystallization_pH IS NOT NULL OR crystallization_details IS NOT NULL"
136+
}
137+
}
138+
],
139+
"mmcif_order": {
140+
"_software": [
141+
"pdbx_ordinal"
142+
],
143+
"_refine": [
144+
"pdbx_diffrn_id"
145+
],
146+
"_pdbx_initial_refinement_model": [
147+
"id"
148+
],
149+
"_exptl_crystal_grow": [
150+
"crystal_id"
151+
]
152+
}
153+
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="mmcif_gen",
11-
version="1.0.6",
11+
version="1.0.7",
1212
packages=find_packages(),
1313
install_requires=[
1414
"argparse",

0 commit comments

Comments
 (0)