Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions biomni/agent/a1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,19 +1879,38 @@ def wrapper(**kwargs) -> dict:
# Map your types to Python types
type_map = {"str": str, "int": int, "float": float, "bool": bool, "List[str]": list[str], "dict": dict}

def get_python_type(param_info):
"""Convert Biomni schema type to Python type."""
param_type_str = param_info["type"]

# Handle array types with proper items inspection
if param_type_str == "array" and "items" in param_info:
items_type = param_info["items"]["type"]
if items_type == "string":
return list[str]
elif items_type == "number":
return list[float]
elif items_type == "integer":
return list[int]
elif items_type == "boolean":
return list[bool]
else:
return list[str] # default to string list

# Handle regular types
return type_map.get(param_type_str, str)

# Add required parameters
for param_info in required_params:
param_name = param_info["name"]
param_type_str = param_info["type"]
param_type = type_map.get(param_type_str, str)
param_type = get_python_type(param_info)

new_params.append(inspect.Parameter(param_name, inspect.Parameter.KEYWORD_ONLY, annotation=param_type))

# Add optional parameters
for param_info in optional_params:
param_name = param_info["name"]
param_type_str = param_info["type"]
param_type = type_map.get(param_type_str, str)
param_type = get_python_type(param_info)

# Make it optional
optional_type = param_type | None
Expand Down
2 changes: 1 addition & 1 deletion biomni/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_llm(
raise ImportError( # noqa: B904
"langchain-openai package is required for Azure OpenAI models. Install with: pip install langchain-openai"
)
API_VERSION = "2024-12-01-preview"
API_VERSION = "2025-04-01-preview"
model = model.replace("azure-", "")
return AzureChatOpenAI(
openai_api_key=os.getenv("OPENAI_API_KEY"),
Expand Down
4 changes: 3 additions & 1 deletion biomni/tool/bioengineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def analyze_cell_migration_metrics(
return log.strip()


def perform_crispr_cas9_genome_editing(guide_rna_sequences, target_genomic_loci, cell_tissue_type):
def perform_crispr_cas9_genome_editing(
guide_rna_sequences: list[str], target_genomic_loci: str, cell_tissue_type: str
) -> str:
"""Simulates CRISPR-Cas9 genome editing process including guide RNA design, delivery, and analysis.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion biomni/tool/cancer_biology.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def analyze_ddr_network_in_cancer(expression_data_path, mutation_data_path, outp
return research_log


def analyze_cell_senescence_and_apoptosis(fcs_file_path):
def analyze_cell_senescence_and_apoptosis(fcs_file_path: str) -> str:
"""Analyze flow cytometry data to quantify senescent and apoptotic cell populations.

Parameters
Expand Down
10 changes: 7 additions & 3 deletions biomni/tool/cell_biology.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def quantify_cell_cycle_phases_from_microscopy(image_paths, output_dir="./results"):
def quantify_cell_cycle_phases_from_microscopy(image_paths: list[str], output_dir: str = "./results") -> str:
"""Quantify the percentage of cells in each cell cycle phase using Calcofluor white stained microscopy images.

This function processes microscopy images where cell walls/septa are stained with Calcofluor white,
Expand Down Expand Up @@ -159,7 +159,9 @@ def quantify_cell_cycle_phases_from_microscopy(image_paths, output_dir="./result
return log


def quantify_and_cluster_cell_motility(image_sequence_path, output_dir="./results", num_clusters=3):
def quantify_and_cluster_cell_motility(
image_sequence_path: str, output_dir: str = "./results", num_clusters: int = 3
) -> str:
"""Quantify cell motility features from time-lapse microscopy images and cluster cells based on motility patterns.

Parameters
Expand Down Expand Up @@ -571,7 +573,9 @@ def analyze_flow_cytometry_immunophenotyping(
return log


def analyze_mitochondrial_morphology_and_potential(morphology_image_path, potential_image_path, output_dir="./output"):
def analyze_mitochondrial_morphology_and_potential(
morphology_image_path: str, potential_image_path: str, output_dir: str = "./output"
) -> str:
"""Quantifies metrics of mitochondrial morphology and membrane potential from fluorescence microscopy images.

Parameters
Expand Down
16 changes: 10 additions & 6 deletions biomni/tool/genomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def create_panhumanpy_env(env_name):
# === Integration ===


def create_scvi_embeddings_scRNA(adata_filename, batch_key, label_key, data_dir):
def create_scvi_embeddings_scRNA(adata_filename: str, batch_key: str, label_key: str, data_dir: str) -> str:
# Import scvi-tools correctly - the package name is still 'scvi' when installed
try:
import scvi
Expand Down Expand Up @@ -839,7 +839,7 @@ def create_scvi_embeddings_scRNA(adata_filename, batch_key, label_key, data_dir)
return "\n".join(steps)


def create_harmony_embeddings_scRNA(adata_filename, batch_key, data_dir):
def create_harmony_embeddings_scRNA(adata_filename: str, batch_key: str, data_dir: str) -> str:
# https://pypi.org/project/harmony-pytorch/
from harmony import harmonize

Expand Down Expand Up @@ -911,7 +911,7 @@ def get_uce_embeddings_scRNA(
return "\n".join(steps)


def map_to_ima_interpret_scRNA(adata_filename, data_dir, custom_args=None):
def map_to_ima_interpret_scRNA(adata_filename: str, data_dir: str, custom_args=None) -> str:
"""Map cell embeddings from the input dataset to the Integrated Megascale Atlas reference dataset using UCE embeddings."""
from sklearn.neighbors import NearestNeighbors

Expand Down Expand Up @@ -1088,7 +1088,9 @@ def gene_set_enrichment_analysis(
return f"An error occurred: {e}"


def analyze_chromatin_interactions(hic_file_path, regulatory_elements_bed, output_dir="./output"):
def analyze_chromatin_interactions(
hic_file_path: str, regulatory_elements_bed: str, output_dir: str = "./output"
) -> str:
"""Analyze chromatin interactions from Hi-C data to identify enhancer-promoter interactions and TADs.

Parameters
Expand Down Expand Up @@ -1421,7 +1423,9 @@ def get_matrix(chrom, balance_if_possible=True):
return "\n".join(log)


def analyze_comparative_genomics_and_haplotypes(sample_fasta_files, reference_genome_path, output_dir="./output"):
def analyze_comparative_genomics_and_haplotypes(
sample_fasta_files: str, reference_genome_path: str, output_dir: str = "./output"
) -> str:
"""Perform comparative genomics and haplotype analysis on multiple genome samples.

This function aligns multiple genome samples to a reference, identifies variants,
Expand Down Expand Up @@ -1962,7 +1966,7 @@ def find_enriched_motifs_with_homer(
return log


def analyze_genomic_region_overlap(region_sets, output_prefix="overlap_analysis"):
def analyze_genomic_region_overlap(region_sets: str, output_prefix: str = "overlap_analysis") -> str:
"""Analyze overlaps between two or more sets of genomic regions.

Parameters
Expand Down
20 changes: 12 additions & 8 deletions biomni/tool/tool_description/bioengineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"nucleotides each) targeting the "
"genomic region of interest",
"name": "guide_rna_sequences",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
},
{
"default": None,
Expand Down Expand Up @@ -120,13 +121,15 @@
"default": None,
"description": "Time points at which drug concentrations were measured (in hours)",
"name": "time_points",
"type": "List[float] or numpy.ndarray",
"type": "array",
"items": {"type": "number"},
},
{
"default": None,
"description": "Measured drug concentration at each time point",
"name": "concentration_data",
"type": "List[float] or numpy.ndarray",
"type": "array",
"items": {"type": "number"},
},
],
},
Expand Down Expand Up @@ -192,13 +195,13 @@
"default": None,
"description": "Neural spiking activity data, shape (n_timepoints, n_neurons)",
"name": "neural_data",
"type": "numpy.ndarray",
"type": "array",
},
{
"default": None,
"description": "Behavioral data, shape (n_timepoints, n_behavioral_variables)",
"name": "behavioral_data",
"type": "numpy.ndarray",
"type": "array",
},
],
},
Expand All @@ -216,13 +219,14 @@
"simple example whole-cell model "
"will be used.",
"name": "ode_function",
"type": "callable",
"type": "object",
},
{
"default": "(0, 100)",
"description": "Tuple of (start_time, end_time) for the simulation.",
"name": "time_span",
"type": "tuple",
"type": "array",
"items": {"type": "number"},
},
{
"default": 1000,
Expand All @@ -247,7 +251,7 @@
"If array-like, order must match the "
"order expected by the ODE function.",
"name": "initial_conditions",
"type": "dict or array-like",
"type": "object",
},
{
"default": None,
Expand Down
3 changes: 2 additions & 1 deletion biomni/tool/tool_description/cell_biology.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"default": None,
"description": "List of file paths to microscopy images of cells stained with Calcofluor white",
"name": "image_paths",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
}
],
},
Expand Down
6 changes: 4 additions & 2 deletions biomni/tool/tool_description/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@
"default": None,
"description": "List of specific attributes to retrieve",
"name": "attributes",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
},
],
"required_parameters": [
{
"default": None,
"description": "List of PDB identifiers to query",
"name": "identifiers",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
}
],
},
Expand Down
9 changes: 6 additions & 3 deletions biomni/tool/tool_description/genomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"default": None,
"description": "Custom command line arguments to pass to the UCE script",
"name": "custom_args",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
},
],
"required_parameters": [
Expand Down Expand Up @@ -329,7 +330,8 @@
"default": None,
"description": "Paths to FASTA files containing whole-genome sequences to be analyzed",
"name": "sample_fasta_files",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
},
{
"default": None,
Expand Down Expand Up @@ -650,7 +652,8 @@
"default": None,
"description": "List of Ensembl gene IDs (e.g., ['ENSG00000012048', 'ENSG00000012049'])",
"name": "ensembl_gene_ids",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
}
],
},
Expand Down
18 changes: 12 additions & 6 deletions biomni/tool/tool_description/microbiology.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
"default": None,
"description": "Names of the biofilm samples corresponding to od_values",
"name": "sample_names",
"type": "List[str]",
"type": "array",
"items": {"type": "string"},
},
{
"default": 0,
Expand All @@ -270,7 +271,8 @@
"representing absorbance readings "
"for samples",
"name": "od_values",
"type": "List[float] or numpy.ndarray",
"type": "array",
"items": {"type": "number"},
}
],
},
Expand Down Expand Up @@ -427,25 +429,29 @@
"default": None,
"description": "Initial population sizes for each microbial species",
"name": "initial_populations",
"type": "List[int]",
"type": "array",
"items": {"type": "integer"},
},
{
"default": None,
"description": "Per capita growth rates for each species",
"name": "growth_rates",
"type": "List[float]",
"type": "array",
"items": {"type": "number"},
},
{
"default": None,
"description": "Per capita death/clearance rates for each species",
"name": "clearance_rates",
"type": "List[float]",
"type": "array",
"items": {"type": "number"},
},
{
"default": None,
"description": "Maximum sustainable population for each species",
"name": "carrying_capacities",
"type": "List[float]",
"type": "array",
"items": {"type": "number"},
},
],
},
Expand Down
Loading