Skip to content
Snippets Groups Projects
Commit 0dcb662d authored by Laros's avatar Laros
Browse files

Minor (punctuation) changes in the about page.

Modified describe.py to comply with the preferred programming style.


git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@594 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
parent fcf63867
No related branches found
No related tags found
No related merge requests found
......@@ -12,24 +12,23 @@ from mutalyzer.util import longest_common_prefix, longest_common_suffix
from mutalyzer.util import palinsnoop, roll
from mutalyzer import models
def LCSMatrix(s1, s2) :
def LCSMatrix(s1, s2):
"""
Todo: Not yet in use.
"""
y_max = len(s1) + 1
x_max = len(s2) + 1
M = [[0] * x_max for i in xrange(y_max)]
for x in xrange(1, y_max) :
for y in xrange(1, x_max) :
if s1[x - 1] == s2[y - 1] :
for x in xrange(1, y_max):
for y in xrange(1, x_max):
if s1[x - 1] == s2[y - 1]:
M[x][y] = M[x - 1][y - 1] + 1
return M
#LCSMatrix
def findMax(M, x1, x2, y1, y2) :
def findMax(M, x1, x2, y1, y2):
"""
M = describe.LCSMatrix("banaan", "ana")
......@@ -41,17 +40,16 @@ def findMax(M, x1, x2, y1, y2) :
Todo: Not yet in use.
"""
longest, x_longest, y_longest = 0, 0, 0
for x in xrange(x1, x2) :
for x in xrange(x1, x2):
x_relative = x - x1
for y in xrange(y1, y2) :
for y in xrange(y1, y2):
y_relative = y - y1
realVal = min(x_relative, y_relative, M[x][y])
if realVal > longest :
if realVal > longest:
longest = realVal
x_longest = x_relative
y_longest = y_relative
......@@ -62,7 +60,7 @@ def findMax(M, x1, x2, y1, y2) :
return x_longest, y_longest, longest
#findMax
def LongestCommonSubstring(s1, s2) :
def LongestCommonSubstring(s1, s2):
"""
Find the longest common substring between {s1} and {s2}.
......@@ -78,18 +76,17 @@ def LongestCommonSubstring(s1, s2) :
@returns: The end locations and the length of the longest common substring.
@rtype: tuple(int, int, int)
"""
len_s1 = len(s1)
len_s2 = len(s2)
M = [[0] * (len_s2 + 1) for i in xrange(len_s1 + 1)]
longest, x_longest, y_longest = 0, 0, 0
for x in xrange(1, len_s1 + 1) :
for y in xrange(1, len_s2 + 1) :
if s1[x - 1] == s2[y - 1] :
for x in xrange(1, len_s1 + 1):
for y in xrange(1, len_s2 + 1):
if s1[x - 1] == s2[y - 1]:
M[x][y] = M[x - 1][y - 1] + 1
if M[x][y] > longest :
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
y_longest = y
......@@ -103,7 +100,7 @@ def LongestCommonSubstring(s1, s2) :
return x_longest, y_longest, longest
#LongestCommonSubstring
class RawVar(models.RawVar) :
class RawVar(models.RawVar):
"""
Container for a raw variant.
......@@ -116,7 +113,7 @@ class RawVar(models.RawVar) :
"""
def __init__(self, start=0, start_offset=0, end=0, end_offset=0,
type="none", deleted="", inserted="", shift=0, hgvs="") :
type="none", deleted="", inserted="", shift=0):
"""
Initialise the class with the appropriate values.
......@@ -139,7 +136,6 @@ class RawVar(models.RawVar) :
"""
# TODO: Will this container be used for all variants, or only genomic?
# start_offset and end_offset may be never used.
self.start = start
self.start_offset = start_offset
self.end = end
......@@ -148,10 +144,10 @@ class RawVar(models.RawVar) :
self.deleted = deleted
self.inserted = inserted
self.shift = shift
self.hgvs = hgvs
self.hgvs = self.description()
#__init__
def description(self) :
def description(self):
"""
Give the HGVS description of the raw variant stored in this class.
......@@ -161,19 +157,18 @@ class RawVar(models.RawVar) :
@returns: The HGVS description of the raw variant stored in this class.
@rtype: str
"""
if not self.start :
if not self.start:
return "="
descr = "%i" % self.start
if self.end :
if self.end:
descr += "_%i" % self.end
if self.type != "subst" :
if self.type != "subst":
descr += "%s" % self.type
if self.inserted :
if self.inserted:
return descr + "%s" % self.inserted
return descr
#if
......@@ -181,7 +176,7 @@ class RawVar(models.RawVar) :
return descr + "%s>%s" % (self.deleted, self.inserted)
#description
def descriptionLength(self) :
def descriptionLength(self):
"""
Give the standardised length of the HGVS description of the raw variant
stored in this class.
......@@ -193,7 +188,6 @@ class RawVar(models.RawVar) :
variant stored in this class.
@rtype: int
"""
if not self.start : # =
return 1
......@@ -202,22 +196,19 @@ class RawVar(models.RawVar) :
if self.end : # '_' and end position.
descrLen += 2
if self.type != "subst" :
if self.type != "subst":
descrLen += len(self.type)
if self.inserted :
if self.inserted:
return descrLen + len(self.inserted)
return descrLen
#if
return 4 # Start position, '>' and end position.
#descriptionLength
def putHGVS(self):
self.hgvs = self.description()
#RawVar
def alleleDescription(allele) :
def alleleDescription(allele):
"""
Convert a list of raw variants to an HGVS allele description.
......@@ -227,13 +218,12 @@ def alleleDescription(allele) :
@returns: The HGVS description of {allele}.
@rval: str
"""
if len(allele) > 1 :
if len(allele) > 1:
return "[%s]" % ';'.join(map(lambda x : x.hgvs, allele))
return allele[0].hgvs
#alleleDescription
def alleleDescriptionLength(allele) :
def alleleDescriptionLength(allele):
"""
Calculate the standardised length of an HGVS allele description.
......@@ -243,24 +233,22 @@ def alleleDescriptionLength(allele) :
@returns: The standardised length of the HGVS description of {allele}.
@rval: int
"""
return sum(map(lambda x : x.descriptionLength(), allele))
#alleleDescriptionLength
def printpos(s, start, end, fill = 0) :
def printpos(s, start, end, fill = 0):
"""
For debugging purposes.
"""
# TODO: See if this can partially replace or be merged with the
# visualisation in the __mutate() function of mutator.py
fs = 10 # Flank size.
return "%s %s%s %s" % (s[start - fs:start], s[start:end], '-' * fill,
s[end:end + fs])
#printpos
def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end):
"""
Give an allele description of the change from {s1} to {s2} in the range
{s1_start}..{s1_end} on {s1} and {s2_start}..{s2_end} on {s2}.
......@@ -290,7 +278,7 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
return [RawVar()]
# Insertion / Duplication.
if s1_start == s1_end :
if s1_start == s1_end:
ins_length = s2_end - s2_start
shift5, shift3 = roll(s2, s2_start + 1, s2_end)
shift = shift5 + shift3
......@@ -301,40 +289,39 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
s2_end += shift3
if s2_start - ins_length >= 0 and \
s1[s1_start - ins_length:s1_start] == s2[s2_start:s2_end] :
s1[s1_start - ins_length:s1_start] == s2[s2_start:s2_end]:
if ins_length == 1 :
return [RawVar(start = s1_start, type = "dup", shift = shift)]
return [RawVar(start = s1_start - ins_length + 1, end = s1_end,
type = "dup", shift = shift)]
if ins_length == 1:
return [RawVar(start=s1_start, type="dup", shift=shift)]
return [RawVar(start=s1_start - ins_length + 1, end=s1_end,
type="dup", shift=shift)]
#if
return [RawVar(start = s1_start, end = s1_start + 1,
inserted = s2[s2_start:s2_end], type = "ins", shift = shift)]
return [RawVar(start=s1_start, end=s1_start + 1,
inserted=s2[s2_start:s2_end], type="ins", shift=shift)]
#if
# Deletion.
if s2_start == s2_end :
if s2_start == s2_end:
shift5, shift3 = roll(s1, s1_start + 1, s1_end)
shift = shift5 + shift3
s1_start += shift3 + 1
s1_end += shift3
if s1_start == s1_end :
return [RawVar(start = s1_start, type = "del", shift = shift)]
return [RawVar(start = s1_start, end = s1_end, type = "del",
shift = shift)]
if s1_start == s1_end:
return [RawVar(start=s1_start, type="del", shift=shift)]
return [RawVar(start=s1_start, end=s1_end, type="del", shift=shift)]
#if
# Substitution.
if s1_start + 1 == s1_end and s2_start + 1 == s2_end :
return [RawVar(start = s1_start + 1, deleted = s1[s1_start],
inserted = s2[s2_start], type = "subst")]
if s1_start + 1 == s1_end and s2_start + 1 == s2_end:
return [RawVar(start=s1_start + 1, deleted=s1[s1_start],
inserted=s2[s2_start], type="subst")]
# Simple InDel.
if s1_start + 1 == s1_end :
return [RawVar(start = s1_start + 1, inserted = s2[s2_start:s2_end],
type = "delins")]
if s1_start + 1 == s1_end:
return [RawVar(start=s1_start + 1, inserted=s2[s2_start:s2_end],
type="delins")]
# TODO: Refactor the code after this point.
......@@ -351,14 +338,14 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
lcs_r_len = 0 # s1_end_r and s2_end_r should not be used after this.
# Inversion or Compound variant.
default = [RawVar(start = s1_start + 1, end = s1_end,
inserted = s2[s2_start:s2_end], type = "delins")]
default = [RawVar(start=s1_start + 1, end=s1_end,
inserted=s2[s2_start:s2_end], type="delins")]
if not (lcs_f_len or lcs_r_len) : # Optimisation, not really needed.
return default
# Inversion.
if lcs_f_len <= lcs_r_len :
if lcs_f_len <= lcs_r_len:
if trim > 0 : # Partial palindrome.
s1_end_r -= trim
s2_end_r -= trim
......@@ -366,8 +353,8 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
#if
# Simple Inversion.
if s2_end - s2_start == lcs_r_len and s1_end - s1_start == lcs_r_len :
return [RawVar(start = s1_start + 1, end = s1_end, type = "inv")]
if s2_end - s2_start == lcs_r_len and s1_end - s1_start == lcs_r_len:
return [RawVar(start=s1_start + 1, end=s1_end, type="inv")]
r1_len = s1_end_r - lcs_r_len
r2_len = s1_end - s1_start - s1_end_r
......@@ -378,26 +365,26 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
# generate descriptions conditionally.
leftRv = []
rightRv = []
if r1_len or m2_len :
if r1_len or m2_len:
lcs = len(longest_common_suffix(s1[s1_start:s1_start + r1_len],
s2[s2_start:s2_start + m2_len]))
leftRv = DNA_description(M, s1, s2,
s1_start, s1_start + r1_len - lcs,
s2_start, s2_start + m2_len - lcs)
#if
if r2_len or m1_len :
if r2_len or m1_len:
lcp = len(longest_common_prefix(s1[s1_end - r2_len:s1_end],
s2[s2_end - m1_len:s2_end]))
rightRv = DNA_description(M, s1, s2,
s1_end - r2_len + lcp, s1_end, s2_end - m1_len + lcp, s2_end)
#if
partial = leftRv + [RawVar(start = s1_start + r1_len + 1,
end = s1_end - r2_len, type = "inv")] + rightRv
partial = leftRv + [RawVar(start=s1_start + r1_len + 1,
end=s1_end - r2_len, type="inv")] + rightRv
#if
# Compound variant.
else :
else:
r1_len = s1_end_f - lcs_f_len
r2_len = s1_end - s1_start - s1_end_f
m1_len = s2_end_f - lcs_f_len
......@@ -408,12 +395,12 @@ def DNA_description(M, s1, s2, s1_start, s1_end, s2_start, s2_end) :
s1_end - r2_len, s1_end, s2_end - m2_len, s2_end)
#else
if alleleDescriptionLength(partial) <= alleleDescriptionLength(default) :
if alleleDescriptionLength(partial) <= alleleDescriptionLength(default):
return partial
return default
#DNA_description
def describeDNA(original, mutated) :
def describeDNA(original, mutated):
"""
Convenience function for DNA_description().
......@@ -425,7 +412,6 @@ def describeDNA(original, mutated) :
@returns: A list of RawVar objects, representing the allele.
@rval: list(RawVar)
"""
s1 = str(original)
s2 = str(mutated)
lcp = len(longest_common_prefix(s1, s2))
......@@ -435,9 +421,5 @@ def describeDNA(original, mutated) :
M = LCSMatrix(s1, s2)
description = DNA_description(M, s1, s2, lcp, s1_end, lcp, s2_end)
for i in description:
i.putHGVS()
return description
return DNA_description(M, s1, s2, lcp, s1_end, lcp, s2_end)
#describeDNA
......@@ -8,13 +8,13 @@
<h3>About</h3>
</center>
Mutalyzer <span tal:content = "structure string:${version}"></span>
is designed and developed by Jeroen F. J. Laros, with the
is designed and developed by Jeroen F.J. Laros, with the
following exceptions:
<ul>
<li>The LRG parser, as well as the Batch interfaces are written
by Gerben R. Stouten.</li>
<li>The position converter interfaces (webservice and WWW) are
written by Gerard C. P. Schaafsma.</li>
written by Gerard C.P. Schaafsma.</li>
<li>Current development and maintenance is done by Martijn
Vermaat.</li>
</ul>
......@@ -22,12 +22,12 @@
valuable work on previous versions that acted as a guideline for the
development of the current version:
<ul>
<li>Martin Wildeman.</li>
<li>Ernest van Ophuizen.</li>
<li>Martin Wildeman.</li>
<li>Corinne Bareil.</li>
<li>Gerben R. Stouten.</li>
</ul>
Specifications are given by Peter E. M. Taschner and Johan T. den
Specifications are given by Peter E.M. Taschner and Johan T. den
Dunnen.<br>
<br>
Since references to WWW-sites are not yet acknowledged as citations,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment