Mercurial > repos > bimib > cobraxy
comparison COBRAxy/utils/general_utils.py @ 394:a0b53ccc73a8 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Fri, 05 Sep 2025 13:05:29 +0000 |
| parents | f73d57641124 |
| children | f413b78d61bf |
comparison
equal
deleted
inserted
replaced
| 393:52658ddcaa5d | 394:a0b53ccc73a8 |
|---|---|
| 14 | 14 |
| 15 import zipfile | 15 import zipfile |
| 16 import gzip | 16 import gzip |
| 17 import bz2 | 17 import bz2 |
| 18 from io import StringIO | 18 from io import StringIO |
| 19 | |
| 20 | |
| 19 | 21 |
| 20 class ValueErr(Exception): | 22 class ValueErr(Exception): |
| 21 def __init__(self, param_name, expected, actual): | 23 def __init__(self, param_name, expected, actual): |
| 22 super().__init__(f"Invalid value for {param_name}: expected {expected}, got {actual}") | 24 super().__init__(f"Invalid value for {param_name}: expected {expected}, got {actual}") |
| 23 | 25 |
| 697 raise Exception(f"Error during model extraction: {str(e)}") | 699 raise Exception(f"Error during model extraction: {str(e)}") |
| 698 | 700 |
| 699 | 701 |
| 700 | 702 |
| 701 def __str__(self) -> str: return self.value | 703 def __str__(self) -> str: return self.value |
| 704 | |
| 705 | |
| 706 def convert_genes(model,annotation): | |
| 707 from cobra.manipulation import rename_genes | |
| 708 model2=model.copy() | |
| 709 try: | |
| 710 dict_genes={gene.id:gene.notes[annotation] for gene in model2.genes} | |
| 711 except: | |
| 712 print("No annotation in gene dict!") | |
| 713 return -1 | |
| 714 rename_genes(model2,dict_genes) | |
| 715 | |
| 716 return model2 |
