Skip to content

Commit

Permalink
Simplified return object and updated example script
Browse files Browse the repository at this point in the history
  • Loading branch information
fu committed Dec 5, 2018
2 parents 4038c55 + 7c3d79e commit b9e8e7a
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 129 deletions.
12 changes: 12 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

.. examples:
.. default-domain:: py

Examples
########

Get parameter information
-------------------------

.. autofunction:: get_param_info.main
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Contents
:maxdepth: 2
:caption: Contents:


examples

Indices and tables
==================
Expand Down
2 changes: 1 addition & 1 deletion docs/source/uparma.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.. unimod_mapper:
.. uparma:
.. default-domain:: py

Expand Down
33 changes: 0 additions & 33 deletions examples/map_ursgal.py

This file was deleted.

26 changes: 26 additions & 0 deletions examples/mapping_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
import uparma
import pprint

def main():
up = uparma.UParma(refresh_jsons=True)
print('Original input:')
input_dict = {
"precursor_mass_tolerance_unit": "ppm",
"min_pep_length" : 8,
"max_num_mods" : 3,
}
pprint.pprint(input_dict)

msgf_params = up.convert(
input_dict,
target_style = 'msgfplus_style_1'
)
print('\nMapped to msgf+:')
pprint.pprint(msgf_params)

print('\nDetails:')
pprint.pprint(msgf_params.details)

if __name__ == '__main__':
main()
39 changes: 0 additions & 39 deletions uparma/parameters.json

This file was deleted.

31 changes: 1 addition & 30 deletions uparma/styles.json
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
{
"msgfplus_style_1" : {
"name" : "MS-GF+",
"version" : [
"v2018.01.20",
"v2018.06.28",
"v2018.09.12"
],
"reference" : "Kim S, Mischerikow N, Bandeira N, Navarro JD, Wich L, 'Mohammed S, Heck AJ, Pevzner PA. (2010) The Generating Function of CID, ETD, and CID/ETD Pairs of Tandem Mass Spectra: Applications to Database Search."
},
"msfragger_style_1" : {
"name" : "MSFragger",
"version" : [
"20170103"
],
"reference" : "Kong, A. T., Leprevost, F. V, Avtonomov, D. M., Mellacheruvu, D., and Nesvizhskii, A. I. (2017) MSFragger: ultrafast and comprehensive peptide identification in mass spectrometry-based proteomics. Nature Methods 14"
},
"ursgal_style_1" : {
"name" : "Ursgal",
"version" : [
"0.6.0",
"0.6.1"
],
"reference" : "Kremer, L. P. M., Leufken, J., Oyunchimeg, P., Schulze, S. & Fufezan, C. (2016) Ursgal, Universal Python Module Combining Common Bottom-Up Proteomics Tools for Large-Scale Analysis. J. Proteome res. 15, 788-794."
},
"searchgui_style_1" : {},
"searchgui_style_2" : {},
"psi_ms_style_1" : {},
"xtandem_style_1" : {}
}
{'msgfplus_style_1': {'name': 'MS-GF+', 'version': ['v2018.01.30', 'v2018.06.28', 'v2018.09.12'], 'reference': "Kim S, Mischerikow N, Bandeira N, Navarro JD, Wich L, 'Mohammed S, Heck AJ, Pevzner PA. (2010) The Generating Function of CID, ETD, and CID/ETD Pairs of Tandem Mass Spectra: Applications to Database Search."}, 'msfragger_style_1': {'name': 'MSFragger', 'version': ['20170103'], 'reference': 'Kong, A. T., Leprevost, F. V, Avtonomov, D. M., Mellacheruvu, D., and Nesvizhskii, A. I. (2017) MSFragger: ultrafast and comprehensive peptide identification in mass spectrometry-based proteomics. Nature Methods 14'}, 'ursgal_style_1': {'name': 'Ursgal', 'version': ['0.6.0', '0.6.1'], 'reference': 'Kremer, L. P. M., Leufken, J., Oyunchimeg, P., Schulze, S. & Fufezan, C. (2016) Ursgal, Universal Python Module Combining Common Bottom-Up Proteomics Tools for Large-Scale Analysis. J. Proteome res. 15, 788-794.'}, 'searchgui_style_1': {}, 'searchgui_style_2': {}, 'psi_ms_style_1': {}, 'xtandem_style_1': {'name': 'X!Tandem', 'version': ['vengeance', 'alanine'], 'reference': ''}, 'masamanda_style_1': {'name': 'MS Amanda', 'version': ['2_0_0_9695', '2_0_0_9706', '2_0_0_10695']}}
58 changes: 33 additions & 25 deletions uparma/uparma.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import requests
import os
import json
Expand All @@ -6,8 +7,10 @@


URLS = {
'parameter_url' : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/parameters.json',
'styles_url' : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/styles.json'
('general', 'parameters') : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/general_parameters.json',
('spectrum', 'parameters') : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/spectrum_parameters.json',
('modifications', 'parameters') : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/modification_parameters.json',
('general', 'styles') : 'https://raw.githubusercontent.com/uparma/uparma-lib/master/styles.json'
}


Expand Down Expand Up @@ -46,12 +49,11 @@ def __init__(self, refresh_jsons=False, source_style="ursgal_style_1"):
with requests.get(url) as req:
with open(json_file_name, 'w') as j:
print(req.json(), file=j)
self.jsons[json_file_name] = req.json()
self.jsons[url_id] = req.json()
else:
for url_id, url in URLS.items():

with open(full_path) as j:
self.jsons[json_file_name] = json.load(j)
self.jsons[url_id] = json.load(j)

self._parse_jsons()

Expand All @@ -65,24 +67,27 @@ def _parse_jsons(self):
}
"""
for uparma_entry in self.jsons['parameters.json']:

_id = uparma_entry['_id']
self.parameters[_id] = uparma_entry

for key, value in uparma_entry.items():
if "style" in key:
if isinstance(value, list):
value = ", ".join(value)
try:
self.parameter2id[key][value] = _id
except:
self.parameter2id[key] = {value: _id}
self.available_styles.append(key)

assert _id in self.parameters.keys(), """
ID {0} is not unique in parameters.json
""".format(_id)
for url_id in self.jsons.keys():
json_tag, json_type = url_id
if json_type != 'parameters':
continue
for uparma_entry in self.jsons[url_id]:
_id = uparma_entry['_id']
self.parameters[_id] = uparma_entry

for key, value in uparma_entry.items():
if "style" in key:
if isinstance(value, list):
value = ", ".join(value)
try:
self.parameter2id[key][value] = _id
except:
self.parameter2id[key] = {value: _id}
self.available_styles.append(key)

assert _id in self.parameters.keys(), """
ID {0} is not unique in parameters.json
""".format(_id)

def convert(self, param_dict, target_style=None):
"""
Expand Down Expand Up @@ -173,12 +178,15 @@ class UParmaDict(dict):
"""
UParma Dict
Is a dict which offers original key and values that have been translated by
the UParMa.
Offers original key and values that have been translated by
the UParMa in self.details.
"""
def __init__(self,*args, **kwargs):
self.details = {}
super().__init__(*args, **kwargs)



if __name__ == '__main__':
UParma(refresh_jsons=True)

0 comments on commit b9e8e7a

Please sign in to comment.