File size: 5,090 Bytes
6f1e670 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction\n",
"\n",
"This notebook will discuss how to use the various featurizers in the ```multievolve``` package."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from model.splitters import *\n",
"from model.featurizers import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up\n",
"\n",
"First, define the following variables:\n",
"\n",
"- ```protein_name```: the name of the protein\n",
"\n",
"- ```wt_file```: the path to the wildtype sequence\n",
"\n",
"- ```training_dataset_fname```: the path to the training dataset"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"protein_name = \"example_protein\"\n",
"wt_file = \"../../../data/example_protein/apex.fasta\"\n",
"training_dataset_fname = '../../../data/example_protein/example_dataset.csv'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define a splitter object 鈥?we will just use this to load the dataset and pull sequences from to featurizer later."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"splitter = RandomProteinSplitter(protein_name, training_dataset_fname, wt_file, csv_has_header=True, use_cache=True, y_scaling=False, val_split=None)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Featurizers\n",
"\n",
"There are many featurizers available in the ```multievolve``` package. We discuss a few of the most common ones below. \n",
"\n",
"- ```OneHotFeaturizer```: One-hot encoding of the protein sequence\n",
"\n",
"- ```GeorgievFeaturizer```: Georgiev et al. (2022) featurizer\n",
"\n",
"- ```AAIdxFeaturizer```: amino acid index featurizer \n",
"\n",
"- ```ESMLogitsFeaturizer```: ESM-2 logits featurizer\n",
"\n",
"- ```ESM2EmbedFeaturizer```: ESM-2 embedding featurizer\n",
"\n",
"There are also combinatorial featurizers that combine multiple featurizers.\n",
"\n",
"- ```ESMAugmentedFeaturizer```: One-hot encoding augmented likelihood scores from the ESM-1/ESM-2 models\n",
"\n",
"- ```OnehotAndGeorgievFeaturizer```: One-hot encoding combined with Georgiev et al. (2022) featurizer, wherein the encodings are stacked along the last axis (i.e. by position)\n",
"\n",
"- ```OnehotAndAAIdxFeaturizer```: One-hot encoding augmented with amino acid index featurizer, wherein the encodings are stacked along the last axis (i.e. by position)\n",
"\n",
"- ```OnehotAndESMLogitsFeaturizer```: One-hot encoding augmented with ESM-2 logits featurizer, wherein the encodings are stacked along the last axis (i.e. by position)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Base Featurizers\n",
"onehot = OneHotFeaturizer(protein=protein_name, use_cache=True)\n",
"georgiev = GeorgievFeaturizer(protein=protein_name, use_cache=True)\n",
"aa_idx = AAIdxFeaturizer(protein=protein_name, use_cache=True)\n",
"esm_logits = ESMLogitsFeaturizer(protein=protein_name, use_cache=True)\n",
"esm_embed = ESM2EmbedFeaturizer(protein=protein_name, use_cache=True)\n",
"\n",
"# Combinatorial Featurizers\n",
"esm_augmented = ESMAugmentedFeaturizer(protein=protein_name, use_cache=True, wt_file=wt_file)\n",
"onehotgeorgiev = OnehotAndGeorgievFeaturizer(protein=protein_name, use_cache=True)\n",
"onehotaaidx = OnehotAndAAIdxFeaturizer(protein=protein_name, use_cache=True)\n",
"onehotesmlogits = OnehotAndESMLogitsFeaturizer(protein=protein_name, use_cache=True)\n",
"onehotesmmsalogits = OnehotAndESMMSALogitsFeaturizer(protein=protein_name, use_cache=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Featurizers have the function ```featurize```, which takes in a list of sequences and returns the featurized sequences."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"example_sequences = splitter.data[0][:5].tolist()\n",
"\n",
"onehot.featurize(example_sequences)"
]
}
],
"metadata": {
"environment": {
"kernel": "multievolve",
"name": "workbench-notebooks.m128",
"type": "gcloud",
"uri": "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/workbench-notebooks:m128"
},
"kernelspec": {
"display_name": "multievolve",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|