### Install fr3d-python for 2.5D Annotations Source: https://github.com/cgoliver/rnaglib/blob/master/INSTALL.md Installs the fr3d-python package from its GitHub repository. This is required for building 2.5D annotations from PDB and mmCIF files. ```bash pip install git+https://github.com/cgoliver/fr3d-python.git ``` -------------------------------- ### Small Molecule Binding Example Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/rnaglib.examples.md This script demonstrates a more complex example of learning binding protein preferences and small molecule binding, including a pretraining phase using the R_graphlets kernel. ```APIDOC ## Small Molecule Binding Example ### Description This script demonstrates a more complicated example: learning binding protein preferences as well as small molecules binding from the nucleotide types and the graph structure. It also includes a pretraining phase based on the R_graphlets kernel. ### Method Python Script ### Endpoint N/A ### Parameters N/A ### Request Example ```python from rnaglib.learning import models, learn from rnaglib.data_transforms import graphloader as loader from rnaglib.benchmark import evaluate from rnaglib.kernels import node_sim import torch # Choose the data, features and targets to use node_features = ['nt_code'] node_target = ['binding_protein'] ###### Unsupervised phase : print('Starting to pretrain the network') node_sim_func = node_sim.SimFunctionNode(method='R_graphlets', depth=2) unsupervised_dataset = loader.UnsupervisedDataset(node_simfunc=node_sim_func, node_features=node_features) train_loader = loader.Loader(dataset=unsupervised_dataset, split=False, num_workers=0, max_size_kernel=100).get_data() embedder_model = models.Embedder(infeatures_dim=unsupervised_dataset.input_dim, dims=[64, 64]) optimizer = torch.optim.Adam(embedder_model.parameters()) learn.pretrain_unsupervised(model=embedder_model, optimizer=optimizer, train_loader=train_loader, learning_routine=learn.LearningRoutine(num_epochs=10), rec_params={"similarity": True, "normalize": False, "use_graph": True, "hops": 2}) print() ###### Now the supervised phase : print('We have finished pretraining the network, let us fine tune it') train_split, test_split = evaluate.get_task_split(node_target=node_target) supervised_train_dataset = loader.SupervisedDataset(node_features=node_features, redundancy='NR', node_target=node_target, all_graphs=train_split) train_loader = loader.Loader(dataset=supervised_train_dataset, split=False).get_data() classifier_model = models.Classifier(embedder=embedder_model, classif_dims=[supervised_train_dataset.output_dim]) optimizer = torch.optim.Adam(classifier_model.parameters(), lr=0.001) learn.train_supervised(model=classifier_model, optimizer=optimizer, train_loader=train_loader, learning_routine=learn.LearningRoutine(num_epochs=10)) metric = evaluate.get_performance(node_target=node_target, node_features=node_features, model=classifier_model) print('We get a performance of :', metric) ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### Protein Binding Example Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/rnaglib.examples.md This script demonstrates a basic example of learning protein binding preferences from nucleotide types and graph structure using RNAGLIB. ```APIDOC ## Protein Binding Example ### Description This script shows a basic example of learning protein binding preferences from nucleotide types and the graph structure. It involves choosing data, creating a data loader, building an RGCN model, and training it. ### Method Python Script ### Endpoint N/A ### Parameters N/A ### Request Example ```python from rnaglib.learning import models, learn from rnaglib.dataset import RNADataset from rnaglib.transforms import FeaturesComputer from rnaglib.dataset_transforms import get_loader import torch # Choose the features and targets to use features_computer = FeaturesComputer(nt_features='nt_code', nt_targets='binding_protein') supervised_dataset = RNADataset(features_computer=features_computer) train_loader, validation_loader, test_loader = get_loader(dataset=supervised_dataset).get_data() # Define a model, we first embed our data in 10 dimensions, and then add one classification input_dim, target_dim = features_computer.input_dim, features_computer.output_dim embedder_model = models.Embedder(dims=[10, 10], infeatures_dim=input_dim) classifier_model = models.Classifier(embedder=embedder_model, classif_dims=[target_dim]) # Finally get the training going optimizer = torch.optim.Adam(classifier_model.parameters(), lr=0.001) learn.train_supervised(model=classifier_model, optimizer=optimizer, train_loader=train_loader) ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### Complete Task Definition Example Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/tasks/README.md A full implementation of a custom task including initialization, splitting, annotation, and dataset construction. ```python class TutorialTask(ResidueClassificationTask): target_var = 'binding_ion' input_var = "nt_code" def __init__(self, **kwargs): super().__init__(**kwargs) def default_splitter(self): return RandomSplitter() def _annotator(self, x): dummy = {node: 1 for node, nodedata in x.nodes.items()} set_node_attributes(x, dummy, 'dummy') return x def build_dataset(self, root): graph_index = load_index() rnas_keep = [graph.split(".")[0] for graph, attrs in graph_index.items() if "node_" + self.target_var in attrs] return RNADataset(nt_targets=[self.target_var], nt_features=[self.input_var], rna_filter=lambda x: x.graph['pdbid'][0].lower() in rnas_keep, annotator=self._annotator) ``` -------------------------------- ### Install Torch-Geometric for Graph Loading and Training Source: https://github.com/cgoliver/rnaglib/blob/master/INSTALL.md Installs the PyTorch Geometric library, an alternative to DGL for loading graphs and training models, particularly when using PyTorch. ```bash pip install torch_geometric ``` -------------------------------- ### Install DGL for Graph Loading and Training Source: https://github.com/cgoliver/rnaglib/blob/master/INSTALL.md Installs the Deep Graph Library (DGL), which is used for loading graphs and training models within RNAGLIB. ```bash pip install dgl ``` -------------------------------- ### Install External Dependencies for Advanced Data Splitting Source: https://github.com/cgoliver/rnaglib/blob/master/INSTALL.md Installs external executables like cd-hit and RNAalign using a provided shell script. These tools are necessary for advanced dataset splitting based on sequence or structure similarity. Note: This script is tested on Linux and may require manual installation on other systems. ```bash chmod u+x install_dependencies.sh ./install_dependencies.sh /my/path/to/executables ``` -------------------------------- ### RfamTransform Example Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/rnaglib.transforms.md This example demonstrates how to use the RfamTransform to add Rfam IDs to RNA data. ```APIDOC ## RfamTransform Example ### Description This example shows how to apply the `RfamTransform` to an `RNADataset` to add an 'rfam' field containing the Rfam ID to each RNA. ### Method N/A (Python code example) ### Endpoint N/A (Python code example) ### Parameters N/A (Python code example) ### Request Example ```python from rnaglib.transforms import RfamTransform from rnaglib.dataset import RNADataset dataset = RNADataset(debug=True) t = RfamTransform() dataset = t(dataset) print(dataset[2]['rna'].graph['rfam']) ``` ### Response #### Success Response (200) N/A (Python code example) #### Response Example ``` RF00005 ``` ``` -------------------------------- ### Initialize LigandIdentification Task Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.tasks.LigandIdentification.md Instantiates the LigandIdentification task class. This setup allows for filtering RNA structures by size and specifying which ligands to consider for the classification model. ```python from rnaglib.tasks import LigandIdentification # Initialize the task with custom thresholds and ligands task = LigandIdentification( size_thresholds=(20, 400), admissible_ligands=('PAR', 'LLL'), use_balanced_sampler=True ) ``` -------------------------------- ### Train Machine Learning Model on RNA Task Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/pages/quickstart.md Demonstrates how to load a predefined RNA task, set up a machine learning model, add a graph representation, and obtain data loaders for training, validation, and testing. It also includes an example of evaluating the model on test data. ```python from rnaglib.tasks import get_task from rnaglib.transforms import GraphRepresentation from rnaglib.learning.task_models import PygModel # Load task, representation, and get loaders task = get_task(root="my_root", task_id="rna_cm") model = PygModel.from_task(task) pyg_rep = GraphRepresentation(framework="pyg") task.add_representation(pyg_rep) train_loader, val_loader, test_loader = task.get_split_loaders(batch_size=8) for batch in train_loader: batch = batch['graph'].to(model.device) output = model(batch) test_metrics = model.evaluate(task, split='test') ``` -------------------------------- ### Load Task, Representation, and Get Data Loaders in rnaglib Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/tutorials/tuto_tasks.md This snippet demonstrates the basic workflow for setting up a machine learning task in rnaglib. It involves loading a task, defining a graph representation, and obtaining data loaders for training, validation, and testing. The code assumes the availability of a root directory for the task data and a specific task ID. ```python from rnaglib.tasks import get_task from rnaglib.transforms import GraphRepresentation from rnaglib.learning.task_models import PygModel # Load task, representation, and get loaders task = get_task(root="my_root", task_id="rna_cm") model = PygModel.from_task(task) pyg_rep = GraphRepresentation(framework="pyg") task.add_representation(pyg_rep) train_loader, val_loader, test_loader = task.get_split_loaders(batch_size=8) for batch in train_loader: batch = batch['graph'].to(model.device) output = model(batch) test_metrics = model.evaluate(task, split='test') ``` -------------------------------- ### PyTorch DataLoader Setup with Custom Collater Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/tasks/models/gmsm_model.ipynb Demonstrates how to set up PyTorch DataLoaders for training, validation, and testing. It utilizes a custom `Collater` class to handle batching of graph data, specifying batch sizes and shuffling behavior for each loader. ```python collater = Collater(train_set) train_loader = DataLoader(train_set, batch_size=1, shuffle=True, collate_fn=collater) val_loader = DataLoader(val_set, batch_size=2, shuffle=False, collate_fn=collater) test_loader = DataLoader(test_set, batch_size=2, shuffle=False, collate_fn=collater) ``` -------------------------------- ### Generate Python Code for RNAGLIB Task Setup Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/_static/interactive_codebox.html Dynamically generates Python code to set up an RNA task using RNAGLIB. It selects the task, representation, and data splitting strategy based on user input from HTML elements. The generated code includes necessary imports and configurations for the task. ```javascript function generateCode() { const taskId = document.getElementById('task-select').value; const representation = document.getElementById('representation-select').value; const splitType = document.getElementById('split-select').value; const repConfig = representations[representation]; let splitterImport = ''; let splitterCode = ''; if (splitType === 'random') { splitterImport = 'from rnaglib.dataset_transforms import RandomSplitter'; splitterCode = 'task.splitter = RandomSplitter()'; } else if (splitType === 'sequence') { splitterImport = 'from rnaglib.dataset_transforms import ClusterSplitter'; splitterCode = 'task.splitter = ClusterSplitter(distance_name="cd_hit")'; } else if (splitType === 'structure') { splitterImport = 'from rnaglib.dataset_transforms import ClusterSplitter'; splitterCode = 'task.splitter = ClusterSplitter(distance_name="USalign")'; } const imports = [ repConfig.import, 'from rnaglib.tasks import get_task', 'from rnaglib.learning.task_models import PygModel' ]; if (splitterImport) { imports.push(splitterImport); } const importSection = imports.join('\n'); let codeSection = `task.add_representation(${repConfig.variable})`; if (splitterCode) { codeSection += `\n${splitterCode}`; } const code = `${importSection} # Load task, representation, and get loaders task = get_task(root="my_root", task_id="${taskId}") ${codeSection} # Get data loaders train_loader, val_loader, test_loader = task.get_loaders(batch_size=32, num_workers=4) # Initialize model model = PygModel(task=task, representation=repConfig.variable) print(f"Generated code for task: {taskId}, representation: {representation}, split: {splitType}")`; document.getElementById('generated-code').textContent = code; } ``` -------------------------------- ### Load and Instantiate Tasks Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/task.md Demonstrates how to initialize tasks from local storage or download precomputed datasets from Zenodo. It highlights the caching mechanism that prevents redundant computations. ```python from rnaglib.tasks import BindingSite from rnaglib.tasks import DummyTask # Load local task task = DummyTask(root="test_task") # Download task from Zenodo task_site = BindingSite(root='my_root') ``` -------------------------------- ### Install RNAGLIB Package Source: https://github.com/cgoliver/rnaglib/blob/master/INSTALL.md Installs the core RNAGLIB package using pip. This is the primary method for getting the library into your Python environment. ```bash pip install rnaglib ``` -------------------------------- ### Initialize BindingSite Task Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Shows an alternative method to initialize a specific BindingSite task by instantiating the class directly. ```python from rnaglib.tasks import BindingSite task_site = BindingSite(root='toto') ``` -------------------------------- ### GET /algorithms/bfs Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.algorithms.bfs.md Performs a BFS traversal on a graph starting from initial nodes up to a specified depth. ```APIDOC ## GET /algorithms/bfs ### Description Executes a Breadth-First Search starting from seed nodes within a provided networkx graph. It explores the graph up to a defined number of hops. ### Method GET ### Endpoint rnaglib.algorithms.bfs(graph, initial_nodes, nc_block=False, depth=2, label='label') ### Parameters #### Path Parameters - **graph** (nx.Graph) - Required - The networkx graph object to traverse. - **initial_nodes** (node or iterable) - Required - The starting node or list of nodes for the BFS. #### Query Parameters - **depth** (int) - Optional - The number of hops to conduct from the root nodes. Defaults to 2. - **nc_block** (bool) - Optional - Whether to block non-coding regions. Defaults to False. - **label** (str) - Optional - The label attribute to use for nodes. Defaults to 'label'. ### Request Example { "graph": "", "initial_nodes": ["node1", "node2"], "depth": 3 } ### Response #### Success Response (200) - **nodes** (list) - A list of nodes reached during the BFS traversal. #### Response Example { "nodes": ["node1", "node2", "node3", "node4"] } ``` -------------------------------- ### Visualize RNA 2.5D Graph Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/tutorials/tuto_2.5d.md Visualizes the RNA 2.5D graph using the rnaglib drawing toolbox. Requires a working LaTeX installation for optimal plotting. If LaTeX is not detected, it falls back to using matplotlib's reduced features. The 'spring' layout is used in this example. ```python from rnaglib.drawing import rna_draw rna_draw(G, show=True, layout="spring") ``` -------------------------------- ### Manage Datasets and Splitting Source: https://context7.com/cgoliver/rnaglib/llms.txt Demonstrates dataset initialization, redundancy removal based on sequence/structure similarity, and creating PyTorch-compatible data loaders. ```python from rnaglib.dataset import RNADataset from rnaglib.dataset_transforms import RandomSplitter, ClusterSplitter, CDHitComputer, RedundancyRemover, Collater from torch.utils.data import DataLoader dataset = RNADataset(debug=True) random_splitter = RandomSplitter(split_train=0.7, split_valid=0.15) train_idx, val_idx, test_idx = random_splitter(dataset) cd_hit = CDHitComputer(similarity_threshold=0.9) dataset = cd_hit(dataset) nr_dataset = RedundancyRemover(distance_name="cd_hit", threshold=0.9)(dataset) collater = Collater(dataset) loader = DataLoader(dataset, batch_size=8, collate_fn=collater) ``` -------------------------------- ### Initialize SimFunctionNode Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.algorithms.SimFunctionNode.md Demonstrates how to instantiate the SimFunctionNode factory class to configure node similarity computation parameters such as method, depth, and normalization. ```python from rnaglib.algorithms import SimFunctionNode # Initialize the similarity function factory sim_func = SimFunctionNode( method="hungarian", depth=2, decay=0.5, idf=False, normalization="sqrt" ) ``` -------------------------------- ### Initialize RNADataset with Features and Representations Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Demonstrates how to set up an RNADataset by defining specific nucleotide features and targets, and selecting a graph representation framework like PyG. ```python from rnaglib.dataset import RNADataset from rnaglib.transforms import FeaturesComputer, GraphRepresentation fc = FeaturesComputer(nt_features=['nt_code'], nt_targets=['is_modified']) rep = GraphRepresentation(framework='pyg') dset = RNADataset(debug=True, features_computer=fc, representations=rep) dset[0] ``` -------------------------------- ### Initialize and Apply RNA Transforms Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/rna_transforms.md Demonstrates how to load an RNA dataset and apply a transformation to an RNA dictionary item. ```python from rnaglib.dataset import RNADataset from rnaglib.transforms import IdentityTransform # Load dataset dataset = RNADataset(debug=True) rna = dataset[10] # Apply transform t = IdentityTransform() new_rna = t(rna) ``` -------------------------------- ### Configure Features and Datasets Source: https://context7.com/cgoliver/rnaglib/llms.txt Demonstrates how to define input and target features using FeaturesComputer and initialize an RNADataset. It also shows how to access computed features and dynamically add custom features to the computer. ```python features_computer = FeaturesComputer(nt_features=["nt_code"], nt_targets=["binding_protein"]) dataset = RNADataset(debug=True, features_computer=features_computer) rna_dict = dataset[0] features_dict = features_computer(rna_dict) features_computer.add_feature(feature_names="nt_code", input_feature=True, feature_level="residue") print(f"Input dimension: {features_computer.input_dim}") ``` -------------------------------- ### Instantiate BindingSite Task in Python Source: https://github.com/cgoliver/rnaglib/blob/master/tutorial.ipynb Demonstrates how to instantiate a BindingSite task, a common benchmarking task for RNA analysis. This involves specifying a root directory for the dataset. Dependencies include the rnaglib.tasks module. ```python from rnaglib.tasks import BindingSite task_site = BindingSite(root='my_root') ``` ```python from rnaglib.tasks import BindingSite from rnaglib.transforms import FeaturesComputer task = BindingSite(root="my_root") ``` -------------------------------- ### Initialize RNA Task via get_task Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Demonstrates how to initialize an RNA task using the get_task utility, which automatically handles dataset downloading and loading from Zenodo. ```python from rnaglib.tasks import get_task task_site = get_task(root="test_site", task_id="rna_site") ``` -------------------------------- ### Initialize SmallMoleculeBindingTransform Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.transforms.SmallMoleculeBindingTransform.md Demonstrates how to instantiate the SmallMoleculeBindingTransform class. It requires a directory path to mmCIF files and allows configuration of distance cutoffs and mass limits for ligand filtering. ```python from rnaglib.transforms import SmallMoleculeBindingTransform # Initialize the transform with custom parameters transform = SmallMoleculeBindingTransform( structures_dir="/path/to/cifs", cutoffs=[4.0, 6.0, 8.0], mass_lower_limit=160, mass_upper_limit=1000, verbose=True ) ``` -------------------------------- ### Initialize and Apply BindingSiteAnnotator Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.transforms.BindingSiteAnnotator.md Demonstrates how to instantiate the BindingSiteAnnotator and apply it to an RNA dictionary object. This transform adds a binary feature to nodes indicating binding site status. ```python from rnaglib.transforms import BindingSiteAnnotator # Initialize the annotator transform = BindingSiteAnnotator(include_ions=True, cutoff=6.0) # Apply to an RNA dictionary object # rna_dict is expected to be a graph-like dictionary structure annotated_data = transform.forward(rna_dict) ``` -------------------------------- ### GET /tasks/ligand_identification/evaluate Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.tasks.LigandIdentification.md Evaluates model performance on a specified dataset loader. ```APIDOC ## GET /tasks/ligand_identification/evaluate ### Description Evaluates the provided model against the dataset using the specified data loader. ### Method GET ### Endpoint /tasks/ligand_identification/evaluate ### Parameters #### Query Parameters - **model** (object) - Required - The trained model instance. - **loader** (object) - Required - The data loader containing the evaluation set. ### Request Example { "model": "model_instance", "loader": "test_loader" } ### Response #### Success Response (200) - **metrics** (object) - Dictionary containing performance metrics. #### Response Example { "metrics": { "accuracy": 0.95, "f1_score": 0.92 } } ``` -------------------------------- ### Execute ML Benchmark Tasks Source: https://context7.com/cgoliver/rnaglib/llms.txt Illustrates how to initialize pre-built RNA machine learning tasks such as binding site prediction or chemical modification. It includes retrieving data loaders and iterating through batches for training. ```python task = BindingSite(root="./binding_site_task", debug=True) task.add_representation(GraphRepresentation(framework="pyg")) train_loader, val_loader, test_loader = task.get_split_loaders(batch_size=8) for batch in train_loader: graph = batch['graph'] print(f"Batch nodes: {graph.x.shape[0]}") break ``` -------------------------------- ### GET /tasks/evaluate Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.tasks.ClassificationTask.md Evaluates a trained model against a specified dataset loader. ```APIDOC ## GET /tasks/evaluate ### Description Runs evaluation on a model using the provided dataloader to compute performance metrics. ### Method GET ### Endpoint /tasks/evaluate ### Parameters #### Query Parameters - **model** (object) - Required - The model instance to evaluate. - **loader** (object) - Required - The dataloader containing the test set. ### Request Example { "model": "model_instance", "loader": "test_loader" } ### Response #### Success Response (200) - **metrics** (object) - Calculated performance metrics. #### Response Example { "accuracy": 0.95, "f1_score": 0.92 } ``` -------------------------------- ### Filter Transform Example Source: https://github.com/cgoliver/rnaglib/blob/master/tutorial.ipynb Demonstrates using a SizeFilter to filter RNAs based on their size. ```APIDOC ## Filter Transform Example ### Description Applies a `SizeFilter` to an RNA object. This filter checks if the RNA's size is within the specified maximum limit. ### Method ```python from rnaglib.transforms import SizeFilter t = SizeFilter(max_size=200) t(rna) # Assuming 'rna' is an RNA object ``` ### Response Example ``` True ``` ``` -------------------------------- ### GET /rnaglib/dataset_transforms/get_loader Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.dataset_transforms.get_loader.md Retrieves a DataLoader or a set of split DataLoaders for a provided RNADataset object. ```APIDOC ## GET rnaglib.dataset_transforms.get_loader ### Description Fetches a loader object for a given dataset, with optional support for splitting the data into training, validation, and testing sets. ### Method GET ### Endpoint rnaglib.dataset_transforms.get_loader ### Parameters #### Query Parameters - **dataset** (RNADataset) - Required - The dataset object to load. - **batch_size** (int) - Optional - Number of items per batch (default: 5). - **num_workers** (int) - Optional - Number of worker processes (default: 0). - **split** (bool) - Optional - Whether to compute train/val/test splits (default: True). - **split_train** (float) - Optional - Proportion of dataset for training (default: 0.7). - **split_valid** (float) - Optional - Proportion of dataset for validation (default: 0.85). - **verbose** (bool) - Optional - Print updates during loading (default: False). - **persistent_workers** (bool) - Optional - Keep workers alive between epochs (default: True). ### Request Example { "dataset": "", "batch_size": 32, "split": true } ### Response #### Success Response (200) - **loaders** (DataLoader | Tuple) - Returns a single DataLoader if split=False, or a tuple of (train_loader, valid_loader, test_loader) if split=True. #### Response Example { "status": "success", "data": "(train_loader, valid_loader, test_loader)" } ``` -------------------------------- ### Initialize GCN Model and Training Configuration Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/tasks/models/IF_model.ipynb Sets up the GCN model architecture based on dataset input dimensions and class counts. Configures the device, optimizer, and loss function for training. ```python num_classes = train_loader.dataset[0]['graph'].y.size(1) model = GCN(train_set.input_dim, num_classes) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = model.to(device) optimizer = optim.Adam(model.parameters(), lr=0.0001) criterion = torch.nn.CrossEntropyLoss() ``` -------------------------------- ### GET /rna_from_pdbid Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/rnaglib.dataset.md Fetches an annotated graph representation of an RNA structure using its PDB identifier. ```APIDOC ## GET /rna_from_pdbid ### Description Retrieves an annotated graph object for a specific RNA structure identified by its PDBID. ### Method GET ### Endpoint /rnaglib.dataset.rna_from_pdbid ### Parameters #### Query Parameters - **pdbid** (string) - Required - The PDB identifier of the RNA structure. - **version** (string) - Optional - The dataset version to retrieve. - **annotated** (boolean) - Optional - Whether to return the annotated version of the graph. ### Response #### Success Response (200) - **rna_object** (dictionary) - A dictionary representation of the RNA graph structure. #### Response Example { "nodes": [...], "edges": [...], "metadata": {...} } ``` -------------------------------- ### Initialize and Subset RNADataset Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/dataset.md Demonstrates how to instantiate an RNADataset with specific versions and redundancy levels, and how to create subsets using lists of RNA names or IDs. ```python from rnaglib.dataset import RNADataset # Initialize dataset dataset = RNADataset(in_memory=False, version="2.0.2", redundancy="nr") # Subset by names or IDs rna_names = ['1a9n', '1av6', '1b23'] rna_ids = [0, 1, 2] subset1 = RNADataset(in_memory=False, version="2.0.2", redundancy="nr", rna_id_subset=rna_names) subset2 = dataset.subset(list_of_names=rna_names) subset3 = dataset.subset(list_of_ids=rna_ids) ``` -------------------------------- ### RNADataset Initialization and Subsetting Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/dataset.md How to instantiate an RNADataset with specific versions and redundancy levels, and how to create subsets of the data. ```APIDOC ## POST /dataset/initialize ### Description Initializes a new RNADataset instance. Users can specify the version and redundancy level to filter the dataset upon creation. ### Method POST ### Parameters #### Request Body - **in_memory** (boolean) - Optional - Whether to load the dataset into memory. - **version** (string) - Optional - The dataset version (e.g., "2.0.2"). - **redundancy** (string) - Optional - Redundancy level (e.g., "nr"). - **rna_id_subset** (list) - Optional - A list of RNA names to include in the subset. ### Request Example { "version": "2.0.2", "redundancy": "nr", "rna_id_subset": ["1a9n", "1av6"] } ### Response #### Success Response (200) - **dataset_id** (string) - The identifier for the initialized dataset. ## POST /dataset/subset ### Description Creates a subset of an existing dataset based on provided names or IDs. ### Method POST ### Parameters #### Request Body - **list_of_names** (list) - Optional - List of RNA names to subset. - **list_of_ids** (list) - Optional - List of RNA IDs to subset. ### Request Example { "list_of_names": ["1a9n", "1av6"] } ``` -------------------------------- ### GET /rnaglib/tasks Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/index.md Retrieves metadata and descriptions for various RNA-related machine learning tasks supported by the library. ```APIDOC ## GET /rnaglib/tasks ### Description Provides details on available biological tasks, including the task type (e.g., binary classification) and its biological significance. ### Method GET ### Endpoint /rnaglib/tasks ### Parameters #### Query Parameters - **task_id** (string) - Required - The identifier for the task (e.g., 'rna_cm', 'rna_go'). ### Request Example GET /rnaglib/tasks?task_id=rna_cm ### Response #### Success Response (200) - **name** (string) - Human-readable name of the task. - **description** (string) - Detailed explanation of the task type and biological meaning. #### Response Example { "name": "Chemical Modification", "description": "Task type: Binary classification (residue-level). Predicts whether a given residue is chemically modified." } ``` -------------------------------- ### Transform Usage Example Source: https://github.com/cgoliver/rnaglib/blob/master/tutorial.ipynb Illustrates the use of the Transform class, specifically IdentityTransform, to process an individual RNA object. ```APIDOC ## Transform Usage Example ### Description Applies an `IdentityTransform` to an RNA object obtained from the dataset. The `IdentityTransform` returns the RNA object unchanged. ### Method ```python from rnaglib.transforms import IdentityTransform rna = dataset[10] # Assuming dataset is already initialized t = IdentityTransform() new_rna = t(rna) ``` ### Response Example ```json { "rna": "", "graph_path": "PosixPath('/home/vincent/.rnaglib/datasets/rnaglib-nr-2.0.2/graphs/1d4r.json')", "cif_path": "PosixPath('/home/vincent/.rnaglib/structures/1d4r.cif')" } ``` ``` -------------------------------- ### Accessing RNAglib CLI help Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/prepare_data/README.md Displays the help menu for the rnaglib_prepare_data command line interface to view available arguments and usage instructions. ```bash rnaglib_prepare_data -h ``` -------------------------------- ### GET /rnaglib/representations Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/index.md Retrieves the configuration and instantiation code for various RNA data representations used in the RNAGlib library. ```APIDOC ## GET /rnaglib/representations ### Description Retrieves the necessary Python code to instantiate specific data representations for RNA structures. Users can choose between Graph, Voxel, Point Cloud, or Sequence formats. ### Method GET ### Endpoint /rnaglib/representations ### Parameters #### Query Parameters - **type** (string) - Required - The representation type: 'graph', 'voxel', 'point_cloud', or 'sequence'. ### Request Example GET /rnaglib/representations?type=graph ### Response #### Success Response (200) - **import** (string) - The Python import statement. - **instantiation** (string) - The class instantiation code. - **variable** (string) - The recommended variable name. #### Response Example { "import": "from rnaglib.transforms import GraphRepresentation", "instantiation": "GraphRepresentation(framework=\"pyg\")", "variable": "pyg_rep" } ``` -------------------------------- ### Initialize RNADataset Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.dataset.RNADataset.md Demonstrates how to create an instance of the RNADataset class. This can be done with default parameters to load a standard dataset or with custom parameters to specify data sources, versions, and processing options. ```python from rnaglib.dataset import RNADataset dataset = RNADataset() ``` -------------------------------- ### GET rnaglib.dataset.rna_from_pdbid Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.dataset.rna_from_pdbid.md Fetches an annotated RNA graph object based on a provided PDB ID and configuration parameters. ```APIDOC ## GET rnaglib.dataset.rna_from_pdbid ### Description Retrieves an annotated RNA graph dictionary object from the rnaglib database using a PDB ID. ### Method GET ### Endpoint rnaglib.dataset.rna_from_pdbid(pdbid, version='2.0.0', annotated=False, chop=False, redundancy='nr', download_dir=None, verbose=True) ### Parameters #### Path Parameters - **pdbid** (string) - Required - The PDB identifier to fetch. #### Query Parameters - **version** (string) - Optional - Database version to query (default: '2.0.0'). - **annotated** (boolean) - Optional - Whether to fetch annotated graphs (default: False). - **chop** (boolean) - Optional - Whether to chop the graph (default: False). - **redundancy** (string) - Optional - Redundancy filter (default: 'nr'). - **download_dir** (string) - Optional - Path containing annotated graphs. - **verbose** (boolean) - Optional - Enable verbose output (default: True). ### Response #### Success Response (200) - **RNA dictionary object** (dict) - The retrieved RNA graph structure. ### Response Example { "pdbid": "1EHZ", "nodes": [...], "edges": [...] } ``` -------------------------------- ### Loading and Saving Tasks Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/task.md Demonstrates how to create, save, and load tasks, highlighting the caching mechanism that prevents recomputation. ```APIDOC ## Loading a Task Once created, tasks can be saved and loaded seamlessly. ### Method ```default >>> task = DummyTask(root="test_task") >>> task = DummyTask(root="test_task") Task was found and not overwritten ``` Observe that on second call, the computations were not run a second time. Moreover, for the set of proposed tasks (available in the `rnaglib.task.TASKS` variable), we host precomputed tasks on Zenodo. ### Method ```default >>> from rnaglib.tasks import BindingSite >>> task_site = BindingSite(root='my_root') Downloading task dataset from Zenodo... Done ``` Users can access our tasks by id, using `rnaglib.task.get_task` small function. ``` -------------------------------- ### Class: rnaglib.transforms.PartitionFromDict Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.transforms.PartitionFromDict.md Documentation for initializing and using the PartitionFromDict transformation class. ```APIDOC ## CLASS rnaglib.transforms.PartitionFromDict ### Description Partitions an RNA structure according to a partition defined in a dictionary. This transformation breaks down a single RNA into multiple sub-RNAs based on specified residue groupings. ### Parameters - **partition_dict** (dict) - Required - A dictionary where keys are RNA names and values are lists of lists, each containing residue names for a specific sub-RNA. ### Methods - **__init__(partition_dict, **kwargs)**: Initializes the partitioner with the provided dictionary. - **forward(rna_dict)**: Applies the partition transformation to the input RNA dictionary. - **new_name(rna_partition)**: Computes the name for the resulting sub-RNA partition. ### Usage Example ```python from rnaglib.transforms import PartitionFromDict partition_map = {'RNA_1': [['res1', 'res2'], ['res3', 'res4']]} transformer = PartitionFromDict(partition_dict=partition_map) # Apply to an rna_dict # result = transformer.forward(rna_dict) ``` ``` -------------------------------- ### Data Access Patterns Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/data_reference/rna_ref.md Examples for loading the graph data and accessing individual node attributes within the RNAGlib framework. ```APIDOC ## Data Access Patterns ### Description How to load the graph into a NetworkX object and access specific residue attributes. ### Code Example ```python import json from networkx.readwrite.json_graph import node_link_graph # Load the graph G = node_link_graph(open('path/to/graph', 'r')) # Access node data by ID # Node IDs follow the format: [pdb id].[chain name].[residue number] node_data = G.nodes['1RNA.A.101'] # Common attributes include: # - nt_name: Nucleotide name # - nt_resnum: PDB residue number # - sse: Secondary structure information # - binding_protein: RNA-Protein interface data ``` ``` -------------------------------- ### BindingSiteAnnotator Class Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.transforms.BindingSiteAnnotator.md Documentation for the BindingSiteAnnotator class and its initialization parameters. ```APIDOC ## CLASS rnaglib.transforms.BindingSiteAnnotator ### Description Annotation transform adding to each node of the dataset a binary node feature indicating whether it is part of a binding site. ### Parameters - **include_ions** (bool) - Optional - If set to False, only small-molecule-binding RNA residues are considered. If True, ion-binding RNA residues are also included. Default: False. - **cutoff** (float) - Optional - The maximal distance (in Angstroms) between an RNA residue and any small molecule or ion atom. Supported values: 4.0, 6.0, 8.0. Default: 6.0. ### Methods - **__init__(include_ions=False, cutoff=6.0)**: Initializes the annotator. - **forward(rna_dict)**: Applies the transformation to an RNA dictionary object. ``` -------------------------------- ### GET /rnaglib/utils/download_graphs Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_index/generated/rnaglib.utils.download_graphs.md Downloads RNA graph data from the latest release based on specified parameters and saves it to the local directory. ```APIDOC ## GET rnaglib.utils.download_graphs ### Description Retrieves RNA graph data from the latest release and stores it in the specified download directory. Supports filtering for non-redundant sets and including graphlet annotations. ### Method GET ### Endpoint rnaglib.utils.download_graphs ### Parameters #### Query Parameters - **redundancy** (string) - Optional - Whether to include all RNAs or just a non-redundant set (default: 'nr') - **version** (string) - Optional - The version of the dataset to retrieve (default: '2.0.2') - **annotated** (boolean) - Optional - Whether to include graphlet annotations (default: False) - **chop** (boolean) - Optional - Whether to chop the data (default: False) - **overwrite** (boolean) - Optional - Whether to overwrite existing data (default: False) - **data_root** (string) - Optional - Custom directory path to save the data (default: ~/.rnaglib/) - **verbose** (boolean) - Optional - Enable verbose logging (default: False) - **get_pdbs** (boolean) - Optional - Whether to store associated PDBs (default: False) - **debug** (boolean) - Optional - Enable debug mode (default: False) ### Response #### Success Response (200) - **path** (string) - The file system path where the data and hashing information are stored. #### Response Example { "data_path": "~/.rnaglib/graphs/2.0.2/nr", "hashing_path": "~/.rnaglib/graphs/2.0.2/hashing" } ``` -------------------------------- ### Applying Dataset Transformations Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Demonstrates the application of several dataset transformations including CDHitComputer, StructureDistanceComputer, and RedundancyRemover. It also shows how to compute and access distance matrices. ```python from rnaglib.dataset import RNADataset rna_names = ['1a9n', '1av6', '1b23'] dataset = RNADataset(rna_id_subset=rna_names) from rnaglib.dataset_transforms import CDHitComputer, RandomSplitter from rnaglib.dataset_transforms import StructureDistanceComputer dataset = CDHitComputer()(dataset) dataset = StructureDistanceComputer()(dataset) dataset.distances ``` ```python from rnaglib.dataset_transforms import RedundancyRemover usalign_rr = RedundancyRemover(distance_name="USalign", threshold=0.8) dataset_non_redundant = usalign_rr(dataset) len(dataset_non_redundant) ``` -------------------------------- ### GET /data/graph Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/data_reference/rna_ref.md Retrieves the RNA structure graph for a specific PDB entry. The graph is provided in a JSON node-link format compatible with NetworkX. ```APIDOC ## GET /data/graph ### Description Retrieves the structural graph for a PDB entry. The graph contains nodes representing residues and edges representing interactions, stored in JSON node-link format. ### Method GET ### Endpoint /data/graph ### Parameters #### Query Parameters - **pdb_id** (string) - Required - The 4-character PDB identifier. ### Request Example GET /data/graph?pdb_id=1RNA ### Response #### Success Response (200) - **graph** (object) - A NetworkX compatible node-link JSON object. #### Response Example { "directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "1RNA.A.1", "nt_name": "G", "nt_resnum": 1, ...}], "links": [{"source": "1RNA.A.1", "target": "1RNA.A.2", "type": "backbone"}] } ``` -------------------------------- ### Initialize and Prepare RNA Dataset Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/tasks/depr/model_experimental.ipynb Initializes a benchmark dataset for ligand binding site detection and adds a PyTorch Geometric graph representation. This process requires the rnaglib library and handles dataset directory management. ```python import shutil from rnaglib.tasks import BenchmarkLigandBindingSiteDetection from rnaglib.representations import GraphRepresentation shutil.rmtree('test_fri') ta = BenchmarkLigandBindingSiteDetection(root='test_fri') ta.dataset.add_representation(GraphRepresentation(framework='pyg')) ``` -------------------------------- ### Defining a Custom Task for Residue Classification Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Provides an example of defining a custom task class, DummyTask, that inherits from ResidueClassificationTask. It specifies input and target variables and a default splitter. ```python from rnaglib.tasks import ResidueClassificationTask from rnaglib.dataset import RNADataset from rnaglib.transforms import FeaturesComputer from rnaglib.dataset_transforms import RandomSplitter class DummyTask(ResidueClassificationTask): input_var = "nt_code" target_var = "is_modified" name = "rna_dummy" def __init__(self, **kwargs): super().__init__(additional_metadata={"multi_label": False}, **kwargs) def process(self) -> RNADataset: return RNADataset(in_memory=self.in_memory, debug=True) def post_process(self): pass def get_task_vars(self) -> FeaturesComputer: return FeaturesComputer(nt_features=self.input_var, nt_targets=self.target_var) @property def default_splitter(self): return RandomSplitter() task = DummyTask(root="test_task") ``` -------------------------------- ### Compute Features and Targets for RNA with RNAGLIB Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/reproduce_snippets.ipynb Utilizes the FeaturesComputer transform from rnaglib.transforms to compute nucleotide features and targets. This example computes 'nt_code' features and 'is_modified' targets for the RNA structure. ```python from rnaglib.transforms import FeaturesComputer ft = FeaturesComputer(nt_features=['nt_code'], nt_targets=['is_modified']) features_dict = ft(rna) features_dict ``` -------------------------------- ### Run Training Process (Python) Source: https://github.com/cgoliver/rnaglib/blob/master/src/rnaglib/tasks/depr/model_experimental.ipynb Sets the computation device (GPU or CPU) and initiates the GCN model training loop. It iterates for a specified number of epochs, calling the `train` and `test` functions, and logs the training and validation accuracy using Weights & Biases. ```python device = 'cuda' if torch.cuda.is_available() else 'cpu' model = model.to(device) for epoch in range(50): train() train_acc = test(train_loader) val_acc = test(val_loader) print(f'Epoch: {epoch}, Train Acc: {train_acc:.4f}, Val Acc: {val_acc:.4f}') wandb.log({"train_acc": train_acc, "val_acc": val_acc}) ``` -------------------------------- ### Load and Train with RNAGlib Tasks Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/index.md Demonstrates how to initialize a task, load a model, and iterate through data loaders for training. This snippet assumes a configured task and representation. ```python task = get_task(root="my_root", task_id="${taskId}") model = PygModel.from_task(task) ${repConfig.variable} = ${repConfig.instantiation} train_loader, val_loader, test_loader = task.get_split_loaders(batch_size=8) for batch in train_loader: batch = batch[${repConfig.variable}.name].to(model.device) output = model(batch) test_metrics = model.evaluate(task, split='test') ``` -------------------------------- ### Full Implementation of a Residue Classification Task Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/tutorials/tuto_custom_task.md A complete example of a custom task class inheriting from ResidueClassificationTask. It includes initialization, feature definition, data processing with filters, and default splitting logic. ```python from rnaglib.dataset import RNADataset from rnaglib.tasks import ResidueClassificationTask from rnaglib.transforms import FeaturesComputer, ResidueAttributeFilter, PDBIDNameTransform from rnaglib.dataset_transforms import Splitter, ClusterSplitter class ChemicalModification(ResidueClassificationTask): target_var = "is_modified" def get_task_vars(self): return FeaturesComputer(nt_targets=self.target_var) def process(self): rnas = ResidueAttributeFilter(attribute=self.target_var, value_checker=lambda val: val == True)(RNADataset(debug=self.debug)) rnas = PDBIDNameTransform()(rnas) return RNADataset(rnas=[r["rna"] for r in rnas]) def default_splitter(self) -> Splitter: return ClusterSplitter(distance_name="USalign", similarity_threshold=0.6) ``` -------------------------------- ### Initialize RNADataset with a Subset Source: https://github.com/cgoliver/rnaglib/blob/master/docs/source/code_architecture/dataset_transforms.md Demonstrates how to create an RNADataset instance by specifying a subset of RNA IDs. This is useful for working with specific datasets. ```python from rnaglib.dataset import RNADataset rna_names = ['1a9n', '1av6', '1b23'] dataset = RNADataset(rna_id_subset=rna_names) ```