def amino_acids(): return jsonify({ "amino_acids": [{ "one_letter_code": amino_acid.one_letter_code, "name": amino_acid.name } for amino_acid in AminoAcid.all()] })
def check_partition_boundaries_sequence(self, boundaries): # Beginning with 0 self.assertEqual(boundaries[0][1], 0) # Each upper boundary of the current partition must match lower boundary of the next partition for idx in range(len(boundaries) - 1): self.assertEqual(boundaries[idx][2], boundaries[idx + 1][1]) # Last partition needs a upper limit of 60 times Tryptophan + 1 Water + 1 for the explicit boundary upper_boundary = AminoAcid.get_haviest().mono_mass * 60 + NeutralLoss.get_by_name("H2O").mono_mass + 1 self.assertEqual(boundaries[len(boundaries) - 1][2], upper_boundary)
def calculate_mass(cls, sequence: str) -> int: """ Calculates the mass of the given amino acid sequence. Parameters ---------- sequence: str Amino acid sequence """ mass = H2O.mono_mass for amino_acid_one_letter_code in sequence: mass += AminoAcid.get_by_one_letter_code( amino_acid_one_letter_code).mono_mass return mass
def from_dict(cls, attributes: dict) -> Modification: """ Creates modification from dictionary. Parameters ---------- attributes : dict Dictionary of attributes with key: 'accession', 'name', 'amino_acid', 'delta', 'is_static' and 'position' Returns ------- Modification """ return Modification( attributes["accession"], attributes["name"], AminoAcid.get_by_one_letter_code(attributes["amino_acid"]), attributes["delta"], attributes["is_static"], ModificationPosition.from_string(attributes["position"]) )
def read_from_csv_file(cls, csv_file_path: pathlib.Path) -> List[Modification]: """ Reads modifications from CSV file. Parameters ---------- csv_file_path : pathlib.Path Path of the CSV-file Returns ------- List of modifications """ modifications = [] with csv_file_path.open("r") as csv_file: csv_reader = csv.reader(csv_file) # Omit header next(csv_reader) for row in csv_reader: modifications.append( Modification(row[0], row[1], AminoAcid.get_by_one_letter_code(row[2]), mass_to_int(float(row[3])), cls.string_to_is_static(row[4].lower()), ModificationPosition.from_string(row[5])) ) return modifications
def test_mass_calculation(self): fictional_peptide = Peptide(FICTIONAL_SEQUENCE, 0) # If the amino acid cound test passes, we can use the counts to calculate the mass manally. # Actually there is no external tool which supports all of our known amino acids, so we can double check the weigth. mass = fictional_peptide.a_count * AminoAcid.get_by_one_letter_code('A').mono_mass \ + fictional_peptide.b_count * AminoAcid.get_by_one_letter_code('B').mono_mass \ + fictional_peptide.c_count * AminoAcid.get_by_one_letter_code('C').mono_mass \ + fictional_peptide.d_count * AminoAcid.get_by_one_letter_code('D').mono_mass \ + fictional_peptide.e_count * AminoAcid.get_by_one_letter_code('E').mono_mass \ + fictional_peptide.f_count * AminoAcid.get_by_one_letter_code('F').mono_mass \ + fictional_peptide.g_count * AminoAcid.get_by_one_letter_code('G').mono_mass \ + fictional_peptide.h_count * AminoAcid.get_by_one_letter_code('H').mono_mass \ + fictional_peptide.i_count * AminoAcid.get_by_one_letter_code('I').mono_mass \ + fictional_peptide.j_count * AminoAcid.get_by_one_letter_code('J').mono_mass \ + fictional_peptide.k_count * AminoAcid.get_by_one_letter_code('K').mono_mass \ + fictional_peptide.l_count * AminoAcid.get_by_one_letter_code('L').mono_mass \ + fictional_peptide.m_count * AminoAcid.get_by_one_letter_code('M').mono_mass \ + fictional_peptide.n_count * AminoAcid.get_by_one_letter_code('N').mono_mass \ + fictional_peptide.o_count * AminoAcid.get_by_one_letter_code('O').mono_mass \ + fictional_peptide.p_count * AminoAcid.get_by_one_letter_code('P').mono_mass \ + fictional_peptide.q_count * AminoAcid.get_by_one_letter_code('Q').mono_mass \ + fictional_peptide.r_count * AminoAcid.get_by_one_letter_code('R').mono_mass \ + fictional_peptide.s_count * AminoAcid.get_by_one_letter_code('S').mono_mass \ + fictional_peptide.t_count * AminoAcid.get_by_one_letter_code('T').mono_mass \ + fictional_peptide.u_count * AminoAcid.get_by_one_letter_code('U').mono_mass \ + fictional_peptide.v_count * AminoAcid.get_by_one_letter_code('V').mono_mass \ + fictional_peptide.w_count * AminoAcid.get_by_one_letter_code('W').mono_mass \ + fictional_peptide.y_count * AminoAcid.get_by_one_letter_code('Y').mono_mass \ + fictional_peptide.z_count * AminoAcid.get_by_one_letter_code('Z').mono_mass \ + H2O.mono_mass self.assertEqual(mass, fictional_peptide.mass)
def test_validation(self): static_carbamidomethylation_of_c = Modification( 'unimod:4', 'carbamidomethylation of cysteine', AminoAcid.get_by_one_letter_code('C'), mass_to_int(57.021464), True, ModificationPosition.ANYWHERE) variable_oxidation_of_m = Modification( 'unimod:35', 'oxidation of methionine', AminoAcid.get_by_one_letter_code('M'), mass_to_int(15.994915), False, ModificationPosition.ANYWHERE) static_custom_modification_of_n_terminal_d = Modification( 'custom:1', 'custom of aspartic acid', AminoAcid.get_by_one_letter_code('D'), mass_to_int(10.01541), True, ModificationPosition.N_TERMINUS) variable_custom_modification_of_n_terminal_d = Modification( 'custom:2', 'custom of aspartic acid', AminoAcid.get_by_one_letter_code('D'), mass_to_int(10.01541), False, ModificationPosition.N_TERMINUS) static_custom_modification_of_c_terminal_r = Modification( 'custom:3', 'custom of arginine', AminoAcid.get_by_one_letter_code('R'), mass_to_int(6.153215), True, ModificationPosition.C_TERMINUS) variable_custom_modification_of_c_terminal_r = Modification( 'custom:4', 'custom of arginine', AminoAcid.get_by_one_letter_code('R'), mass_to_int(6.153215), False, ModificationPosition.C_TERMINUS) peptide = Peptide(LEPTIN_PEPTIDE_SEQUENCE, 2) # Static carbamidomethylation of C expected_peptide_mass = peptide.weight + peptide.c_count * static_carbamidomethylation_of_c.delta modification_collection = ModificationCollection( [static_carbamidomethylation_of_c]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 0, precursor_range) self.assertTrue(validator.validate(peptide)) # This should als match with allowed variable modification (where actually none is applied) # Static carbamidomethylation of C # Variable oxidation of M (not considered in expected_weight) modification_collection = ModificationCollection( [static_carbamidomethylation_of_c, variable_oxidation_of_m]) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # Static carbamidomethylation of C # 1 variable oxidation of M expected_peptide_mass = peptide.weight \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 1 * variable_oxidation_of_m.delta modification_collection = ModificationCollection( [static_carbamidomethylation_of_c, variable_oxidation_of_m]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # This should not match if no variable modifiations are allowed # Static carbamidomethylation of C # Variable oxidation of M (considered in expected_weight but no variable modification allowed in validation) validator.set_maximum_number_of_variable_modifications(0) self.assertFalse(validator.validate(peptide)) # Lets replace two Js with Ms and test 3 applied variable oxidations of M # Static carbamidomethylation of C # 3 Variable oxidation of M peptide = Peptide(LEPTIN_PEPTIDE_SEQUENCE.replace('J', 'M', 2), 2) expected_peptide_mass = peptide.weight \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 3 * variable_oxidation_of_m.delta modification_collection = ModificationCollection( [static_carbamidomethylation_of_c, variable_oxidation_of_m]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # This should fail with only 2 allowed variable modifications validator.set_maximum_number_of_variable_modifications(2) self.assertFalse(validator.validate(peptide)) # Test variable n-terminal # Variable n-terminal modification of D # Static carbamidomethylation of C # 2 variable oxidation of M expected_peptide_mass = peptide.weight \ + variable_custom_modification_of_n_terminal_d.delta \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 2 * variable_oxidation_of_m.delta modification_collection = ModificationCollection([ static_carbamidomethylation_of_c, variable_oxidation_of_m, variable_custom_modification_of_n_terminal_d ]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # This should fail with only 2 allowed variable modifications validator.set_maximum_number_of_variable_modifications(2) self.assertFalse(validator.validate(peptide)) # Test static n-terminal modification # Static n-terminal modification of D # Static carbamidomethylation of C # 2 variable oxidation of M expected_peptide_mass = peptide.weight \ + static_custom_modification_of_n_terminal_d.delta \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 2 * variable_oxidation_of_m.delta modification_collection = ModificationCollection([ static_carbamidomethylation_of_c, variable_oxidation_of_m, static_custom_modification_of_n_terminal_d ]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # Test variable n-terminal # Variable c-terminal modification of R # Static carbamidomethylation of C # 2 variable oxidation of M expected_peptide_mass = peptide.weight \ + variable_custom_modification_of_c_terminal_r.delta \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 2 * variable_oxidation_of_m.delta modification_collection = ModificationCollection([ static_carbamidomethylation_of_c, variable_oxidation_of_m, variable_custom_modification_of_c_terminal_r ]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide)) # This should fail with only 2 allowed variable modifications validator.set_maximum_number_of_variable_modifications(2) self.assertFalse(validator.validate(peptide)) # Test static n-terminal modification # Static c-terminal modification of R # Static carbamidomethylation of C # 2 variable oxidation of M expected_peptide_mass = peptide.weight \ + static_custom_modification_of_c_terminal_r.delta \ + peptide.c_count * static_carbamidomethylation_of_c.delta \ + 2 * variable_oxidation_of_m.delta modification_collection = ModificationCollection([ static_carbamidomethylation_of_c, variable_oxidation_of_m, static_custom_modification_of_c_terminal_r ]) precursor_range = PrecursorRange(expected_peptide_mass, 0, 0) validator = PeptideMassValidator(modification_collection, 3, precursor_range) self.assertTrue(validator.validate(peptide))