diff --git a/rpg/core.py b/rpg/core.py index 37c63b178371ba7fa1c36594159de4d9ef794f47..124e34864efbaa268ed1338a4684269fb329cc4d 100644 --- a/rpg/core.py +++ b/rpg/core.py @@ -23,6 +23,7 @@ ######################################################################## """Contains generic functions and global variables used by RPG""" +import decimal import sys import gzip @@ -31,71 +32,71 @@ AMINOACIDS = ["A", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "#", "*"] """All character accepted in a peptide.""" -AA_MASS_AVERAGE = {"*" : 0.0, - "A" : 71.0788, - "C" : 103.1388, - "D" : 115.0886, - "E" : 129.1155, - "F" : 147.1766, - "G" : 57.0519, - "H" : 137.1411, - "I" : 113.1594, - "J" : 113.1594, - "K" : 128.1741, - "L" : 113.1594, - "M" : 131.1926, - "N" : 114.1038, - "O" : 237.3018, - "P" : 97.1167, - "Q" : 128.1307, - "R" : 156.1875, - "S" : 87.0782, - "T" : 101.1051, - "U" : 150.0388, - "V" : 99.1326, - "W" : 186.2132, - "Y" : 163.1760, - "B" : 0.0, - "X" : 0.0, - "Z" : 0.0, - "#" : 0.0} +AA_MASS_AVERAGE = {"*" : decimal.Decimal("0.0"), + "A" : decimal.Decimal("71.0788"), + "C" : decimal.Decimal("103.1388"), + "D" : decimal.Decimal("115.0886"), + "E" : decimal.Decimal("129.1155"), + "F" : decimal.Decimal("147.1766"), + "G" : decimal.Decimal("57.0519"), + "H" : decimal.Decimal("137.1411"), + "I" : decimal.Decimal("113.1594"), + "J" : decimal.Decimal("113.1594"), + "K" : decimal.Decimal("128.1741"), + "L" : decimal.Decimal("113.1594"), + "M" : decimal.Decimal("131.1926"), + "N" : decimal.Decimal("114.1038"), + "O" : decimal.Decimal("237.3018"), + "P" : decimal.Decimal("97.1167"), + "Q" : decimal.Decimal("128.1307"), + "R" : decimal.Decimal("156.1875"), + "S" : decimal.Decimal("87.0782"), + "T" : decimal.Decimal("101.1051"), + "U" : decimal.Decimal("150.0388"), + "V" : decimal.Decimal("99.1326"), + "W" : decimal.Decimal("186.2132"), + "Y" : decimal.Decimal("163.1760"), + "B" : decimal.Decimal("0.0"), + "X" : decimal.Decimal("0.0"), + "Z" : decimal.Decimal("0.0"), + "#" : decimal.Decimal("0.0")} """ Average mass of all amino acids.""" -AA_MASS_MONO = {"*" : 0.0, - "A" : 71.037113805, - "C" : 103.009184505, - "D" : 115.026943065, - "E" : 129.042593135, - "F" : 147.068413945, - "G" : 57.021463735, - "H" : 137.058911875, - "I" : 113.084064015, - "J" : 113.084064015, - "K" : 128.09496305, - "L" : 113.084064015, - "M" : 131.040484645, - "N" : 114.04292747, - "O" : 237.147726925, - "P" : 97.052763875, - "Q" : 128.05857754, - "R" : 156.10111105, - "S" : 87.032028435, - "T" : 101.047678505, - "U" : 150.953633405, - "V" : 99.068413945, - "W" : 186.07931298, - "Y" : 163.063328575, - "B" : 0.0, - "X" : 0.0, - "Z" : 0.0, - "#" : 0.0} +AA_MASS_MONO = {"*" : decimal.Decimal("0.0"), + "A" : decimal.Decimal("71.037113805"), + "C" : decimal.Decimal("103.009184505"), + "D" : decimal.Decimal("115.026943065"), + "E" : decimal.Decimal("129.042593135"), + "F" : decimal.Decimal("147.068413945"), + "G" : decimal.Decimal("57.021463735"), + "H" : decimal.Decimal("137.058911875"), + "I" : decimal.Decimal("113.084064015"), + "J" : decimal.Decimal("113.084064015"), + "K" : decimal.Decimal("128.09496305"), + "L" : decimal.Decimal("113.084064015"), + "M" : decimal.Decimal("131.040484645"), + "N" : decimal.Decimal("114.04292747"), + "O" : decimal.Decimal("237.147726925"), + "P" : decimal.Decimal("97.052763875"), + "Q" : decimal.Decimal("128.05857754"), + "R" : decimal.Decimal("156.10111105"), + "S" : decimal.Decimal("87.032028435"), + "T" : decimal.Decimal("101.047678505"), + "U" : decimal.Decimal("150.953633405"), + "V" : decimal.Decimal("99.068413945"), + "W" : decimal.Decimal("186.07931298"), + "Y" : decimal.Decimal("163.063328575"), + "B" : decimal.Decimal("0.0"), + "X" : decimal.Decimal("0.0"), + "Z" : decimal.Decimal("0.0"), + "#" : decimal.Decimal("0.0")} """ Monoisotopic mass of all amino acids. From https://proteomicsresource.washington.edu/protocols06/masses.php """ -WATER_MASS = 18.01528 +WATER_MASS = decimal.Decimal("18.01528") """Mass of a water molecule.""" -WATER_MASS_MONO = 18.0105647 +WATER_MASS_MONO = decimal.Decimal("18.0105647") """Monoisotopic mass of a water molecule.""" # Biochemistry Stryer 7th diff --git a/rpg/sequence.py b/rpg/sequence.py index 374445c41da526f3303d8be5f5a11b1108ac98a1..efea0abe631b5aae5d769fcc2c3286fc75bf1d16 100644 --- a/rpg/sequence.py +++ b/rpg/sequence.py @@ -23,6 +23,7 @@ ######################################################################## """Contains classes and function related to sequences""" +import decimal from rpg import core class Peptide: @@ -66,10 +67,9 @@ class Peptide: self.position = position # position of cleavage self.size = len(sequence) # size of the peptide # Mass of the peptide - tmp_mass = water_mass + self.mass = water_mass for i in sequence: - tmp_mass += aa_mass[i] - self.mass = round(tmp_mass, len(str(aa_mass["A"]).split(".")[1])) # mass of the peptide + self.mass += aa_mass[i] self.p_i = self.get_isoelectric_point() # self representation for print diff --git a/tests/test_core.py b/tests/test_core.py index 54542eaa17ee41be9bdb9b980e3570d0a21fca51..2239df7bb80e35134514616728f378ec20aa4ba5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -91,12 +91,12 @@ def test_output_results(capsys, tmp_path): assert out == outf.read() assert out == "Original_header,No_peptide,Enzyme,Cleaving_"\ "pos,Peptide_size,Peptide_mass,pI,Sequence\n"\ - "Input,0,fake_enzyme1,4,4,534.20743,3.14,WQS"\ - "D\nInput,1,fake_enzyme1,7,3,349.11213,3.04,"\ - "ESD\nInput,2,fake_enzyme1,12,5,495.19653,3."\ - "14,FZQSD\nInput,3,fake_enzyme1,15,3,349.112"\ - "13,3.04,ESD\nInput,4,fake_enzyme1,16,1,165."\ - "07898,5.97,F\n" + "Input,0,fake_enzyme1,4,4,534.207426720,3.14,WQS"\ + "D\nInput,1,fake_enzyme1,7,3,349.112129335,3.04,"\ + "ESD\nInput,2,fake_enzyme1,12,5,495.196527685,3."\ + "14,FZQSD\nInput,3,fake_enzyme1,15,3,349.112129335"\ + ",3.04,ESD\nInput,4,fake_enzyme1,16,1,165."\ + "078978645,5.97,F\n" # CSV output seq = "WQSDESDFZQSDESDF"