def clean(self): logger.debug("starting to clean MRparam form") cleaned_data = self.cleaned_data mol_weight = cleaned_data.get("mol_weight") if not mol_weight: sequence = cleaned_data.get("sequence") if sequence: mol_weight = utils.calcMW(sequence) cleaned_data["mol_weight"] = mol_weight else: raise forms.ValidationError("Please enter either a " + "number for the molecular weight or an amino acid " + "sequence for your input data.") logger.debug(repr(self._errors)) logger.debug("ending to clean MRparam form") return cleaned_data
def testCalcMW(self): testSequence = "SEKIIHLTDDSFDTDVLKADGAILVDFWAEWCGPCKMIAPILDEIADEYQGKL\ TVAKLNIDQNPGTAPKYGIRGIPTLLLFKNGEVAATKVGALSKGQLKEFLDANLA" self.assertAlmostEqual(utils.calcMW(testSequence), 11671.4421, 4, "Molecular weights are calculated wrongly")