Commit 72ac54c5 authored by Lars Yunker's avatar Lars Yunker
Browse files

Merge branch '44-include-psi-ms-obo-in-distribution' into 'master'

Resolve "include psi-ms obo in distribution"

Closes #44

See merge request !39
parents 4da28448 e9e02bbe
Pipeline #152981120 passed with stage
in 2 minutes and 31 seconds
......@@ -2,9 +2,6 @@
# PyCharm stuff
.idea
# obo files (distributed in psi-ms-CV repository)
*.obo
# saved Molecule properties
/molecules
*.mol
......
......@@ -99,4 +99,8 @@ shape and managing impractically precise x values.
Contains classes for interacting with mzML files in a pythonic manner.
### License
These tools are licensed under the [MIT license](https://opensource.org/licenses/MIT).
\ No newline at end of file
These tools are licensed under the [MIT license](https://opensource.org/licenses/MIT).
A [HUPO PSI-MS](https://www.hupo.org/Proteomics-Standards-Initiative) type definition file (psi-ms.obo) is distributed with this package as
a reference for the `mzml` package. This file is included [without modification](https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo)
and is included under the [Creative Commons Attribution 4.0 International (CC BY 4.0) license](https://creativecommons.org/licenses/by/4.0/).
\ No newline at end of file
__version__ = '2.2.0'
__version__ = '2.2.1'
This diff is collapsed.
"""Classes for interacting with HUPO-PSI-MS controlled variable names and descriptions"""
import os
import obonet
import textwrap
import urllib
import pathlib
from packaging import version
from typing import Union
from xml.etree import ElementTree
cv_param_def = None # default state for loaded CV parameters
def find_obos(paths: list):
"""
locates any *.obo files in the specified directory
:param paths: paths to search
:return: list of paths
:rtype: list
"""
locations = []
for eachpath in paths:
for root, dirs, files in os.walk(eachpath):
for ind in files:
if ind.endswith('.obo'):
locations.append(os.path.join(root, ind))
return locations
def newest_version(paths: list):
"""
Select the newest possible obo version in the supplied paths
......@@ -32,16 +17,17 @@ def newest_version(paths: list):
:return: selected path
:rtype: str
"""
ver = 0.
ver: version = version.parse('0.')
out = ''
for loc in paths:
hndl = open(loc, 'rt')
lines = hndl.readlines()
hndl.close()
for line in lines:
if line.startswith('format-version:'):
if float(line.split()[1]) > ver:
ver = float(line.split()[1])
if line.startswith('data-version:'):
loc_ver = version.parse(line.split()[1])
if loc_ver > ver:
ver = loc_ver
out = loc
break
return out
......@@ -63,7 +49,7 @@ def verify_obo(path):
])
def find_local_obo(custom_paths: list = None):
def find_local_obo(*custom_paths: Union[str, pathlib.Path]):
"""
Finds local paths to obo files
......@@ -71,13 +57,17 @@ def find_local_obo(custom_paths: list = None):
:return: path to newest, local obo or None
:rtype: str
"""
paths = [
os.getcwd(), # by default, check CWD
default_search_paths = [
pathlib.Path(__file__).parent, # check default save location
pathlib.Path.cwd(), # check current working directory
]
default_search_paths.extend(custom_paths)
obo_paths = []
for path in default_search_paths:
obo_paths.extend(path.glob('**/*.obo'))
if custom_paths is not None:
paths.extend(paths)
possible = find_obos(paths) # retrieve possible locations
verified = [path for path in possible if verify_obo(path) is True] # verify correct paths
default_search_paths.extend(default_search_paths)
verified = [path for path in obo_paths if verify_obo(path) is True] # verify correct paths
if len(verified) == 0:
return None # if there are no valid possibilities, return None
return newest_version(verified)
......@@ -85,9 +75,9 @@ def find_local_obo(custom_paths: list = None):
# url for accessing the most up-to-date version of the psi-ms obo file
OBOURL = 'https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo'
local_obo = find_local_obo() # try to find a local obo and use instead
if local_obo is not None:
OBOURL = local_obo
TARGET_OBO = find_local_obo() # try to find a local obo and use instead
if TARGET_OBO is None:
TARGET_OBO = OBOURL
def interpret_term_string(string: str):
......@@ -415,7 +405,7 @@ class CVParameterSet(object):
class CVParameterDefinitions(CVParameterSet):
def __init__(self,
obo_path=OBOURL,
obo_path=TARGET_OBO,
):
"""
Loads and interprets a PSI-MS obo file into a python-interpretable format.
......@@ -442,10 +432,10 @@ class CVParameterDefinitions(CVParameterSet):
)
def __repr__(self):
return f'{self.__class__.__name__}(v{self.format_version})'
return f'{self.__class__.__name__}(v{self.data_version})'
def __str__(self):
return f'{self.__class__.__name__} format version {self.format_version} with {len(self.cv_values)} keys'
return f'{self.__class__.__name__} data version {self.data_version} with {len(self.cv_values)} keys'
def print_properties(self, key):
cvparam = self.__getitem__(key)
......
......@@ -48,6 +48,10 @@ setup(
'obonet==0.2.5', # they changed attribute names without deprecationwarnings, so only this version is verified
'isospecpy>=2.0.2',
'tqdm>=4.46.0',
'packaging>=20.1',
],
package_data={
'': ['*.obo']
},
keywords=KEYWORDS,
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment