/usr/share/pyshared/Bio/SeqUtils/lcc.py is in python-biopython 1.58-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | # Copyright 2003, 2007 by Sebastian Bassi. sbassi@genesdigitales.com
# All rights reserved. This code is part of the Biopython
# distribution and governed by its license.
# Please see the LICENSE file that should have been included as part
# of this package.
import math
def lcc_mult(seq,wsize):
"""Local Composition Complexity (LCC) values over sliding window.
Returns a list of floats, the LCC values for a sliding window over
the sequence.
seq - an unambiguous DNA sequence (a string or Seq object)
wsize - window size, integer
The result is the same as applying lcc_simp multiple times, but this
version is optimized for speed. The optimization works by using the
value of previous window as a base to compute the next one."""
l2 = math.log(2)
tamseq = len(seq)
try:
#Assume its a string
upper = seq.upper()
except AttributeError:
#Should be a Seq object then
upper = seq.tostring().upper()
compone = [0]
lccsal = [0]
for i in range(wsize):
compone.append(((i+1)/float(wsize))*
((math.log((i+1)/float(wsize)))/l2))
window = seq[0:wsize]
cant_a = window.count('A')
cant_c = window.count('C')
cant_t = window.count('T')
cant_g = window.count('G')
term_a = compone[cant_a]
term_c = compone[cant_c]
term_t = compone[cant_t]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
tail = seq[0]
for x in range (tamseq-wsize):
window = upper[x+1:wsize+x+1]
if tail==window[-1]:
lccsal.append(lccsal[-1])
elif tail=='A':
cant_a -= 1
if window.endswith('C'):
cant_c += 1
term_a = compone[cant_a]
term_c = compone[cant_c]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('T'):
cant_t += 1
term_a = compone[cant_a]
term_t = compone[cant_t]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('G'):
cant_g += 1
term_a = compone[cant_a]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif tail=='C':
cant_c -= 1
if window.endswith('A'):
cant_a += 1
term_a = compone[cant_a]
term_c = compone[cant_c]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('T'):
cant_t += 1
term_c = compone[cant_c]
term_t = compone[cant_t]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('G'):
cant_g += 1
term_c = compone[cant_c]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif tail=='T':
cant_t -= 1
if window.endswith('A'):
cant_a += 1
term_a = compone[cant_a]
term_t = compone[cant_t]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('C'):
cant_c += 1
term_c = compone[cant_c]
term_t = compone[cant_t]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('G'):
cant_g += 1
term_t = compone[cant_t]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif tail=='G':
cant_g -= 1
if window.endswith('A'):
cant_a += 1
term_a = compone[cant_a]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('C'):
cant_c += 1
term_c = compone[cant_c]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
elif window.endswith('T'):
cant_t += 1
term_t = compone[cant_t]
term_g = compone[cant_g]
lccsal.append(-(term_a+term_c+term_t+term_g))
tail = window[0]
return lccsal
def lcc_simp(seq):
"""Local Composition Complexity (LCC) for a sequence.
seq - an unambiguous DNA sequence (a string or Seq object)
Returns the Local Composition Complexity (LCC) value for the entire
sequence (as a float).
Reference:
Andrzej K Konopka (2005) Sequence Complexity and Composition
DOI: 10.1038/npg.els.0005260
"""
wsize = len(seq)
try:
#Assume its a string
upper = seq.upper()
except AttributeError:
#Should be a Seq object then
upper = seq.tostring().upper()
l2 = math.log(2)
if 'A' not in seq:
term_a = 0
# Check to avoid calculating the log of 0.
else:
term_a = ((upper.count('A'))/float(wsize))*((math.log((upper.count('A'))
/float(wsize)))/l2)
if 'C' not in seq:
term_c = 0
else:
term_c = ((upper.count('C'))/float(wsize))*((math.log((upper.count('C'))
/float(wsize)))/l2)
if 'T' not in seq:
term_t = 0
else:
term_t = ((upper.count('T'))/float(wsize))*((math.log((upper.count('T'))
/float(wsize)))/l2)
if 'G' not in seq:
term_g = 0
else:
term_g = ((upper.count('G'))/float(wsize))*((math.log((upper.count('G'))
/float(wsize)))/l2)
return -(term_a+term_c+term_t+term_g)
|