The nmrstarlib API Reference¶
Routines for working with BMRB NMR-STAR
and PDB CIF
formatted files.
This package includes the following modules:
nmrstarlib
- This module provides the
StarFile
superclass andNMRStarFile
andCIFFile
which are python dictionary representation of a BMRB NMR-STAR file and PDB CIF file, respectively. Data can be accessed directly from the instance using bracket accessors. Thenmrstarlib
module relies on thebmrblex
module for processing of tokens. bmrblex
- This module provides the
bmrblex()
generator that is responsible for the syntax analysis of BMRB NMR-STAR and PDB CIF files, processing word, number, single quoted, double quoted, multiline quoted tokens. converter
- This module provides the
Converter
class that is responsible for the conversion of NMR-STAR and CIF formatted files. csviewer
- This module provides the
CSViewer
class that visualizes chemical shift values from NMR-STAR files using the Graphviz (http://www.graphviz.org/) DOT Languge description and provides code example for utilizing the library. noise
- This module provides the
NoiseGenerator
class for adding random normal noise values to peaks in simulated peak list for NMR-STAR formatted files. plsimulator
- This module provides necessary interfaces in order to create a simulated
PeakList
from NMR-STAR formatted files. translator
- This module provides
StarFileToStarFile
for conversion between NMR-STAR/CIF and JSONized NMR-STAR/CIF formatted files andStarFileToPeakList
for conversion of NMR-STAR formatted files into peak list files using chemical shift values and assignment information. fileio
- This module provides the
read_files()
generator to open files from different sources (single file/multiple files on a local machine, directory/archive of files, URL address of a file).
nmrstarlib.nmrstarlib¶
This module provides the StarFile
superclass
and NMRStarFile
and CIFFile
subclasses that store data from a single NMR-STAR file and CIF file in the form of an
OrderedDict
. Data can be accessed directly from the
StarFile
instance using bracket
accessors.
The NMR-STAR format is a hierarchical dictionary containing data on NMR experiments. The data is divided into a series of “saveframes” which each contain a number of key-value pairs and “loops”.
Each “saveframe” has a unique name, which is used as the key in the dictionary, corresponding to another dictionary containing the information in the “saveframe”. Since “loops” in NMR-Star format do not have unique names, the keys for them inside the “saveframe” dictionary are simply “loop_0”, “loop_1”, etc.
The CIF format is another STAR-derived format that is similar to NMR-STAR, i.e. it contains key-value pairs of data and contains “loops” but does not have “saveframe” data organization.
-
nmrstarlib.nmrstarlib.
update_constants
(nmrstar2cfg='', nmrstar3cfg='', resonance_classes_cfg='', spectrum_descriptions_cfg='')[source]¶ Update constant variables.
Returns: None Return type: None
-
class
nmrstarlib.nmrstarlib.
StarFile
(*args, **kwds)[source]¶ StarFile class that stores the data from a single NMR-STAR or CIF file in the form of an
OrderedDict
.-
__init__
(*args, **kwds)[source]¶ StarFile initializer. Leave frame_categories as
None
to read everything. Otherwise it can be a list of saveframe categories to read, skipping the rest.Parameters: source (str) – Source StarFile instance was created from - local file or URL address.
-
static
read
(filehandle, source)[source]¶ Read data into a
StarFile
instance.Parameters: - filehandle (
io.TextIOWrapper
,gzip.GzipFile
,bz2.BZ2File
,zipfile.ZipFile
) – file-like object. - source (str) – String indicating where file is coming from (path, url).
Returns: subclass of
StarFile
.Return type: - filehandle (
-
write
(filehandle, file_format)[source]¶ Write
StarFile
data into file.Parameters: - filehandle (
io.TextIOWrapper
) – file-like object. - file_format (str) – Format to use to write data: nmrstar, cif, or json.
Returns: None
Return type: - filehandle (
-
writestr
(file_format)[source]¶ Write
StarFile
data into string.Parameters: file_format (str) – Format to use to write data: nmrstar, cif, or json. Returns: String representing the StarFile
instance.Return type: str
-
print_file
(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='', tw=3)[source]¶ Print
StarFile
into a file or stdout.Parameters: - f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: nmrstar, cif, or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
_to_star
()[source]¶ Save
StarFile
into NMR-STAR or CIF formatted string.Returns: NMR-STAR string. Return type: str
-
static
_is_nmrstar
(string)[source]¶ Test if input string is in NMR-STAR format.
Parameters: string ( str
orbytes
) – Input string.Returns: Input string if in NMR-STAR format or False otherwise. Return type: str
orFalse
-
-
class
nmrstarlib.nmrstarlib.
NMRStarFile
(source='', frame_categories=None, *args, **kwds)[source]¶ NMRStarFile class that stores the data from a single NMR-STAR file in the form of an
OrderedDict
.-
__init__
(source='', frame_categories=None, *args, **kwds)[source]¶ NMRStarFile initializer. Leave frame_categories as
None
to read everything. Otherwise it can be a list of saveframe categories to read, skipping the rest.Parameters:
-
_build_file
(nmrstar_str)[source]¶ Build
NMRStarFile
object.Parameters: nmrstar_str ( str
orbytes
) – NMR-STAR-formatted string.Returns: instance of NMRStarFile
.Return type: NMRStarFile
-
_build_saveframe
(lexer)[source]¶ Build NMR-STAR file saveframe.
Parameters: lexer ( bmrblex()
) – instance of the lexical analyzer.Returns: Saveframe dictionary. Return type: collections.OrderedDict
-
_build_loop
(lexer)[source]¶ Build saveframe loop.
Parameters: lexer ( bmrblex()
) – instance of lexical analyzer.Returns: Fields and values of the loop. Return type: tuple
-
_skip_saveframe
(lexer)[source]¶ Skip entire saveframe - keep emitting tokens until the end of saveframe.
Parameters: lexer ( bmrblex
) – instance of the lexical analyzer class.Returns: None Return type: None
-
print_file
(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]¶ Print
NMRStarFile
into a file or stdout.Parameters: - f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: nmrstar or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
print_saveframe
(sf, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]¶ Print saveframe into a file or stdout. We need to keep track of how far over everything is tabbed. The “tab width” variable tw does this for us.
Parameters: - sf (str) – Saveframe name.
- f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: nmrstar or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
print_loop
(sf, sftag, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='nmrstar', tw=3)[source]¶ Print loop into a file or stdout.
Parameters: - sf (str) – Saveframe name.
- sftag (str) – Saveframe tag, i.e. field name.
- f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: nmrstar or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
-
class
nmrstarlib.nmrstarlib.
CIFFile
(source='', *args, **kwds)[source]¶ CIFFile class that stores the data from a single CIF file in the form of an
OrderedDict
.-
__init__
(source='', *args, **kwds)[source]¶ CIFFile initializer.
Parameters: source (str) – Source CIFFile instance was created from - local file or URL address.
-
_build_file
(cif_str)[source]¶ Build
CIFFile
object.Parameters: cif_str ( str
orbytes
) – NMR-STAR-formatted string.Returns: instance of CIFFile
.Return type: CIFFile
-
_build_loop
(lexer)[source]¶ Build loop.
Parameters: lexer ( bmrblex()
) – instance of lexical analyzer.Returns: Fields and values of the loop. Return type: tuple
-
print_file
(f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='cif', tw=0)[source]¶ Print
CIFFile
into a file or stdout.Parameters: - f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: cif or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
print_loop
(loop_number, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, file_format='cif', tw=0)[source]¶ Print loop into a file or stdout.
Parameters: - f (io.StringIO) – writable file-like stream.
- file_format (str) – Format to use: cif or json.
- tw (int) – Tab width.
Returns: None
Return type:
-
-
exception
nmrstarlib.nmrstarlib.
InvalidToken
(value)[source]¶ -
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
exception
nmrstarlib.nmrstarlib.
SkipSaveFrame
[source]¶ -
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
nmrstarlib.nmrstarlib.
list_spectrums
()[source]¶ List all available spectrum names that can be used for peak list simulation.
Returns: None Return type: None
-
nmrstarlib.nmrstarlib.
list_spectrum_descriptions
(*args)[source]¶ List all available spectrum descriptions that can be used for peak list simulation.
Parameters: args (str) – Spectrum name(s), e.g. list_spectrum_descriptions(“HNCO”, “HNcoCACB”), leave empty to list everything. Returns: None Return type: None
nmrstarlib.bmrblex¶
This module provides bmrblex()
lexical analyzer for
BMRB NMR-STAR format syntax. It is implemented as Python generator-based
state machine which generates (yields) token one at a time when
next()
is invoked on bmrblex()
instance.
Simplified description of parsing rules:¶
- Each word or number separated by whitespace characters is a separate BMRB token.
- Each single quoted (‘) string is a separate BMRB token, it should start with a single quote (‘) and end with a single quote always followed by whitespace character(s).
- Each double quoted (“) string is a separate BMRB token, it should start with a double quote (“) and end with a double quote always followed by whitespace character(s).
- Single quoted and double quoted strings have to be processed separately.
- Single quoted and double quoted strings are processed one character at a time.
- Multiline strings start with a semicolon always followed by new line character and ending with a semicolon always followed by whitespace character(s).
- Multiline strings are processed one line at a time.
Note
- For a full description of NMR-STAR file format, see official documentation: http://www.bmrb.wisc.edu/dictionary/
- For a concise description of the NMR-STAR file format grammar see: https://github.com/mattfenwick/NMRPyStar#nmr-star-grammar
-
nmrstarlib.bmrblex.
bmrblex
(text)[source]¶ A lexical analyzer for the BMRB NMR-STAR format syntax.
Parameters: text ( str
orbytes
) – Input text.Returns: Current token. Return type: str
nmrstarlib.converter¶
This module provides functionality for converting between the BMRB NMR-STAR/CIF format and its equivalent JSONized NMR-STAR/CIF format.
The following conversions are possible:
- Local files:
- One-to-one file conversions:
- textfile - to - textfile
- textfile - to - textfile.gz
- textfile - to - textfile.bz2
- textfile.gz - to - textfile
- textfile.gz - to - textfile.gz
- textfile.gz - to - textfile.bz2
- textfile.bz2 - to - textfile
- textfile.bz2 - to - textfile.gz
- textfile.bz2 - to - textfile.bz2
- textfile / textfile.gz / textfile.bz2 - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
- Many-to-many files conversions:
- Directories:
- directory - to - directory
- directory - to - directory.zip
- directory - to - directory.tar
- directory - to - directory.tar.bz2
- directory - to - directory.tar.gz
- directory - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- Zipfiles:
- zipfile.zip - to - directory
- zipfile.zip - to - zipfile.zip
- zipfile.zip - to - tarfile.tar
- zipfile.zip - to - tarfile.tar.gz
- zipfile.zip - to - tarfile.tar.bz2
- zipfile.zip - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- Tarfiles:
- tarfile.tar - to - directory
- tarfile.tar - to - zipfile.zip
- tarfile.tar - to - tarfile.tar
- tarfile.tar - to - tarfile.tar.gz
- tarfile.tar - to - tarfile.tar.bz2
- tarfile.tar - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- tarfile.tar.gz - to - directory
- tarfile.tar.gz - to - zipfile.zip
- tarfile.tar.gz - to - tarfile.tar
- tarfile.tar.gz - to - tarfile.tar.gz
- tarfile.tar.gz - to - tarfile.tar.bz2
- tarfile.tar.gz - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- tarfile.tar.bz2 - to - directory
- tarfile.tar.bz2 - to - zipfile.zip
- tarfile.tar.bz2 - to - tarfile.tar
- tarfile.tar.bz2 - to - tarfile.tar.gz
- tarfile.tar.bz2 - to - tarfile.tar.bz2
- tarfile.tar.bz2 - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- URL files:
- One-to-one file conversions:
- id - to - textfile
- id - to - textfile.gz
- id - to - textfile.bz2
- id - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
- textfileurl - to - textfile
- textfileurl - to - textfile.gz
- textfileurl - to - textfile.bz2
- textfileurl.gz - to - textfile
- textfileurl.gz - to - textfile.gz
- textfileurl.gz - to - textfile.bz2
- textfileurl.bz2 - to - textfile
- textfileurl.bz2 - to - textfile.gz
- textfileurl.bz2 - to - textfile.bz2
- textfileurl / textfileurl.gz / textfileurl.bz2 - to - textfile.zip / textfile.tar / textfile.tar.gz / textfile.tar.bz2 (TypeError: One-to-many conversion)
- Many-to-many files conversions:
- Zipfiles:
- zipfileurl.zip - to - directory
- zipfileurl.zip - to - zipfile.zip
- zipfileurl.zip - to - tarfile.tar
- zipfileurl.zip - to - tarfile.tar.gz
- zipfileurl.zip - to - tarfile.tar.bz2
- zipfileurl.zip - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- Tarfiles:
- tarfileurl.tar - to - directory
- tarfileurl.tar - to - zipfile.zip
- tarfileurl.tar - to - tarfile.tar
- tarfileurl.tar - to - tarfile.tar.gz
- tarfileurl.tar - to - tarfile.tar.bz2
- tarfileurl.tar - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- tarfileurl.tar.gz - to - directory
- tarfileurl.tar.gz - to - zipfile.zip
- tarfileurl.tar.gz - to - tarfile.tar
- tarfileurl.tar.gz - to - tarfile.tar.gz
- tarfileurl.tar.gz - to - tarfile.tar.bz2
- tarfileurl.tar.gz - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
- tarfileurl.tar.bz2 - to - directory
- tarfileurl.tar.bz2 - to - zipfile.zip
- tarfileurl.tar.bz2 - to - tarfile.tar
- tarfileurl.tar.bz2 - to - tarfile.tar.gz
- tarfileurl.tar.bz2 - to - tarfile.tar.bz2
- tarfileurl.tar.bz2 - to - directory.gz / directory.bz2 (TypeError: Many-to-one conversion)
-
class
nmrstarlib.converter.
Converter
(file_generator)[source]¶ Converter class to convert NMR-STAR/CIF files from NMR-STAR/CIF to JSON or from JSON to NMR-STAR/CIF format.
-
__init__
(file_generator)[source]¶ Converter initializer.
Parameters: file_generator ( nmrstarlib.converter.Translator
) –
-
convert
()[source]¶ Convert file(s) from NMR-STAR/CIF format to JSON format or from JSON format to NMR-STAR/CIF format.
Returns: None Return type: None
-
_to_bz2file
(file_generator)[source]¶ Convert file to bz2-compressed file.
Returns: None Return type: None
-
_to_gzipfile
(file_generator)[source]¶ Convert file to gzip-compressed file.
Returns: None Return type: None
-
_to_textfile
(file_generator)[source]¶ Convert file to regular text file.
Returns: None Return type: None
-
_output_path
(inputpath, to_format, archive=False)[source]¶ Construct an output path string from an input path string.
Parameters: inputpath (str) – Input path string. Returns: Output path string. Return type: str
-
__weakref__
¶ list of weak references to the object (if defined)
-
nmrstarlib.csviewer¶
This module provides the CSViewer
class - Chemical Shifts Viewer
that visualizes chemical shifts values.
-
class
nmrstarlib.csviewer.
CSViewer
(from_path, amino_acids=None, atoms=None, amino_acids_and_atoms=None, filename=None, csview_format='svg', nmrstar_version='3')[source]¶ Chemical Shifts Viewer uses
chem_shifts_by_residue()
method to get chemical shifts organized by residue and visualizes chemical shifts values using the Graphviz (http://www.graphviz.org/) DOT Languge description.-
__init__
(from_path, amino_acids=None, atoms=None, amino_acids_and_atoms=None, filename=None, csview_format='svg', nmrstar_version='3')[source]¶ CSViewer initializer.
Parameters: - from_path (str) – Path to single NMR-STAR file or BMRB id.
- amino_acids (
list
ortuple
) – Sequence of amino acids three letter codes, e.g. ‘ALA’, ‘GLY’, ‘SER’, etc. Leave as None to include everything. - atoms (
list
ortuple
) – Sequence of atom types, e.g. ‘CA’, ‘CB’, ‘HA’, etc. Leave as None to include everything. - amino_acids_and_atoms (dict) – Amino acid and its atoms key-value pairs.
- filename (str) – Output filename chemical shifts graph to be saved.
- csview_format (str) – svg, png, pdf. See http://www.graphviz.org/doc/info/output.html for all available formats.
- nmrstar_version (str) – Version of NMR-STAR format to use for look up chemichal shifts loop.
Returns: None
Return type:
-
csview
(view=False)[source]¶ View chemical shift values organized by amino acid residue.
Parameters: view ( True
orFalse
) – Open in default image viewer or save file in current working directory quietly.Returns: None Return type: None
-
__weakref__
¶ list of weak references to the object (if defined)
-
nmrstarlib.noise¶
This module provides the NoiseGenerator
class for adding noise values to Peak
dimensions within a PeakList
.
-
class
nmrstarlib.noise.
NoiseGenerator
(parameters=None, distribution_name='normal', seed=None)[source]¶ Noise generator class.
-
__init__
(parameters=None, distribution_name='normal', seed=None)[source]¶ Noise generator initializer.
Parameters:
-
__weakref__
¶ list of weak references to the object (if defined)
-
nmrstarlib.plsimulator¶
This module provides interface classes necessary to create simulated peak list file.
-
class
nmrstarlib.plsimulator.
DimensionComponent
(label, position)[source]¶ Dimensions component interface.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
Dimension
(label, position, assignment=None, chemshift=None)[source]¶ Concrete dimension.
-
class
nmrstarlib.plsimulator.
Peak
(labels)[source]¶ Peak within a peak list.
-
assignments_list
¶ List of assignments per each dimension within a peak.
Returns: List of assignments. Return type: list
-
chemshifts_list
¶ List of chemical shift values per each dimensions within a peak.
Returns: List of chemical shifts. Return type: list
-
apply_noise
(noise_generator, split_idx, ndigits=6)[source]¶ Apply noise to dimensions within a peak.
Parameters: - noise_generator – Noise generator object.
- split_idx (int) – Index specifying which peak list split parameters to use.
Returns: None
Return type:
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
PeakList
(spectrum_name, labels, source, chain_idx)[source]¶ Peak list contains chemical shift values and assignment information for each peak.
-
__init__
(spectrum_name, labels, source, chain_idx)[source]¶ Peak list initializer.
Parameters: - spectrum_name (str) – Spectrum name from which peak list will be simulated.
- labels (list) – Sequence of labels as they appear in a peak.
- source (str) –
NMRStarFile
source. - chain_idx (int) –
NMRStarFile
chain index.
-
_to_sparky
()[source]¶ Save
PeakList
into Sparky-formatted string.Returns: Peak list representation in Sparky format. Return type: str
-
_to_autoassign
()[source]¶ Save
PeakList
into AutoAssign-formatted string.Returns: Peak list representation in AutoAssign format. Return type: str
-
_to_json
()[source]¶ Save
PeakList
into JSON string.Returns: Peak list representation in JSON format. Return type: str
-
write
(filehandle, fileformat)[source]¶ Write
PeakList
data into file.Parameters: - filehandle (
io.TextIOWrapper
) – file-like object. - fileformat (str) – Format to use to write data: sparky, autoassign, or json.
Returns: None
Return type: - filehandle (
-
writestr
(fileformat)[source]¶ Write
PeakList
data into string.Parameters: fileformat (str) – Format to use to write data: sparky, autoassign, or json. Returns: String representing the PeakList
instance.Return type: str
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
SpinSystem
[source]¶ Spin system - collection of related resonances associated with specific atoms in a molecule.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
SequenceSite
(residues)[source]¶ Sequence site.
-
is_sequential
()[source]¶ Check if residues that sequence site is composed of are in sequential order.
Returns: If sequence site is in valid sequential order (True) or not (False). Return type: True
orFalse
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
PeakTemplate
(dimensions)[source]¶ Peak templates defined as a list of concrete dimensions.
-
dimension_labels
¶ List of dimension labels.
Returns: List of dimension labels of a peak template. Return type: list
-
dimension_positions
¶ List of dimension positions.
Returns: List of dimension positions of a peak template. Return type: list
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
PeakDescription
(fraction, dimension_labels)[source]¶ Peak descriptions defined as list of general dimension groups.
-
__init__
(fraction, dimension_labels)[source]¶ Peak description initializer.
Parameters: - fraction (float) – Describes expected number of peaks.
- dimension_labels – List of dimension labels.
-
static
create_dimension_groups
(dimension_positions)[source]¶ Create list of dimension groups.
Parameters: dimension_positions (zip) – List of tuples describing dimension and its position within sequence site. Returns: List of dimension groups. Return type: list
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.plsimulator.
Spectrum
(name, labels, min_spin_system_peaks, amino_acids_and_atoms=None)[source]¶ Spectrum object described as a list of general peak descriptions.
-
__init__
(name, labels, min_spin_system_peaks, amino_acids_and_atoms=None)[source]¶ Spectrum initializer.
Parameters:
-
peak_templates
¶ Create a list of concrete peak templates from a list of general peak descriptions.
Returns: List of peak templates. Return type: list
-
seq_site_length
¶ Calculate length of a single sequence site based upon relative positions specified in peak descriptions.
Returns: Length of sequence site. Return type: int
-
__weakref__
¶ list of weak references to the object (if defined)
-
nmrstarlib.translator¶
This module provides the Translator
abstract class
and concrete classes: StarFileToStarFile
for converting between
NMR-STAR/CIF and JSONized NMR-STAR/CIF formats and StarFileToPeakList
for converting NMR-STAR formatted file into simulated peak list file.
-
class
nmrstarlib.translator.
Translator
(from_path, to_path, from_format=None, to_format=None)[source]¶ Translator abstract class.
-
__init__
(from_path, to_path, from_format=None, to_format=None)[source]¶ Translator initializer.
Parameters:
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
nmrstarlib.translator.
StarFileToStarFile
(from_path, to_path, from_format=None, to_format=None)[source]¶ Translator concrete class that can convert between NMR-STAR/CIF and JSONized NMR-STAR/CIF formats.
-
class
nmrstarlib.translator.
StarFileToPeakList
(from_path, to_path, from_format, to_format, spectrum_name, plsplit=None, noise_generator=None, nmrstar_version='3')[source]¶ Translator concrete class that can convert NMR-STAR of JSONized NMR-STAR formatted file into peak list file.
-
__init__
(from_path, to_path, from_format, to_format, spectrum_name, plsplit=None, noise_generator=None, nmrstar_version='3')[source]¶ StarFileToPeakList initializer.
Parameters: - from_path (str) – Path to input file(s).
- to_path (str) – Path to output file(s).
- from_format (str) – Input format: nmrstar or json.
- to_format (str) – Output format: json or sparky.
- spectrum_name (str) – Name of spectrum from which to simulate peak list.
- plsplit (tuple) – How to split peak list in order to account for multiple sources of variance.
- nmrstar_version (str) – Version of NMR-STAR format to use for look up chemical shifts loop.
- noise_generator (
NoiseGenerator
) – Subclasses ofNoiseGenerator
object.
-
static
create_spectrum
(spectrum_name)[source]¶ Initialize spectrum and peak descriptions.
Parameters: spectrum_name (str) – Name of the spectrum from which peak list will be simulated. Returns: Spectrum object. Return type: Spectrum
-
static
create_sequence_sites
(chain, seq_site_length)[source]¶ Create sequence sites using sequence ids.
Parameters: Returns: List of sequence sites.
Return type:
-
static
calculate_intervals
(chunk_sizes)[source]¶ Calculate intervals for a given chunk sizes.
Parameters: chunk_sizes (list) – List of chunk sizes. Returns: Tuple of intervals. Return type: tuple
-
split_by_percent
(spin_systems_list)[source]¶ Split list of spin systems by specified percentages.
Parameters: spin_systems_list (list) – List of spin systems. Returns: List of spin systems divided into sub-lists corresponding to specified split percentages. Return type: list
-
nmrstarlib.fileio¶
This module provides routines for reading NMR-STAR
and CIF
formatted files from difference kinds of sources:
- Single
NMR-STAR
orCIF
formatted file on a local machine.- Directory containing multiple
NMR-STAR
orCIF
formatted files.- Compressed zip/tar archive of
NMR-STAR
orCIF
formatted files.- URL address of
NMR-STAR
orCIF
formatted file.BMRB ID
ofNMR-STAR
orPDB ID
ofCIF
formatted file.
-
nmrstarlib.fileio.
_generate_filenames
(sources)[source]¶ Generate filenames.
Parameters: sources (tuple) – Sequence of strings representing path to file(s). Returns: Path to file(s). Return type: str
-
nmrstarlib.fileio.
_generate_handles
(filenames)[source]¶ Open a sequence of filenames one at time producing file objects. The file is closed immediately when proceeding to the next iteration.
Parameters: filenames (generator) – Generator object that yields the path to each file, one at a time. Returns: Filehandle to be processed into a StarFile
instance.
-
nmrstarlib.fileio.
read_files
(*sources)[source]¶ Construct a generator that yields
StarFile
instances.Parameters: sources – One or more strings representing path to file(s). Returns: StarFile
instance(s).Return type: StarFile
-
class
nmrstarlib.fileio.
GenericFilePath
(path)[source]¶ GenericFilePath class knows how to open local files or files over URL.
-
__init__
(path)[source]¶ Initialize path.
Parameters: path (str) – String representing a path to local file(s) or valid URL address of file(s).
-
open
()[source]¶ Generator that opens and yields filehandles using appropriate facilities: test if path represents a local file or file over URL, if file is compressed or not.
Returns: Filehandle to be processed into a StarFile
instance.
-
static
is_compressed
(path)[source]¶ Test if path represents compressed file(s).
Parameters: path (str) – Path to file(s). Returns: String specifying compression type if compressed, “” otherwise. Return type: str
-
static
is_url
(path)[source]¶ Test if path represents a valid URL.
Parameters: path (str) – Path to file. Returns: True if path is valid url string, False otherwise. Return type: True
orFalse
-
__weakref__
¶ list of weak references to the object (if defined)
-