Skip to content

Commit

Permalink
Set CpG neighbors at flanks of chromosome to 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cangermueller committed May 6, 2017
1 parent c79c745 commit bb2d6ca
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions deepcpg/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def get_first_conv_layer(layers, get_act=False):
Returns
-------
Keras layer
Convolutional layer or tuple of convolutional layer and activation layer if
`get_act=True`.
Convolutional layer or tuple of convolutional layer and activation layer
if `get_act=True`.
"""
conv_layer = None
act_layer = None
Expand Down Expand Up @@ -535,14 +535,29 @@ def _prepro_dna(self, dna):
return int_to_onehot(dna)

def _prepro_cpg(self, states, dists):
"""Preprocess the state and distance of neighboring CpG sites."""
"""Preprocess the state and distance of neighboring CpG sites.
Parameters
----------
states: list
List of CpG states of all replicates.
dists: list
List of CpG distances of all replicates.
Returns
-------
prepro_states: list
List of preprocessed CpG states of all replicates.
prepro_dists: list
List of preprocessed CpG distances of all replicates.
"""
prepro_states = []
prepro_dists = []
for state, dist in zip(states, dists):
nan = state == dat.CPG_NAN
if np.any(nan):
state[nan] = np.random.binomial(1, state[~nan].mean(),
nan.sum())
# Set CpG neighbors at the flanks of a chromosome to 0.5
state[nan] = 0.5
dist[nan] = self.cpg_max_dist
dist = np.minimum(dist, self.cpg_max_dist) / self.cpg_max_dist
prepro_states.append(np.expand_dims(state, 1))
Expand Down

0 comments on commit bb2d6ca

Please sign in to comment.