pynmrstar 3.3.3__cp311-cp311-win32.whl → 3.3.5__cp311-cp311-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pynmrstar might be problematic. Click here for more details.
- cnmrstar.cp311-win32.pyd +0 -0
- pynmrstar/_internal.py +5 -3
- pynmrstar/entry.py +39 -17
- pynmrstar/loop.py +53 -22
- pynmrstar/parser.py +15 -6
- pynmrstar/saveframe.py +57 -19
- pynmrstar/schema.py +6 -9
- {pynmrstar-3.3.3.dist-info → pynmrstar-3.3.5.dist-info}/METADATA +3 -3
- pynmrstar-3.3.5.dist-info/RECORD +19 -0
- {pynmrstar-3.3.3.dist-info → pynmrstar-3.3.5.dist-info}/WHEEL +1 -1
- pynmrstar-3.3.3.dist-info/RECORD +0 -19
- {pynmrstar-3.3.3.dist-info → pynmrstar-3.3.5.dist-info}/LICENSE +0 -0
- {pynmrstar-3.3.3.dist-info → pynmrstar-3.3.5.dist-info}/top_level.txt +0 -0
cnmrstar.cp311-win32.pyd
CHANGED
|
Binary file
|
pynmrstar/_internal.py
CHANGED
|
@@ -13,7 +13,7 @@ from urllib.request import urlopen, Request
|
|
|
13
13
|
|
|
14
14
|
import pynmrstar
|
|
15
15
|
|
|
16
|
-
__version__: str = "3.3.
|
|
16
|
+
__version__: str = "3.3.5"
|
|
17
17
|
min_cnmrstar_version: str = "3.2.0"
|
|
18
18
|
|
|
19
19
|
# If we have requests, open a session to reuse for the duration of the program run
|
|
@@ -141,7 +141,9 @@ def _get_url_reliably(url: str, wait_time: float = 10, raw: bool = False, timeou
|
|
|
141
141
|
return serialized_ent.decode()
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
def _get_entry_from_database(entry_num: Union[str, int],
|
|
144
|
+
def _get_entry_from_database(entry_num: Union[str, int],
|
|
145
|
+
convert_data_types: bool = False,
|
|
146
|
+
schema: 'pynmrstar.Schema' = None) -> 'pynmrstar.Entry':
|
|
145
147
|
""" Fetches an entry from the API (or falls back to the FTP site) in
|
|
146
148
|
as reliable and robust a way as possible. Used by Entry.from_database(). """
|
|
147
149
|
|
|
@@ -190,7 +192,7 @@ def _get_entry_from_database(entry_num: Union[str, int], convert_data_types: boo
|
|
|
190
192
|
each_loop.source = ent.source
|
|
191
193
|
|
|
192
194
|
if convert_data_types:
|
|
193
|
-
schema = pynmrstar.utils.get_schema()
|
|
195
|
+
schema = pynmrstar.utils.get_schema(schema)
|
|
194
196
|
for each_saveframe in ent:
|
|
195
197
|
for tag in each_saveframe.tags:
|
|
196
198
|
cur_tag = each_saveframe.tag_prefix + "." + tag[0]
|
pynmrstar/entry.py
CHANGED
|
@@ -279,7 +279,10 @@ class Entry(object):
|
|
|
279
279
|
return self._frame_list
|
|
280
280
|
|
|
281
281
|
@classmethod
|
|
282
|
-
def from_database(cls,
|
|
282
|
+
def from_database(cls,
|
|
283
|
+
entry_num: Union[str, int],
|
|
284
|
+
convert_data_types: bool = False,
|
|
285
|
+
schema: Schema = None):
|
|
283
286
|
"""Create an entry corresponding to the most up to date entry on
|
|
284
287
|
the public BMRB server. (Requires ability to initiate outbound
|
|
285
288
|
HTTP connections.)
|
|
@@ -292,13 +295,19 @@ class Entry(object):
|
|
|
292
295
|
dates will become datetime.date objects. When printing str() is called
|
|
293
296
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
294
297
|
notation floats to lowercase "e"s this should not cause any change in
|
|
295
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
298
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
299
|
+
schema object to use using the schema parameter."""
|
|
296
300
|
|
|
297
|
-
return _get_entry_from_database(entry_num,
|
|
301
|
+
return _get_entry_from_database(entry_num,
|
|
302
|
+
convert_data_types=convert_data_types,
|
|
303
|
+
schema=schema)
|
|
298
304
|
|
|
299
305
|
@classmethod
|
|
300
|
-
def from_file(cls,
|
|
301
|
-
|
|
306
|
+
def from_file(cls,
|
|
307
|
+
the_file: Union[str, TextIO, BinaryIO],
|
|
308
|
+
convert_data_types: bool = False,
|
|
309
|
+
raise_parse_warnings: bool = False,
|
|
310
|
+
schema: Schema = None):
|
|
302
311
|
"""Create an entry by loading in a file. If the_file starts with
|
|
303
312
|
http://, https://, or ftp:// then we will use those protocols to
|
|
304
313
|
attempt to open the file.
|
|
@@ -311,14 +320,17 @@ class Entry(object):
|
|
|
311
320
|
dates will become datetime.date objects. When printing str() is called
|
|
312
321
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
313
322
|
notation floats to lowercase "e"s this should not cause any change in
|
|
314
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
323
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
324
|
+
schema object to use using the schema parameter.
|
|
315
325
|
|
|
316
326
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
317
327
|
ParsingError rather than logging a warning when non-valid (but
|
|
318
328
|
ignorable) issues are found. """
|
|
319
329
|
|
|
320
|
-
return cls(file_name=the_file,
|
|
321
|
-
|
|
330
|
+
return cls(file_name=the_file,
|
|
331
|
+
convert_data_types=convert_data_types,
|
|
332
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
333
|
+
schema=schema)
|
|
322
334
|
|
|
323
335
|
@classmethod
|
|
324
336
|
def from_json(cls, json_dict: Union[dict, str]):
|
|
@@ -352,8 +364,11 @@ class Entry(object):
|
|
|
352
364
|
return ret
|
|
353
365
|
|
|
354
366
|
@classmethod
|
|
355
|
-
def from_string(cls,
|
|
356
|
-
|
|
367
|
+
def from_string(cls,
|
|
368
|
+
the_string: str,
|
|
369
|
+
convert_data_types: bool = False,
|
|
370
|
+
raise_parse_warnings: bool = False,
|
|
371
|
+
schema: Schema = None):
|
|
357
372
|
"""Create an entry by parsing a string.
|
|
358
373
|
|
|
359
374
|
|
|
@@ -365,14 +380,17 @@ class Entry(object):
|
|
|
365
380
|
dates will become datetime.date objects. When printing str() is called
|
|
366
381
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
367
382
|
notation floats to lowercase "e"s this should not cause any change in
|
|
368
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
383
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
384
|
+
schema object to use using the schema parameter.
|
|
369
385
|
|
|
370
386
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
371
387
|
ParsingError rather than logging a warning when non-valid (but
|
|
372
388
|
ignorable) issues are found."""
|
|
373
389
|
|
|
374
|
-
return cls(the_string=the_string,
|
|
375
|
-
|
|
390
|
+
return cls(the_string=the_string,
|
|
391
|
+
convert_data_types=convert_data_types,
|
|
392
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
393
|
+
schema=schema)
|
|
376
394
|
|
|
377
395
|
@classmethod
|
|
378
396
|
def from_scratch(cls, entry_id: Union[str, int]):
|
|
@@ -383,7 +401,11 @@ class Entry(object):
|
|
|
383
401
|
return cls(entry_id=entry_id)
|
|
384
402
|
|
|
385
403
|
@classmethod
|
|
386
|
-
def from_template(cls,
|
|
404
|
+
def from_template(cls,
|
|
405
|
+
entry_id,
|
|
406
|
+
all_tags=False,
|
|
407
|
+
default_values=False,
|
|
408
|
+
schema=None) -> 'Entry':
|
|
387
409
|
""" Create an entry that has all of the saveframes and loops from the
|
|
388
410
|
schema present. No values will be assigned. Specify the entry
|
|
389
411
|
ID when calling this method.
|
|
@@ -452,7 +474,7 @@ class Entry(object):
|
|
|
452
474
|
|
|
453
475
|
return diffs
|
|
454
476
|
|
|
455
|
-
def add_missing_tags(self, schema:
|
|
477
|
+
def add_missing_tags(self, schema: Schema = None, all_tags: bool = False) -> None:
|
|
456
478
|
""" Automatically adds any missing tags (according to the schema)
|
|
457
479
|
to all saveframes and loops and sorts the tags. """
|
|
458
480
|
|
|
@@ -561,7 +583,7 @@ class Entry(object):
|
|
|
561
583
|
|
|
562
584
|
return results
|
|
563
585
|
|
|
564
|
-
def normalize(self, schema: Optional[
|
|
586
|
+
def normalize(self, schema: Optional[Schema] = None) -> None:
|
|
565
587
|
""" Sorts saveframes, loops, and tags according to the schema
|
|
566
588
|
provided (or BMRB default if none provided).
|
|
567
589
|
|
|
@@ -881,7 +903,7 @@ class Entry(object):
|
|
|
881
903
|
if val == old_reference:
|
|
882
904
|
each_row[pos] = new_reference
|
|
883
905
|
|
|
884
|
-
def validate(self, validate_schema: bool = True, schema:
|
|
906
|
+
def validate(self, validate_schema: bool = True, schema: Schema = None,
|
|
885
907
|
validate_star: bool = True) -> List[str]:
|
|
886
908
|
"""Validate an entry in a variety of ways. Returns a list of
|
|
887
909
|
errors found. 0-length list indicates no errors found. By
|
pynmrstar/loop.py
CHANGED
|
@@ -108,7 +108,9 @@ class Loop(object):
|
|
|
108
108
|
csv_file = csv_reader(star_buffer)
|
|
109
109
|
self.add_tag(next(csv_file))
|
|
110
110
|
for row in csv_file:
|
|
111
|
-
self.add_data(row,
|
|
111
|
+
self.add_data(row,
|
|
112
|
+
convert_data_types=kwargs.get('convert_data_types', False),
|
|
113
|
+
schema=kwargs.get('schema', None))
|
|
112
114
|
self.source = f"from_csv('{kwargs['csv']}')"
|
|
113
115
|
return
|
|
114
116
|
|
|
@@ -118,8 +120,11 @@ class Loop(object):
|
|
|
118
120
|
star_buffer = StringIO(f"data_0 save_internaluseyoushouldntseethis_frame _internal.use internal "
|
|
119
121
|
f"{star_buffer.read()} save_")
|
|
120
122
|
parser = Parser(entry_to_parse_into=tmp_entry)
|
|
121
|
-
parser.parse(star_buffer.read(),
|
|
122
|
-
|
|
123
|
+
parser.parse(star_buffer.read(),
|
|
124
|
+
source=self.source,
|
|
125
|
+
convert_data_types=kwargs.get('convert_data_types', False),
|
|
126
|
+
raise_parse_warnings=kwargs.get('raise_parse_warnings', False),
|
|
127
|
+
schema=kwargs.get('schema', None))
|
|
123
128
|
|
|
124
129
|
# Check that there was only one loop here
|
|
125
130
|
if len(tmp_entry[0].loops) > 1:
|
|
@@ -288,8 +293,12 @@ class Loop(object):
|
|
|
288
293
|
return self._tags
|
|
289
294
|
|
|
290
295
|
@classmethod
|
|
291
|
-
def from_file(cls,
|
|
292
|
-
|
|
296
|
+
def from_file(cls,
|
|
297
|
+
the_file: Union[str, TextIO, BinaryIO],
|
|
298
|
+
csv: bool = False,
|
|
299
|
+
convert_data_types: bool = False,
|
|
300
|
+
raise_parse_warnings: bool = False,
|
|
301
|
+
schema: Schema = None):
|
|
293
302
|
"""Create a loop by loading in a file. Specify csv=True if
|
|
294
303
|
the file is a CSV file. If the_file starts with http://,
|
|
295
304
|
https://, or ftp:// then we will use those protocols to attempt
|
|
@@ -303,14 +312,18 @@ class Loop(object):
|
|
|
303
312
|
dates will become datetime.date objects. When printing str() is called
|
|
304
313
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
305
314
|
notation floats to lowercase "e"s this should not cause any change in
|
|
306
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
315
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
316
|
+
schema object to use using the schema parameter.
|
|
307
317
|
|
|
308
318
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
309
319
|
ParsingError rather than logging a warning when non-valid (but
|
|
310
320
|
ignorable) issues are found."""
|
|
311
321
|
|
|
312
|
-
return cls(file_name=the_file,
|
|
313
|
-
|
|
322
|
+
return cls(file_name=the_file,
|
|
323
|
+
csv=csv,
|
|
324
|
+
convert_data_types=convert_data_types,
|
|
325
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
326
|
+
schema=schema)
|
|
314
327
|
|
|
315
328
|
@classmethod
|
|
316
329
|
def from_json(cls, json_dict: Union[dict, str]):
|
|
@@ -340,7 +353,9 @@ class Loop(object):
|
|
|
340
353
|
return ret
|
|
341
354
|
|
|
342
355
|
@classmethod
|
|
343
|
-
def from_scratch(cls,
|
|
356
|
+
def from_scratch(cls,
|
|
357
|
+
category: str = None,
|
|
358
|
+
source: str = "from_scratch()"):
|
|
344
359
|
"""Create an empty saveframe that you can programmatically add
|
|
345
360
|
to. You may also pass the tag prefix as the second argument. If
|
|
346
361
|
you do not pass the tag prefix it will be set the first time you
|
|
@@ -349,9 +364,13 @@ class Loop(object):
|
|
|
349
364
|
return cls(category=category, source=source)
|
|
350
365
|
|
|
351
366
|
@classmethod
|
|
352
|
-
def from_string(cls,
|
|
353
|
-
|
|
354
|
-
|
|
367
|
+
def from_string(cls,
|
|
368
|
+
the_string: str,
|
|
369
|
+
csv: bool = False,
|
|
370
|
+
convert_data_types: bool = False,
|
|
371
|
+
raise_parse_warnings: bool = False,
|
|
372
|
+
schema: Schema = None):
|
|
373
|
+
"""Create a loop by parsing a string. Specify csv=True if
|
|
355
374
|
the string is in CSV format and not NMR-STAR format.
|
|
356
375
|
|
|
357
376
|
Setting convert_data_types to True will automatically convert
|
|
@@ -362,17 +381,23 @@ class Loop(object):
|
|
|
362
381
|
dates will become datetime.date objects. When printing str() is called
|
|
363
382
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
364
383
|
notation floats to lowercase "e"s this should not cause any change in
|
|
365
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
384
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
385
|
+
schema object to use using the schema parameter.
|
|
366
386
|
|
|
367
387
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
368
388
|
ParsingError rather than logging a warning when non-valid (but
|
|
369
389
|
ignorable) issues are found."""
|
|
370
390
|
|
|
371
|
-
return cls(the_string=the_string,
|
|
372
|
-
|
|
391
|
+
return cls(the_string=the_string,
|
|
392
|
+
csv=csv,
|
|
393
|
+
convert_data_types=convert_data_types,
|
|
394
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
395
|
+
schema=schema)
|
|
373
396
|
|
|
374
397
|
@classmethod
|
|
375
|
-
def from_template(cls, tag_prefix: str,
|
|
398
|
+
def from_template(cls, tag_prefix: str,
|
|
399
|
+
all_tags: bool = False,
|
|
400
|
+
schema: Schema = None):
|
|
376
401
|
""" Create a loop that has all of the tags from the schema present.
|
|
377
402
|
No values will be assigned. Specify the tag prefix of the loop.
|
|
378
403
|
|
|
@@ -380,8 +405,10 @@ class Loop(object):
|
|
|
380
405
|
rather than just the mandatory tags."""
|
|
381
406
|
|
|
382
407
|
schema = utils.get_schema(schema)
|
|
383
|
-
return cls(tag_prefix=tag_prefix,
|
|
384
|
-
|
|
408
|
+
return cls(tag_prefix=tag_prefix,
|
|
409
|
+
all_tags=all_tags,
|
|
410
|
+
schema=schema,
|
|
411
|
+
source=f"from_template({schema.version})")
|
|
385
412
|
|
|
386
413
|
@staticmethod
|
|
387
414
|
def _get_tags_from_schema(category: str, schema: Schema = None, all_tags: bool = False) -> List[str]:
|
|
@@ -434,7 +461,8 @@ class Loop(object):
|
|
|
434
461
|
def add_data(self,
|
|
435
462
|
data: Union[List[dict], Dict[str, List], List[Union[str, float, int]], List[List[Any]]],
|
|
436
463
|
rearrange: bool = False,
|
|
437
|
-
convert_data_types: bool = False
|
|
464
|
+
convert_data_types: bool = False,
|
|
465
|
+
schema: Schema = None):
|
|
438
466
|
"""Add data to a loop. You can provide the data to add organized in four different ways, though the first
|
|
439
467
|
two are recommended for new code. The other two (#3 and #4) are preserved for sake of existing code (written
|
|
440
468
|
prior to version 3.3) and for niche use cases:
|
|
@@ -470,6 +498,9 @@ class Loop(object):
|
|
|
470
498
|
:param rearrange: If true, rearrange data provided in method #4 as necessary to fit in the loop. This only
|
|
471
499
|
exists for parsers, and it's use is strongly discouraged.
|
|
472
500
|
:type rearrange: bool
|
|
501
|
+
:param schema: A pynmrstar Schema object, which will be used to determine data types if convert_data_types
|
|
502
|
+
is True.
|
|
503
|
+
:type schema: pynmrstar.Schema
|
|
473
504
|
"""
|
|
474
505
|
|
|
475
506
|
if not data:
|
|
@@ -537,7 +568,7 @@ class Loop(object):
|
|
|
537
568
|
|
|
538
569
|
# Auto convert data types if option set
|
|
539
570
|
if convert_data_types:
|
|
540
|
-
schema = utils.get_schema()
|
|
571
|
+
schema = utils.get_schema(schema)
|
|
541
572
|
for row in pending_data:
|
|
542
573
|
for tag_id, datum in enumerate(row):
|
|
543
574
|
row[tag_id] = schema.convert_tag(f"{self.category}.{self._tags[tag_id]}", datum)
|
|
@@ -574,7 +605,7 @@ class Loop(object):
|
|
|
574
605
|
raise ValueError("You cannot add data out of tag order.")
|
|
575
606
|
self.data[-1].append(value)
|
|
576
607
|
|
|
577
|
-
def add_missing_tags(self, schema:
|
|
608
|
+
def add_missing_tags(self, schema: Schema = None, all_tags: bool = False) -> None:
|
|
578
609
|
""" Automatically adds any missing tags (according to the schema),
|
|
579
610
|
sorts the tags, and renumbers the tags by ordinal. """
|
|
580
611
|
|
|
@@ -1038,7 +1069,7 @@ class Loop(object):
|
|
|
1038
1069
|
|
|
1039
1070
|
self.category = utils.format_category(category)
|
|
1040
1071
|
|
|
1041
|
-
def sort_tags(self, schema:
|
|
1072
|
+
def sort_tags(self, schema: Schema = None) -> None:
|
|
1042
1073
|
""" Rearranges the tag names and data in the loop to match the order
|
|
1043
1074
|
from the schema. Uses the BMRB schema unless one is provided."""
|
|
1044
1075
|
|
pynmrstar/parser.py
CHANGED
|
@@ -2,7 +2,7 @@ import logging
|
|
|
2
2
|
import re
|
|
3
3
|
from typing import Optional
|
|
4
4
|
|
|
5
|
-
from pynmrstar import definitions, cnmrstar, entry as entry_mod, loop as loop_mod, saveframe as saveframe_mod
|
|
5
|
+
from pynmrstar import definitions, cnmrstar, entry as entry_mod, loop as loop_mod, saveframe as saveframe_mod, schema as schema_mod
|
|
6
6
|
from pynmrstar.exceptions import ParsingError
|
|
7
7
|
|
|
8
8
|
logger = logging.getLogger('pynmrstar')
|
|
@@ -48,8 +48,12 @@ class Parser(object):
|
|
|
48
48
|
|
|
49
49
|
cnmrstar.load_string(data)
|
|
50
50
|
|
|
51
|
-
def parse(self,
|
|
52
|
-
|
|
51
|
+
def parse(self,
|
|
52
|
+
data: str,
|
|
53
|
+
source: str = "unknown",
|
|
54
|
+
raise_parse_warnings: bool = False,
|
|
55
|
+
convert_data_types: bool = False,
|
|
56
|
+
schema: 'schema_mod.Schema' = None) -> 'entry_mod.Entry':
|
|
53
57
|
""" Parses the string provided as data as an NMR-STAR entry
|
|
54
58
|
and returns the parsed entry. Raises ParsingError on exceptions.
|
|
55
59
|
|
|
@@ -170,8 +174,10 @@ class Parser(object):
|
|
|
170
174
|
f"either missing from or duplicated in this loop.",
|
|
171
175
|
self.line_number)
|
|
172
176
|
try:
|
|
173
|
-
cur_loop.add_data(cur_data,
|
|
174
|
-
|
|
177
|
+
cur_loop.add_data(cur_data,
|
|
178
|
+
rearrange=True,
|
|
179
|
+
convert_data_types=convert_data_types,
|
|
180
|
+
schema=schema)
|
|
175
181
|
# If there is an issue with the loops during parsing, raise a parse error
|
|
176
182
|
# rather than the ValueError that would be raised if they made the mistake
|
|
177
183
|
# directly
|
|
@@ -260,7 +266,10 @@ class Parser(object):
|
|
|
260
266
|
"is quoted. You may be missing a data value on the previous line. "
|
|
261
267
|
f"Illegal value: '{self.token}'", self.line_number)
|
|
262
268
|
try:
|
|
263
|
-
cur_frame.add_tag(cur_tag,
|
|
269
|
+
cur_frame.add_tag(cur_tag,
|
|
270
|
+
self.token,
|
|
271
|
+
convert_data_types=convert_data_types,
|
|
272
|
+
schema=schema)
|
|
264
273
|
except ValueError as err:
|
|
265
274
|
raise ParsingError(str(err), line_number=self.line_number)
|
|
266
275
|
|
pynmrstar/saveframe.py
CHANGED
|
@@ -333,7 +333,10 @@ class Saveframe(object):
|
|
|
333
333
|
return {x[0].lower(): x[1] for x in self._tags}
|
|
334
334
|
|
|
335
335
|
@classmethod
|
|
336
|
-
def from_scratch(cls,
|
|
336
|
+
def from_scratch(cls,
|
|
337
|
+
sf_name: str,
|
|
338
|
+
tag_prefix: str = None,
|
|
339
|
+
source: str = "from_scratch()"):
|
|
337
340
|
"""Create an empty saveframe that you can programmatically add
|
|
338
341
|
to. You may also pass the tag prefix as the second argument. If
|
|
339
342
|
you do not pass the tag prefix it will be set the first time you
|
|
@@ -342,8 +345,12 @@ class Saveframe(object):
|
|
|
342
345
|
return cls(saveframe_name=sf_name, tag_prefix=tag_prefix, source=source)
|
|
343
346
|
|
|
344
347
|
@classmethod
|
|
345
|
-
def from_file(cls,
|
|
346
|
-
|
|
348
|
+
def from_file(cls,
|
|
349
|
+
the_file: Union[str, TextIO, BinaryIO],
|
|
350
|
+
csv: bool = False,
|
|
351
|
+
convert_data_types: bool = False,
|
|
352
|
+
raise_parse_warnings: bool = False,
|
|
353
|
+
schema: Schema = None):
|
|
347
354
|
"""Create a saveframe by loading in a file. Specify csv=True is
|
|
348
355
|
the file is a CSV file. If the_file starts with http://,
|
|
349
356
|
https://, or ftp:// then we will use those protocols to attempt
|
|
@@ -357,14 +364,18 @@ class Saveframe(object):
|
|
|
357
364
|
dates will become datetime.date objects. When printing str() is called
|
|
358
365
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
359
366
|
notation floats to lowercase "e"s this should not cause any change in
|
|
360
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
367
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
368
|
+
schema object to use using the schema parameter.
|
|
361
369
|
|
|
362
370
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
363
371
|
ParsingError rather than logging a warning when non-valid (but
|
|
364
372
|
ignorable) issues are found."""
|
|
365
373
|
|
|
366
|
-
return cls(file_name=the_file,
|
|
367
|
-
|
|
374
|
+
return cls(file_name=the_file,
|
|
375
|
+
csv=csv,
|
|
376
|
+
convert_data_types=convert_data_types,
|
|
377
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
378
|
+
schema=schema)
|
|
368
379
|
|
|
369
380
|
@classmethod
|
|
370
381
|
def from_json(cls, json_dict: Union[dict, str]):
|
|
@@ -395,8 +406,12 @@ class Saveframe(object):
|
|
|
395
406
|
return ret
|
|
396
407
|
|
|
397
408
|
@classmethod
|
|
398
|
-
def from_string(cls,
|
|
399
|
-
|
|
409
|
+
def from_string(cls,
|
|
410
|
+
the_string: str,
|
|
411
|
+
csv: bool = False,
|
|
412
|
+
convert_data_types: bool = False,
|
|
413
|
+
raise_parse_warnings: bool = False,
|
|
414
|
+
schema: Schema = None):
|
|
400
415
|
"""Create a saveframe by parsing a string. Specify csv=True is
|
|
401
416
|
the string is in CSV format and not NMR-STAR format.
|
|
402
417
|
|
|
@@ -408,18 +423,27 @@ class Saveframe(object):
|
|
|
408
423
|
dates will become datetime.date objects. When printing str() is called
|
|
409
424
|
on all objects. Other that converting uppercase "E"s in scientific
|
|
410
425
|
notation floats to lowercase "e"s this should not cause any change in
|
|
411
|
-
the way re-printed NMR-STAR objects are displayed.
|
|
426
|
+
the way re-printed NMR-STAR objects are displayed. Specify a custom
|
|
427
|
+
schema object to use using the schema parameter.
|
|
412
428
|
|
|
413
429
|
Setting raise_parse_warnings to True will result in the raising of a
|
|
414
430
|
ParsingError rather than logging a warning when non-valid (but
|
|
415
431
|
ignorable) issues are found."""
|
|
416
432
|
|
|
417
|
-
return cls(the_string=the_string,
|
|
418
|
-
|
|
433
|
+
return cls(the_string=the_string,
|
|
434
|
+
csv=csv,
|
|
435
|
+
convert_data_types=convert_data_types,
|
|
436
|
+
raise_parse_warnings=raise_parse_warnings,
|
|
437
|
+
schema=schema)
|
|
419
438
|
|
|
420
439
|
@classmethod
|
|
421
|
-
def from_template(cls,
|
|
422
|
-
|
|
440
|
+
def from_template(cls,
|
|
441
|
+
category: str,
|
|
442
|
+
name: str = None,
|
|
443
|
+
entry_id: Union[str, int] = None,
|
|
444
|
+
all_tags: bool = False,
|
|
445
|
+
default_values: bool = False,
|
|
446
|
+
schema: Schema = None):
|
|
423
447
|
""" Create a saveframe that has all of the tags and loops from the
|
|
424
448
|
schema present. No values will be assigned. Specify the category
|
|
425
449
|
when calling this method. Optionally also provide the name of the
|
|
@@ -432,8 +456,12 @@ class Saveframe(object):
|
|
|
432
456
|
values from the schema."""
|
|
433
457
|
|
|
434
458
|
schema = utils.get_schema(schema)
|
|
435
|
-
return cls(category=category,
|
|
436
|
-
|
|
459
|
+
return cls(category=category,
|
|
460
|
+
saveframe_name=name,
|
|
461
|
+
entry_id=entry_id,
|
|
462
|
+
all_tags=all_tags,
|
|
463
|
+
default_values=default_values,
|
|
464
|
+
schema=schema,
|
|
437
465
|
source=f"from_template({schema.version})")
|
|
438
466
|
|
|
439
467
|
def __repr__(self) -> str:
|
|
@@ -527,7 +555,12 @@ class Saveframe(object):
|
|
|
527
555
|
|
|
528
556
|
self._loops.append(loop_to_add)
|
|
529
557
|
|
|
530
|
-
def add_tag(self,
|
|
558
|
+
def add_tag(self,
|
|
559
|
+
name: str,
|
|
560
|
+
value: Any,
|
|
561
|
+
update: bool = False,
|
|
562
|
+
convert_data_types: bool = False,
|
|
563
|
+
schema: Schema = None) -> None:
|
|
531
564
|
"""Add a tag to the tag list. Does a bit of validation and
|
|
532
565
|
parsing.
|
|
533
566
|
|
|
@@ -535,7 +568,10 @@ class Saveframe(object):
|
|
|
535
568
|
than raise an exception.
|
|
536
569
|
|
|
537
570
|
Set convert_data_types to True to convert the tag value from str to
|
|
538
|
-
whatever type the tag is as defined in the schema.
|
|
571
|
+
whatever type the tag is as defined in the schema.
|
|
572
|
+
|
|
573
|
+
Optionally specify a schema if you don't want to use the default schema.
|
|
574
|
+
"""
|
|
539
575
|
|
|
540
576
|
if not isinstance(name, str):
|
|
541
577
|
raise ValueError('Tag names must be strings.')
|
|
@@ -581,7 +617,7 @@ class Saveframe(object):
|
|
|
581
617
|
|
|
582
618
|
# See if we need to convert the data type
|
|
583
619
|
if convert_data_types:
|
|
584
|
-
new_tag = [name, utils.get_schema().convert_tag(self.tag_prefix + "." + name, value)]
|
|
620
|
+
new_tag = [name, utils.get_schema(schema).convert_tag(self.tag_prefix + "." + name, value)]
|
|
585
621
|
else:
|
|
586
622
|
new_tag = [name, value]
|
|
587
623
|
|
|
@@ -612,7 +648,9 @@ class Saveframe(object):
|
|
|
612
648
|
else:
|
|
613
649
|
raise ValueError(f"You provided an invalid tag/value to add: '{tag_pair}'.")
|
|
614
650
|
|
|
615
|
-
def add_missing_tags(self,
|
|
651
|
+
def add_missing_tags(self,
|
|
652
|
+
schema: Schema = None,
|
|
653
|
+
all_tags: bool = False,
|
|
616
654
|
recursive: bool = True) -> None:
|
|
617
655
|
""" Automatically adds any missing tags (according to the schema)
|
|
618
656
|
and sorts the tags.
|
pynmrstar/schema.py
CHANGED
|
@@ -213,7 +213,8 @@ class Schema(object):
|
|
|
213
213
|
|
|
214
214
|
# If we don't know what the tag is, just return it
|
|
215
215
|
if tag.lower() not in self.schema:
|
|
216
|
-
|
|
216
|
+
if tag != '_internal.use':
|
|
217
|
+
logger.warning(f"Couldn't convert tag data type because it is not in the dictionary: {tag}")
|
|
217
218
|
return value
|
|
218
219
|
|
|
219
220
|
full_tag = self.schema[tag.lower()]
|
|
@@ -272,14 +273,10 @@ class Schema(object):
|
|
|
272
273
|
for y in range(0, len(values[0])):
|
|
273
274
|
lengths.append(max([len(str(x[y])) for x in values]))
|
|
274
275
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
%s
|
|
280
|
-
%-*s %-*s %-*s %-*s
|
|
281
|
-
""".format(format_parameters)
|
|
282
|
-
|
|
276
|
+
text = f"""BMRB schema from: '{self.schema_file}' version '{self.version}'
|
|
277
|
+
{''}
|
|
278
|
+
{'Tag_Prefix':<{lengths[0]}} {'Tag':<{lengths[1] - 6}} {'Type':<{lengths[2]}} {'Null_Allowed':<{lengths[3]}} {'SF_Category'}
|
|
279
|
+
"""
|
|
283
280
|
last_tag = ""
|
|
284
281
|
|
|
285
282
|
for tag in self.schema_order:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pynmrstar
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.5
|
|
4
4
|
Summary: PyNMR-STAR provides tools for reading, writing, modifying, and interacting with NMR-STAR files. Maintained by the BMRB.
|
|
5
5
|
Home-page: https://github.com/uwbmrb/PyNMRSTAR
|
|
6
6
|
Author: Jon Wedell
|
|
@@ -10,12 +10,12 @@ Keywords: bmrb,parser,nmr,nmrstar,biomagresbank,biological magnetic resonance ba
|
|
|
10
10
|
Classifier: Development Status :: 6 - Mature
|
|
11
11
|
Classifier: Environment :: Console
|
|
12
12
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.8
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Intended Audience :: Developers
|
|
20
20
|
Classifier: License :: OSI Approved :: MIT License
|
|
21
21
|
Classifier: Natural Language :: English
|
|
@@ -28,7 +28,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
28
28
|
Requires-Python: >=3.7
|
|
29
29
|
Description-Content-Type: text/x-rst
|
|
30
30
|
License-File: LICENSE
|
|
31
|
-
Requires-Dist: requests
|
|
31
|
+
Requires-Dist: requests<=3,>=2.21.0
|
|
32
32
|
|
|
33
33
|
Welcome to PyNMR-STAR!
|
|
34
34
|
======================================
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cnmrstar.cp311-win32.pyd,sha256=DmRxpayzjxqLv_q5k5F4M_QDgmC_sKb94rpjoYCYKyA,15872
|
|
2
|
+
pynmrstar/__init__.py,sha256=vV4IROb9si1NJLIdtrD2tmQjYvGKMRkyGa-pv0BUih8,2022
|
|
3
|
+
pynmrstar/_internal.py,sha256=MQHdBmr5fnxqWa49Aj5AHMlsUUzBvo6zyV7J3bXWgOo,12360
|
|
4
|
+
pynmrstar/definitions.py,sha256=QnNYWPkx4ojPhy52K1WQNJbJn6nNZhU0DkwCVSYabls,1542
|
|
5
|
+
pynmrstar/entry.py,sha256=PlM9KuVXJZtPhvWh5qVnuedFhfWvusmZhglP5gAUbos,47210
|
|
6
|
+
pynmrstar/exceptions.py,sha256=ot0eaeYwhFrblMI_DAnkp0q8ZlryQsmjgSuJcND1Cxg,1492
|
|
7
|
+
pynmrstar/loop.py,sha256=59VCE_-LTCCWM8dYcR7oUNEIO4vPVxhLTJPOxd4U6iE,53089
|
|
8
|
+
pynmrstar/parser.py,sha256=_J67XasZ0Uo8qjCckg_GHCCL_-r2xQTRhihz8le268U,15833
|
|
9
|
+
pynmrstar/saveframe.py,sha256=A0o3RpVAt5VuIVNszx6lA1I2Op91zmVOKo2EpGkMZxE,45148
|
|
10
|
+
pynmrstar/schema.py,sha256=a5s9xBeCjbQbKmoWobPMMncZns5ob2qQrp87D-PVCmI,16146
|
|
11
|
+
pynmrstar/utils.py,sha256=YSTWdns233SN8_VE4VgpZtxN-ku3sS1ZXwEXsEqrT-M,4796
|
|
12
|
+
pynmrstar/reference_files/comments.str,sha256=1-fbj4NiJgt4CL28UDMYFvLOKSBgDhfklEIaakoQ-Sk,10480
|
|
13
|
+
pynmrstar/reference_files/data_types.csv,sha256=G-49mpz04Q0qlNsWJGFxhG6lyJqKKUMb4Kvc8CK6UZQ,3456
|
|
14
|
+
pynmrstar/reference_files/schema.csv,sha256=RIpLkp_Yi25CvTr_CI26_EwAxtVmzcDrK6wP9fNGJCI,3701428
|
|
15
|
+
pynmrstar-3.3.5.dist-info/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
|
16
|
+
pynmrstar-3.3.5.dist-info/METADATA,sha256=6x7uigrwdn6tOoXL6bqkZKUr7eL61tbhGBbrYaxuBgs,2497
|
|
17
|
+
pynmrstar-3.3.5.dist-info/WHEEL,sha256=CUEEiZcEHBQHmNAhE1m6c3jIKGBZTzLJKgzKvvbu8OI,97
|
|
18
|
+
pynmrstar-3.3.5.dist-info/top_level.txt,sha256=e5QP9re453LfgZ_mZNGHa7E5HFAXiRoNBPkF1hnn7JQ,19
|
|
19
|
+
pynmrstar-3.3.5.dist-info/RECORD,,
|
pynmrstar-3.3.3.dist-info/RECORD
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
cnmrstar.cp311-win32.pyd,sha256=d1HOXPDl88h_cUNtEcDlZNThxgdK8DqSYm-4OAPl2CQ,15360
|
|
2
|
-
pynmrstar/__init__.py,sha256=vV4IROb9si1NJLIdtrD2tmQjYvGKMRkyGa-pv0BUih8,2022
|
|
3
|
-
pynmrstar/_internal.py,sha256=HqkEQTwzAORWMDMq1gOzfsEqnuw_cOTj_Qs_SGUBBJg,12259
|
|
4
|
-
pynmrstar/definitions.py,sha256=QnNYWPkx4ojPhy52K1WQNJbJn6nNZhU0DkwCVSYabls,1542
|
|
5
|
-
pynmrstar/entry.py,sha256=uZWJeMy_-gxUr2yqZ7AOjTTMC-SJyzC7ZteF4avMdeE,46434
|
|
6
|
-
pynmrstar/exceptions.py,sha256=ot0eaeYwhFrblMI_DAnkp0q8ZlryQsmjgSuJcND1Cxg,1492
|
|
7
|
-
pynmrstar/loop.py,sha256=Z9RtJMeOQ770C0n_nChp-Y8NtDoOz6b2qzyVsouxHE4,52034
|
|
8
|
-
pynmrstar/parser.py,sha256=j2CU6mdocV_q56DTy_g1NL6nLERHWtkFOD2cpYFR7A8,15430
|
|
9
|
-
pynmrstar/saveframe.py,sha256=BvHJqVi3qoFLfUSJDtNb2y0MmdzKjfFAefwJkfehm98,44123
|
|
10
|
-
pynmrstar/schema.py,sha256=J5gnLfM-rZTIyIuqXtSDb331KvwsJB0TfC4elL-P_wM,16228
|
|
11
|
-
pynmrstar/utils.py,sha256=YSTWdns233SN8_VE4VgpZtxN-ku3sS1ZXwEXsEqrT-M,4796
|
|
12
|
-
pynmrstar/reference_files/comments.str,sha256=1-fbj4NiJgt4CL28UDMYFvLOKSBgDhfklEIaakoQ-Sk,10480
|
|
13
|
-
pynmrstar/reference_files/data_types.csv,sha256=G-49mpz04Q0qlNsWJGFxhG6lyJqKKUMb4Kvc8CK6UZQ,3456
|
|
14
|
-
pynmrstar/reference_files/schema.csv,sha256=RIpLkp_Yi25CvTr_CI26_EwAxtVmzcDrK6wP9fNGJCI,3701428
|
|
15
|
-
pynmrstar-3.3.3.dist-info/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
|
16
|
-
pynmrstar-3.3.3.dist-info/METADATA,sha256=Qqq7otpscy7aw-aPhtajY5eZJvA5WzHdKI3LAMchjZk,2497
|
|
17
|
-
pynmrstar-3.3.3.dist-info/WHEEL,sha256=KgshXv6CHUP_9leRW1dLCnjffy1d9N5d8PLjWHQzULs,98
|
|
18
|
-
pynmrstar-3.3.3.dist-info/top_level.txt,sha256=e5QP9re453LfgZ_mZNGHa7E5HFAXiRoNBPkF1hnn7JQ,19
|
|
19
|
-
pynmrstar-3.3.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|