Skip to content

Commit

Permalink
Improved method parameters names.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Jan 11, 2017
1 parent 9eed933 commit fef5df1
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 35 deletions.
156 changes: 148 additions & 8 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,146 @@ using bracket accessors.
chemical shits into :py:class:`collections.OrderedDict` data structure (`keys` - sequence id,
`values` - chemical shift data):

>>> starfile.chem_shifts_by_residue()
[OrderedDict([
('1', OrderedDict([('AA3Code', 'MET'),
('Seq_ID', '1'),
('H', '8.55'),
('HA', '4.548'),
('HB2', '1.994'),
('HB3', '2.118'),
('CA', '55.489'),
('CB', '32.848'),
('N', '122.221')])),
('2', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '2'),
('H', '8.225'),
('HA', '4.420'),
('HB2', '3.805'),
('HB3', '3.857'),
('CA', '58.593'),
('CB', '64.057'),
('N', '117.197')])),
('3', OrderedDict([('AA3Code', 'GLU'),
('Seq_ID', '3'),
('H', '8.002'),
('HA', '4.848'),
('HB2', '1.852'),
('HB3', '1.963'),
('HG2', '1.981'),
('HG3', '2.191'),
('CA', '55.651'),
('CB', '32.952'),
('CG', '37.425'),
('N', '119.833')])), ...
...
]
>>>
>>> starfile.chem_shifts_by_residue(amino_acids=["SER"], atoms=["CA", "CB"])
[OrderedDict([
('2', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '2'),
('CA', '58.593'),
('CB', '64.057')])),
('8', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '8'),
('CA', '57.456'),
('CB', '64.863')])),
('9', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '9'),
('CA', '57.852'),
('CB', '67.332')])),
('34', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '34'),
('CA', '59.113'),
('CB', '66.248')])),
('46', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '46'),
('CA', '55.939'),
('CB', '66.829')])),
('95', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '95'),
('CA', '57.013'),
('CB', '66.501')])),
('108', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '108'),
('CA', '61.617'),
('CB', '62.493')]))])
]
>>>



>>> starfile.chem_shifts_by_residue()
[OrderedDict([
('1', OrderedDict([('AA3Code', 'MET'),
('Seq_ID', '1'),
('H', '8.55'),
('HA', '4.548'),
('HB2', '1.994'),
('HB3', '2.118'),
('CA', '55.489'),
('CB', '32.848'),
('N', '122.221')])),
('2', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '2'),
('H', '8.225'),
('HA', '4.420'),
('HB2', '3.805'),
('HB3', '3.857'),
('CA', '58.593'),
('CB', '64.057'),
('N', '117.197')])),
('3', OrderedDict([('AA3Code', 'GLU'),
('Seq_ID', '3'),
('H', '8.002'),
('HA', '4.848'),
('HB2', '1.852'),
('HB3', '1.963'),
('HG2', '1.981'),
('HG3', '2.191'),
('CA', '55.651'),
('CB', '32.952'),
('CG', '37.425'),
('N', '119.833')])), ...
...
]
>>>
>>> starfile.chem_shifts_by_residue(amino_acids=["SER"], atoms=["CA", "CB"])
[OrderedDict([
('2', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '2'),
('CA', '58.593'),
('CB', '64.057')])),
('8', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '8'),
('CA', '57.456'),
('CB', '64.863')])),
('9', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '9'),
('CA', '57.852'),
('CB', '67.332')])),
('34', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '34'),
('CA', '59.113'),
('CB', '66.248')])),
('46', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '46'),
('CA', '55.939'),
('CB', '66.829')])),
('95', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '95'),
('CA', '57.013'),
('CB', '66.501')])),
('108', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '108'),
('CA', '61.617'),
('CB', '62.493')]))])
]
>>>



>>> starfile.chem_shifts_by_residue()
[OrderedDict([
('1', OrderedDict([('AA3Code', 'MET'),
Expand Down Expand Up @@ -360,7 +500,7 @@ using bracket accessors.
...
]
>>>
>>> starfile.chem_shifts_by_residue(aminoacids=["SER"], atoms=["CA", "CB"])
>>> starfile.chem_shifts_by_residue(amino_acids=["SER"], atoms=["CA", "CB"])
[OrderedDict([
('2', OrderedDict([('AA3Code', 'SER'),
('Seq_ID', '2'),
Expand Down Expand Up @@ -448,7 +588,7 @@ Chemical Shifts Viewer module.
>>> csviewer = CSViewer(from_path="18569", filename="18569_chem_shifts_all", csview_format="png")
>>> csviewer.csview(view=True)
>>>
>>> csviewer = CSViewer(from_path="18569", aminoacids=["SER", "THR"], atoms=["CA", "CB"],
>>> csviewer = CSViewer(from_path="18569", amino_acids=["SER", "THR"], atoms=["CA", "CB"],
... filename="18569_chem_shifts_SER_THR_CA_CB", csview_format="png")
>>> csviewer.csview(view=True) # open in a default image viewer or pdf viewer
>>> csviewer.csview(view=False) # save output file in current working directory
Expand Down Expand Up @@ -477,14 +617,14 @@ Command Line Interface functionality:
nmrstarlib convert (<from_path> <to_path>) [--from_format=<format>]
[--to_format=<format>]
[--bmrb_url=<url>]
[--nmrstarversion=<version>]
[--nmrstar_version=<version>]
[--verbose]
nmrstarlib csview <starfile_path> [--aminoacids=<aa>]
nmrstarlib csview <starfile_path> [--amino_acids=<aa>]
[--atoms=<at>]
[--csview_outfile=<path>]
[--csview_format=<format>]
[--nmrstarversion=<version>]
[--nmrstar_version=<version>]
[--verbose]
Options:
Expand All @@ -495,11 +635,11 @@ Command Line Interface functionality:
nmrstar, json [default: nmrstar]
--to_format=<format> Output file format, available formats:
nmrstar, json [default: json]
--nmrstarversion=<version> Version of NMR-STAR format to use, available:
--nmrstar_version=<version> Version of NMR-STAR format to use, available:
3, 2 [default: 3]
--bmrb_url=<url> URL to BMRB REST interface
[default: http://rest.bmrb.wisc.edu/bmrb/NMR-STAR3/]
--aminoacids=<aa> Comma-separated amino acid three-letter codes
--amino_acids=<aa> Comma-separated amino acid three-letter codes
--atoms=<at> Comma-separated BMRB atom codes
--csview_outfile=<path> Where to save chemical shifts table
--csview_format=<format> Format to which save chamical shift table
Expand Down Expand Up @@ -608,7 +748,7 @@ Visualizing chemical shift values
.. code:: bash
$ python3 -m nmrstarlib csview 18569 \
--aminoacids=GLU,THR --atoms=CA,CB,CG,CG2 \
--amino_acids=GLU,THR --atoms=CA,CB,CG,CG2 \
--csview_outfile=18569_chem_shifts_GLU_THR_CA_CB_CG_CG2 \
--csview_format=png
Expand Down
14 changes: 7 additions & 7 deletions nmrstarlib/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
Usage:
nmrstarlib -h | --help
nmrstarlib --version
nmrstarlib convert (<from_path> <to_path>) [--from_format=<format>] [--to_format=<format>] [--bmrb_url=<url>] [--nmrstarversion=<version>] [--verbose]
nmrstarlib csview <starfile_path> [--aminoacids=<aa>] [--atoms=<at>] [--csview_outfile=<path>] [--csview_format=<format>] [--nmrstarversion=<version>] [--verbose]
nmrstarlib convert (<from_path> <to_path>) [--from_format=<format>] [--to_format=<format>] [--bmrb_url=<url>] [--nmrstar_version=<version>] [--verbose]
nmrstarlib csview <starfile_path> [--amino_acids=<aa>] [--atoms=<at>] [--csview_outfile=<path>] [--csview_format=<format>] [--nmrstar_version=<version>] [--verbose]
Options:
-h, --help Show this screen.
--version Show version.
--verbose Print what files are processing.
--from_format=<format> Input file format, available formats: nmrstar, json [default: nmrstar]
--to_format=<format> Output file format, available formats: nmrstar, json [default: json]
--nmrstarversion=<version> Version of NMR-STAR format to use, available: 3, 2 [default: 3]
--nmrstar_version=<version> Version of NMR-STAR format to use, available: 3, 2 [default: 3]
--bmrb_url=<url> URL to BMRB REST interface [default: http://rest.bmrb.wisc.edu/bmrb/NMR-STAR3/]
--aminoacids=<aa> Comma-separated amino acid three-letter codes
--amino_acids=<aa> Comma-separated amino acid three-letter codes
--atoms=<at> Comma-separated BMRB atom codes
--csview_outfile=<path> Where to save chemical shifts table
--csview_format=<format> Format to which save chamical shift table [default: svg]
Expand All @@ -36,17 +36,17 @@ def main(cmdargs):
if cmdargs["convert"]:
nmrstarlib.BMRB_REST = cmdargs["--bmrb_url"]
nmrstarlib.VERBOSE = cmdargs["--verbose"]
nmrstarlib.NMRSTAR_VERSION = cmdargs["--nmrstarversion"]
nmrstarlib.NMRSTAR_VERSION = cmdargs["--nmrstar_version"]

nmrstarconverter = Converter(from_path=cmdargs["<from_path>"], to_path=cmdargs["<to_path>"],
from_format=cmdargs['--from_format'], to_format=cmdargs["--to_format"])
nmrstarconverter.convert()

elif cmdargs["csview"]:
aminoacids = cmdargs["--aminoacids"].split(",") if cmdargs["--aminoacids"] else []
aminoacids = cmdargs["--amino_acids"].split(",") if cmdargs["--amino_acids"] else []
atoms = cmdargs["--atoms"].split(",") if cmdargs["--atoms"] else []

csviewer = CSViewer(from_path=cmdargs["<starfile_path>"], aminoacids=aminoacids, atoms=atoms,
csviewer = CSViewer(from_path=cmdargs["<starfile_path>"], amino_acids=aminoacids, atoms=atoms,
filename=cmdargs["--csview_outfile"], csview_format=cmdargs["--csview_format"])
csviewer.csview(view=True)

Expand Down
26 changes: 13 additions & 13 deletions nmrstarlib/csviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ class CSViewer(object):
}}
'''

def __init__(self, from_path, aminoacids=None, atoms=None, filename=None, csview_format="svg", nmrstarversion="3"):
def __init__(self, from_path, amino_acids=None, atoms=None, filename=None, csview_format="svg", nmrstar_version="3"):
"""CSViewer initializer.
:param str from_path: Path to single NMR-STAR file or BMRB id.
:param list or tuple aminoacids: List of atom types, e.g. 'ALA', 'GLY', 'SER', etc. Leave as `None` to include everything.
:param list or tuple amino_acids: List of atom types, e.g. 'ALA', 'GLY', 'SER', etc. Leave as `None` to include everything.
:param list or tuple atoms: List of atom types, e.g. 'CA', 'CB', 'HA', etc. Leave as `None` to include everything.
:param str filename: Output filename chemical shifts graph to be saved.
:param str csview_format: `svg`, `png`, `pdf`. See http://www.graphviz.org/doc/info/output.html for all available formats.
:param str nmrstarversion: Version of NMR-STAR format to use for look up chemichal shifts loop.
:param str nmrstar_version: Version of NMR-STAR format to use for look up chemichal shifts loop.
:return: None
:rtype: :py:obj:`None`
"""
self.from_path = from_path
self.aminoacids = aminoacids
self.amino_acids = amino_acids
self.atoms = atoms
self.filename = filename
self.csview_format = csview_format
self.nmrstarversion = nmrstarversion
self.nmrstar_version = nmrstar_version

def csview(self, view=False):
"""View chemical shift values organized by amino acid residue.
Expand All @@ -73,7 +73,7 @@ def csview(self, view=False):
:rtype: :py:obj:`None`
"""
for starfile in nmrstarlib.read_files(self.from_path):
chains = starfile.chem_shifts_by_residue(self.aminoacids, self.atoms, self.nmrstarversion)
chains = starfile.chem_shifts_by_residue(self.amino_acids, self.atoms, self.nmrstar_version)
for idx, chemshifts_dict in enumerate(chains):
nodes = []
edges = []
Expand All @@ -86,17 +86,17 @@ def csview(self, view=False):
nodes.append(aanode_entry)
currnodename = aaname

for atomtype in chemshifts_dict[seq_id]:
if atomtype in ["AA3Code", "Seq_ID"]:
for atom_type in chemshifts_dict[seq_id]:
if atom_type in ["AA3Code", "Seq_ID"]:
continue
else:
atname = "{}_{}".format(aaname, atomtype)
label = '"{{{}|{}}}"'.format(atomtype, chemshifts_dict[seq_id][atomtype])
if atomtype.startswith("H"):
atname = "{}_{}".format(aaname, atom_type)
label = '"{{{}|{}}}"'.format(atom_type, chemshifts_dict[seq_id][atom_type])
if atom_type.startswith("H"):
color = 4
elif atomtype.startswith("C"):
elif atom_type.startswith("C"):
color = 6
elif atomtype.startswith("N"):
elif atom_type.startswith("N"):
color = 10
else:
color = 8
Expand Down
14 changes: 7 additions & 7 deletions nmrstarlib/nmrstarlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,19 @@ def _is_json(string):
except ValueError:
return False

def chem_shifts_by_residue(self, aminoacids=None, atoms=None, nmrstarversion="3"):
def chem_shifts_by_residue(self, amino_acids=None, atoms=None, nmrstar_version="3"):
"""Organize chemical shifts by amino acid residue.
:param list aminoacids: List of aminoacids three-letter codes.
:param list amino_acids: List of amino_acids three-letter codes.
:param list atoms: List of BMRB atom type codes.
:param str nmrstarversion: Version of NMR-STAR format to use for look up chemichal shifts loop.
:param str nmrstar_version: Version of NMR-STAR format to use for look up chemichal shifts loop.
:return: List of OrderedDict per each chain
:rtype: :py:class:`list` of :py:class:`collections.OrderedDict`
"""
this_directory = os.path.dirname(__file__)
if nmrstarversion == "2":
if nmrstar_version == "2":
config_filepath = os.path.join(this_directory, 'conf/constants_nmrstar2.json')
elif nmrstarversion == "3":
elif nmrstar_version == "3":
config_filepath = os.path.join(this_directory, 'conf/constants_nmrstar3.json')
else:
config_filepath = os.path.join(this_directory, 'conf/constants_nmrstar3.json')
Expand Down Expand Up @@ -458,10 +458,10 @@ def chem_shifts_by_residue(self, aminoacids=None, atoms=None, nmrstarversion="3"
chemshifts_dict[residueid][entry[atom_code]] = entry[chemshift_value]
chains.append(chemshifts_dict)

if aminoacids:
if amino_acids:
for chemshifts_dict in chains:
for aa in list(chemshifts_dict.values()):
if aa[u"AA3Code"].upper() not in aminoacids:
if aa[u"AA3Code"].upper() not in amino_acids:
chemshifts_dict.pop(aa[u"Seq_ID"])

if atoms:
Expand Down

0 comments on commit fef5df1

Please sign in to comment.