Skip to content

Commit

Permalink
Updated json reading to grouped jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
JB-MS committed Dec 5, 2018
1 parent 2967edb commit 7c3d79e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 94 deletions.
6 changes: 4 additions & 2 deletions examples/map_ursgal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import pprint

def main():
up = uparma.UParma()
up = uparma.UParma(refresh_jsons=True)
msgf_params = up.convert(
{
"precursor_mass_tolerance_unit": "ppm",
"min_pep_length" : 8
"min_pep_length" : 8,
"max_num_mods" : 3,

},
target_style = 'msgfplus_style_1'
)
Expand Down
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']}}
53 changes: 30 additions & 23 deletions uparma/uparma.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env python3
import requests
import os
import json
from collections import defaultdict as ddict

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 @@ -44,12 +47,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 @@ -63,24 +65,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 @@ -153,4 +158,6 @@ def translate(self, param_dict, source_style=None, target_style=None):



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

0 comments on commit 7c3d79e

Please sign in to comment.