<jupyter_start><jupyter_text>Load the Basic- and APADB-tuned APARENT model-- Load the basic APARENT model, which has been trained to predict the isoform abundance and cut profile of a proximal PAS given a fixed background distal PAS (trained on random 3' UTR APA MPRA data).-- Load the APADB-fitted APARENT model, composed of two siamese APARENT networks which score the proximal and distal PASs. Linear regression of the proximal and distal scores are used to infer the relative APA isoform abundance (fitted on human pooled-tissue APADB data).<jupyter_code>#Load base APARENT model and input encoder

aparent_model = load_model('../saved_models/aparent_large_lessdropout_all_libs_no_sampleweights.h5')
aparent_encoder = get_aparent_encoder()

#Load APADB-tuned APARENT model and input encoder

apadb_model = load_model('../saved_models/aparent_apadb_fitted_large_lessdropout_no_sampleweights.h5')
apadb_encoder = get_apadb_encoder()<jupyter_output>WARNING:tensorflow:From /home/johli/anaconda3/envs/aparent/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /home/johli/anaconda3/envs/aparent/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.<jupyter_text>Example 1: PSMC6 Gene APA prediction-- First predict the non-normalized isoform score of each PAS sequence (score is relative to the average random MPRA distal bias).-- Then predict the relative APA isoform abundance using the APADB-fitted model.<jupyter_code>#Example APA sites from APADB (gene = PSMC6)

#Proximal and Distal PAS Sequences
seq_prox = 'AGATAGTGGTATAAGAAAGCATTTCTTATGACTTATTTTGTATCATTTGTTTTCCTCATCTAAAAAGTTGAATAAAATCTGTTTGATTCAGTTCTCCTACATATATATTCTTGTCTTTTCTGAGTATATTTACTGTGGTCCTTTAGGTTCTTTAGCAAGTAAACTATTTGATAACCCAGATGGATTGTGGATTTTTGAATATTAT'
seq_dist = 'TGGATTGTGGATTTTTGAATATTATTTTAAAATAGTACACATACTTAATGTTCATAAGATCATCTTCTTAAATAAAACATGGATGTGTGGGTATGTCTGTACTCCTCCTTTCAGAAAGTGTTTACATATTCTTCATCTACTGTGATTAAGCTCATTGTTGGTTAATTGAAAATATACATGCACATCCATAACTTTTTAAAGAGTA'

#Site Distance
site_distance = 180

#Proximal and Distal cut intervals within each sequence defining the isoforms
prox_cut_start, prox_cut_end = 80, 105
dist_cut_start, dist_cut_end = 80, 105

#Predict with base APARENT model
_, cut_pred_prox = aparent_model.predict(x=aparent_encoder([seq_prox]))
_, cut_pred_dist = aparent_model.predict(x=aparent_encoder([seq_dist]))

print("Non-normalized proximal sum-cut logit = " + str(logit(np.sum(cut_pred_prox[0, prox_cut_start:prox_cut_end]))))
print("Non-normalized distal sum-cut logit = " + str(logit(np.sum(cut_pred_dist[0, dist_cut_start:dist_cut_end]))))
print("")

#Predict with APADB-tuned APARENT model
iso_pred, cut_prox, cut_dist = apadb_model.predict(x=apadb_encoder([seq_prox], [seq_dist], [prox_cut_start], [prox_cut_end], [dist_cut_start], [dist_cut_end], [site_distance]))

print("Predicted proximal vs. distal isoform % (APADB) = " + str(iso_pred[0, 0]))

f = plt.figure(figsize=(8, 3))
plt.plot(np.arange(205), np.ravel(cut_prox), linewidth=2, color='black')
plt.title("Normalized proximal cut profile", fontsize=16)
plt.xticks([70, 76], ['CSE', 'CSE+6'], fontsize=14, rotation=45)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()

f = plt.figure(figsize=(8, 3))
plt.plot(np.arange(205), np.ravel(cut_dist), linewidth=2, color='black')
plt.title("Normalized distal cut profile", fontsize=16)
plt.xticks([70, 76], ['CSE', 'CSE+6'], fontsize=14, rotation=45)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()<jupyter_output>Non-normalized proximal sum-cut logit = 2.068363954922734
Non-normalized distal sum-cut logit = 1.7659008653702761

Predicted proximal vs. distal isoform % (APADB) = 0.7347708<jupyter_text>Example 2: KTN1 Gene APA prediction-- First predict the non-normalized isoform score of each PAS sequence (score is relative to the average random MPRA distal bias).-- Then predict the relative APA isoform abundance using the APADB-fitted model.<jupyter_code>#Example APA sites from APADB (gene = KTN1)

seq_prox = 'AAAACTGTTTGAATAATTAGACCTTTACATTCCTGAAGATAAACATGTAATCTTTTATCTTATTTTGCTCAATAAAATTGTTCAGAAGATCAAAGTGGTAAAGACAATGTAAAATTTAACATTTTAATACTGATGTTGTACACTGTTTTACTTAACATTTTGGGAAGTAACTGCCTCTGACTTCAACTCAAGAAAACACTTTTTT'
seq_dist = 'GCCTCTGACTTCAACTCAAGAAAACACTTTTTTGTTGCTAATGTAATCGGTTTTTGTAATGGCGTCAGCAAATAAAAGGATGCTTATTATTCAAACTTGACTTGTTCTAATTTTTATTGAGCTTTAACAGATTTCATTAGTAGTACAGATCATTGTAATTTAGAATACAGCTATTAATTGGCAACCATTCAACAAGATAGGTTTA'

#Site Distance
site_distance = 171

#Proximal and Distal cut intervals within each sequence defining the isoforms
prox_cut_start, prox_cut_end = 70, 105
dist_cut_start, dist_cut_end = 70, 105

#One-hot encode the sequences
onehot_encoder = iso.OneHotEncoder(len(seq_prox))
onehot_prox, onehot_dist = onehot_encoder(seq_prox), onehot_encoder(seq_dist)

#Predict with base APARENT model
_, cut_pred_prox = aparent_model.predict(x=aparent_encoder([seq_prox]))
_, cut_pred_dist = aparent_model.predict(x=aparent_encoder([seq_dist]))

print("Non-normalized proximal sum-cut logit = " + str(logit(np.sum(cut_pred_prox[0, prox_cut_start:prox_cut_end]))))
print("Non-normalized distal sum-cut logit = " + str(logit(np.sum(cut_pred_dist[0, dist_cut_start:dist_cut_end]))))
print("")

#Predict with APADB-tuned APARENT model
iso_pred, cut_prox, cut_dist = apadb_model.predict(x=apadb_encoder([seq_prox], [seq_dist], [prox_cut_start], [prox_cut_end], [dist_cut_start], [dist_cut_end], [site_distance]))

print("Predicted proximal vs. distal isoform % (APADB) = " + str(iso_pred[0, 0]))

f = plt.figure(figsize=(8, 3))
plt.plot(np.arange(205), np.ravel(cut_prox), linewidth=2, color='black')
plt.title("Normalized proximal cut profile", fontsize=16)
plt.xticks([70, 76], ['CSE', 'CSE+6'], fontsize=14, rotation=45)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()

f = plt.figure(figsize=(8, 3))
plt.plot(np.arange(205), np.ravel(cut_dist), linewidth=2, color='black')
plt.title("Normalized distal cut profile", fontsize=16)
plt.xticks([70, 76], ['CSE', 'CSE+6'], fontsize=14, rotation=45)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()<jupyter_output>Non-normalized proximal sum-cut logit = 0.9036148900010471
Non-normalized distal sum-cut logit = 3.738104808277522

Predicted proximal vs. distal isoform % (APADB) = 0.16782887
{'fraction_non_alphanumeric': 0.10344311377245509, 'fraction_numerical': 0.032335329341317366, 'mean_word_length': 7.779237844940868, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '403057', 'license': 'MIT', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2437, 'n_words': 520, 'path': 'examples/aparent_example_isoform_prediction.ipynb', 'repo_name': '876lkj/APARENT', 'size': '6680'}