Views
No views yet

1from biofm_eval import AnnotatedModel, AnnotationTokenizer, Embedder, VCFConverter
2import torch
3
4# Define paths to the pre-trained BioFM model and tokenizer
5MODEL_PATH = "m42-health/BioFM-265M"
6TOKENIZER_PATH = "m42-health/BioFM-265M"
7
8# Load the pre-trained BioFM model and BioToken tokenizer
9model = AnnotatedModel.from_pretrained(
10 MODEL_PATH,
11 torch_dtype=torch.bfloat16,
12)
13tokenizer = AnnotationTokenizer.from_pretrained(TOKENIZER_PATH)
14
15# Initialize the embedder using the model and tokenizer
16embedder = Embedder(model, tokenizer)
17
18# Set up the VCF converter with paths to gene annotations and reference genome
19vcf_converter = VCFConverter(
20 gene_annotation_path="./gencode.v38.annotation.gff3",
21 reference_genome_path="./GCA_000001405.15_GRCh38_no_alt_plus_hs38d1_analysis_set.fna"
22)
23
24# Convert a VCF file into an annotated dataset using BioTokens
25annotated_dataset = vcf_converter.vcf_to_annotated_dataset(
26 vcf_path = './HG01779_b.vcf.gz',
27 max_variants=200 # Set to None to process all variants in the VCF file
28)
29
30# Extract BioFM embeddings for all annotated variants
31embeddings = embedder.get_dataset_embeddings(annotated_dataset)
32print(embeddings)
33
34# Example output (dict):
35# {
36# 'embeddings': array of shape (num_variants, 2*embedding_dim), # Numeric embeddings for each variant
37# 'labels': array of shape (num_variants,) # Present only during supervised embedding extraction
38# }
391from biofm_eval import AnnotatedModel, AnnotationTokenizer, Generator
2import torch
3
4# Define paths to the pre-trained BioFM model and tokenizer
5MODEL_PATH = "m42-health/BioFM-265M"
6TOKENIZER_PATH = "m42-health/BioFM-265M"
7
8# Load the pre-trained BioFM model and BioToken tokenizer
9model = AnnotatedModel.from_pretrained(
10 MODEL_PATH,
11 torch_dtype=torch.bfloat16,
12)
13tokenizer = AnnotationTokenizer.from_pretrained(TOKENIZER_PATH)
14
15# Initializing the generator using model and tokenizer
16seq_generator = Generator(model, tokenizer)
17
18# Generate DNA sequences
19input_sequences = ['AGCT', 'GACTGCA']
20output = seq_generator.generate(
21 input_sequences,
22 max_new_tokens=10,
23 temperature=1.0,
24 do_sample=True,
25 top_k=4)
26
27print(output)
28
29# Example output: List[str] = ['AGCTACTCCCCTCC', 'GACTGCACCACTGTACT']
30| sQTL prediction | Expression prediction |
|---|---|
![]() | ![]() |
| Variant benchmark | Genomics long-range benchmark |
|---|---|
![]() | ![]() |
@article {Medvedev2025.03.27.645711,
author = {Medvedev, Aleksandr and Viswanathan, Karthik and Kanithi, Praveenkumar and Vishniakov, Kirill and Munjal, Prateek and Christophe, Clement and Pimentel, Marco AF and Rajan, Ronnie and Khan, Shadab},
title = {BioToken and BioFM - Biologically-Informed Tokenization Enables Accurate and Efficient Genomic Foundation Models},
elocation-id = {2025.03.27.645711},
year = {2025},
doi = {10.1101/2025.03.27.645711},
publisher = {Cold Spring Harbor Laboratory},
URL = {https://www.biorxiv.org/content/early/2025/04/01/2025.03.27.645711},
eprint = {https://www.biorxiv.org/content/early/2025/04/01/2025.03.27.645711.full.pdf},
journal = {bioRxiv}
}