UTRGAN

Model Introduction

UTRGAN is a generative and optimization framework for 5′ UTR design. It can generate candidate 5′ UTR sequences and predict and rank them according to gene expression, Mean Ribosome Load (MRL), and Translation Efficiency (TE).

The Hugging Face model package already contains the data and pretrained weights required for the basic workflow, so no additional model files need to be downloaded during inference.

Model Description

UTRGAN consists of multiple cooperating models:

  • WGAN-GP Generator: Generates candidate 5′ UTR sequences of up to 128 nt from a 40-dimensional random latent vector;
  • WGAN-GP Critic: Used during generative-model training;
  • Xpresso: Predicts gene-expression-related scores;
  • FramePool: Predicts Mean Ribosome Load (MRL);
  • MTtrans: Predicts Translation Efficiency (TE);
  • G4Boost: Performs G4-related classification and regression analyses.

WGAN, Xpresso, and FramePool use TensorFlow/Keras, while MTtrans uses PyTorch.

To maintain compatibility with the legacy H5 model files released by the original projects, Legacy Keras is used when loading the corresponding models.

Use Cases

Use Case Description
5′ UTR candidate generation Generate 5′ UTR candidate sequences in batches using the official pretrained WGAN.
MRL prediction and ranking Use FramePool to calculate MRL scores and rank candidate sequences.
TE prediction and ranking Use MTtrans to calculate TE scores and rank candidate sequences.
MRL/TE-directed optimization Freeze the pretrained models and optimize the latent noise to improve the target score.
Gene-expression optimization Combine UTRGAN with Xpresso to evaluate gene-expression-related properties of candidate sequences.
WGAN-GP training Validate or retrain the generative model using the included UTRdb2 dataset.

Usage

1. OneCode

You can use the OneCode online environment for an intelligent one-click AI4S programming experience:

Try OneCode for AI4S Programming

2. Manual Installation

Hardware Requirements

  • CPU inference is supported;
  • A OneScience-supported DCU environment is recommended for batch generation, ranking, and training;
  • TensorFlow and PyTorch access the same DCU through their compatible accelerator interfaces;
  • Full training time depends on the number of candidate sequences, batch size, and device performance.

Download the Model Package

Install the Hugging Face command-line tool and download the model repository:

python -m pip install -U huggingface_hub

hf download OneScience-Group/UTRGAN --local-dir ./UTRGAN
cd UTRGAN

Install the Runtime Environment

Create and activate a Python 3.11 environment, and then install the OneScience bioscience base environment:

conda create -n utrgan python=3.11 -y
conda activate utrgan

pip install onescience[bio-dcu]

Then install the additional or replacement dependencies specified in requirements.txt:

python -m pip install --no-deps -r requirements.txt

Note: This model adaptation uses DTK 26.04. The corresponding TensorFlow runtime has also been upgraded to TensorFlow 2.18.

Check the frameworks and available devices:

python - <<'PY'
import tensorflow as tf
import torch

print("TensorFlow:", tf.__version__)
print("TensorFlow devices:", tf.config.list_physical_devices("GPU"))
print("PyTorch:", torch.__version__)
print("HIP:", torch.version.hip)
print("DCU available:", torch.cuda.is_available())
PY

Weights and Data Preparation

The Hugging Face model package already contains the resources required for basic generation, prediction, ranking, and training validation:

Resource Location Purpose
UTRdb2 conf/data/utrdb2.csv WGAN-GP training data
Motif data conf/data/motifs.csv Motif statistics and optimization analysis
WGAN Generator weight/checkpoint_3000.h5 Generate candidate 5′ UTR sequences
FramePool weight/utr_model_combined_residual_new.h5 MRL prediction
Xpresso weight/humanMedian_trainepoch.11-0.426.h5 Gene-expression-related prediction
Xpresso weight/GM12878_trainepoch.06-0.5062.h5 GM12878 expression-related prediction
Xpresso weight/K562_trainepoch.11-0.4917.h5 K562 expression-related prediction
MTtrans weight/mttrans/RL_hard_share_MTL/3R/schedule_MTL-model_best_cv1.pth TE prediction
G4Boost weight/G4Boost_classifier.json G4 classification
G4Boost weight/G4Boost_regressor.json G4 regression

After applying the filtering and deduplication logic used by the official training scripts, UTRdb2 contains approximately 33,250 sequences with lengths between 65 and 128 nt.

The basic workflow does not require additional dataset downloads or precomputed features.

Optional Dependencies

requirements.txt includes XGBoost, ViennaRNA, logomaker, ruptures, and cliffs-delta for G4-related and downstream analysis scripts.

NUPACK is used only by optional MFE preprocessing scripts.

Because NUPACK 4 must be obtained and installed separately according to the licensing and installation requirements of its publisher, it is not automatically installed through standard PyPI dependencies in this model package.

NUPACK is not required for:

  • Basic inference;
  • MRL ranking;
  • TE ranking;
  • WGAN-GP training.

Quick Inference

Use the official pretrained WGAN to generate candidate sequences and rank them independently by MRL and TE.

Purpose: Generate 5′ UTR candidates in batches on DCU and output separate MRL and TE ranking results.

python scripts/predict.py \
  --device dcu \
  --device-id 0 \
  --num-candidates 1024 \
  --batch-size 128 \
  --seed 33 \
  --output-dir outputs/pretrained_batch_ranking

The results are saved to:

outputs/pretrained_batch_ranking/
├── all_candidates_scores.csv
├── ranked_by_mrl.csv
├── ranked_by_te.csv
├── generator_probabilities.npy
└── summary.json

The output files contain:

  • all_candidates_scores.csv: all candidate sequences together with their MRL and TE prediction scores;
  • ranked_by_mrl.csv: candidates ranked from highest to lowest MRL score;
  • ranked_by_te.csv: candidates ranked from highest to lowest TE score;
  • is_duplicate: indicates whether a generated sequence is duplicated;
  • MRL and TE are measured on different scales and their raw scores should not be directly added together.

MRL-Directed Optimization

Purpose: Freeze the WGAN and FramePool models and optimize the latent noise to increase the predicted MRL score of generated candidates.

python scripts/optimize_te_mrl.py \
  -gpu 0 \
  -task mrl \
  -bs 64 \
  -s 10 \
  --output-dir outputs/optimization_mrl

During this process, the WGAN and FramePool model weights remain frozen. Only the latent noise is updated.

TE-Directed Optimization

Purpose: Freeze the WGAN and MTtrans models and optimize the latent noise to increase the predicted TE score of generated candidates.

python scripts/optimize_te_mrl.py \
  -gpu 0 \
  -task te \
  -bs 64 \
  -s 10 \
  --output-dir outputs/optimization_te

During this process, the WGAN and MTtrans model weights remain frozen.

Therefore, this workflow is latent-space optimization rather than fine-tuning of the pretrained models.

Training

UTRGAN supports WGAN-GP training.

The trainable components in this workflow are:

  • Generator;
  • Critic.

Xpresso, FramePool, and MTtrans do not participate in this training entry point.

To run one epoch using the complete data-processing pipeline and the UTRdb2 dataset included in the repository:

python scripts/train.py \
  -gpu 0 \
  -bs 64 \
  -lr 5 \
  -mxl 128 \
  -dim 40 \
  --epochs 1 \
  --output-dir outputs/train_1epoch

According to the upstream README, -lr 5 corresponds to a learning rate of:

1e-5

The adapted training entry point adds the --epochs argument and corrects the learning-rate expression in the upstream script so that it is consistent with the documented definition.

To run the full upstream training configuration, use the complete UTRdb2 training dataset for 4000 epochs:

python scripts/train.py \
  -gpu 0 \
  -bs 64 \
  -lr 5 \
  -mxl 128 \
  -dim 40 \
  --epochs 4000 \
  --output-dir outputs/train_full

This retrains the WGAN-GP Generator and Critic.

Full training can require substantial runtime. Training progress should be evaluated according to available accelerator resources and training logs.

Generated checkpoints are saved in the specified output directory and do not overwrite the official pretrained weights under:

weight/

OneScience Official Resources

Platform OneScience Main Repository Skills Repository
Gitee OneScience OneSkills
GitHub OneScience OneSkills

Citation and License


中文说明

模型简介

UTRGAN 是一个用于 5′ UTR 设计的生成与优化框架。它可以生成候选 5′ UTR 序列,并依据基因表达、平均核糖体负载(Mean Ribosome Load, MRL)和翻译效率(Translation Efficiency, TE)对其进行预测和排序。

Hugging Face 模型包已经包含了基础流程所需的数据和预训练权重,因此推理时无需额外下载模型文件。

模型描述

UTRGAN 由多个协同工作的模型组成:

  • WGAN-GP 生成器: 从 40 维随机隐向量生成长度至多 128 nt 的候选 5′ UTR 序列;
  • WGAN-GP 判别器(Critic): 用于生成模型的训练过程;
  • Xpresso: 预测与基因表达相关的分数;
  • FramePool: 预测平均核糖体负载(MRL);
  • MTtrans: 预测翻译效率(TE);
  • G4Boost: 执行 G4 相关的分类与回归分析。

WGAN、Xpresso 和 FramePool 使用 TensorFlow/Keras,而 MTtrans 使用 PyTorch。

为了与原始项目发布的旧版 H5 模型文件保持兼容,加载相应模型时使用 Legacy Keras。

应用场景

应用场景 说明
5′ UTR 候选序列生成 使用官方预训练的 WGAN 批量生成 5′ UTR 候选序列。
MRL 预测与排序 使用 FramePool 计算 MRL 分数并对候选序列排序。
TE 预测与排序 使用 MTtrans 计算 TE 分数并对候选序列排序。
MRL/TE 定向优化 冻结预训练模型,优化隐空间噪声以提升目标分数。
基因表达优化 将 UTRGAN 与 Xpresso 结合,评估候选序列与基因表达相关的性质。
WGAN-GP 训练 使用内置的 UTRdb2 数据集验证或重新训练生成模型。

使用方式

1. OneCode

您可以使用 OneCode 在线环境体验一键智能 AI4S 编程:

体验 OneCode AI4S 编程

2. 手动安装

硬件要求

  • 支持 CPU 推理;
  • 批量生成、排序和训练推荐使用 OneScience 支持的 DCU 环境;
  • TensorFlow 和 PyTorch 通过各自兼容的加速器接口访问同一块 DCU;
  • 完整训练时间取决于候选序列数量、批大小和设备性能。

下载模型包

安装 Hugging Face 命令行工具并下载模型仓库:

python -m pip install -U huggingface_hub

hf download OneScience-Group/UTRGAN --local-dir ./UTRGAN
cd UTRGAN

安装运行环境

创建并激活 Python 3.11 环境,然后安装 OneScience 生物科学基础环境:

conda create -n utrgan python=3.11 -y
conda activate utrgan

pip install onescience[bio-dcu]

然后安装 requirements.txt 中指定的额外依赖或替换依赖:

python -m pip install --no-deps -r requirements.txt

注意: 本模型适配使用 DTK 26.04。相应的 TensorFlow 运行时也已升级到 TensorFlow 2.18。

检查框架和可用设备:

python - <<'PY'
import tensorflow as tf
import torch

print("TensorFlow:", tf.__version__)
print("TensorFlow devices:", tf.config.list_physical_devices("GPU"))
print("PyTorch:", torch.__version__)
print("HIP:", torch.version.hip)
print("DCU available:", torch.cuda.is_available())
PY

权重与数据准备

Hugging Face 模型包已经包含了基础生成、预测、排序和训练验证所需的资源:

资源 位置 用途
UTRdb2 conf/data/utrdb2.csv WGAN-GP 训练数据
Motif 数据 conf/data/motifs.csv Motif 统计与优化分析
WGAN 生成器 weight/checkpoint_3000.h5 生成候选 5′ UTR 序列
FramePool weight/utr_model_combined_residual_new.h5 MRL 预测
Xpresso weight/humanMedian_trainepoch.11-0.426.h5 基因表达相关预测
Xpresso weight/GM12878_trainepoch.06-0.5062.h5 GM12878 表达相关预测
Xpresso weight/K562_trainepoch.11-0.4917.h5 K562 表达相关预测
MTtrans weight/mttrans/RL_hard_share_MTL/3R/schedule_MTL-model_best_cv1.pth TE 预测
G4Boost weight/G4Boost_classifier.json G4 分类
G4Boost weight/G4Boost_regressor.json G4 回归

在应用官方训练脚本所使用的过滤和去重逻辑后,UTRdb2 包含约 33,250 条长度在 65 至 128 nt 之间的序列。

基础流程不需要额外下载数据集或预先计算特征。

可选依赖

requirements.txt 包含 XGBoost、ViennaRNA、logomaker、ruptures 和 cliffs-delta,供 G4 相关脚本和下游分析脚本使用。

NUPACK 仅被可选的 MFE 预处理脚本使用。

由于 NUPACK 4 必须按照其发布方的许可和安装要求单独获取并安装,本模型包不会通过标准 PyPI 依赖自动安装它。

以下场景不需要 NUPACK:

  • 基础推理;
  • MRL 排序;
  • TE 排序;
  • WGAN-GP 训练。

快速推理

使用官方预训练的 WGAN 生成候选序列,并分别按 MRL 和 TE 独立排序。

目的: 在 DCU 上批量生成 5′ UTR 候选序列,并分别输出 MRL 和 TE 的排序结果。

python scripts/predict.py \
  --device dcu \
  --device-id 0 \
  --num-candidates 1024 \
  --batch-size 128 \
  --seed 33 \
  --output-dir outputs/pretrained_batch_ranking

结果保存到:

outputs/pretrained_batch_ranking/
├── all_candidates_scores.csv
├── ranked_by_mrl.csv
├── ranked_by_te.csv
├── generator_probabilities.npy
└── summary.json

输出文件包含:

  • all_candidates_scores.csv:所有候选序列及其 MRL 和 TE 预测分数;
  • ranked_by_mrl.csv:按 MRL 分数从高到低排序的候选序列;
  • ranked_by_te.csv:按 TE 分数从高到低排序的候选序列;
  • is_duplicate:指示生成的序列是否重复;
  • MRL 和 TE 的量纲不同,其原始分数不应直接相加。

MRL 定向优化

目的: 冻结 WGAN 和 FramePool 模型,优化隐空间噪声以提高所生成候选序列的 MRL 预测分数。

python scripts/optimize_te_mrl.py \
  -gpu 0 \
  -task mrl \
  -bs 64 \
  -s 10 \
  --output-dir outputs/optimization_mrl

在此过程中,WGAN 和 FramePool 的模型权重保持冻结,只更新隐空间噪声。

TE 定向优化

目的: 冻结 WGAN 和 MTtrans 模型,优化隐空间噪声以提高所生成候选序列的 TE 预测分数。

python scripts/optimize_te_mrl.py \
  -gpu 0 \
  -task te \
  -bs 64 \
  -s 10 \
  --output-dir outputs/optimization_te

在此过程中,WGAN 和 MTtrans 的模型权重保持冻结。

因此,该流程属于隐空间优化,而非对预训练模型的微调(fine-tuning)。

训练

UTRGAN 支持 WGAN-GP 训练。

该流程中可训练的组件为:

  • 生成器;
  • 判别器(Critic)。

Xpresso、FramePool 和 MTtrans 不参与该训练入口。

使用完整的数据处理流程和仓库中自带的 UTRdb2 数据集运行一个 epoch:

python scripts/train.py \
  -gpu 0 \
  -bs 64 \
  -lr 5 \
  -mxl 128 \
  -dim 40 \
  --epochs 1 \
  --output-dir outputs/train_1epoch

根据上游 README,-lr 5 对应的学习率为:

1e-5

适配后的训练入口增加了 --epochs 参数,并修正了上游脚本中的学习率表达式,使其与文档中的定义保持一致。

要运行完整的上游训练配置,请使用完整的 UTRdb2 训练数据集训练 4000 个 epoch:

python scripts/train.py \
  -gpu 0 \
  -bs 64 \
  -lr 5 \
  -mxl 128 \
  -dim 40 \
  --epochs 4000 \
  --output-dir outputs/train_full

这会重新训练 WGAN-GP 的生成器和判别器。

完整训练可能需要大量运行时间。应根据可用的加速器资源和训练日志来评估训练进度。

生成的模型权重(检查点)保存在指定的输出目录中,不会覆盖以下位置的官方预训练权重:

weight/

OneScience 官方资源

平台 OneScience 主仓库 技能仓库
Gitee OneScience OneSkills
GitHub OneScience OneSkills

引用与许可

Downloads last month
8
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support