Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from kipoi.model import BaseModel
import numpy as np
from maxentpy.maxent import score5, score3, load_matrix5, load_matrix3
import pdb
class MaxEntModel(BaseModel):
def __init__(self, side='5prime'):
"""
"""
if side not in ['5prime', '3prime']:
raise Exception("side should be 5prime or 3prime")
self.side = side
if self.side == '5prime':
self.matrix = load_matrix5()
self.model = score5
else:
self.matrix = load_matrix3()
self.model = score3
def score_seq(self, seq):
from kipoi.model import BaseModel
class MMSpliceModel(BaseModel):
'''Directly give the modular predictions'''
def predict_on_batch(self, inputs):
return inputs
from kipoi.model import BaseModel
from mmsplice import EFFICIENCY_MODEL
from mmsplice.utils.postproc import transform
class MMSpliceModel(BaseModel):
'''Model to predict delta logit PSI'''
def predict_on_batch(self, inputs):
'''inputs shape (,10), corresponding to 5 module predictions of mut and wt'''
X = transform(inputs[:, :5] - inputs[:, -5:], True)[:, [1, 2, 3, 5]]
return EFFICIENCY_MODEL.predict(X)
from kipoi.model import BaseModel
import numpy as np
class HALModel(BaseModel):
def __init__(self, pkl_file="model_files/HAL_mer_scores.npz", mer_len=6):
"""
"""
self._bases = ['A', 'T', 'C', 'G']
self.mer_len = mer_len
self.model_file = pkl_file
self.model = self._load_model()
def _load_model(self):
w = np.load(self.model_file)['weights']
self.mer6_dict = dict(zip(self.make_mer_list(6), range(4**6)))
self.w_mat = w
def make_mer_list(self, mer_len=6):
)
self.diso_classifier = nn.Sequential(
nn.Conv2d( n_final_in, 2, kernel_size=(7,1), padding=(3,0))
)
def forward( self, x):
x = self.elmo_feature_extractor( x )
d3_Yhat = self.dssp3_classifier( x )
d8_Yhat = self.dssp8_classifier( x )
diso_Yhat = self.diso_classifier( x )
return d3_Yhat, d8_Yhat, diso_Yhat
class SeqVec2structure( BaseModel ):
def __init__(self, weights):
self.model = self.load_weights( weights )
def load_weights( self, weights ):
model = CNN()
weights = torch.load( weights )
model.load_state_dict(weights)
return model.eval()
def get_predictions( self, Yhat ):
Yhat = Yhat.squeeze(dim=-1) # remove last empty dim
Yhat = torch.max( Yhat.data, dim=1 )[1] # get index of most reliable class prediction
DSSP3_MAPPING = {0:'H',1:'E',2:'C'} # map indices to labels
predictions = list() # container for predictions
from kipoi.model import BaseModel
from mmsplice import LINEAR_MODEL
from mmsplice.utils.postproc import transform
class MMSpliceModel(BaseModel):
'''Model to predict delta logit PSI'''
def predict_on_batch(self, inputs):
return LINEAR_MODEL.predict(transform(inputs, False))
import os
os.environ["KERAS_BACKEND"] = "theano"
import sys
import inspect
filename = inspect.getframeinfo(inspect.currentframe()).filename
this_path = os.path.dirname(os.path.abspath(filename))
sys.path.append(this_path)
from kipoi.model import BaseModel
from keras.models import model_from_json
import bio_utils
import keras.backend as K
class Model(BaseModel):
def __init__(self, embd_arch, embd_weights, arch, weights):
self.embd_model = model_from_json(open(embd_arch).read())
self.embd_model.load_weights(embd_weights)
self.model = model_from_json(open(arch).read())
self.model.load_weights(weights)
def predict_on_batch(self, inputs):
# pre-compute the embeddings
X_mirna_embd = self.embd_model.predict(inputs["mirna_int_seq"])
X_mrna_embd = self.embd_model.predict(inputs["mrna_int_seq"])
return self.model.predict([X_mirna_embd, X_mrna_embd], verbose=0)
from kipoi.model import BaseModel
import numpy as np
from maxentpy.maxent import score5, score3, load_matrix5, load_matrix3
import pdb
class MaxEntModel(BaseModel):
def __init__(self, side='5prime'):
"""
"""
if side not in ['5prime', '3prime']:
raise Exception("side should be 5prime or 3prime")
self.side = side
if self.side == '5prime':
self.matrix = load_matrix5()
self.model = score5
else:
self.matrix = load_matrix3()
self.model = score3
def _score_seq(self, seqs):
from math import log, exp
import os
import sys
import kipoi
# shared utils
from utils import read_json, onehot, elongate_intron
# access the absolute path to this script
# https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory-in-python
import inspect
this_file_path = os.path.abspath(inspect.getframeinfo(inspect.currentframe()).filename)
this_dir = os.path.dirname(this_file_path)
class CleavageTimeModel(BaseModel):
def __init__(self, acc_model, don_model, features_path=None):
self.don_model = joblib.load(don_model)
self.acc_model = joblib.load(acc_model)
if features_path is None:
features_path = os.path.join(this_dir, "../features.json")
self.features_metadata = read_json(features_path)
# acceptor and donor site indexes are unified across SOI
# NB! This indexes are pos=1 of the region, and index-1 is already pos=-1, not 0!
self.don_i = 3
self.acc_i = -21
self.labranchor = kipoi.get_model("labranchor", with_dataloader=False)
# add current dir to python path for multiprocessing
sys.path.append(this_dir)
def predict_on_batch(self, x):
"""
model_names = [os.path.basename(os.path.dirname(x))
for x in glob("../*/model.yaml")
if "template" not in x and "merged" not in x]
os.makedirs("model_files", exist_ok=True)
with open("models.txt", "w") as f:
f.write("\n".join(model_names))
def read_txt(file_path):
with open(file_path, "r") as f:
lines = f.readlines()
return [l.strip() for l in lines]
class MergedModel(BaseModel):
def __init__(self):
from keras import backend as K
K.clear_session()
self.model_names = read_txt("models.txt")
# hard-code the path to this models
# if we'd use `source='dir'`, then the models wouldn't
# be updated
self.models = [kipoi.get_model("CpGenie/{0}".format(m), source='kipoi',
with_dataloader=False)
for m in self.model_names]
def predict_on_batch(self, x):
return np.stack([model.predict_on_batch(x)[:, 0]