def test_parse_target(self): spaced = 'Q @ N-term' part_spaced = 'Q @N-Term' part_spaced2 = 'Q@ n-term' no_space = 'Q@N-term' spaced_parsed = modification.extract_targets_from_string(spaced) self.assertEqual(spaced_parsed, modification.extract_targets_from_string(part_spaced)) self.assertEqual(spaced_parsed, modification.extract_targets_from_string(part_spaced2)) self.assertEqual(spaced_parsed, modification.extract_targets_from_string(no_space))
def transform_modification(mod): if isinstance(mod, basestring): mod_inst = modification.Modification(mod) target = modification.extract_targets_from_string(mod) new_rule = mod_inst.rule.clone({target}) return new_rule return mod
def add_modification(): name = request.values.get("new-modification-name") formula = request.values.get("new-modification-formula") target = request.values.get("new-modification-target") if name is None or name == "": g.add_message("Modification Name Cannot Be Empty") return abort(400) try: composition = Composition(str(formula)) except ChemicalCompositionError: g.add_message("Invalid Formula") return abort(400) try: target = extract_targets_from_string(target) except Exception: g.add_message("Invalid Target Specification") return abort(400) rule = ModificationRule(target, name, None, composition.mass, composition) try: add_user_peptide_modification_rule(rule) except Exception: g.add_message("Failed to save modification rule") return abort(400) return jsonify(name=rule.name, formula=formula, mass=rule.mass, specificities=list(rule.as_spec_strings()))
def parse_peptide_modification_target_spec(context, spec_string_list): out = [] for spec_string in spec_string_list: try: spec = extract_targets_from_string(spec_string) out.append(spec) except Exception as e: raise ValueError(str(e)) return out