Skip to content

Commit 74cd4d8

Browse files
author
Alexis Morrissey
committed
Retrained CNNs to be compatible with tensorflow 2.17
1 parent c758f6b commit 74cd4d8

20 files changed

+73
-42
lines changed

Allo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from . import predictPeak
22
from . import allocation
33

4-
__version__ = '1.1.2'
4+
__version__ = '1.2.0'

Allo/allo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#Arguments
66
import argparse
7-
version = "1.1.2"
7+
version = "1.2.0"
88
parser = argparse.ArgumentParser(prog = 'allo', \
99
description = '(Version ' + version + ') Allo is a software that allocates multi-mapped reads in gene regulatory data.\n' \
1010
'Developed by Mahony Laboratory @ The Pennsylvania State University', \

Allo/allocation.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import math
77
import random
88
import os
9+
import contextlib, io
10+
import logging
911
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
1012
import tensorflow as tf
1113
from tensorflow import keras
@@ -16,9 +18,9 @@
1618
import sys
1719
import multiprocessing
1820
import re
19-
import absl.logging
20-
absl.logging.set_verbosity(absl.logging.ERROR)
21-
import contextlib, io
21+
from contextlib import contextmanager
22+
from absl import logging
23+
import warnings
2224

2325
#Add reads to UMR dictionary
2426
def addToDict(tempFile, genLand, spliceD, seq):
@@ -381,14 +383,15 @@ def parseMulti(tempFile, winSize, genLand, modelName, cnn_scores, rc, keep, rmz,
381383
#Getting trained CNN
382384
if rc == 0:
383385
try:
384-
json_file = open(modelName+'.json', 'r')
385-
loaded_model_json = json_file.read()
386-
json_file.close()
387-
model = tf.keras.models.model_from_json(loaded_model_json)
388-
model.load_weights(modelName+'.h5')
389-
model = LiteModel.from_keras_model(model)
386+
with suppress_output():
387+
json_file = open(modelName+'.json', 'r')
388+
loaded_model_json = json_file.read()
389+
json_file.close()
390+
model = tf.keras.models.model_from_json(loaded_model_json)
391+
model.load_weights(modelName+'.weights.h5')
392+
model = LiteModel.from_keras_model(model)
390393
except:
391-
print("Could not load Tensorflow model :( Allo was written with Tensorflow version 2.11")
394+
print("Could not load Tensorflow model :( This version of Allo was written with Tensorflow version 2.17")
392395
sys.exit(0)
393396
else:
394397
model = None
@@ -779,14 +782,15 @@ def parseMultiPE(tempFile, winSize, genLand, modelName, cnn_scores, rc, keep, rm
779782
#Getting trained CNN and making sure there is a compatible tensorflow installed
780783
if rc == 0:
781784
try:
782-
json_file = open(modelName+'.json', 'r')
783-
loaded_model_json = json_file.read()
784-
json_file.close()
785-
model = tf.keras.models.model_from_json(loaded_model_json)
786-
model.load_weights(modelName+'.h5')
787-
model = LiteModel.from_keras_model(model)
785+
with suppress_output():
786+
json_file = open(modelName+'.json', 'r')
787+
loaded_model_json = json_file.read()
788+
json_file.close()
789+
model = tf.keras.models.model_from_json(loaded_model_json)
790+
model.load_weights(modelName+'.weights.h5')
791+
model = LiteModel.from_keras_model(model)
788792
except:
789-
print("Could not load Tensorflow model :( Allo was written with Tensorflow version 2.11")
793+
print("Could not load Tensorflow model :( This version of Allo was written with Tensorflow version 2.17")
790794
sys.exit(0)
791795
else:
792796
model = None
@@ -888,6 +892,9 @@ def from_keras_model(cls, kmodel):
888892
return LiteModel(tf.lite.Interpreter(model_content=tflite_model))
889893

890894
def __init__(self, interpreter):
895+
logging.set_verbosity(logging.ERROR)
896+
warnings.filterwarnings('ignore')
897+
tf.get_logger().setLevel('ERROR')
891898
self.interpreter = interpreter
892899
self.interpreter.allocate_tensors()
893900
input_det = self.interpreter.get_input_details()[0]
@@ -916,4 +923,19 @@ def predict_single(self, inp):
916923
out = self.interpreter.get_tensor(self.output_index)
917924
return out[0]
918925

926+
#Supressing output from tensorflow
927+
@contextmanager
928+
def suppress_output():
929+
with open(os.devnull, 'w') as devnull:
930+
old_stdout_fd = os.dup(sys.stdout.fileno())
931+
old_stderr_fd = os.dup(sys.stderr.fileno())
919932

933+
try:
934+
os.dup2(devnull.fileno(), sys.stdout.fileno())
935+
os.dup2(devnull.fileno(), sys.stderr.fileno())
936+
yield
937+
finally:
938+
os.dup2(old_stdout_fd, sys.stdout.fileno())
939+
os.dup2(old_stderr_fd, sys.stderr.fileno())
940+
os.close(old_stdout_fd)
941+
os.close(old_stderr_fd)

Allo/atac.h5

-285 KB
Binary file not shown.

Allo/atac.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"class_name": "Sequential", "config": {"name": "sequential_2", "layers": [{"module": "keras.layers", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 100, 100], "dtype": "float32", "sparse": false, "ragged": false, "name": "conv1d_6_input"}, "registered_name": null}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d_6", "trainable": true, "dtype": "float32", "batch_input_shape": [null, 100, 100], "filters": 2, "kernel_size": [64], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 100, 100]}}, {"module": "keras.layers", "class_name": "AveragePooling1D", "config": {"name": "average_pooling1d_2", "trainable": true, "dtype": "float32", "strides": [2], "pool_size": [2], "padding": "valid", "data_format": "channels_last"}, "registered_name": null, "build_config": {"input_shape": [null, 100, 2]}}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d_7", "trainable": true, "dtype": "float32", "filters": 2, "kernel_size": [32], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d_8", "trainable": true, "dtype": "float32", "filters": 2, "kernel_size": [32], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Dropout", "config": {"name": "dropout_2", "trainable": true, "dtype": "float32", "rate": 0.1, "noise_shape": null, "seed": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Flatten", "config": {"name": "flatten_2", "trainable": true, "dtype": "float32", "data_format": "channels_last"}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_4", "trainable": true, "dtype": "float32", "units": 528, "activation": "relu", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 100]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_5", "trainable": true, "dtype": "float32", "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 528]}}]}, "keras_version": "2.15.0", "backend": "tensorflow"}
1+
{"module": "keras", "class_name": "Sequential", "config": {"name": "sequential", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "layers": [{"module": "keras.layers", "class_name": "InputLayer", "config": {"batch_shape": [null, 100, 100], "dtype": "float32", "sparse": false, "name": "input_layer"}, "registered_name": null}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 2, "kernel_size": [64], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 100, 100]}}, {"module": "keras.layers", "class_name": "AveragePooling1D", "config": {"name": "average_pooling1d", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "pool_size": [2], "padding": "valid", "strides": [2], "data_format": "channels_last"}, "registered_name": null, "build_config": {"input_shape": [null, 100, 2]}}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d_1", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 2, "kernel_size": [32], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Conv1D", "config": {"name": "conv1d_2", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 2, "kernel_size": [32], "strides": [1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Dropout", "config": {"name": "dropout", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "rate": 0.5, "seed": null, "noise_shape": null}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Flatten", "config": {"name": "flatten", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "data_format": "channels_last"}, "registered_name": null, "build_config": {"input_shape": [null, 50, 2]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "units": 528, "activation": "relu", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 100]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 528]}}], "build_input_shape": [null, 100, 100]}, "registered_name": null, "build_config": {"input_shape": [null, 100, 100]}, "compile_config": {"optimizer": {"module": "keras.optimizers", "class_name": "Adam", "config": {"name": "adam", "learning_rate": 0.0010000000474974513, "weight_decay": null, "clipnorm": null, "global_clipnorm": null, "clipvalue": null, "use_ema": false, "ema_momentum": 0.99, "ema_overwrite_frequency": null, "loss_scale_factor": null, "gradient_accumulation_steps": null, "beta_1": 0.9, "beta_2": 0.999, "epsilon": 1e-07, "amsgrad": false}, "registered_name": null}, "loss": "binary_crossentropy", "loss_weights": null, "metrics": ["accuracy"], "weighted_metrics": null, "run_eagerly": false, "steps_per_execution": 1, "jit_compile": true}}

Allo/atac.weights.h5

815 KB
Binary file not shown.

Allo/dnase.h5

-285 KB
Binary file not shown.

0 commit comments

Comments
 (0)