Skip to content

Commit

Permalink
Add NMRView peak reader and parserlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
yokochi47 committed Dec 4, 2024
1 parent c224a75 commit 330ccdb
Show file tree
Hide file tree
Showing 55 changed files with 5,339 additions and 2,237 deletions.
12 changes: 6 additions & 6 deletions wwpdb/utils/nmr/NEFTranslator/NEFTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

from packaging import version
from operator import itemgetter
from typing import List
from typing import List, Optional, Union

from wwpdb.utils.align.alignlib import PairwiseAlign # pylint: disable=no-name-in-module

Expand Down Expand Up @@ -474,7 +474,7 @@
}


def get_first_sf_tag(sf=None, tag=None) -> str:
def get_first_sf_tag(sf: Optional[pynmrstar.Saveframe] = None, tag: Optional[str] = None) -> str:
""" Return the first value of a given saveframe tag.
@return: The first tag value, empty string otherwise.
"""
Expand All @@ -490,7 +490,7 @@ def get_first_sf_tag(sf=None, tag=None) -> str:
return array[0] if array[0] is not None else ''


def get_idx_msg(idx_tag_ids: List[int], tags: List[str], row) -> str:
def get_idx_msg(idx_tag_ids: List[int], tags: List[str], row: dict) -> str:
""" Return description about current index.
@author: Masashi Yokochi
@return: description
Expand All @@ -512,7 +512,7 @@ def get_idx_msg(idx_tag_ids: List[int], tags: List[str], row) -> str:
return ''


def is_empty_loop(star_data, lp_category: str) -> bool:
def is_empty_loop(star_data: Union[pynmrstar.Entry, pynmrstar.Saveframe, pynmrstar.Loop], lp_category: str) -> bool:
""" Return whether one of specified loops is empty loop.
@return: True for empty loop exists, False otherwise
"""
Expand All @@ -530,7 +530,7 @@ def is_empty_loop(star_data, lp_category: str) -> bool:
return len(star_data) == 0


def count_non_empty_loops(star_data, lp_category: str) -> int:
def count_non_empty_loops(star_data: Union[pynmrstar.Entry, pynmrstar.Saveframe, pynmrstar.Loop], lp_category: str) -> int:
""" Return the number of non-empty loops.
@return: the number of non-empty loops.
"""
Expand All @@ -548,7 +548,7 @@ def count_non_empty_loops(star_data, lp_category: str) -> int:
return 0 if len(star_data) == 0 else 1


def get_sf_tag_values_with_empty_loop(star_data, lp_category: str, sf_category: str) -> List[str]:
def get_sf_tag_values_with_empty_loop(star_data: Union[pynmrstar.Entry, pynmrstar.Saveframe, pynmrstar.Loop], lp_category: str, sf_category: str) -> List[str]:
""" Return list of saveframe tag values with empty loop.
@return: list of saveframe tag values
"""
Expand Down
4 changes: 2 additions & 2 deletions wwpdb/utils/nmr/NmrDpReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@
import re

from operator import itemgetter
from typing import Optional
from typing import Any, Optional

try:
from wwpdb.utils.nmr.AlignUtil import emptyValue, monDict3, unknownResidue, getPrettyJson
except ImportError:
from nmr.AlignUtil import emptyValue, monDict3, unknownResidue, getPrettyJson


def get_value_safe(d=None, key=None) -> Optional[str]:
def get_value_safe(d: Optional[dict] = None, key: Any = None) -> Optional[str]:
""" Return value of a given dictionary for a key.
@return: value for a key, None otherwise
"""
Expand Down
22 changes: 11 additions & 11 deletions wwpdb/utils/nmr/NmrDpUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
from munkres import Munkres
from operator import itemgetter
from striprtf.striprtf import rtf_to_text
from typing import List, Tuple, Optional
from typing import Any, List, Tuple, Optional

from mmcif.io.IoAdapterPy import IoAdapterPy
from wwpdb.utils.align.alignlib import PairwiseAlign # pylint: disable=no-name-in-module
Expand Down Expand Up @@ -569,7 +569,7 @@
'nm-res-syb', 'nm-res-ros', 'nm-res-xpl')


def detect_bom(fPath: str, default='utf-8') -> str:
def detect_bom(fPath: str, default: str = 'utf-8') -> str:
""" Detect BOM of input file.
"""

Expand All @@ -586,7 +586,7 @@ def detect_bom(fPath: str, default='utf-8') -> str:
return default


def convert_codec(inPath: str, outPath: str, in_codec='utf-8', out_codec='utf-8'):
def convert_codec(inPath: str, outPath: str, in_codec: str = 'utf-8', out_codec: str = 'utf-8'):
""" Convert codec of input file.
"""

Expand Down Expand Up @@ -701,7 +701,7 @@ def get_type_of_star_file(fPath: str) -> str:
pass


def has_key_value(d=None, key=None) -> bool:
def has_key_value(d: Optional[dict] = None, key: Any = None) -> bool:
""" Return whether a given dictionary has effective value for a key.
@return: True if d[key] has effective value, False otherwise
"""
Expand All @@ -715,7 +715,7 @@ def has_key_value(d=None, key=None) -> bool:
return False


def get_first_sf_tag(sf=None, tag=None) -> str:
def get_first_sf_tag(sf: Optional[pynmrstar.Saveframe] = None, tag: Optional[str] = None) -> str:
""" Return the first value of a given saveframe tag.
@return: The first tag value, empty string otherwise.
"""
Expand All @@ -731,7 +731,7 @@ def get_first_sf_tag(sf=None, tag=None) -> str:
return array[0] if array[0] is not None else ''


def set_sf_tag(sf, tag: str, value):
def set_sf_tag(sf: pynmrstar.Saveframe, tag: str, value):
""" Set saveframe tag.
"""

Expand Down Expand Up @@ -1062,7 +1062,7 @@ def concat_nmr_restraint_names(content_subtype: Optional[str]) -> str:
return ', '.join(f)


def is_peak_list(line: str, has_header=True) -> bool:
def is_peak_list(line: str, has_header: bool = True) -> bool:
""" Return whether a given input is derived from peak list in any native format.
"""

Expand All @@ -1082,7 +1082,7 @@ def is_peak_list(line: str, has_header=True) -> bool:
return False


def get_peak_list_format(line: str, has_header=True) -> Optional[str]:
def get_peak_list_format(line: str, has_header: bool = True) -> Optional[str]:
""" Return peak list format for a given input.
"""

Expand Down Expand Up @@ -1137,7 +1137,7 @@ def get_number_of_dimensions_of_peak_list(file_format: str, line: str) -> Option
return None


def is_like_planality_boundary(row, lower_limit_name: str, upper_limit_name: str) -> bool:
def is_like_planality_boundary(row: dict, lower_limit_name: str, upper_limit_name: str) -> bool:
""" Return whether boundary conditions like planality restraint.
"""

Expand Down Expand Up @@ -1165,7 +1165,7 @@ def is_like_planality_boundary(row, lower_limit_name: str, upper_limit_name: str
return False


def get_atom_name_mapping(lp, list_of_tags: List[List[str]]) -> Optional[List[dict]]:
def get_atom_name_mapping(lp: pynmrstar.Loop, list_of_tags: List[List[str]]) -> Optional[List[dict]]:
""" Return atom name mapping history for each comp_id.
Each tags should be array of 'comp_id', 'atom_id', and 'atom_name'.
"""
Expand Down Expand Up @@ -29956,7 +29956,7 @@ def __retrieveCoordAssemblyChecker(self):
self.__caC = coordAssemblyChecker(self.__verbose, self.__lfh,
self.__representative_model_id,
self.__representative_alt_id,
self.__cR, None, nmrPolySeq)
self.__cR, self.__ccU, None, nmrPolySeq)

if self.__caC is not None and self.__asmChkCachePath is not None:
write_as_pickle(self.__caC, self.__asmChkCachePath)
Expand Down
6 changes: 3 additions & 3 deletions wwpdb/utils/nmr/NmrVrptUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def compress_as_gzip_file(inPath: str, outPath: str):
ofh.write(line)


def load_from_pickle(file_name: str, default=None) -> Any:
def load_from_pickle(file_name: str, default: Any = None) -> Any:
""" Load object from pickle file.
"""

Expand Down Expand Up @@ -1177,7 +1177,7 @@ def __retrieveCoordAssemblyChecker(self):
self.__caC = coordAssemblyChecker(self.__verbose, self.__lfh,
self.__representative_model_id,
self.__representative_alt_id,
self.__cR, None, None)
self.__cR, self.__ccU, None, None)

if self.__caC is not None and cache_path:
write_as_pickle(self.__caC, cache_path)
Expand All @@ -1186,7 +1186,7 @@ def __retrieveCoordAssemblyChecker(self):
self.__caC = coordAssemblyChecker(self.__verbose, self.__lfh,
self.__representative_model_id,
self.__representative_alt_id,
self.__cR, None, None, False)
self.__cR, self.__ccU, None, None, False)

return True

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AmberMRParserListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,12 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__cR = cR
self.__hasCoord = cR is not None

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if self.__hasCoord:
ret = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, caC)
cR, self.__ccU, caC)
self.__modelNumName = ret['model_num_name']
self.__authAsymId = ret['auth_asym_id']
self.__authSeqId = ret['auth_seq_id']
Expand Down Expand Up @@ -574,9 +577,6 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__concatHetero = False
break

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AmberMRReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__representativeAltId = representativeAltId
self.__mrAtomNameMapping = mrAtomNameMapping

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if cR is not None and caC is None:
caC = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, None, None, fullCheck=False)
cR, self.__ccU, None, None, fullCheck=False)

self.__cR = cR
self.__caC = caC

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AmberPTParserListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ def __init__(self, verbose=True, log=sys.stdout,

self.__hasCoord = cR is not None

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if self.__hasCoord:
ret = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, caC, None, fullCheck=True)
cR, self.__ccU, caC, None, fullCheck=True)
self.__polySeqModel = ret['polymer_sequence']
self.__nonPolyModel = ret['non_polymer']
self.__branchedModel = ret['branched']
Expand All @@ -175,9 +178,6 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__hasBranchedModel = self.__branchedModel is not None and len(self.__branchedModel) > 0
self.__noWaterMol = not self.__hasNonPolyModel or not any(np['comp_id'][0] == 'HOH' for np in self.__nonPolyModel)

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AmberPTReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__representativeAltId = representativeAltId
self.__mrAtomNameMapping = mrAtomNameMapping

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if cR is not None and caC is None:
caC = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, None, None, fullCheck=False)
cR, self.__ccU, None, None, fullCheck=False)

self.__cR = cR
self.__caC = caC

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AriaMRParserListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,12 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__cR = cR
self.__hasCoord = cR is not None

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if self.__hasCoord:
ret = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, caC)
cR, self.__ccU, caC)
self.__modelNumName = ret['model_num_name']
self.__authAsymId = ret['auth_asym_id']
self.__authSeqId = ret['auth_seq_id']
Expand Down Expand Up @@ -352,9 +355,6 @@ def __init__(self, verbose=True, log=sys.stdout,
else:
self.__nonPolySeq = self.__branched

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/AriaMRReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__representativeAltId = representativeAltId
self.__mrAtomNameMapping = mrAtomNameMapping

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if cR is not None and caC is None:
caC = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, None, None, fullCheck=False)
cR, self.__ccU, None, None, fullCheck=False)

self.__cR = cR
self.__caC = caC

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/BiosymMRParserListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,12 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__cR = cR
self.__hasCoord = cR is not None

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if self.__hasCoord:
ret = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, caC)
cR, self.__ccU, caC)
self.__modelNumName = ret['model_num_name']
self.__authAsymId = ret['auth_asym_id']
self.__authSeqId = ret['auth_seq_id']
Expand Down Expand Up @@ -363,9 +366,6 @@ def __init__(self, verbose=True, log=sys.stdout,
else:
self.__nonPolySeq = self.__branched

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
8 changes: 4 additions & 4 deletions wwpdb/utils/nmr/mr/BiosymMRReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ def __init__(self, verbose=True, log=sys.stdout,
self.__representativeAltId = representativeAltId
self.__mrAtomNameMapping = mrAtomNameMapping

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

if cR is not None and caC is None:
caC = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId,
cR, None, None, fullCheck=False)
cR, self.__ccU, None, None, fullCheck=False)

self.__cR = cR
self.__caC = caC

# CCD accessing utility
self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU

# BMRB chemical shift statistics
self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat

Expand Down
Loading

0 comments on commit 330ccdb

Please sign in to comment.