Skip to content

Commit

Permalink
Biopython 1.76 Compatibility and Alphabet Removal
Browse files Browse the repository at this point in the history
pssm_model.py and binding_model.py updated to run biopython 1.76 with the
removal of the alphabet function. Alphabet added to parent class
binding_model.py for the use of pssm_model.py
  • Loading branch information
abigraken committed Jul 21, 2021
1 parent 9d6bd73 commit 8aac73e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
10 changes: 8 additions & 2 deletions cgb/binding_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ class TFBindingModel():
__metaclass__ = ABCMeta

def __init__(self, collections,
background={'A': 0.25, 'C': 0.25, 'G': 0.25, 'T': 0.25}):
background={'A': 0.25, 'C': 0.25, 'G': 0.25, 'T': 0.25}, alphabet="ACGT"):
"""Constructor for the TFBindingModel class.
Combines multiple PSWMs using phylogenetic weighting to derive a
species-specific PWM.
"""
self._background = background
self._collection_set = collections

self._alphabet = alphabet

@cached_property
def alphabet(self):
"""Returns the DNA alphabet to be used by pssm_model.py"""
return self._alphabet

@cached_property
def background(self):
"""Returns the background distribution of the model."""
Expand Down
22 changes: 7 additions & 15 deletions cgb/pssm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class PSSMModel(TFBindingModel):
target species.
"""
def __init__(self, collections, weights,
background={'A': 0.25, 'C': 0.25, 'G': 0.25, 'T': 0.25}):
background={'A': 0.25, 'C': 0.25, 'G': 0.25, 'T': 0.25}, alphabet="ACGT"):
"""Constructor for the PSSMModel class."""
super(PSSMModel, self).__init__(collections, background)
self._pwm = self._combine_pwms([c.pwm for c in collections], weights)
super(PSSMModel, self).__init__(collections, background, alphabet)
self._pwm = self._combine_pwms([c.pwm for c in collections], weights, alphabet)

@cached_property
def pwm(self):
Expand All @@ -53,12 +53,7 @@ def pssm(self):
def rev_comp_pssm(self):
"""Returns the reverse complement of the PSSM."""
return self.pssm.reverse_complement()

@property
def alphabet(self):
"""Returns the alphabet of the motif."""
return self.pwm.alphabet


@cached_property
def IC(self):
"""Returns the information content of the PSSM."""
Expand Down Expand Up @@ -140,7 +135,7 @@ def score_seq(self, seq, both=True):
@property
def weblogo_from_pwm(self):
s = len(self.sites)
alpha = self.alphabet.letters
alpha = self._alphabet
cols = []
for i in range(self.length):
cols.append("")
Expand All @@ -162,16 +157,13 @@ def weblogo_from_pwm(self):
return filename

@staticmethod
def _combine_pwms(pwms, weights):
def _combine_pwms(pwms, weights, alphabet):
"""Combines the given PWMs according to the given weights."""
len = pwms[0].length
alphabet = pwms[0].alphabet
# Check if all PWMs are of the same length.
assert all(len == pwm.length for pwm in pwms)
# Check if all PWMs have the same alphabet -- 'ACGT'
assert all(alphabet == pwm.alphabet for pwm in pwms)
# Combine all PWMs according to given weights
pwm_vals = {let: [sum(pwm[let][i]*w for pwm, w in zip(pwms, weights))
for i in xrange(len)]
for let in alphabet.letters}
for let in alphabet}
return PositionWeightMatrix(alphabet, pwm_vals)
6 changes: 3 additions & 3 deletions conda_cgb_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- scipy=1.2.1
- matplotlib=2.2.5
- pyparsing=2.4.7
- biopython=1.73
- biopython=1.76
- pyzmq=19.0.0
- ipython=5.8.0
- spyder=4.1.1
Expand All @@ -21,7 +21,7 @@ dependencies:
- pip
- pip:
# works for regular pip packages
- ete3=3.1.1
- tqdm=4.47.0
- ete3==3.1.1
- tqdm==4.47.0
- weblogo==3.4

0 comments on commit 8aac73e

Please sign in to comment.