-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmrML_lib.py
More file actions
8412 lines (8214 loc) · 422 KB
/
nmrML_lib.py
File metadata and controls
8412 lines (8214 loc) · 422 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated Wed Dec 18 17:30:45 2013 by generateDS.py version 2.11a.
#
import sys
import getopt
import re as re_
import base64
import datetime as datetime_
etree_ = None
Verbose_import_ = False
(
XMLParser_import_none, XMLParser_import_lxml,
XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
# lxml
from lxml import etree as etree_
XMLParser_import_library = XMLParser_import_lxml
if Verbose_import_:
print("running with lxml.etree")
except ImportError:
try:
# cElementTree from Python 2.5+
import xml.etree.cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# ElementTree from Python 2.5+
import xml.etree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree")
except ImportError:
raise ImportError(
"Failed to import ElementTree from any known place")
def parsexml_(*args, **kwargs):
if (XMLParser_import_library == XMLParser_import_lxml and
'parser' not in kwargs):
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
kwargs['parser'] = etree_.ETCompatXMLParser()
doc = etree_.parse(*args, **kwargs)
return doc
#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
# in a module named generatedssuper.py.
try:
from generatedssuper import GeneratedsSuper
except ImportError, exp:
class GeneratedsSuper(object):
tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$')
class _FixedOffsetTZ(datetime_.tzinfo):
def __init__(self, offset, name):
self.__offset = datetime_.timedelta(minutes=offset)
self.__name = name
def utcoffset(self, dt):
return self.__offset
def tzname(self, dt):
return self.__name
def dst(self, dt):
return None
def gds_format_string(self, input_data, input_name=''):
return input_data
def gds_validate_string(self, input_data, node, input_name=''):
return input_data
def gds_format_base64(self, input_data, input_name=''):
return base64.b64encode(input_data)
def gds_validate_base64(self, input_data, node, input_name=''):
return input_data
def gds_format_integer(self, input_data, input_name=''):
return '%d' % input_data
def gds_validate_integer(self, input_data, node, input_name=''):
return input_data
def gds_format_integer_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_integer_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
float(value)
except (TypeError, ValueError):
raise_parse_error(node, 'Requires sequence of integers')
return input_data
def gds_format_float(self, input_data, input_name=''):
return ('%.15f' % input_data).rstrip('0')
def gds_validate_float(self, input_data, node, input_name=''):
return input_data
def gds_format_float_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_float_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
float(value)
except (TypeError, ValueError):
raise_parse_error(node, 'Requires sequence of floats')
return input_data
def gds_format_double(self, input_data, input_name=''):
return '%e' % input_data
def gds_validate_double(self, input_data, node, input_name=''):
return input_data
def gds_format_double_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_double_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
float(value)
except (TypeError, ValueError):
raise_parse_error(node, 'Requires sequence of doubles')
return input_data
def gds_format_boolean(self, input_data, input_name=''):
return ('%s' % input_data).lower()
def gds_validate_boolean(self, input_data, node, input_name=''):
return input_data
def gds_format_boolean_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_boolean_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
if value not in ('true', '1', 'false', '0', ):
raise_parse_error(
node,
'Requires sequence of booleans '
'("true", "1", "false", "0")')
return input_data
def gds_validate_datetime(self, input_data, node, input_name=''):
return input_data
def gds_format_datetime(self, input_data, input_name=''):
if input_data.microsecond == 0:
_svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % (
input_data.year,
input_data.month,
input_data.day,
input_data.hour,
input_data.minute,
input_data.second,
)
else:
_svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % (
input_data.year,
input_data.month,
input_data.day,
input_data.hour,
input_data.minute,
input_data.second,
('%f' % (float(input_data.microsecond) / 1000000))[2:],
)
if input_data.tzinfo is not None:
tzoff = input_data.tzinfo.utcoffset(input_data)
if tzoff is not None:
total_seconds = tzoff.seconds + (86400 * tzoff.days)
if total_seconds == 0:
_svalue += 'Z'
else:
if total_seconds < 0:
_svalue += '-'
total_seconds *= -1
else:
_svalue += '+'
hours = total_seconds // 3600
minutes = (total_seconds - (hours * 3600)) // 60
_svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
return _svalue
@classmethod
def gds_parse_datetime(cls, input_data):
tz = None
if input_data[-1] == 'Z':
tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
input_data = input_data[:-1]
else:
results = GeneratedsSuper.tzoff_pattern.search(input_data)
if results is not None:
tzoff_parts = results.group(2).split(':')
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
if results.group(1) == '-':
tzoff *= -1
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
if len(input_data.split('.')) > 1:
dt = datetime_.datetime.strptime(
input_data, '%Y-%m-%dT%H:%M:%S.%f')
else:
dt = datetime_.datetime.strptime(
input_data, '%Y-%m-%dT%H:%M:%S')
dt = dt.replace(tzinfo=tz)
return dt
def gds_validate_date(self, input_data, node, input_name=''):
return input_data
def gds_format_date(self, input_data, input_name=''):
_svalue = '%04d-%02d-%02d' % (
input_data.year,
input_data.month,
input_data.day,
)
try:
if input_data.tzinfo is not None:
tzoff = input_data.tzinfo.utcoffset(input_data)
if tzoff is not None:
total_seconds = tzoff.seconds + (86400 * tzoff.days)
if total_seconds == 0:
_svalue += 'Z'
else:
if total_seconds < 0:
_svalue += '-'
total_seconds *= -1
else:
_svalue += '+'
hours = total_seconds // 3600
minutes = (total_seconds - (hours * 3600)) // 60
_svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
except AttributeError:
pass
return _svalue
@classmethod
def gds_parse_date(cls, input_data):
tz = None
if input_data[-1] == 'Z':
tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
input_data = input_data[:-1]
else:
results = GeneratedsSuper.tzoff_pattern.search(input_data)
if results is not None:
tzoff_parts = results.group(2).split(':')
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
if results.group(1) == '-':
tzoff *= -1
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
dt = datetime_.datetime.strptime(input_data, '%Y-%m-%d')
dt = dt.replace(tzinfo=tz)
return dt.date()
def gds_validate_time(self, input_data, node, input_name=''):
return input_data
def gds_format_time(self, input_data, input_name=''):
if input_data.microsecond == 0:
_svalue = '%02d:%02d:%02d' % (
input_data.hour,
input_data.minute,
input_data.second,
)
else:
_svalue = '%02d:%02d:%02d.%s' % (
input_data.hour,
input_data.minute,
input_data.second,
('%f' % (float(input_data.microsecond) / 1000000))[2:],
)
if input_data.tzinfo is not None:
tzoff = input_data.tzinfo.utcoffset(input_data)
if tzoff is not None:
total_seconds = tzoff.seconds + (86400 * tzoff.days)
if total_seconds == 0:
_svalue += 'Z'
else:
if total_seconds < 0:
_svalue += '-'
total_seconds *= -1
else:
_svalue += '+'
hours = total_seconds // 3600
minutes = (total_seconds - (hours * 3600)) // 60
_svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
return _svalue
@classmethod
def gds_parse_time(cls, input_data):
tz = None
if input_data[-1] == 'Z':
tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC')
input_data = input_data[:-1]
else:
results = GeneratedsSuper.tzoff_pattern.search(input_data)
if results is not None:
tzoff_parts = results.group(2).split(':')
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
if results.group(1) == '-':
tzoff *= -1
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
if len(input_data.split('.')) > 1:
dt = datetime_.datetime.strptime(input_data, '%H:%M:%S.%f')
else:
dt = datetime_.datetime.strptime(input_data, '%H:%M:%S')
dt = dt.replace(tzinfo=tz)
return dt.time()
def gds_str_lower(self, instring):
return instring.lower()
def get_path_(self, node):
path_list = []
self.get_path_list_(node, path_list)
path_list.reverse()
path = '/'.join(path_list)
return path
Tag_strip_pattern_ = re_.compile(r'\{.*\}')
def get_path_list_(self, node, path_list):
if node is None:
return
tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
if tag:
path_list.append(tag)
self.get_path_list_(node.getparent(), path_list)
def get_class_obj_(self, node, default_class=None):
class_obj1 = default_class
if 'xsi' in node.nsmap:
classname = node.get('{%s}type' % node.nsmap['xsi'])
if classname is not None:
names = classname.split(':')
if len(names) == 2:
classname = names[1]
class_obj2 = globals().get(classname)
if class_obj2 is not None:
class_obj1 = class_obj2
return class_obj1
def gds_build_any(self, node, type_name=None):
return None
@classmethod
def gds_reverse_node_mapping(cls, mapping):
return dict(((v, k) for k, v in mapping.iteritems()))
#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#
## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
## banner = 'Dropping into IPython',
## exit_msg = 'Leaving Interpreter, back to program.')
# Then use the following line where and when you want to drop into the
# IPython shell:
# ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
#
# Globals
#
ExternalEncoding = 'utf-8'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')
#
# Support/utility functions.
#
def showIndent(outfile, level, pretty_print=True):
if pretty_print:
for idx in range(level):
outfile.write(' ')
def quote_xml(inStr):
if not inStr:
return ''
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
return s1
def quote_attrib(inStr):
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
if '"' in s1:
if "'" in s1:
s1 = '"%s"' % s1.replace('"', """)
else:
s1 = "'%s'" % s1
else:
s1 = '"%s"' % s1
return s1
def quote_python(inStr):
s1 = inStr
if s1.find("'") == -1:
if s1.find('\n') == -1:
return "'%s'" % s1
else:
return "'''%s'''" % s1
else:
if s1.find('"') != -1:
s1 = s1.replace('"', '\\"')
if s1.find('\n') == -1:
return '"%s"' % s1
else:
return '"""%s"""' % s1
def get_all_text_(node):
if node.text is not None:
text = node.text
else:
text = ''
for child in node:
if child.tail is not None:
text += child.tail
return text
def find_attr_value_(attr_name, node):
attrs = node.attrib
attr_parts = attr_name.split(':')
value = None
if len(attr_parts) == 1:
value = attrs.get(attr_name)
elif len(attr_parts) == 2:
prefix, name = attr_parts
namespace = node.nsmap.get(prefix)
if namespace is not None:
value = attrs.get('{%s}%s' % (namespace, name, ))
return value
class GDSParseError(Exception):
pass
def raise_parse_error(node, msg):
if XMLParser_import_library == XMLParser_import_lxml:
msg = '%s (element %s/line %d)' % (
msg, node.tag, node.sourceline, )
else:
msg = '%s (element %s)' % (msg, node.tag, )
raise GDSParseError(msg)
class MixedContainer:
# Constants for category:
CategoryNone = 0
CategoryText = 1
CategorySimple = 2
CategoryComplex = 3
# Constants for content_type:
TypeNone = 0
TypeText = 1
TypeString = 2
TypeInteger = 3
TypeFloat = 4
TypeDecimal = 5
TypeDouble = 6
TypeBoolean = 7
TypeBase64 = 8
def __init__(self, category, content_type, name, value):
self.category = category
self.content_type = content_type
self.name = name
self.value = value
def getCategory(self):
return self.category
def getContenttype(self, content_type):
return self.content_type
def getValue(self):
return self.value
def getName(self):
return self.name
def export(self, outfile, level, name, namespace, pretty_print=True):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
outfile.write(self.value)
elif self.category == MixedContainer.CategorySimple:
self.exportSimple(outfile, level, name)
else: # category == MixedContainer.CategoryComplex
self.value.export(outfile, level, namespace, name, pretty_print)
def exportSimple(self, outfile, level, name):
if self.content_type == MixedContainer.TypeString:
outfile.write('<%s>%s</%s>' % (
self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeInteger or \
self.content_type == MixedContainer.TypeBoolean:
outfile.write('<%s>%d</%s>' % (
self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeFloat or \
self.content_type == MixedContainer.TypeDecimal:
outfile.write('<%s>%f</%s>' % (
self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeDouble:
outfile.write('<%s>%g</%s>' % (
self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeBase64:
outfile.write('<%s>%s</%s>' % (
self.name, base64.b64encode(self.value), self.name))
def to_etree(self, element):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
if len(element) > 0:
if element[-1].tail is None:
element[-1].tail = self.value
else:
element[-1].tail += self.value
else:
if element.text is None:
element.text = self.value
else:
element.text += self.value
elif self.category == MixedContainer.CategorySimple:
subelement = etree_.SubElement(element, '%s' % self.name)
subelement.text = self.to_etree_simple()
else: # category == MixedContainer.CategoryComplex
self.value.to_etree(element)
def to_etree_simple(self):
if self.content_type == MixedContainer.TypeString:
text = self.value
elif (self.content_type == MixedContainer.TypeInteger or
self.content_type == MixedContainer.TypeBoolean):
text = '%d' % self.value
elif (self.content_type == MixedContainer.TypeFloat or
self.content_type == MixedContainer.TypeDecimal):
text = '%f' % self.value
elif self.content_type == MixedContainer.TypeDouble:
text = '%g' % self.value
elif self.content_type == MixedContainer.TypeBase64:
text = '%s' % base64.b64encode(self.value)
return text
def exportLiteral(self, outfile, level, name):
if self.category == MixedContainer.CategoryText:
showIndent(outfile, level)
outfile.write(
'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % (
self.category, self.content_type, self.name, self.value))
elif self.category == MixedContainer.CategorySimple:
showIndent(outfile, level)
outfile.write(
'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % (
self.category, self.content_type, self.name, self.value))
else: # category == MixedContainer.CategoryComplex
showIndent(outfile, level)
outfile.write(
'model_.MixedContainer(%d, %d, "%s",\n' % (
self.category, self.content_type, self.name,))
self.value.exportLiteral(outfile, level + 1)
showIndent(outfile, level)
outfile.write(')\n')
class MemberSpec_(object):
def __init__(self, name='', data_type='', container=0):
self.name = name
self.data_type = data_type
self.container = container
def set_name(self, name): self.name = name
def get_name(self): return self.name
def set_data_type(self, data_type): self.data_type = data_type
def get_data_type_chain(self): return self.data_type
def get_data_type(self):
if isinstance(self.data_type, list):
if len(self.data_type) > 0:
return self.data_type[-1]
else:
return 'xs:string'
else:
return self.data_type
def set_container(self, container): self.container = container
def get_container(self): return self.container
def _cast(typ, value):
if typ is None or value is None:
return value
return typ(value)
#
# Data representation classes.
#
class nmrMLType(GeneratedsSuper):
"""This is the root element for the COordination Of Standards In
MetabOlomicS nmrML schema, which is intended to capture the use
of a nuclear magnetic resonance spectrometer, the data
generated, and the initial processing of that data (to the level
of the peak list).The nmrML version used to create the
document.Optional accession number for the nmrML document. Used
for storage (for example MetaboLights) Optional attribute for
retrieva of an nmrML document. Usefull when the document has
been retrieved from a public database.An optional ID for the
nmrML document."""
subclass = None
superclass = None
def __init__(self, version=None, accession_url=None, accession=None, id=None, cvList=None, fileDescription=None, contactList=None, referenceableParamGroupList=None, sourceFileList=None, softwareList=None, instrumentConfigurationList=None, dataProcessingList=None, sampleList=None, acquisition=None, spectrumList=None):
self.version = _cast(None, version)
self.accession_url = _cast(None, accession_url)
self.accession = _cast(None, accession)
self.id = _cast(None, id)
self.cvList = cvList
self.fileDescription = fileDescription
self.contactList = contactList
self.referenceableParamGroupList = referenceableParamGroupList
self.sourceFileList = sourceFileList
self.softwareList = softwareList
self.instrumentConfigurationList = instrumentConfigurationList
self.dataProcessingList = dataProcessingList
self.sampleList = sampleList
self.acquisition = acquisition
self.spectrumList = spectrumList
def factory(*args_, **kwargs_):
if nmrMLType.subclass:
return nmrMLType.subclass(*args_, **kwargs_)
else:
return nmrMLType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_cvList(self): return self.cvList
def set_cvList(self, cvList): self.cvList = cvList
def get_fileDescription(self): return self.fileDescription
def set_fileDescription(self, fileDescription): self.fileDescription = fileDescription
def get_contactList(self): return self.contactList
def set_contactList(self, contactList): self.contactList = contactList
def get_referenceableParamGroupList(self): return self.referenceableParamGroupList
def set_referenceableParamGroupList(self, referenceableParamGroupList): self.referenceableParamGroupList = referenceableParamGroupList
def get_sourceFileList(self): return self.sourceFileList
def set_sourceFileList(self, sourceFileList): self.sourceFileList = sourceFileList
def get_softwareList(self): return self.softwareList
def set_softwareList(self, softwareList): self.softwareList = softwareList
def get_instrumentConfigurationList(self): return self.instrumentConfigurationList
def set_instrumentConfigurationList(self, instrumentConfigurationList): self.instrumentConfigurationList = instrumentConfigurationList
def get_dataProcessingList(self): return self.dataProcessingList
def set_dataProcessingList(self, dataProcessingList): self.dataProcessingList = dataProcessingList
def get_sampleList(self): return self.sampleList
def set_sampleList(self, sampleList): self.sampleList = sampleList
def get_acquisition(self): return self.acquisition
def set_acquisition(self, acquisition): self.acquisition = acquisition
def get_spectrumList(self): return self.spectrumList
def set_spectrumList(self, spectrumList): self.spectrumList = spectrumList
def get_version(self): return self.version
def set_version(self, version): self.version = version
def get_accession_url(self): return self.accession_url
def set_accession_url(self, accession_url): self.accession_url = accession_url
def get_accession(self): return self.accession
def set_accession(self, accession): self.accession = accession
def get_id(self): return self.id
def set_id(self, id): self.id = id
def hasContent_(self):
if (
self.cvList is not None or
self.fileDescription is not None or
self.contactList is not None or
self.referenceableParamGroupList is not None or
self.sourceFileList is not None or
self.softwareList is not None or
self.instrumentConfigurationList is not None or
self.dataProcessingList is not None or
self.sampleList is not None or
self.acquisition is not None or
self.spectrumList is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='dx:', name_='nmrMLType', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='nmrMLType')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='dx:', name_='nmrMLType'):
if self.version is not None and 'version' not in already_processed:
already_processed.add('version')
outfile.write(' version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
if self.accession_url is not None and 'accession_url' not in already_processed:
already_processed.add('accession_url')
outfile.write(' accession_url=%s' % (self.gds_format_string(quote_attrib(self.accession_url).encode(ExternalEncoding), input_name='accession_url'), ))
if self.accession is not None and 'accession' not in already_processed:
already_processed.add('accession')
outfile.write(' accession=%s' % (self.gds_format_string(quote_attrib(self.accession).encode(ExternalEncoding), input_name='accession'), ))
if self.id is not None and 'id' not in already_processed:
already_processed.add('id')
outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
def exportChildren(self, outfile, level, namespace_='dx:', name_='nmrMLType', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.cvList is not None:
self.cvList.export(outfile, level, namespace_, name_='cvList', pretty_print=pretty_print)
if self.fileDescription is not None:
self.fileDescription.export(outfile, level, namespace_, name_='fileDescription', pretty_print=pretty_print)
if self.contactList is not None:
self.contactList.export(outfile, level, namespace_, name_='contactList', pretty_print=pretty_print)
if self.referenceableParamGroupList is not None:
self.referenceableParamGroupList.export(outfile, level, namespace_, name_='referenceableParamGroupList', pretty_print=pretty_print)
if self.sourceFileList is not None:
self.sourceFileList.export(outfile, level, namespace_, name_='sourceFileList', pretty_print=pretty_print)
if self.softwareList is not None:
self.softwareList.export(outfile, level, namespace_, name_='softwareList', pretty_print=pretty_print)
if self.instrumentConfigurationList is not None:
self.instrumentConfigurationList.export(outfile, level, namespace_, name_='instrumentConfigurationList', pretty_print=pretty_print)
if self.dataProcessingList is not None:
self.dataProcessingList.export(outfile, level, namespace_, name_='dataProcessingList', pretty_print=pretty_print)
if self.sampleList is not None:
self.sampleList.export(outfile, level, namespace_, name_='sampleList', pretty_print=pretty_print)
if self.acquisition is not None:
self.acquisition.export(outfile, level, namespace_, name_='acquisition', pretty_print=pretty_print)
if self.spectrumList is not None:
self.spectrumList.export(outfile, level, namespace_, name_='spectrumList', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='nmrMLType'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.version is not None and 'version' not in already_processed:
already_processed.add('version')
showIndent(outfile, level)
outfile.write('version="%s",\n' % (self.version,))
if self.accession_url is not None and 'accession_url' not in already_processed:
already_processed.add('accession_url')
showIndent(outfile, level)
outfile.write('accession_url="%s",\n' % (self.accession_url,))
if self.accession is not None and 'accession' not in already_processed:
already_processed.add('accession')
showIndent(outfile, level)
outfile.write('accession="%s",\n' % (self.accession,))
if self.id is not None and 'id' not in already_processed:
already_processed.add('id')
showIndent(outfile, level)
outfile.write('id="%s",\n' % (self.id,))
def exportLiteralChildren(self, outfile, level, name_):
if self.cvList is not None:
showIndent(outfile, level)
outfile.write('cvList=model_.CVListType(\n')
self.cvList.exportLiteral(outfile, level, name_='cvList')
showIndent(outfile, level)
outfile.write('),\n')
if self.fileDescription is not None:
showIndent(outfile, level)
outfile.write('fileDescription=model_.FileDescriptionType(\n')
self.fileDescription.exportLiteral(outfile, level, name_='fileDescription')
showIndent(outfile, level)
outfile.write('),\n')
if self.contactList is not None:
showIndent(outfile, level)
outfile.write('contactList=model_.ContactListType(\n')
self.contactList.exportLiteral(outfile, level, name_='contactList')
showIndent(outfile, level)
outfile.write('),\n')
if self.referenceableParamGroupList is not None:
showIndent(outfile, level)
outfile.write('referenceableParamGroupList=model_.ReferenceableParamGroupListType(\n')
self.referenceableParamGroupList.exportLiteral(outfile, level, name_='referenceableParamGroupList')
showIndent(outfile, level)
outfile.write('),\n')
if self.sourceFileList is not None:
showIndent(outfile, level)
outfile.write('sourceFileList=model_.SourceFileListType(\n')
self.sourceFileList.exportLiteral(outfile, level, name_='sourceFileList')
showIndent(outfile, level)
outfile.write('),\n')
if self.softwareList is not None:
showIndent(outfile, level)
outfile.write('softwareList=model_.SoftwareListType(\n')
self.softwareList.exportLiteral(outfile, level, name_='softwareList')
showIndent(outfile, level)
outfile.write('),\n')
if self.instrumentConfigurationList is not None:
showIndent(outfile, level)
outfile.write('instrumentConfigurationList=model_.InstrumentConfigurationListType(\n')
self.instrumentConfigurationList.exportLiteral(outfile, level, name_='instrumentConfigurationList')
showIndent(outfile, level)
outfile.write('),\n')
if self.dataProcessingList is not None:
showIndent(outfile, level)
outfile.write('dataProcessingList=model_.DataProcessingListType(\n')
self.dataProcessingList.exportLiteral(outfile, level, name_='dataProcessingList')
showIndent(outfile, level)
outfile.write('),\n')
if self.sampleList is not None:
showIndent(outfile, level)
outfile.write('sampleList=model_.SampleListType(\n')
self.sampleList.exportLiteral(outfile, level, name_='sampleList')
showIndent(outfile, level)
outfile.write('),\n')
if self.acquisition is not None:
showIndent(outfile, level)
outfile.write('acquisition=model_.AcquisitionType(\n')
self.acquisition.exportLiteral(outfile, level, name_='acquisition')
showIndent(outfile, level)
outfile.write('),\n')
if self.spectrumList is not None:
showIndent(outfile, level)
outfile.write('spectrumList=model_.SpectrumListType(\n')
self.spectrumList.exportLiteral(outfile, level, name_='spectrumList')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('version', node)
if value is not None and 'version' not in already_processed:
already_processed.add('version')
self.version = value
value = find_attr_value_('accession_url', node)
if value is not None and 'accession_url' not in already_processed:
already_processed.add('accession_url')
self.accession_url = value
value = find_attr_value_('accession', node)
if value is not None and 'accession' not in already_processed:
already_processed.add('accession')
self.accession = value
value = find_attr_value_('id', node)
if value is not None and 'id' not in already_processed:
already_processed.add('id')
self.id = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'cvList':
obj_ = CVListType.factory()
obj_.build(child_)
self.cvList = obj_
elif nodeName_ == 'fileDescription':
obj_ = FileDescriptionType.factory()
obj_.build(child_)
self.fileDescription = obj_
elif nodeName_ == 'contactList':
obj_ = ContactListType.factory()
obj_.build(child_)
self.contactList = obj_
elif nodeName_ == 'referenceableParamGroupList':
obj_ = ReferenceableParamGroupListType.factory()
obj_.build(child_)
self.referenceableParamGroupList = obj_
elif nodeName_ == 'sourceFileList':
obj_ = SourceFileListType.factory()
obj_.build(child_)
self.sourceFileList = obj_
elif nodeName_ == 'softwareList':
obj_ = SoftwareListType.factory()
obj_.build(child_)
self.softwareList = obj_
elif nodeName_ == 'instrumentConfigurationList':
obj_ = InstrumentConfigurationListType.factory()
obj_.build(child_)
self.instrumentConfigurationList = obj_
elif nodeName_ == 'dataProcessingList':
obj_ = DataProcessingListType.factory()
obj_.build(child_)
self.dataProcessingList = obj_
elif nodeName_ == 'sampleList':
obj_ = SampleListType.factory()
obj_.build(child_)
self.sampleList = obj_
elif nodeName_ == 'acquisition':
obj_ = AcquisitionType.factory()
obj_.build(child_)
self.acquisition = obj_
elif nodeName_ == 'spectrumList':
obj_ = SpectrumListType.factory()
obj_.build(child_)
self.spectrumList = obj_
# end class nmrMLType
class CVListType(GeneratedsSuper):
"""Container for one or more controlled vocabulary definitions.The
number of CV definitions in this nmrML file."""
subclass = None
superclass = None
def __init__(self, count=None, cv=None):
self.count = _cast(int, count)
if cv is None:
self.cv = []
else:
self.cv = cv
def factory(*args_, **kwargs_):
if CVListType.subclass:
return CVListType.subclass(*args_, **kwargs_)
else:
return CVListType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_cv(self): return self.cv
def set_cv(self, cv): self.cv = cv
def add_cv(self, value): self.cv.append(value)
def insert_cv(self, index, value): self.cv[index] = value
def get_count(self): return self.count
def set_count(self, count): self.count = count
def hasContent_(self):
if (
self.cv
):
return True
else:
return False
def export(self, outfile, level, namespace_='dx:', name_='CVListType', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='CVListType')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='dx:', name_='CVListType'):
if self.count is not None and 'count' not in already_processed:
already_processed.add('count')
outfile.write(' count="%s"' % self.gds_format_integer(self.count, input_name='count'))
def exportChildren(self, outfile, level, namespace_='dx:', name_='CVListType', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for cv_ in self.cv:
cv_.export(outfile, level, namespace_, name_='cv', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='CVListType'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.count is not None and 'count' not in already_processed:
already_processed.add('count')
showIndent(outfile, level)
outfile.write('count=%d,\n' % (self.count,))
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('cv=[\n')
level += 1
for cv_ in self.cv:
showIndent(outfile, level)
outfile.write('model_.CVType(\n')
cv_.exportLiteral(outfile, level, name_='CVType')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('count', node)
if value is not None and 'count' not in already_processed:
already_processed.add('count')