Commit b55c7eaa authored by Nicolas  MAILLET's avatar Nicolas MAILLET
Browse files

change miss_cleavage to miscleavage

parent 24c9cf56
......@@ -116,14 +116,14 @@ def list_enzyme():
for enz in ALL_ENZYMES:
print("%i: %s" % (enz.id_, enz.name))
def create_enzymes_to_use(enzymes, miss_cleavage):
def create_enzymes_to_use(enzymes, miscleavage):
"""Create the list of chosen :py:class:`~rpg.enzyme.Enzyme` to use.
Each enzyme can be associated to a miscleavage value.
:param enzymes: enzymes ids chosen by user
:param miss_cleavage: associated miscleavage values
:param miscleavage: associated miscleavage values
:type enzymes: list(int)
:type miss_cleavage: list(float)
:type miscleavage: list(float)
:return: list of enzyme's id with associated miscleavage values
:rtype: list(int)
......@@ -133,24 +133,24 @@ def create_enzymes_to_use(enzymes, miss_cleavage):
enzymes_to_use = []
if enzymes:
# Too much miscleavage values
if len(miss_cleavage) > len(enzymes):
if len(miscleavage) > len(enzymes):
core.handle_errors("Too much miscleavage values. Last values"
" will be ignored.")
# Get only the first ones
miss_cleavage = miss_cleavage[:len(enzymes)]
miscleavage = miscleavage[:len(enzymes)]
cur_pos = -1
# Get all enzymes with a given miss_cleavage
for i, _ in enumerate(miss_cleavage):
# Get all enzymes with a given miscleavage
for i, _ in enumerate(miscleavage):
# In all available enzymes
for enz in ALL_ENZYMES:
# Get the current one
if enz.id_ == enzymes[i]:
# Change miss_cleavage ratio
enz.ratio_miss_cleavage = miss_cleavage[i]
# Change miscleavage ratio
enz.ratio_miscleavage = miscleavage[i]
# Add it
enzymes_to_use.append(enz)
cur_pos = i
# Get all enzymes without miss_cleavage value
# Get all enzymes without miscleavage value
for i in enzymes[cur_pos + 1:]:
# In all available enzymes
for enz in ALL_ENZYMES:
......@@ -161,17 +161,17 @@ def create_enzymes_to_use(enzymes, miss_cleavage):
# Return enzymes to use
return enzymes_to_use
# Not tested
def get_enzymes_to_use(mode, id_enz_selected, miss_cleavage):
def get_enzymes_to_use(mode, id_enz_selected, miscleavage):
"""Get the list of chosen :py:class:`~rpg.enzyme.Enzyme` to use.
Each enzyme (and associated miscleavage value) are inputed by
user. If there is a problem, user is interrogated again.
:param mode: Digestion mode. If 'concurrent', no miscleavage values are used
:param enzymes: enzyme's ids chosen by user
:param miss_cleavage: associated miscleavage values
:param miscleavage: associated miscleavage values
:type mode: str
:type enzymes: list(int)
:type miss_cleavage: list(float)
:type miscleavage: list(float)
:return: list of enzyme's id with associated miscleavage values
:rtype: list(int)
......@@ -180,7 +180,7 @@ def get_enzymes_to_use(mode, id_enz_selected, miss_cleavage):
"""
# Get the correct Enzymes inputed
enzymes_to_use = create_enzymes_to_use(id_enz_selected, miss_cleavage)
enzymes_to_use = create_enzymes_to_use(id_enz_selected, miscleavage)
# No good Enzymes inputed, let user choose
if not enzymes_to_use:
id_enz_inputed = []
......@@ -373,7 +373,7 @@ def main():
print("Enzyme(s) used: " + str([enz.name for enz in enzymes_to_use]))
print("Mode: " + mode)
print("miscleavage ratio: " +
str([enz.ratio_miss_cleavage for enz in enzymes_to_use]))
str([enz.ratio_miscleavage for enz in enzymes_to_use]))
print("Output file: " + os.path.abspath(output_file))
# Make the actual digestion of input data
......
......@@ -35,31 +35,31 @@ class ResultOneDigestion:
:param enzyme_name: name of the enzyme used
:param peptides: all resulting peptides after digestion
:param nb_cleavage: number of cleavage that occurs
:param pos_miss_cleavage: position of miscleavage that occurs
:param pos_miscleavage: position of miscleavage that occurs
:type enzyme_name: str
:type peptides: list(:py:class:`~rpg.sequence.Peptide`)
:type nb_cleavage: int
:type pos_miss_cleavage: list(int)
:type pos_miscleavage: list(int)
"""
def __init__(self, enzyme_name, peptides=None, nb_cleavage=0,
pos_miss_cleavage=None):
pos_miscleavage=None):
self.enzyme_name = enzyme_name # Enzyme name used for this digestion
self.peptides = peptides
if self.peptides is None:
self.peptides = []
self.nb_cleavage = nb_cleavage # number of cleavage
self.pos_miss_cleavage = pos_miss_cleavage # position of m-c
if self.pos_miss_cleavage is None:
self.pos_miss_cleavage = []
self.pos_miscleavage = pos_miscleavage # position of m-c
if self.pos_miscleavage is None:
self.pos_miscleavage = []
# self representation for print
def __repr__(self):
return "Number of cleavage: " + str(self.nb_cleavage) + \
"\nNumber of miscleavage: " + \
str(len(self.pos_miss_cleavage)) + \
"\nPositions of miscleavage: " + str(self.pos_miss_cleavage)\
str(len(self.pos_miscleavage)) + \
"\nPositions of miscleavage: " + str(self.pos_miscleavage)\
+ "\nRatio of miscleavage: " + \
str(self.get_ratio_miss_cleavage()) + \
str(self.get_ratio_miscleavage()) + \
"\nPeptides: " + str(self.peptides) + "\n"
# Equality between two ResultOneDigestion
......@@ -101,44 +101,44 @@ class ResultOneDigestion:
"""Increase :attr:`self.nb_cleavage` by 1."""
self.nb_cleavage += 1
def get_nb_miss_cleavage(self):
def get_nb_miscleavage(self):
"""Get the number of miscleavages that occurs
on this digestion.
:return: number of miscleavage
:rtype: int
"""
return len(self.pos_miss_cleavage)
return len(self.pos_miscleavage)
def add_miss_cleavage(self, new_pos_miss_cleavage):
"""Add a miscleavage to :attr:`self.pos_miss_cleavage`.
def add_miscleavage(self, new_pos_miscleavage):
"""Add a miscleavage to :attr:`self.pos_miscleavage`.
:param new_pos_miss_cleavage: position of miscleavage
:type new_pos_miss_cleavage: int
:param new_pos_miscleavage: position of miscleavage
:type new_pos_miscleavage: int
"""
self.pos_miss_cleavage.append(new_pos_miss_cleavage)
self.pos_miscleavage.append(new_pos_miscleavage)
def get_ratio_miss_cleavage(self):
def get_ratio_miscleavage(self):
"""Get ratio of miscleavage.
:return: ratio of miscleavage
:rtype: float
"""
ret = 0
if self.nb_cleavage > 0 or self.get_nb_miss_cleavage() > 0:
ret = self.get_nb_miss_cleavage() / (self.nb_cleavage + \
self.get_nb_miss_cleavage()) \
if self.nb_cleavage > 0 or self.get_nb_miscleavage() > 0:
ret = self.get_nb_miscleavage() / (self.nb_cleavage + \
self.get_nb_miscleavage()) \
* 100
return ret
def get_miss_cleavage_pos(self):
def get_miscleavage_pos(self):
"""Get positions of miscleavage as a string.
:return: positions of miscleavage
:rtype: str
"""
ret = ""
for i in self.pos_miss_cleavage:
for i in self.pos_miscleavage:
ret += str(i) + ", "
return ret[:-2]
......@@ -158,7 +158,7 @@ class ResultOneDigestion:
"""Fuse two :py:class:`ResultOneDigestion` by adding to
:attr:`self` the peptides of :attr:`other` and changing their
:py:class:`~rpg.enzyme.Enzyme`. It also update :attr:`self.nb_cleavage` and
:attr:`self.pos_miss_cleavage`.
:attr:`self.pos_miscleavage`.
:param other: object to fuse with `self`
:type other: :py:class:`ResultOneDigestion`
......@@ -169,8 +169,8 @@ class ResultOneDigestion:
self.add_peptide(peptide)
# Add nb_cleavage from other
self.nb_cleavage += other.nb_cleavage
# Add pos_miss_cleavage from other
self.pos_miss_cleavage += other.pos_miss_cleavage
# Add pos_miscleavage from other
self.pos_miscleavage += other.pos_miscleavage
def get_smallest_peptide(self):
"""Get the (first) smallest peptide of :attr:`self.peptides`.
......@@ -195,10 +195,10 @@ class ResultOneDigestion:
ret = ""
ret += "\nNumber of cleavage: " + str(self.nb_cleavage) + "\n"
ret += "Cleavage position: " + self.get_cleavage_pos() + "\n"
ret += "Number of miscleavage: " + str(self.get_nb_miss_cleavage())\
ret += "Number of miscleavage: " + str(self.get_nb_miscleavage())\
+ "\n"
ret += "miscleavage position: " + self.get_miss_cleavage_pos() + "\n"
ret += "miscleavage ratio: %.2f%%\n" % self.get_ratio_miss_cleavage()
ret += "miscleavage position: " + self.get_miscleavage_pos() + "\n"
ret += "miscleavage ratio: %.2f%%\n" % self.get_ratio_miscleavage()
ret += "Smallest peptide size: " + \
str(self.get_smallest_peptide().size) + "\n"
ret += "N terminal peptide: " + self.peptides[0].sequence + "\n"
......@@ -252,8 +252,8 @@ def one_digest(pep, enz):
if rule.handle_rule(pep.sequence, pos, rul, cut):
# Random to handle miscleavage
tmp_rand = random.random() * 100
# Rand > ratio_miss_cleavage, no miscleavage occurs
if tmp_rand > enz.ratio_miss_cleavage:
# Rand > ratio_miscleavage, no miscleavage occurs
if tmp_rand > enz.ratio_miscleavage:
# Test, this should NEVER be used
if rul.pos == -1:
core.handle_errors("not able to understand if I shou"
......@@ -285,7 +285,7 @@ def one_digest(pep, enz):
ret.inc_nb_cleavage()
# A miscleavage occurs
else:
ret.add_miss_cleavage(pos)
ret.add_miscleavage(pos)
# End of the peptide
if a_cut_occurs:
tmp_pos = len(pep.sequence) # Last portion of protein
......
......@@ -45,22 +45,22 @@ class Enzyme:
:param id_: id of the enzyme
:param name: name of the enzyme
:param rules: cleaving rules
:param ratio_miss_cleavage: miscleavage ratio
:param ratio_miscleavage: miscleavage ratio
:type id_: int
:type name: str
:type rules: list(:py:class:`~rpg.rule.Rule`)
:type ratio_miss_cleavage: float
:type ratio_miscleavage: float
"""
def __init__(self, id_, name, rules, ratio_miss_cleavage=0):
def __init__(self, id_, name, rules, ratio_miscleavage=0):
self.id_ = id_
self.name = name
self.ratio_miss_cleavage = ratio_miss_cleavage
self.ratio_miscleavage = ratio_miscleavage
self.rules = rules
# self representation for print
def __repr__(self):
return "Id: %s\nName: %s\nRatio Miss Cleaveage: %.2f%%\nRules: %s\n" %\
(self.id_, self.name, self.ratio_miss_cleavage, self.rules)
(self.id_, self.name, self.ratio_miscleavage, self.rules)
# Equality between two Enzymes
def __eq__(self, other):
......
......@@ -58,10 +58,10 @@ def test_list_enzyme(capsys):
"de\n27: Trypsin\n"
def test_create_enzymes_to_use(capsys):
"""Test function 'create_enzymes_to_use(enzymes, miss_cleavage)'"""
"""Test function 'create_enzymes_to_use(enzymes, miscleavage)'"""
enzymes = [19, 22, 21]
miss_cleavage = [1.1, 20]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miss_cleavage)
miscleavage = [1.1, 20]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
assert res.__repr__() == "[Id: 19\nName: Glu-C\nRatio Miss Cleaveage: 1.1"\
"0%\nRules: [index=0\nletter=D\ncut=True\npos=1\n,"\
" index=0\nletter=E\ncut=True\npos=1\n]\n, Id: 22"\
......@@ -70,8 +70,8 @@ def test_create_enzymes_to_use(capsys):
"21\nName: Lys-N\nRatio Miss Cleaveage: 0.00%\nRul"\
"es: [index=0\nletter=K\ncut=True\npos=0\n]\n]"
enzymes = [19, 22]
miss_cleavage = [1.1, 20, 40]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miss_cleavage)
miscleavage = [1.1, 20, 40]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
_, err = capsys.readouterr()
assert err == "Warning: Too much miscleavage values. Last values will "\
"be ignored.\n"
......
......@@ -79,18 +79,18 @@ def test_resultonedigestion():
res_dig5.inc_nb_cleavage()
assert res_dig5.nb_cleavage == 4
# Test function 'get_nb_miss_cleavage()'
assert res_dig5.get_nb_miss_cleavage() == 3
# Test function 'get_nb_miscleavage()'
assert res_dig5.get_nb_miscleavage() == 3
# Test function 'add_miss_cleavage()'
res_dig5.add_miss_cleavage(6)
assert res_dig5.get_nb_miss_cleavage() == 4
# Test function 'add_miscleavage()'
res_dig5.add_miscleavage(6)
assert res_dig5.get_nb_miscleavage() == 4
# Test function 'get_ratio_miss_cleavage()'
assert res_dig5.get_ratio_miss_cleavage() == 50.0
# Test function 'get_ratio_miscleavage()'
assert res_dig5.get_ratio_miscleavage() == 50.0
# Test function 'get_miss_cleavage_pos()'
assert res_dig5.get_miss_cleavage_pos() == "2, 3, 4, 6"
# Test function 'get_miscleavage_pos()'
assert res_dig5.get_miscleavage_pos() == "2, 3, 4, 6"
# Test function 'get_cleavage_pos()'
res_dig5.add_peptide(pep1)
......@@ -109,7 +109,7 @@ def test_resultonedigestion():
assert i.enzyme_name == "fake_enzyme"
assert len(res_dig5.peptides) == 4
assert res_dig5.nb_cleavage == 5
assert res_dig5.pos_miss_cleavage == [2, 3, 4, 6, 2, 3]
assert res_dig5.pos_miscleavage == [2, 3, 4, 6, 2, 3]
# Test function 'get_more_info()'
assert res_dig5.get_more_info() == "\nNumber of cleavage: 5\nCleavage pos"\
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment