{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!git clone https://github.com/ml4bio/RNA-FM.git\n!cd ./RNA-FM\n!pip install ./RNA-FM --no-deps\n!pip install ptflops","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-10T14:06:55.161056Z","iopub.execute_input":"2023-11-10T14:06:55.161795Z","iopub.status.idle":"2023-11-10T14:07:13.071907Z","shell.execute_reply.started":"2023-11-10T14:06:55.161763Z","shell.execute_reply":"2023-11-10T14:07:13.070788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport fm\n\n# Load RNA-FM model\nmodel, alphabet = fm.pretrained.rna_fm_t12()\nbatch_converter = alphabet.get_batch_converter()\nmodel.eval()  # disables dropout for deterministic results\n\n# Prepare data\ndata = [\n    (\"RNA1\", \"GGGUGCGAUCAUACCAGCACUAAUGCCCUCCUGGGAAGUCCUCGUGUUGCACCCCU\"),\n    (\"RNA2\", \"GGGUGUCGCUCAGUUGGUAGAGAACGUGCUUGCCUGGCAUGCAAGAAACCUUGGUUCAAUCCCCAGCACUGCA\"),\n    (\"RNA3\", \"CGAUUCNCGUUCCC--CCGCCUCCA\"),\n]\nbatch_labels, batch_strs, batch_tokens = batch_converter(data)\n\n# Extract embeddings (on CPU)\nwith torch.no_grad():\n    results = model(batch_tokens, repr_layers=[12])\ntoken_embeddings = results[\"representations\"][12]","metadata":{"execution":{"iopub.status.busy":"2023-11-10T14:07:13.074583Z","iopub.execute_input":"2023-11-10T14:07:13.075038Z","iopub.status.idle":"2023-11-10T14:07:14.977479Z","shell.execute_reply.started":"2023-11-10T14:07:13.074996Z","shell.execute_reply":"2023-11-10T14:07:14.976591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model","metadata":{"execution":{"iopub.status.busy":"2023-11-10T14:07:14.979033Z","iopub.execute_input":"2023-11-10T14:07:14.979650Z","iopub.status.idle":"2023-11-10T14:07:14.987898Z","shell.execute_reply.started":"2023-11-10T14:07:14.979594Z","shell.execute_reply":"2023-11-10T14:07:14.986991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import fm\nimport torch\n\n\nif __name__==\"__main__\":\n    #path= \"/data/home/chenjiayang/projects/RNA-FM/redevelop/pretrained/Models/SS/RNA-FM-ResNet_PDB-All.pth\"\n    model, alphabet = fm.downstream.build_rnafm_resnet(type=\"ss\") #, model_location=path)\n    batch_converter = alphabet.get_batch_converter()\n    model.eval()  # disables dropout for deterministic results\n\n    # Prepare data\n    data = [\n        (\"RNA1\", \"GGGUGCGAUCAUACCAGCACUAAUGCCCUCCUGGGAAGUCCUCGUGUUGCACCCCU\"),\n    ]\n    batch_labels, batch_strs, batch_tokens = batch_converter(data)\n\n    input = {\n        \"description\": batch_labels,\n        \"token\": batch_tokens\n    }\n\n    # Secodnary Structure Prediction (on CPU)\n    with torch.no_grad():\n        results = model(input)\n    ss_prob_map = results[\"r-ss\"]\n    print(ss_prob_map)\n    print(ss_prob_map.shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-10T14:07:14.989848Z","iopub.execute_input":"2023-11-10T14:07:14.990135Z","iopub.status.idle":"2023-11-10T14:07:16.955284Z","shell.execute_reply.started":"2023-11-10T14:07:14.990097Z","shell.execute_reply":"2023-11-10T14:07:16.954332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model","metadata":{"execution":{"iopub.status.busy":"2023-11-10T14:07:16.956508Z","iopub.execute_input":"2023-11-10T14:07:16.956851Z","iopub.status.idle":"2023-11-10T14:07:16.968069Z","shell.execute_reply.started":"2023-11-10T14:07:16.956824Z","shell.execute_reply":"2023-11-10T14:07:16.967143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir models\n!cp /root/.cache/torch/hub/checkpoints/RNA-FM-ResNet_PDB-All.pth ./models/\n!cp /root/.cache/torch/hub/checkpoints/RNA-FM_pretrained.pth ./models/","metadata":{"execution":{"iopub.status.busy":"2023-11-10T14:07:16.969205Z","iopub.execute_input":"2023-11-10T14:07:16.969470Z","iopub.status.idle":"2023-11-10T14:07:21.218126Z","shell.execute_reply.started":"2023-11-10T14:07:16.969447Z","shell.execute_reply":"2023-11-10T14:07:21.217024Z"},"trusted":true},"execution_count":null,"outputs":[]}]}