omnigenome 0.3.0a1__py3-none-any.whl → 0.3.3a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of omnigenome might be problematic. Click here for more details.
- omnigenome/__init__.py +252 -258
- {omnigenome-0.3.0a1.dist-info → omnigenome-0.3.3a0.dist-info}/METADATA +10 -10
- omnigenome-0.3.3a0.dist-info/RECORD +7 -0
- omnigenome/auto/__init__.py +0 -3
- omnigenome/auto/auto_bench/__init__.py +0 -12
- omnigenome/auto/auto_bench/auto_bench.py +0 -484
- omnigenome/auto/auto_bench/auto_bench_cli.py +0 -230
- omnigenome/auto/auto_bench/auto_bench_config.py +0 -216
- omnigenome/auto/auto_bench/config_check.py +0 -34
- omnigenome/auto/auto_train/__init__.py +0 -13
- omnigenome/auto/auto_train/auto_train.py +0 -430
- omnigenome/auto/auto_train/auto_train_cli.py +0 -222
- omnigenome/auto/bench_hub/__init__.py +0 -12
- omnigenome/auto/bench_hub/bench_hub.py +0 -25
- omnigenome/cli/__init__.py +0 -13
- omnigenome/cli/commands/__init__.py +0 -13
- omnigenome/cli/commands/base.py +0 -83
- omnigenome/cli/commands/bench/__init__.py +0 -13
- omnigenome/cli/commands/bench/bench_cli.py +0 -202
- omnigenome/cli/commands/rna/__init__.py +0 -13
- omnigenome/cli/commands/rna/rna_design.py +0 -178
- omnigenome/cli/omnigenome_cli.py +0 -128
- omnigenome/src/__init__.py +0 -12
- omnigenome/src/abc/__init__.py +0 -12
- omnigenome/src/abc/abstract_dataset.py +0 -622
- omnigenome/src/abc/abstract_metric.py +0 -114
- omnigenome/src/abc/abstract_model.py +0 -689
- omnigenome/src/abc/abstract_tokenizer.py +0 -267
- omnigenome/src/dataset/__init__.py +0 -16
- omnigenome/src/dataset/omni_dataset.py +0 -435
- omnigenome/src/lora/__init__.py +0 -13
- omnigenome/src/lora/lora_model.py +0 -294
- omnigenome/src/metric/__init__.py +0 -15
- omnigenome/src/metric/classification_metric.py +0 -184
- omnigenome/src/metric/metric.py +0 -199
- omnigenome/src/metric/ranking_metric.py +0 -142
- omnigenome/src/metric/regression_metric.py +0 -191
- omnigenome/src/misc/__init__.py +0 -3
- omnigenome/src/misc/utils.py +0 -499
- omnigenome/src/model/__init__.py +0 -19
- omnigenome/src/model/augmentation/__init__.py +0 -12
- omnigenome/src/model/augmentation/model.py +0 -219
- omnigenome/src/model/classification/__init__.py +0 -12
- omnigenome/src/model/classification/model.py +0 -642
- omnigenome/src/model/embedding/__init__.py +0 -12
- omnigenome/src/model/embedding/model.py +0 -263
- omnigenome/src/model/mlm/__init__.py +0 -12
- omnigenome/src/model/mlm/model.py +0 -177
- omnigenome/src/model/module_utils.py +0 -232
- omnigenome/src/model/regression/__init__.py +0 -12
- omnigenome/src/model/regression/model.py +0 -786
- omnigenome/src/model/regression/resnet.py +0 -483
- omnigenome/src/model/rna_design/__init__.py +0 -12
- omnigenome/src/model/rna_design/model.py +0 -469
- omnigenome/src/model/seq2seq/__init__.py +0 -12
- omnigenome/src/model/seq2seq/model.py +0 -44
- omnigenome/src/tokenizer/__init__.py +0 -16
- omnigenome/src/tokenizer/bpe_tokenizer.py +0 -226
- omnigenome/src/tokenizer/kmers_tokenizer.py +0 -247
- omnigenome/src/tokenizer/single_nucleotide_tokenizer.py +0 -249
- omnigenome/src/trainer/__init__.py +0 -14
- omnigenome/src/trainer/accelerate_trainer.py +0 -739
- omnigenome/src/trainer/hf_trainer.py +0 -75
- omnigenome/src/trainer/trainer.py +0 -579
- omnigenome/utility/__init__.py +0 -3
- omnigenome/utility/dataset_hub/__init__.py +0 -13
- omnigenome/utility/dataset_hub/dataset_hub.py +0 -178
- omnigenome/utility/ensemble.py +0 -324
- omnigenome/utility/hub_utils.py +0 -517
- omnigenome/utility/model_hub/__init__.py +0 -12
- omnigenome/utility/model_hub/model_hub.py +0 -231
- omnigenome/utility/pipeline_hub/__init__.py +0 -12
- omnigenome/utility/pipeline_hub/pipeline.py +0 -483
- omnigenome/utility/pipeline_hub/pipeline_hub.py +0 -129
- omnigenome-0.3.0a1.dist-info/RECORD +0 -78
- {omnigenome-0.3.0a1.dist-info → omnigenome-0.3.3a0.dist-info}/WHEEL +0 -0
- {omnigenome-0.3.0a1.dist-info → omnigenome-0.3.3a0.dist-info}/entry_points.txt +0 -0
- {omnigenome-0.3.0a1.dist-info → omnigenome-0.3.3a0.dist-info}/licenses/LICENSE +0 -0
- {omnigenome-0.3.0a1.dist-info → omnigenome-0.3.3a0.dist-info}/top_level.txt +0 -0
omnigenome/src/misc/utils.py
DELETED
|
@@ -1,499 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# file: utils.py
|
|
3
|
-
# time: 14:45 06/04/2024
|
|
4
|
-
# author: YANG, HENG <hy345@exeter.ac.uk> (杨恒)
|
|
5
|
-
# github: https://github.com/yangheng95
|
|
6
|
-
# huggingface: https://huggingface.co/yangheng
|
|
7
|
-
# google scholar: https://scholar.google.com/citations?user=NPq5a_0AAAAJ&hl=en
|
|
8
|
-
# Copyright (C) 2019-2024. All Rights Reserved.
|
|
9
|
-
import multiprocessing
|
|
10
|
-
import os
|
|
11
|
-
import pickle
|
|
12
|
-
import sys
|
|
13
|
-
import tempfile
|
|
14
|
-
import time
|
|
15
|
-
import warnings
|
|
16
|
-
|
|
17
|
-
import ViennaRNA as RNA
|
|
18
|
-
import findfile
|
|
19
|
-
|
|
20
|
-
default_omnigenome_repo = (
|
|
21
|
-
"https://huggingface.co/spaces/yangheng/OmniGenomeLeaderboard/"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def seed_everything(seed=42):
|
|
26
|
-
"""
|
|
27
|
-
Sets random seeds for reproducibility across all random number generators.
|
|
28
|
-
|
|
29
|
-
This function sets seeds for Python's random module, NumPy, PyTorch (CPU and CUDA),
|
|
30
|
-
and sets the PYTHONHASHSEED environment variable to ensure reproducible results
|
|
31
|
-
across different runs.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
seed (int): The seed value to use for all random number generators.
|
|
35
|
-
Defaults to 42.
|
|
36
|
-
|
|
37
|
-
Example:
|
|
38
|
-
>>> # Set seeds for reproducibility
|
|
39
|
-
>>> seed_everything(42)
|
|
40
|
-
>>> # Now all random operations will be reproducible
|
|
41
|
-
"""
|
|
42
|
-
import random
|
|
43
|
-
import numpy as np
|
|
44
|
-
import torch
|
|
45
|
-
|
|
46
|
-
random.seed(seed)
|
|
47
|
-
os.environ["PYTHONHASHSEED"] = str(seed)
|
|
48
|
-
np.random.seed(seed)
|
|
49
|
-
torch.manual_seed(seed)
|
|
50
|
-
torch.cuda.manual_seed(seed)
|
|
51
|
-
torch.backends.cudnn.deterministic = True
|
|
52
|
-
torch.backends.cudnn.benchmark = False
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class RNA2StructureCache(dict):
|
|
56
|
-
"""
|
|
57
|
-
A cache for RNA secondary structure predictions using ViennaRNA.
|
|
58
|
-
|
|
59
|
-
This class provides a caching mechanism for RNA secondary structure predictions
|
|
60
|
-
to avoid redundant computations. It supports both single sequence and batch
|
|
61
|
-
processing with optional multiprocessing for improved performance.
|
|
62
|
-
|
|
63
|
-
Attributes:
|
|
64
|
-
cache (dict): Dictionary storing sequence-structure mappings
|
|
65
|
-
cache_file (str): Path to the cache file on disk
|
|
66
|
-
queue_num (int): Counter for tracking cache updates
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
def __init__(self, cache_file=None, *args, **kwargs):
|
|
70
|
-
"""
|
|
71
|
-
Initialize the RNA structure cache.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
cache_file (str, optional): Path to the cache file. If None, uses
|
|
75
|
-
a default temporary file.
|
|
76
|
-
*args: Additional positional arguments for dict initialization
|
|
77
|
-
**kwargs: Additional keyword arguments for dict initialization
|
|
78
|
-
"""
|
|
79
|
-
super().__init__(*args, **kwargs)
|
|
80
|
-
self.cache = dict(*args, **kwargs)
|
|
81
|
-
self.cache_file = (
|
|
82
|
-
cache_file
|
|
83
|
-
if cache_file is not None
|
|
84
|
-
else os.path.join(tempfile.gettempdir(), "rna_structure_cache.pkl")
|
|
85
|
-
)
|
|
86
|
-
self.queue_num = 0
|
|
87
|
-
|
|
88
|
-
# Load existing cache if available
|
|
89
|
-
if os.path.exists(self.cache_file):
|
|
90
|
-
try:
|
|
91
|
-
with open(self.cache_file, "rb") as f:
|
|
92
|
-
self.cache.update(pickle.load(f))
|
|
93
|
-
except Exception as e:
|
|
94
|
-
warnings.warn(f"Failed to load cache file: {e}")
|
|
95
|
-
|
|
96
|
-
def __getitem__(self, key):
|
|
97
|
-
"""Gets a cached structure prediction."""
|
|
98
|
-
return self.cache[key]
|
|
99
|
-
|
|
100
|
-
def __setitem__(self, key, value):
|
|
101
|
-
"""Sets a structure prediction in the cache."""
|
|
102
|
-
self.cache[key] = value
|
|
103
|
-
|
|
104
|
-
def __str__(self):
|
|
105
|
-
"""String representation of the cache."""
|
|
106
|
-
return str(self.cache)
|
|
107
|
-
|
|
108
|
-
def __repr__(self):
|
|
109
|
-
"""String representation of the cache."""
|
|
110
|
-
return str(self.cache)
|
|
111
|
-
|
|
112
|
-
def _fold_single_sequence(self, sequence):
|
|
113
|
-
"""
|
|
114
|
-
Predict structure for a single sequence (worker function for multiprocessing).
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
sequence (str): RNA sequence to fold
|
|
118
|
-
|
|
119
|
-
Returns:
|
|
120
|
-
tuple: (structure, mfe) tuple
|
|
121
|
-
"""
|
|
122
|
-
try:
|
|
123
|
-
return RNA.fold(sequence)
|
|
124
|
-
except Exception as e:
|
|
125
|
-
warnings.warn(f"Failed to fold sequence {sequence}: {e}")
|
|
126
|
-
return ("." * len(sequence), 0.0)
|
|
127
|
-
|
|
128
|
-
def fold(self, sequence, return_mfe=False, num_workers=1):
|
|
129
|
-
"""
|
|
130
|
-
Predicts RNA secondary structure for given sequences.
|
|
131
|
-
|
|
132
|
-
This method predicts RNA secondary structures using ViennaRNA. It supports
|
|
133
|
-
both single sequences and batches of sequences. The method uses caching
|
|
134
|
-
to avoid redundant predictions and supports multiprocessing for batch
|
|
135
|
-
processing on non-Windows systems.
|
|
136
|
-
|
|
137
|
-
Args:
|
|
138
|
-
sequence (str or list): A single RNA sequence or a list of sequences.
|
|
139
|
-
return_mfe (bool): Whether to return minimum free energy along with
|
|
140
|
-
structure. Defaults to False.
|
|
141
|
-
num_workers (int): Number of worker processes for batch processing.
|
|
142
|
-
Defaults to 1. Set to None for auto-detection.
|
|
143
|
-
|
|
144
|
-
Returns:
|
|
145
|
-
str or list: The predicted structure(s). If return_mfe is True,
|
|
146
|
-
returns tuples of (structure, mfe).
|
|
147
|
-
|
|
148
|
-
Example:
|
|
149
|
-
>>> cache = RNA2StructureCache()
|
|
150
|
-
>>> # Predict structure for a single sequence
|
|
151
|
-
>>> structure = cache.fold("GGGAAAUCC")
|
|
152
|
-
>>> print(structure) # "(((...)))"
|
|
153
|
-
|
|
154
|
-
>>> # Predict structures for multiple sequences
|
|
155
|
-
>>> structures = cache.fold(["GGGAAAUCC", "AUUGCUAA"])
|
|
156
|
-
>>> print(structures) # ["(((...)))", "........"]
|
|
157
|
-
"""
|
|
158
|
-
if not isinstance(sequence, list):
|
|
159
|
-
sequences = [sequence]
|
|
160
|
-
else:
|
|
161
|
-
sequences = sequence
|
|
162
|
-
|
|
163
|
-
# Determine if we should use multiprocessing
|
|
164
|
-
use_multiprocessing = (
|
|
165
|
-
os.name != "nt" and # Not Windows
|
|
166
|
-
len(sequences) > 1 and # Multiple sequences
|
|
167
|
-
num_workers > 1 # Multiple workers requested
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
# Find sequences that need prediction
|
|
171
|
-
sequences_to_predict = [seq for seq in sequences if seq not in self.cache]
|
|
172
|
-
|
|
173
|
-
if sequences_to_predict:
|
|
174
|
-
if use_multiprocessing:
|
|
175
|
-
# Use multiprocessing for batch prediction
|
|
176
|
-
if num_workers is None:
|
|
177
|
-
num_workers = min(os.cpu_count(), len(sequences_to_predict))
|
|
178
|
-
|
|
179
|
-
try:
|
|
180
|
-
# Set multiprocessing start method to 'spawn' for better compatibility
|
|
181
|
-
if multiprocessing.get_start_method(allow_none=True) != 'spawn':
|
|
182
|
-
multiprocessing.set_start_method('spawn', force=True)
|
|
183
|
-
|
|
184
|
-
with multiprocessing.Pool(num_workers) as pool:
|
|
185
|
-
# Use map instead of apply_async for better error handling
|
|
186
|
-
results = pool.map(self._fold_single_sequence, sequences_to_predict)
|
|
187
|
-
|
|
188
|
-
# Update cache with results
|
|
189
|
-
for seq, result in zip(sequences_to_predict, results):
|
|
190
|
-
self.cache[seq] = result
|
|
191
|
-
self.queue_num += 1
|
|
192
|
-
|
|
193
|
-
except Exception as e:
|
|
194
|
-
warnings.warn(f"Multiprocessing failed, falling back to sequential: {e}")
|
|
195
|
-
# Fallback to sequential processing
|
|
196
|
-
for seq in sequences_to_predict:
|
|
197
|
-
self.cache[seq] = self._fold_single_sequence(seq)
|
|
198
|
-
self.queue_num += 1
|
|
199
|
-
else:
|
|
200
|
-
# Sequential processing
|
|
201
|
-
for seq in sequences_to_predict:
|
|
202
|
-
self.cache[seq] = self._fold_single_sequence(seq)
|
|
203
|
-
self.queue_num += 1
|
|
204
|
-
|
|
205
|
-
# Prepare output
|
|
206
|
-
if return_mfe:
|
|
207
|
-
structures = [self.cache[seq] for seq in sequences]
|
|
208
|
-
else:
|
|
209
|
-
structures = [self.cache[seq][0] for seq in sequences]
|
|
210
|
-
|
|
211
|
-
# Update cache file periodically
|
|
212
|
-
self.update_cache_file(self.cache_file)
|
|
213
|
-
|
|
214
|
-
# Return single result or list
|
|
215
|
-
if len(structures) == 1:
|
|
216
|
-
return structures[0]
|
|
217
|
-
else:
|
|
218
|
-
return structures
|
|
219
|
-
|
|
220
|
-
def update_cache_file(self, cache_file=None):
|
|
221
|
-
"""
|
|
222
|
-
Updates the cache file on disk.
|
|
223
|
-
|
|
224
|
-
This method saves the in-memory cache to disk. It only saves when
|
|
225
|
-
the queue_num reaches 100 to avoid excessive disk I/O.
|
|
226
|
-
|
|
227
|
-
Args:
|
|
228
|
-
cache_file (str, optional): Path to the cache file. If None, uses
|
|
229
|
-
the instance's cache_file.
|
|
230
|
-
|
|
231
|
-
Example:
|
|
232
|
-
>>> cache.update_cache_file() # Force save to disk
|
|
233
|
-
"""
|
|
234
|
-
if self.queue_num < 100:
|
|
235
|
-
return
|
|
236
|
-
|
|
237
|
-
if cache_file is None:
|
|
238
|
-
cache_file = self.cache_file
|
|
239
|
-
|
|
240
|
-
try:
|
|
241
|
-
if not os.path.exists(os.path.dirname(cache_file)):
|
|
242
|
-
os.makedirs(os.path.dirname(cache_file))
|
|
243
|
-
|
|
244
|
-
with open(cache_file, "wb") as f:
|
|
245
|
-
pickle.dump(self.cache, f)
|
|
246
|
-
|
|
247
|
-
self.queue_num = 0
|
|
248
|
-
except Exception as e:
|
|
249
|
-
warnings.warn(f"Failed to update cache file: {e}")
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def env_meta_info():
|
|
253
|
-
"""
|
|
254
|
-
Collects metadata about the current environment and library versions.
|
|
255
|
-
|
|
256
|
-
This function gathers information about the current Python environment,
|
|
257
|
-
including versions of key libraries like PyTorch and Transformers,
|
|
258
|
-
as well as OmniGenome version information.
|
|
259
|
-
|
|
260
|
-
Returns:
|
|
261
|
-
dict: A dictionary containing environment metadata including:
|
|
262
|
-
- library_name: Name of the OmniGenome library
|
|
263
|
-
- omnigenome_version: Version of OmniGenome
|
|
264
|
-
- torch_version: PyTorch version with CUDA info
|
|
265
|
-
- transformers_version: Transformers library version
|
|
266
|
-
|
|
267
|
-
Example:
|
|
268
|
-
>>> metadata = env_meta_info()
|
|
269
|
-
>>> print(metadata['torch_version']) # "2.0.0+cu118+git..."
|
|
270
|
-
"""
|
|
271
|
-
from torch.version import __version__ as torch_version
|
|
272
|
-
from torch.version import cuda as torch_cuda_version
|
|
273
|
-
from torch.version import git_version
|
|
274
|
-
from transformers import __version__ as transformers_version
|
|
275
|
-
from ... import __version__ as omnigenome_version
|
|
276
|
-
from ... import __name__ as omnigenome_name
|
|
277
|
-
|
|
278
|
-
return {
|
|
279
|
-
"library_name": omnigenome_name,
|
|
280
|
-
"omnigenome_version": omnigenome_version,
|
|
281
|
-
"torch_version": f"{torch_version}+cu{torch_cuda_version}+git{git_version}",
|
|
282
|
-
"transformers_version": transformers_version,
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
def naive_secondary_structure_repair(sequence, structure):
|
|
287
|
-
"""
|
|
288
|
-
Repair the secondary structure of a sequence.
|
|
289
|
-
|
|
290
|
-
This function attempts to repair malformed RNA secondary structure
|
|
291
|
-
representations by ensuring proper bracket matching. It handles
|
|
292
|
-
common issues like unmatched brackets by converting them to dots.
|
|
293
|
-
|
|
294
|
-
Args:
|
|
295
|
-
sequence (str): A string representing the sequence.
|
|
296
|
-
structure (str): A string representing the secondary structure.
|
|
297
|
-
|
|
298
|
-
Returns:
|
|
299
|
-
str: A string representing the repaired secondary structure.
|
|
300
|
-
|
|
301
|
-
Example:
|
|
302
|
-
>>> sequence = "GGGAAAUCC"
|
|
303
|
-
>>> structure = "(((...)" # Malformed structure
|
|
304
|
-
>>> repaired = naive_secondary_structure_repair(sequence, structure)
|
|
305
|
-
>>> print(repaired) # "(((...))"
|
|
306
|
-
"""
|
|
307
|
-
repaired_structure = ""
|
|
308
|
-
stack = []
|
|
309
|
-
for i, (s, c) in enumerate(zip(structure, sequence)):
|
|
310
|
-
if s == "(":
|
|
311
|
-
stack.append(i)
|
|
312
|
-
elif s == ")":
|
|
313
|
-
if stack:
|
|
314
|
-
stack.pop()
|
|
315
|
-
else:
|
|
316
|
-
repaired_structure += "."
|
|
317
|
-
else:
|
|
318
|
-
repaired_structure += s
|
|
319
|
-
for i in stack:
|
|
320
|
-
repaired_structure = repaired_structure[:i] + "." + repaired_structure[i + 1 :]
|
|
321
|
-
return repaired_structure
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
def save_args(config, save_path):
|
|
325
|
-
"""
|
|
326
|
-
Save arguments to a file.
|
|
327
|
-
|
|
328
|
-
This function saves the arguments from a configuration object to a text file.
|
|
329
|
-
It's useful for logging experiment parameters and configurations.
|
|
330
|
-
|
|
331
|
-
Args:
|
|
332
|
-
config: A Namespace object containing the arguments.
|
|
333
|
-
save_path (str): A string representing the path of the file to be saved.
|
|
334
|
-
|
|
335
|
-
Example:
|
|
336
|
-
>>> from argparse import Namespace
|
|
337
|
-
>>> config = Namespace(learning_rate=0.001, batch_size=32)
|
|
338
|
-
>>> save_args(config, "config.txt")
|
|
339
|
-
"""
|
|
340
|
-
f = open(os.path.join(save_path), mode="w", encoding="utf8")
|
|
341
|
-
for arg in config.args:
|
|
342
|
-
if config.args_call_count[arg]:
|
|
343
|
-
f.write("{}: {}\n".format(arg, config.args[arg]))
|
|
344
|
-
f.close()
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
def print_args(config, logger=None):
|
|
348
|
-
"""
|
|
349
|
-
Print the arguments to the console.
|
|
350
|
-
|
|
351
|
-
This function prints the arguments from a configuration object to the console
|
|
352
|
-
or a logger. It's useful for debugging and logging experiment parameters.
|
|
353
|
-
|
|
354
|
-
Args:
|
|
355
|
-
config: A Namespace object containing the arguments.
|
|
356
|
-
logger: A logger object. If None, prints to console.
|
|
357
|
-
|
|
358
|
-
Example:
|
|
359
|
-
>>> from argparse import Namespace
|
|
360
|
-
>>> config = Namespace(learning_rate=0.001, batch_size=32)
|
|
361
|
-
>>> print_args(config)
|
|
362
|
-
"""
|
|
363
|
-
if logger is None:
|
|
364
|
-
for arg in config.args:
|
|
365
|
-
if config.args_call_count[arg]:
|
|
366
|
-
print("{}: {}".format(arg, config.args[arg]))
|
|
367
|
-
else:
|
|
368
|
-
for arg in config.args:
|
|
369
|
-
if config.args_call_count[arg]:
|
|
370
|
-
logger.info("{}: {}".format(arg, config.args[arg]))
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
def fprint(*objects, sep=" ", end="\n", file=sys.stdout, flush=False):
|
|
374
|
-
"""
|
|
375
|
-
Enhanced print function with automatic flushing.
|
|
376
|
-
|
|
377
|
-
This function provides a print-like interface with automatic flushing
|
|
378
|
-
to ensure output is displayed immediately. It's useful for real-time
|
|
379
|
-
logging and progress tracking.
|
|
380
|
-
|
|
381
|
-
Args:
|
|
382
|
-
*objects: Objects to print
|
|
383
|
-
sep (str): Separator between objects (default: " ")
|
|
384
|
-
end (str): String appended after the last value (default: "\n")
|
|
385
|
-
file: File-like object to write to (default: sys.stdout)
|
|
386
|
-
flush (bool): Whether to flush the stream (default: False)
|
|
387
|
-
|
|
388
|
-
Example:
|
|
389
|
-
>>> fprint("Training started...", flush=True)
|
|
390
|
-
>>> fprint("Epoch 1/10", "Loss: 0.5", sep=" | ")
|
|
391
|
-
"""
|
|
392
|
-
print(*objects, sep=sep, end=end, file=file, flush=True)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
def clean_temp_checkpoint(days_threshold=7):
|
|
396
|
-
"""
|
|
397
|
-
Clean up temporary checkpoint files older than specified days.
|
|
398
|
-
|
|
399
|
-
This function removes temporary checkpoint files that are older than
|
|
400
|
-
the specified threshold to free up disk space.
|
|
401
|
-
|
|
402
|
-
Args:
|
|
403
|
-
days_threshold (int): Number of days after which files are considered old.
|
|
404
|
-
Defaults to 7.
|
|
405
|
-
|
|
406
|
-
Example:
|
|
407
|
-
>>> clean_temp_checkpoint(3) # Remove files older than 3 days
|
|
408
|
-
"""
|
|
409
|
-
import glob
|
|
410
|
-
import time
|
|
411
|
-
|
|
412
|
-
temp_patterns = [
|
|
413
|
-
"temp_checkpoint_*",
|
|
414
|
-
"checkpoint_*",
|
|
415
|
-
"*.tmp",
|
|
416
|
-
"*.temp",
|
|
417
|
-
]
|
|
418
|
-
|
|
419
|
-
current_time = time.time()
|
|
420
|
-
threshold_time = current_time - (days_threshold * 24 * 60 * 60)
|
|
421
|
-
|
|
422
|
-
for pattern in temp_patterns:
|
|
423
|
-
for file_path in glob.glob(pattern):
|
|
424
|
-
try:
|
|
425
|
-
if os.path.getmtime(file_path) < threshold_time:
|
|
426
|
-
os.remove(file_path)
|
|
427
|
-
except Exception:
|
|
428
|
-
pass
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
def load_module_from_path(module_name, file_path):
|
|
432
|
-
"""
|
|
433
|
-
Load a Python module from a file path.
|
|
434
|
-
|
|
435
|
-
This function dynamically loads a Python module from a file path,
|
|
436
|
-
useful for loading configuration files or custom modules.
|
|
437
|
-
|
|
438
|
-
Args:
|
|
439
|
-
module_name (str): Name to assign to the loaded module
|
|
440
|
-
file_path (str): Path to the Python file to load
|
|
441
|
-
|
|
442
|
-
Returns:
|
|
443
|
-
module: The loaded module object
|
|
444
|
-
|
|
445
|
-
Example:
|
|
446
|
-
>>> config = load_module_from_path("config", "config.py")
|
|
447
|
-
>>> print(config.some_variable)
|
|
448
|
-
"""
|
|
449
|
-
import importlib.util
|
|
450
|
-
|
|
451
|
-
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
|
452
|
-
module = importlib.util.module_from_spec(spec)
|
|
453
|
-
spec.loader.exec_module(module)
|
|
454
|
-
return module
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
def check_bench_version(bench_version, omnigenome_version):
|
|
458
|
-
"""
|
|
459
|
-
Check if benchmark version is compatible with OmniGenome version.
|
|
460
|
-
|
|
461
|
-
This function compares the benchmark version with the OmniGenome version
|
|
462
|
-
to ensure compatibility and warns if there are potential issues.
|
|
463
|
-
|
|
464
|
-
Args:
|
|
465
|
-
bench_version (str): Version of the benchmark
|
|
466
|
-
omnigenome_version (str): Version of OmniGenome
|
|
467
|
-
|
|
468
|
-
Example:
|
|
469
|
-
>>> check_bench_version("0.2.0", "0.3.0")
|
|
470
|
-
"""
|
|
471
|
-
if bench_version != omnigenome_version:
|
|
472
|
-
warnings.warn(
|
|
473
|
-
f"Benchmark version ({bench_version}) differs from "
|
|
474
|
-
f"OmniGenome version ({omnigenome_version}). "
|
|
475
|
-
f"This may cause compatibility issues."
|
|
476
|
-
)
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
def clean_temp_dir_pt_files():
|
|
480
|
-
"""
|
|
481
|
-
Clean up temporary PyTorch files in the current directory.
|
|
482
|
-
|
|
483
|
-
This function removes temporary PyTorch files (like .pt, .pth files)
|
|
484
|
-
that may be left over from previous runs.
|
|
485
|
-
|
|
486
|
-
Example:
|
|
487
|
-
>>> clean_temp_dir_pt_files()
|
|
488
|
-
"""
|
|
489
|
-
import glob
|
|
490
|
-
|
|
491
|
-
temp_patterns = ["*.pt", "*.pth", "temp_*", "checkpoint_*"]
|
|
492
|
-
|
|
493
|
-
for pattern in temp_patterns:
|
|
494
|
-
for file_path in glob.glob(pattern):
|
|
495
|
-
try:
|
|
496
|
-
if os.path.isfile(file_path):
|
|
497
|
-
os.remove(file_path)
|
|
498
|
-
except Exception:
|
|
499
|
-
pass
|
omnigenome/src/model/__init__.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# file: __init__.py
|
|
3
|
-
# time: 14:08 06/04/2024
|
|
4
|
-
# author: YANG, HENG <hy345@exeter.ac.uk> (杨恒)
|
|
5
|
-
# github: https://github.com/yangheng95
|
|
6
|
-
# huggingface: https://huggingface.co/yangheng
|
|
7
|
-
# google scholar: https://scholar.google.com/citations?user=NPq5a_0AAAAJ&hl=en
|
|
8
|
-
# Copyright (C) 2019-2024. All Rights Reserved.
|
|
9
|
-
"""
|
|
10
|
-
This package contains model definitions for various tasks.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
from .classification.model import *
|
|
14
|
-
from .mlm.model import *
|
|
15
|
-
from .regression.model import *
|
|
16
|
-
from .seq2seq.model import *
|
|
17
|
-
from .rna_design.model import *
|
|
18
|
-
from .embedding.model import *
|
|
19
|
-
from .augmentation.model import *
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# file: __init__.py
|
|
3
|
-
# time: 19:06 22/09/2024
|
|
4
|
-
# author: YANG, HENG <hy345@exeter.ac.uk> (杨恒)
|
|
5
|
-
# github: https://github.com/yangheng95
|
|
6
|
-
# huggingface: https://huggingface.co/yangheng
|
|
7
|
-
# google scholar: https://scholar.google.com/citations?user=NPq5a_0AAAAJ&hl=en
|
|
8
|
-
# Copyright (C) 2019-2024. All Rights Reserved.
|
|
9
|
-
"""
|
|
10
|
-
This package contains modules for data augmentation.
|
|
11
|
-
"""
|
|
12
|
-
|