def test_get_default_params_with_list_of_keys(): d = { "input": { ("general", "parameters"): [ { "default_value": "14N", "description": "15N if the corresponding amino acid labeling was applied", "key_translations": { "myrimatch_style_1": "label", "omssa_style_1": ["-tem", "-tom"], "pipi_style_1": "15N", "ursgal_style_1": "label", }, "name": "label", "tag": ["label", "modifications"], "triggers_rerun": True, "value_translations": { "pipi_style_1": [["14N", 0], ["15N", 1]] }, "value_type": "select", }, ] } } up = uparma.UParma(refresh_jsons=False, parameter_data=d["input"]) default_params = up.get_default_params("omssa_style_1") assert default_params["label"]["translated_key"] == ["-tem", "-tom"] assert default_params["label"]["translated_value"] == "14N"
def test_get_default_params_with_no_value_trans_for_default(): d = { "input": { ("general", "parameters"): [ { "default_value": "ppm", "description": "Fragment mass tolerance unit: available in ppm (parts-per-millon), da (Dalton) or mmu (Milli mass unit)", "key_translations": { "xtandem_style_1": "spectrum, fragment monoisotopic mass error units", "ursgal_style_1": "frag_mass_tolerance_unit", }, "name": "frag_mass_tolerance_unit", "tag": ["accuracy", "fragment"], "triggers_rerun": True, "value_translations": { "xtandem_style_1": [["da", "Daltons"]] }, "value_type": "select", }, ] } } up = uparma.UParma(refresh_jsons=False, parameter_data=d["input"]) default_params = up.get_default_params("xtandem_style_1") assert (default_params["frag_mass_tolerance_unit"]["translated_key"] == "spectrum, fragment monoisotopic mass error units") assert default_params["frag_mass_tolerance_unit"][ "translated_value"] == "ppm"
def test_get_default_msfragger_3(): up = uparma.UParma() default_params = up.get_default_params("msfragger_style_3") import pprint pprint.pprint(default_params) assert default_params["enzyme_specificity"]["translated_value"] == 2
def test_get_default_params(test_dict): up = uparma.UParma(parameter_data=test_dict["input"]) default_params = up.get_default_params(style="msfragger_style_3") assert (default_params["precursor_mass_tolerance_unit"]["translated_key"] == "precursor_mass_units") assert default_params["precursor_mass_tolerance_unit"][ "translated_value"] == 1 assert (default_params["precursor_mass_tolerance"]["translated_key"] == "precursor_mass_lower") assert default_params["precursor_mass_tolerance"]["translated_value"] == 5 assert default_params["database"]["translated_value"] is None
def test_shows_meta_tag(test_dict): up = uparma.UParma(parameter_data=param) up.original_style = test_dict["original_style"] translated_params = up.translate( test_dict["input_dict"], original_style=test_dict["original_style"], translated_style=test_dict["translated_style"], ) pprint.pprint(translated_params) assert "is_parameter_collection" in translated_params[ "experiment_setup"].keys()
def test_mapping(test_dict): up = uparma.UParma(parameter_data=param) up.original_style = test_dict["original_style"] translated_params = up.translate( test_dict["input_dict"], original_style=test_dict["original_style"], translated_style=test_dict["translated_style"], ) pprint.pprint(translated_params) for uparma_key in translated_params.keys(): assert all(r_items in translated_params[uparma_key].items() for r_items in test_dict["results"][uparma_key].items())
def main(parameter): ''' Get uparma information for a specific parameter name. Description, value transltion and uparma id is extracted. usage: ./get_param_info.py <parameter_name> E.g.: ./get_param_info.py 'spectrum, parent monoisotopic mass error units' The example provides the name of the monoisotopic mass error units of the X!Tandem engines. This name is mapped back to translation styles matching this name. ''' up = uparma.UParma() original_style_matching_parameter_name = {} for original_style in up.parameter2id.keys(): _id = up.parameter2id[original_style].get(parameter, None) # print(_id) if _id is not None: if parameter in up.parameter2id[original_style].keys(): original_style_matching_parameter_name[original_style] = { '_id': _id } parameter_entry = up.parameters[_id] original_style_matching_parameter_name[original_style][ 'description'] = parameter_entry['description'] original_style_matching_parameter_name[original_style][ 'value_translations'] = parameter_entry[ 'value_translations'].get(original_style, {}) if len(original_style_matching_parameter_name) == 0: print('Parameter "{0}" can not be found! Spelling correct?'.format( parameter)) else: print('Parameter "{0}" is found for the following translation styles:'. format(parameter)) for original_style, original_style_info in original_style_matching_parameter_name.items( ): print( '\t{0}; description: {1}; value_translations: {2}; uparma id: {3}'. format( original_style, original_style_info['description'], original_style_info['value_translations'], original_style_info['_id'], ))
def main(): up = uparma.UParma(refresh_jsons=False) print('Original input:') input_dict = { "precursor_mass_tolerance_unit": "da", "min_pep_length": 8, "max_num_mods": 3, } pprint.pprint(input_dict) msgf_params = up.convert(input_dict, translated_style='msgfplus_style_1') print('\nMapped to msgf+:') pprint.pprint(msgf_params) print('\nDetails:') pprint.pprint(msgf_params.details)
def test_mapping(test_dict): up = uparma.UParma(parameter_data=param) up.original_style = test_dict["original_style"] translated_params = up.translate( test_dict["input_dict"], original_style=test_dict["original_style"], translated_style=test_dict["translated_style"], ) pprint.pprint(translated_params) for uparma_key in translated_params.keys(): for t_value in translated_params[uparma_key]["translated_value"]: translated_sub_dict = {} for sub_key, sub_dict in t_value.items(): translated_sub_dict[ sub_dict["translated_key"]] = sub_dict["translated_value"] assert translated_sub_dict in test_dict["results"][uparma_key]
def test_identify_params_trigger_rerun(test_dict): up = uparma.UParma(parameter_data=test_dict["uparma_jsons"]) rerun_params = up.identify_parameters_triggering_rerun(test_dict["input"]) assert rerun_params == test_dict["results"]
def test_load_data(test_dict): up = uparma.UParma(refresh_jsons=False, parameter_data=test_dict["input"]) assert len(up.available_styles) == 2 assert len(up.parameter2id.keys()) == 2 assert list(up.parameters.keys()) == [0, 1]
def test_load_duplicated_data(test_dict): with pytest.raises(ValueError) as err: up = uparma.UParma(refresh_jsons=False, parameter_data=test_dict["input"]) assert str(err.value) == test_dict["results"]
#!/usr/bin/env python3 import uparma import random import pytest # jsons = { # ("general", "parameters"): "parameters.json", # ("general", "styles"): "styles.json", # } up = uparma.UParma() # filter parameters to ones that can be sensibly used as reverse lookups param_w_value_trans = [ x for x in up.parameters if len(up.parameters[x]["value_translations"]) > 0 ] param_wone = [ x for x in up.parameters if len(up.parameters[x]["value_translations"]) == 1 ] test_data_list = [] for test_id in param_w_value_trans: use_to_test = True for styles, values in up.parameters[test_id]["value_translations"].items(): key_set = set() value_set = set() for key, value in values: key_set.add(key) value_set.add(value) if len(key_set) != len(value_set): use_to_test = False break
import uparma jsons = { ("general", "parameters"): "parameters.json", ("general", "styles"): "styles.json", } up = uparma.UParma(refresh_jsons=True, parameter_data=jsons) data = up.parameter2id_list frequencies = {} style_list = [] for style in data: style_freq = {} for key in data[style]: try: style_freq[len(data[style][key])] += 1 except KeyError: style_freq[len(data[style][key])] = 1 if len(data[style][key]) > 1: print(f"{style}: {key}, ids={data[style][key]}") frequencies[style] = style_freq.copy() if max(style_freq.keys()) > 1: style_list.append((style, style_freq)) print() for style, style_freq in style_list: print(f"{style}: {style_freq}")
def main(): up = uparma.UParma() print("Universal parameter mapper contains:") print(f"\t{len(up.available_styles)} styles") print(f"\t{len(up.parameters)} parameters")