Skip to content

Commit

Permalink
Improved StarFile printing layout for NMR-STAR format.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Jan 10, 2017
1 parent 2b1b1cc commit 2ceb822
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
4 changes: 2 additions & 2 deletions nmrstarlib/bmrblex.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def transform_text(input_txt):
line = inputq.popleft()

while not line.startswith(u";"):
multiline += line
multiline += line + u"\n"
line = inputq.popleft()

multiline += u"\n" + line[:1]
multiline += line[:1]
outputq.append(multiline)

for character in line[1:]:
Expand Down
52 changes: 26 additions & 26 deletions nmrstarlib/cbmrblex.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions nmrstarlib/cbmrblex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def transform_text(input_txt):
line = inputq.popleft()

while not line.startswith(u";"):
multiline += line
multiline += line + u"\n"
line = inputq.popleft()

multiline += u"\n" + line[:1]
multiline += line[:1]
outputq.append(multiline)

for character in line[1:]:
Expand Down
22 changes: 12 additions & 10 deletions nmrstarlib/nmrstarlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ def print_starfile(self, f=sys.stdout, format="nmrstar", tw=3):
"""
if format is "nmrstar":
for saveframe in self.keys():
if saveframe == "data":
if saveframe == u"data":
print(u"{}_{}\n".format(saveframe, self[saveframe]), file=f)
else:
print(u"{}".format(saveframe), file=f)
self.print_saveframe(saveframe, f, format, tw)
print(u"save_\n", file=f)
print(u"\nsave_\n", file=f)

elif format is "json":
print(self._to_json(), file=f)
Expand All @@ -296,17 +296,18 @@ def print_saveframe(self, sf, f=sys.stdout, format="nmrstar", tw=3):
else:
for sftag in self[sf].keys():
# handle the NMR-Star "multiline string"
if self[sf][sftag][0] == ";":
print(tw*u" ", u"_{}".format(sftag), file=f)
if self[sf][sftag][0] == u";":
print(u"{}_{}".format(tw * u" ", sftag), file=f)
print(u"{}".format(self[sf][sftag]), file=f)

# handle loops
elif sftag[:5] == "loop_":
print(tw*u" ", u"loop_", file=f)
print(u"\n{}loop_".format(tw * u" "), file=f)
self.print_loop(sf, sftag, f, format, tw * 2)
print(tw*u" ", u"stop_", file=f)
print(u"\n{}stop_".format(tw * u" "), file=f)
else:
print(tw*u" ", u"_{}\t {}".format(sftag, self[sf][sftag]), file=f)
print(u"{}_{}\t {}".format(tw * u" ", sftag, self[sf][sftag]), file=f)
# print(tw * u" " + u"_{}\t {}".format(sftag, self[sf][sftag]), file=f)

elif format is "json":
print(json.dumps(self[sf], sort_keys=False, indent=4), file=f)
Expand All @@ -325,12 +326,13 @@ def print_loop(self, sf, sftag, f=sys.stdout, format="nmrstar", tw=3):
if format is "nmrstar":
# First print the fields
for field in self[sf][sftag][0]:
print(tw*u" ", u"_{}".format(field), file=f)
print(u"{}_{}".format(tw * u" ", field), file=f)

print(u"", file=f) # new line between fields and values

# Then print the values
for valuesdict in self[sf][sftag][1]:
line = tw*u" " + u" ".join(valuesdict.values())
print(line, file=f)
print(u"{}{}".format(tw * u" ", u" ".join(valuesdict.values())), file=f)

elif format is "json":
print(json.dumps(self[sf][sftag], sort_keys=False, indent=4), file=f)
Expand Down

0 comments on commit 2ceb822

Please sign in to comment.