### Install LaminDB from GitHub Source: https://github.com/laminlabs/lamindb/blob/main/CONTRIBUTING.md Use these commands to clone the repository, set up a virtual environment, and install development dependencies. ```bash git clone --recursive https://github.com/laminlabs/lamindb python -m venv .venv source .venv/bin/activate pip install git+https://github.com/laminlabs/laminci nox -s install ``` -------------------------------- ### Import and track notebook Source: https://github.com/laminlabs/lamindb/blob/main/docs/arrays.md Initial setup to track the notebook and connect to a database. ```python import lamindb as ln import numpy as np ln.track() db = ln.DB("laminlabs/lamindata") # we'll pull dataset from there ``` -------------------------------- ### Setup LaminDB environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Initializes the LaminDB environment and logs in the user. It also cleans up any existing test data to ensure a fresh start. ```python import pytest import shutil import lamindb as ln ``` ```python ln.setup.login("testuser1") ``` ```python try: root_path = ln.UPath("s3://lamindb-ci/test-add-replace-cache") if root_path.exists(): root_path.rmdir() ln.setup.delete("testuser1/test-add-replace-cache", force=True) except BaseException: # noqa: S110 pass ``` ```python ln.setup.init(storage="s3://lamindb-ci/test-add-replace-cache") ``` -------------------------------- ### Start tracking Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Initialize the run tracking context. ```python ln.track("Rx2s9aPTMQLY0000") ``` -------------------------------- ### Install LaminDB Source: https://github.com/laminlabs/lamindb/blob/main/README.md Install the package with recommended dependencies or minimal core components. ```shell pip install lamindb ``` ```shell pip install lamindb-core ``` -------------------------------- ### Install and Enable Gitmoji Source: https://github.com/laminlabs/lamindb/blob/main/CONTRIBUTING.md Install the gitmoji CLI tool and enable it for the current repository to categorize commits. ```bash npm i -g gitmoji-cli ``` ```bash gitmoji -i ``` -------------------------------- ### Setup test dataframe Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/pydantic-pandera.md Import necessary libraries and load a sample dataset for validation testing. ```python import pandas as pd import pydantic import lamindb as ln import bionty as bt import pandera.pandas as pandera import pprint from typing import Literal, Any df = ln.examples.datasets.mini_immuno.get_dataset1() df ``` -------------------------------- ### Initialize LaminDB environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/reference-field.md Install the package and initialize a new LaminDB instance for testing. ```bash # !pip install lamindb lamin init --storage testreference ``` -------------------------------- ### Initialize LaminDB with modules Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/import-modules.md Install the required dependencies and initialize a new LaminDB instance with specific modules. ```bash # !pip install 'lamindb[bionty]' lamin init --storage testmodule --modules bionty ``` -------------------------------- ### Setup and Initialization Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Imports necessary libraries and sets up the lamindb environment for S3 storage. It includes login, cleanup of previous test runs, and initialization of the storage path. ```python import lamindb as ln import pytest ``` ```python ln.setup.login("testuser1") ``` ```python try: root_path = ln.UPath("s3://lamindb-ci/test-upload") if root_path.exists(): root_path.rmdir() ln.setup.delete("testuser1/test-upload", force=True) except BaseException: # noqa: S110 pass ``` ```python ln.setup.init(storage="s3://lamindb-ci/test-upload") ``` -------------------------------- ### Initialize LaminDB session Source: https://github.com/laminlabs/lamindb/blob/main/docs/transfer.md Import the library and start tracking the session. ```python import lamindb as ln ln.track() ``` -------------------------------- ### Load nested example data Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/pydantic-pandera.md Retrieves and displays a nested dictionary example inspired by the CELLxGENE schema. ```python uns_dict = ln.examples.datasets.dict_cellxgene_uns() pprint.pprint(uns_dict) ``` -------------------------------- ### Initialize LaminDB with Bionty Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/symbol-mapping.md Install the necessary dependencies and initialize a new LaminDB instance with the Bionty module enabled. ```bash # !pip install 'lamindb[bionty]' lamin init --storage test-symbols --modules bionty ``` -------------------------------- ### Start Tracking Source: https://github.com/laminlabs/lamindb/blob/main/tests/core/notebooks/with-title-initialized-consecutive-finish-not-last-cell.ipynb Initiates tracking of operations. UIDs are not passed purposefully to observe default behavior. ```python # do not pass uid purposefully ln.track() ``` -------------------------------- ### Initialize LaminDB project Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/validate-fields.md Install the package and initialize a new project to enable field validation features. ```bash # pip install lamindb lamin init --storage ./test-django-validation ``` -------------------------------- ### Connect to laminDB and Track Data Source: https://github.com/laminlabs/lamindb/blob/main/tests/core/notebooks/basic-r-notebook.Rmd.cleaned.html Connects to the laminDB instance and starts tracking a data transformation. Ensure you have the laminr library installed and configured. ```R library(laminr) db <- connect() db$track("lOScuxDTDE0q0000") ``` -------------------------------- ### Enable Pre-commit Hooks Source: https://github.com/laminlabs/lamindb/blob/main/CONTRIBUTING.md Install the pre-commit hooks to enforce code style automatically on every commit. ```bash pre-commit install ``` -------------------------------- ### Import Necessary Libraries Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Import the required libraries from LaminDB and Vitessce. Ensure these are installed in your environment. ```python import lamindb as ln import pytest from vitessce import ( VitessceConfig, AnnDataWrapper, ) ``` -------------------------------- ### Load and Subset Example Data Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Loads a sample dataset (AnnData PBMC68k reduced) and subsets it to a smaller size for faster processing during notebook execution. ```python pbmc68k = ln.examples.datasets.anndata_pbmc68k_reduced() ``` ```python pbmc68k = pbmc68k[:5, :5].copy() ``` ```python pbmc68k ``` -------------------------------- ### Connect, Track, and Finish LaminDB Run in R Source: https://github.com/laminlabs/lamindb/blob/main/tests/core/notebooks/basic-r-notebook.Rmd.html Connect to a LaminDB instance, track a specific operation, and finish the current run. Ensure the 'laminr' library is installed and configured. ```R library(laminr) db <- connect() ``` ```R db$track("lOScuxDTDE0q0000") ``` ```R db$finish() ``` -------------------------------- ### Initialize cloud instance Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Login and initialize a new instance with S3 storage. ```bash lamin login testuser1 lamin init --storage s3://lamindb-ci/keep-artifacts-local ``` -------------------------------- ### Initialize search environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/search.md Sets up a local test Postgres database and initializes a LaminDB instance for benchmarking search. ```python from laminci.db import setup_local_test_postgres import subprocess pgurl = setup_local_test_postgres() subprocess.run( f"lamin init --name benchmark_search --db {pgurl} --modules bionty --storage ./benchmark_search", shell=True, check=True, ) ``` -------------------------------- ### Create sample data file Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Generate a dummy FASTA file for testing artifact saving. ```python open("sample.fasta", "w").write(">seq1\nACGT\n") ``` -------------------------------- ### Initialize target database Source: https://github.com/laminlabs/lamindb/blob/main/docs/transfer.md Set up a new target database instance using the Lamin CLI. ```bash lamin init --storage ./test-sync --modules bionty ``` -------------------------------- ### Initialize LaminDB Environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Log in to your LaminDB account and initialize a new project with S3 storage. This sets up the environment for subsequent operations. ```bash !lamin login testuser1 ``` ```bash !lamin init --storage "s3://lamindb-ci/test-vitessce" ``` -------------------------------- ### Retrieve and cache artifact Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Get an artifact and cache it without triggering automatic input tracking. ```python artifact = ln.Artifact.get(description="My image") ``` ```python artifact.cache() ``` -------------------------------- ### Handle field validation errors Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/validate-fields.md Example of catching FieldValidationError when creating a model instance with invalid fields. ```python try: ln.Reference(name="my ref", doi="abc.ef", url="myurl.com") except FieldValidationError as e: print(e) ``` -------------------------------- ### Initialize LaminDB environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/arrays.md Commands to log in and initialize a storage-backed LaminDB instance. ```bash lamin login testuser1 lamin init --storage s3://lamindb-ci/test-arrays ``` -------------------------------- ### Get currently used ontology version Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Retrieve the specific ontology version currently configured for a given entity. ```python # inspect which ontology version we're about to import bt.Source.get(entity="bionty.CellType", currently_used=True) ``` -------------------------------- ### Define AnnData metadata schema Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Example JSON structure for validating nested metadata keys within an AnnData object. ```json { "study_metadata": {"experiment": "Experiment 1", "temperature": 21.2} } ``` -------------------------------- ### Get Value Counts from Subset Observations Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/anndata-accessor.ipynb Calculates and displays the value counts for a specific column in the observation data of the subsetted AnnData object. ```python adata_subset.obs.cell_type.value_counts() ``` -------------------------------- ### Create and save records Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/idempotency.md Demonstrates creating records and handling potential duplicates via name matching. ```python label = ln.Record(name="My label 1").save() ``` ```python label = ln.Record(name="My label 1a") ``` ```python label.save() ``` ```python label = ln.Record(name="My label 1") ``` ```python label.save() ``` ```python label = ln.Record(name="My label 1b") ``` ```python label = ln.Record(name="My label 1c") ``` -------------------------------- ### Initialize database connection Source: https://github.com/laminlabs/lamindb/blob/main/docs/query-search.md Establishes a connection to a specific LaminDB database instance. ```python import lamindb as ln db = ln.DB("laminlabs/lamindata") ``` -------------------------------- ### Initialize LaminDB instance Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/pydantic-pandera.md Initialize a new LaminDB instance with specific storage and modules. ```bash lamin init --storage test-pydantic-pandera --modules bionty ``` -------------------------------- ### Define artifact for saving Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Create an artifact instance pointing to the sample file. ```python artifact = ln.Artifact("sample.fasta", key="sample.fasta") ``` -------------------------------- ### Configure LaminDB Instance Source: https://github.com/laminlabs/lamindb/blob/main/README.md Authenticate, connect to existing instances, or initialize new ones via CLI. ```shell lamin login lamin connect account/name # add flag --here to sync with current development directory ``` ```shell lamin init --storage ./quickstart-data --modules bionty ``` -------------------------------- ### Manage local storage locations Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Create, list, and set default local storage locations. ```python ln.Storage(root="./our_local_storage", host="abc-institute-drive1").save() ``` ```python ln.Storage.to_dataframe() ``` ```python ln.settings.local_storage = "./our_local_storage" ``` -------------------------------- ### Configure LaminDB environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Set up the testing environment with necessary imports and verbosity settings. ```python import pytest import lamindb as ln from upath import UPath ln.settings.verbosity = "debug" ``` -------------------------------- ### Load and Prepare AnnData Dataset Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Load a sample AnnData dataset, subset it, and write it to a local Zarr file. Then, create a LaminDB artifact from this Zarr file. ```python pbmc68k = ln.examples.datasets.anndata_pbmc68k_reduced()[:100, :200].copy() zarr_filepath = "my_test.zarr" # write the anndata to a local zarr path pbmc68k.write_zarr(zarr_filepath) # create an artifact from the path dataset_artifact = ln.Artifact(zarr_filepath, description="Test dataset").save() # this is the where the zarr folder is located on a public S3 bucket dataset_artifact.path.to_url() ``` -------------------------------- ### Initialize LaminDB storage Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Initialize a new LaminDB instance for testing. ```bash lamin init --storage ./test-acid ``` -------------------------------- ### Switch between local storage locations Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Configure and switch to a different local storage root. ```python ln.Storage(root="./our_local_storage2", host="abc-institute-drive1").save() ln.settings.local_storage = "./our_local_storage2" # switch to the new storage location ``` ```python filepath = ln.examples.datasets.file_fastq() artifact3 = ln.Artifact(filepath, key="example_datasets/file.fastq.gz").save() ``` ```python ln.Artifact.to_dataframe(include=["storage__root", "storage__region"]) ``` -------------------------------- ### Connect to Cloud Instance Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/sync-local-to-cloud.ipynb Establishes a connection to the specified laminDB cloud instance. Ensure you have the necessary credentials and instance name. ```python import lamindb as ln ln.connect("laminlabs/lamin-dev") ``` -------------------------------- ### Describe latest run Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Access and describe the most recent execution of the workflow. ```python transform.latest_run.describe() ``` -------------------------------- ### Initialize LaminDB with S3 Storage Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/anndata-accessor.ipynb Initializes LaminDB and sets the storage location to an S3 bucket. Ensure the S3 bucket is accessible. ```python import lamindb as ln ln.setup.init(storage="s3://lamindb-ci/test-anndata") ``` -------------------------------- ### Configure search queries and import source Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/search.md Defines search query sets and imports the Bionty CellType source. ```python import lamindb as ln import bionty as bt SEARCH_QUERIES_EXACT = ( "t cell", "stem cell", "b cell", "regulatory B cell", "Be2 cell", "adipocyte", ) SEARCH_QUERIES_CONTAINS = ("t cel", "t-cel", "neural", "kidney", "kidne") TOP_N = 20 bt.CellType.import_source() ``` -------------------------------- ### Query Databases and Load Artifacts Source: https://github.com/laminlabs/lamindb/blob/main/README.md Connect to a database, retrieve metadata, and load data into memory or local cache. ```python import lamindb as ln db = ln.DB("laminlabs/cellxgene") # a database object for queries df = db.Artifact.to_dataframe() # a dataframe listing datasets & models ``` ```python artifact = db.Artifact.get("BnMwC3KZz0BuKftR") # a metadata object for a dataset artifact.describe() # describe the context of the dataset ``` ```python local_path = artifact.cache() # return a local path from a cache adata = artifact.load() # load object into memory accessor = artifact.open() # return a streaming accessor ``` ```python alzheimers = db.bionty.Disease.get(name="Alzheimer disease") df = db.Artifact.filter(diseases=alzheimers).to_dataframe() ``` -------------------------------- ### Initialize LaminDB Instance Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/prepare-sync-local-to-cloud.ipynb Initialize a new LaminDB instance with a specified storage path and modules. This prepares the local environment for data storage and synchronization. ```python ln.setup.init(storage="./test-sync-to-cloud", modules="bionty,pertdb") ``` -------------------------------- ### Run script with features and parameters Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Execute a tracking script with specific feature and parameter flags. ```bash python scripts/run_track_with_features_and_params.py --s3-folder s3://my-bucket/my-folder --experiment Experiment1 ``` -------------------------------- ### Import LaminDB Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/reference-field.md Import the lamindb library to begin interacting with the database. ```python import lamindb as ln ``` -------------------------------- ### Track notebook run Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Initialize the LaminDB environment for the current notebook session. ```python # pip install lamindb import lamindb as ln ln.track("l9lFf83aPwRc") ``` -------------------------------- ### Disconnect and Configure Modules Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/prepare-sync-local-to-cloud.ipynb Before preparing for sync, disconnect from any active LaminDB instances and set necessary modules in the environment. This ensures a clean slate for the synchronization process. ```bash !lamin disconnect # need to add pertdb to environment in order to import it !lamin settings modules set bionty,pertdb ``` -------------------------------- ### Track parameters via CLI Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Execute a script with parameters using the command line interface. ```bash python scripts/run_track_with_params.py --input-dir ./mydataset --learning-rate 0.01 --downsample ``` -------------------------------- ### Configure development directory and git sync Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Set the development directory and configure git repository synchronization for local development. ```bash lamin settings set dev-dir . ``` ```bash lamin info ``` ```shell export LAMINDB_SYNC_GIT_REPO = ``` ```python ln.settings.sync_git_repo = ``` -------------------------------- ### Prepare test dataset for lineage tracking Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Create an initial artifact from a dataframe to serve as input for the tracked function. ```python df = ln.examples.datasets.mini_immuno.get_dataset1(otype="DataFrame") input_artifact_key = "my_analysis/dataset.parquet" artifact = ln.Artifact.from_dataframe(df, key=input_artifact_key).save() ``` -------------------------------- ### Sync artifact from source database Source: https://github.com/laminlabs/lamindb/blob/main/docs/transfer.md Connect to a remote database, retrieve an artifact, and save it to the current default database. ```python db = ln.DB("laminlabs/lamindata") # query the artifact on the source database artifact = db.Artifact.get(key="example_datasets/mini_immuno/dataset1.h5ad") # sync the artifact to the current database artifact.save() ``` -------------------------------- ### Inspect synced artifact Source: https://github.com/laminlabs/lamindb/blob/main/docs/transfer.md Verify the artifact details, storage path, and lineage after syncing. ```python artifact.describe() ``` ```python artifact.path ``` ```python artifact.view_lineage() ``` ```python artifact.run.initiated_by_run.transform ``` -------------------------------- ### Configure Vitessce with AnnData Wrapper Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Create a Vitessce configuration and add the prepared AnnData dataset using the AnnDataWrapper. This prepares the data for visualization. ```python vc = VitessceConfig(schema_version="1.0.15") vc.add_dataset(name="test1").add_object( AnnDataWrapper( adata_artifact=dataset_artifact, obs_embedding_paths=["obsm/X_umap"], ), ) vc.to_dict() ``` -------------------------------- ### Ingest a single file into a virtual folder Source: https://github.com/laminlabs/lamindb/blob/main/docs/organize.md Use a slash-separated key to organize an artifact into a virtual directory structure. ```python artifact1 = ln.Artifact("./dataset.csv", key="project1/dataset1.csv").save() ``` -------------------------------- ### Execute script with step tracking Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Run a Python script from the command line that utilizes the @ln.step() decorator. ```bash python scripts/run_script_with_step.py --subset ``` -------------------------------- ### Switch and configure contribution branches Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-changes.md Use CLI or Python APIs to switch branches or define the branch context for new objects. ```bash lamin switch -c my_branch ``` ```python ln.setup.settings.branch = "my_branch" # globally switch the default branch ``` ```python ln.track(branch="my_branch") # default branch for all objects created in a run to my_branch ``` ```python ln.Artifact(..., branch="my_branch") # add an artifact on my_branch ln.ULabel(..., branch="my_branch") # add a ULabel on my_branch ``` -------------------------------- ### Manage projects and artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Create projects, track runs within them, and filter or access associated artifacts. ```python import lamindb as ln my_project = ln.Project(name="My project").save() # create & save a project ln.track(project="My project") # pass project open("sample.fasta", "w").write(">seq1\nACGT\n") # create a dataset ln.Artifact("sample.fasta", key="sample.fasta").save() # auto-labeled by project ``` ```python ln.Artifact.filter(projects=my_project).to_dataframe() ``` ```python my_project.artifacts.to_dataframe() ``` -------------------------------- ### Create and track artifact versions Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-changes.md Use the same key for multiple artifacts to create versions, which can then be inspected via the versions dataframe. ```python import lamindb as ln from pathlib import Path Path("my_file.txt").write_text("v1") artifact = ln.Artifact("my_file.txt", key="my_file.txt").save() Path("my_file.txt").write_text("v2") artifact_v2 = ln.Artifact("my_file.txt", key="my_file.txt").save() artifact_v2.versions.to_dataframe() # see all versions of this artifact ``` -------------------------------- ### Register pre-existing local files Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Register an existing local file as an artifact without moving it. ```python file_in_local_storage = ln.examples.datasets.file_bam() file_in_local_storage.rename("./our_local_storage/output.bam") ln.UPath("our_local_storage/").view_tree() ``` ```python my_existing_file = ln.Artifact("./our_local_storage/output.bam").save() ln.UPath("our_local_storage/").view_tree() ``` ```python my_existing_file.path ``` -------------------------------- ### Run multi-step workflow Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Execute the multi-step workflow script. ```bash python scripts/my_workflow_with_step.py ``` -------------------------------- ### Load transform via CLI Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Load a transform into the current development directory using the Lamin CLI. ```bash lamin load --key my_analyses/my_notebook.ipynb ``` ```bash lamin load https://lamin.ai/laminlabs/lamindata/transform/F4L3oC6QsZvQ ``` -------------------------------- ### Create a new collection of artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/organize.md Initializes a new immutable collection from a list of artifacts and saves it to the database. ```python collection = ln.Collection([artifact1, artifact2], key="my_data_release").save() ``` -------------------------------- ### Describe CLI-based run Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve and describe a run that utilized CLI arguments. ```python run = ln.Run.filter(transform__key="my_workflow_with_click.py").first() run.describe() ``` -------------------------------- ### Create and save records from a specific source Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Create records from a non-default source and view their hierarchy. ```python # since we didn't seed the Organism registry with the NCBITaxon public ontology # we need to save the records to the database records = bt.Organism.from_values( ["iris setosa", "iris versicolor", "iris virginica"], source=source ).save() # now we can query a iris organism and view its parents and children bt.Organism.get(name="iris").view_parents(with_children=True) ``` -------------------------------- ### Import public ontology records Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Populate the local database with records from public ontologies. ```python # populate the database with a public ontology bt.CellType.import_source() ``` -------------------------------- ### Manage Artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/idempotency.md Create, save, and verify artifacts to ensure idempotency through hash lookups. ```python filepath = ln.examples.datasets.file_fcs() ``` ```python artifact = ln.Artifact(filepath, key="my_fcs_file.fcs").save() ``` ```python assert artifact.hash == "rCPvmZB19xs4zHZ7p_-Wrg" assert artifact.run == ln.context.run assert not artifact.recreating_runs.exists() ``` ```python artifact2 = ln.Artifact(filepath, key="my_fcs_file.fcs") ``` ```python assert artifact.id == artifact2.id assert artifact.run == artifact2.run assert not artifact.recreating_runs.exists() ``` ```python artifact2.save() ``` -------------------------------- ### Save and verify local artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Save an artifact to local storage and verify its existence. ```python original_filepath = ln.examples.datasets.file_fcs() artifact = ln.Artifact(original_filepath, key="example_datasets/file1.fcs").save() local_path = artifact.path # local storage path local_path ``` ```python assert artifact.path.exists() assert artifact.path.as_posix().startswith(ln.settings.local_storage.root.as_posix()) ln.settings.local_storage.root.view_tree() ``` -------------------------------- ### Save Notebook as Artifact Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Saves a notebook file as an artifact in the registry with a specified key and description. ```bash lamin save template1.ipynb --key templates/template1.ipynb --description "Template for analysis type 1" --registry artifact ``` -------------------------------- ### Open artifact store for reading Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Opens the artifact's Zarr store directly from its cloud path without syncing to the local cache, allowing inspection of its contents. ```python with artifact.open() as store: assert "add_new_col" in store.obs ``` -------------------------------- ### Replace artifact with virtual key - error handling Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Demonstrates an error scenario when attempting to replace an artifact with a virtual key using a path that is already in storage. This operation is disallowed. ```python with pytest.raises(ValueError) as err: artifact.replace(path_in_storage) assert err.exconly().startswith( "ValueError: Can only replace with a local path not in any Storage." ) ``` -------------------------------- ### Handle Non-Existent File Upload Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Demonstrates error handling when attempting to create an artifact from a file path that does not exist on S3. ```python with pytest.raises(FileNotFoundError): non_existent_h5ad = ln.Artifact( "s3://lamindb-ci/test-upload/non_existent_file.h5ad" ) ``` -------------------------------- ### Track agent plans Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Save and link agent plans to runs to steer non-deterministic agent execution. ```bash lamin save /path/to/.cursor/plans/my_task.plan.md lamin save /path/to/.claude/plans/my_task.md ``` ```python ln.track(plan=".plans/my-agent-plan.md") ``` -------------------------------- ### Define and describe schema Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Instantiates a flexible schema for the dataset and displays its structure. ```python schema = ln.examples.datasets.mini_immuno.define_mini_immuno_schema_flexible() schema.describe() ``` -------------------------------- ### Define features and labels Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Sets up the necessary registries for the dataset features and labels. ```python .. literalinclude:: scripts/define_mini_immuno_features_labels.py :language: python ``` -------------------------------- ### Retrieve and Describe Artifact Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/sync-local-to-cloud.ipynb Connects to a specific artifact in the cloud and retrieves its metadata. Use this to inspect artifact details before or after synchronization. ```python artifact = ln.Artifact.connect("testuser1/test-sync-to-cloud").get( description="test-sync-to-cloud" ) artifact.describe() ``` -------------------------------- ### Upload local artifacts to cloud Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Upload local artifacts to the cloud storage location. ```python artifact.save(upload=True) ``` ```python ln.settings.storage.root.view_tree() ``` ```python assert artifact.path.exists() assert not local_path.exists() assert artifact.path.as_posix().startswith(ln.settings.storage.root.as_posix()) ln.settings.local_storage.root.view_tree() ``` -------------------------------- ### Track a run Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/idempotency.md Initialize tracking for a specific run. ```python import lamindb as ln ln.track("ANW20Fr4eZgM0000") ``` -------------------------------- ### Create a Record with reference fields Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/reference-field.md Register a new record while specifying external vendor IDs using the reference and reference_type fields. ```python ln.Record( name="donor 001", reference="VX984545", reference_type="Donor ID from Vendor X" ) ``` -------------------------------- ### Attempt to replace folder artifact with a file Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Demonstrates that replacing a folder artifact (like a Zarr store) with a file artifact will raise a ValueError. ```python with pytest.raises(ValueError) as err: artifact.replace("./test-files/iris.csv") assert err.exconly().endswith("It is not allowed to replace a folder with a file.") ``` -------------------------------- ### Load artifact with automatic tracking Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Retrieve and load an artifact, which will now be automatically tracked as a run input. ```python artifact = ln.Artifact.get(description="My csv") ``` ```python artifact.load() ``` -------------------------------- ### Retrieve registry overviews Source: https://github.com/laminlabs/lamindb/blob/main/docs/query-search.md Methods to view registry contents as DataFrames or summaries. ```python db.Artifact.to_dataframe() ``` ```python db.Artifact.to_dataframe(include=["created_by__handle"]) ``` ```python db.view() ``` -------------------------------- ### Import Libraries Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/prepare-sync-local-to-cloud.ipynb Import the required LaminDB, Bionty, PerDB, and Pandas libraries for data manipulation and LaminDB operations. ```python import lamindb as ln import bionty as bt import pertdb import pandas as pd ``` -------------------------------- ### Load Transform Template Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Loads a transform template from a URL to create a new version. ```bash lamin load https://lamin.ai/account/instance/transform/Akd7gx7Y9oVO0000 ``` -------------------------------- ### Verify data lineage Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/idempotency.md Check how artifact recreation interacts with data lineage and run tracking. ```python ln.track(new_run=True) artifact3 = ln.Artifact(filepath, key="my_fcs_file.fcs") assert artifact3.id == artifact2.id assert artifact3.run == artifact2.run != ln.context.run # run is not updated assert artifact2.recreating_runs.first() == ln.context.run ``` -------------------------------- ### Bulk Create Records Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/curate-any.md Create validated records from values and save them to the registry. ```python diseases = bt.Disease.from_values(disease, field=bt.Disease.ontology_id).save() ``` -------------------------------- ### Upload from Memory with ID and Implicit Key Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Creates an artifact from an in-memory AnnData object, allowing lamindb to infer the key, and saves it. It also demonstrates deleting the artifact. ```python pbmc68k_h5ad = ln.Artifact.from_anndata(pbmc68k, description="pbmc68k.h5ad") ``` ```python pbmc68k_h5ad.save() ``` ```python pbmc68k_h5ad.delete(permanent=True, storage=True) ``` -------------------------------- ### Create test artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Generate artifacts for testing run input tracking. ```python ln.track(transform=ln.Transform(key="Dummpy pipeline")) ln.Artifact(ln.examples.datasets.file_jpg_paradisi05(), description="My image").save() ln.Artifact(ln.examples.datasets.file_mini_csv(), description="My csv").save() ``` -------------------------------- ### Manage branches Source: https://github.com/laminlabs/lamindb/blob/main/README.md Switch between and merge contribution branches for change management. ```shell lamin switch -c my_branch ``` ```shell lamin switch main # switch to the main branch lamin merge my_branch # merge contribution branch into main ``` -------------------------------- ### Verify Action Attachment Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Assert that the Vitessce configuration artifact is correctly attached to the dataset artifact. This confirms the integration is working as expected. ```python # different equivalent ways of testing that the action is attached assert dataset_artifact._actions.get() == vitessce_config_artifact assert vitessce_config_artifact._action_targets.get() == dataset_artifact assert vitessce_config_artifact._actions.first() is None assert vitessce_config_artifact.kind == "__lamindb_config__" assert ln.Artifact.get(_actions=vitessce_config_artifact) == dataset_artifact ``` -------------------------------- ### Run SOMA Curation Script Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Executes the curation script via the command line. ```bash python scripts/curate_soma_experiment.py ``` -------------------------------- ### Track script execution and lineage Source: https://github.com/laminlabs/lamindb/blob/main/README.md Use ln.track() to initialize tracking for a script and save artifacts with lineage information. ```python import lamindb as ln # → connected lamindb: account/instance ln.track() # track code execution open("sample.fasta", "w").write(">seq1\nACGT\n") # create dataset ln.Artifact("sample.fasta", key="sample.fasta").save() # save dataset ln.finish() # mark run as finished ``` -------------------------------- ### Track projects and agent plans Source: https://github.com/laminlabs/lamindb/blob/main/README.md Associate runs with specific projects or agent plans using Python or CLI commands. ```python ln.track(project="My project", plan="./plans/curate-dataset-x.md") ``` ```shell # create a project with the CLI lamin create project "My project" # save an agent plan with the CLI lamin save /path/to/.cursor/plans/curate-dataset-x.plan.md lamin save /path/to/.claude/plans/curate-dataset-x.md ``` ```python ln.Project(name="My project").save() # create a project in Python ``` -------------------------------- ### Describe and inspect schema Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Examine the schema structure and its slots to understand validation requirements. ```python schema = ln.examples.schemas.anndata_ensembl_gene_ids_and_valid_features_in_obs() schema.describe() ``` ```python schema.slots ``` -------------------------------- ### Load mini immuno dataset Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Retrieves the mini immuno dataset for demonstration purposes. ```python df = ln.examples.datasets.mini_immuno.get_dataset1( with_cell_type_synonym=True, with_cell_type_typo=True ) df ``` -------------------------------- ### Define Test Dataset Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/curate-any.md Create a Zarr group and populate it with sample data for temperature, genes, and diseases. ```python import lamindb as ln import bionty as bt import zarr import numpy as np data = zarr.open_group(store="data.zarr", mode="a") data.create_dataset(name="temperature", shape=(3,), dtype="float32") data.create_dataset(name="knockout_gene", shape=(3,), dtype=str) data.create_dataset(name="disease", shape=(3,), dtype=str) data["knockout_gene"][:] = np.array( ["ENSG00000139618", "ENSG00000141510", "ENSG00000133703"] ) data["disease"][:] = np.random.default_rng().choice( ["MONDO:0004975", "MONDO:0004980"], 3 ) ``` -------------------------------- ### Label and query artifacts Source: https://github.com/laminlabs/lamindb/blob/main/README.md Apply labels to artifacts and perform queries based on metadata fields. ```python my_label = ln.ULabel(name="My label").save() # a universal label project = ln.Project(name="My project").save() # a project label artifact.ulabels.add(my_label) artifact.projects.add(project) ``` ```python ln.Artifact.filter(ulabels=my_label, projects=project).to_dataframe() ``` ```python ln.Artifact.filter(run=run).to_dataframe() # by creating run ln.Artifact.filter(transform=transform).to_dataframe() # by creating transform ln.Artifact.filter(size__gt=1e6).to_dataframe() # size greater than 1MB ``` ```python ln.Artifact.to_dataframe(include=["created_by__name", "storage__root"]) # include fields from related registries ``` -------------------------------- ### Handle Non-Existent Bucket Upload Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Demonstrates error handling when attempting to create an artifact from a bucket that does not exist on S3. This can raise either FileNotFoundError or PermissionError. ```python with pytest.raises((FileNotFoundError, PermissionError)): non_existent_h5ad = ln.Artifact( "s3://non_existent_bucket_6612366/non_existent_file.h5ad" ) ``` -------------------------------- ### Verify artifact after replacement Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Asserts that the artifact's real key, clear storage key, and virtual key are updated correctly after a replacement operation. ```python assert artifact._real_key.endswith("iris.data") assert artifact._clear_storagekey.endswith("iris.csv") assert artifact.key == "iris_test.data" ``` -------------------------------- ### Run workflow with CLI arguments Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Execute the workflow script passing arguments via the command line. ```bash python scripts/my_workflow_with_click.py --key my_analysis/dataset2.parquet ``` -------------------------------- ### Save and Load Artifacts Source: https://github.com/laminlabs/lamindb/blob/main/README.md Manage files and folders as artifacts using Python API or CLI commands. ```python import lamindb as ln # → connected lamindb: account/instance open("sample.fasta", "w").write(">seq1\nACGT\n") # create dataset ln.Artifact("sample.fasta", key="sample.fasta").save() # save dataset ``` ```shell lamin save sample.fasta --key sample.fasta ``` ```shell lamin load --key sample.fasta ``` -------------------------------- ### Manage SQLRecord name search settings Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/idempotency.md Verify and toggle the search_names setting to control automatic record matching. ```python assert ln.settings.creation.search_names ``` ```python ln.settings.creation.search_names = False ``` ```python ln.settings.creation.search_names = True ``` -------------------------------- ### Save markdown notes via CLI Source: https://github.com/laminlabs/lamindb/blob/main/README.md Saves a local markdown file as a record in the development directory. ```shell lamin save / ``` -------------------------------- ### Import schema module Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/import-modules.md Importing the schema module does not trigger lamindb initialization. ```python import bionty as bt ``` -------------------------------- ### Access CLI arguments Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve the command line arguments used to initiate a run. ```python run.cli_args ``` -------------------------------- ### Define labels and features Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Create records for experiment types and features in the registry. ```python experiment_type = ln.Record(name="Experiments", is_type=True).save() experiment_label = ln.Record(name="Experiment1", type=experiment_type).save() ln.Feature(name="s3_folder", dtype=str).save() ln.Feature(name="experiment", dtype=experiment_type).save() ``` -------------------------------- ### Query artifacts by folder path Source: https://github.com/laminlabs/lamindb/blob/main/docs/organize.md Retrieve all artifacts sharing a common prefix in their key. ```python artifacts = ln.Artifact.filter(key__startswith="project1/") ``` -------------------------------- ### Clean Up Local Files and LaminDB Project Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/vitessce.ipynb Remove the local Zarr directory and delete the initialized LaminDB project. This ensures a clean state after the demonstration. ```bash !rm -rf test-vitessce ``` ```bash !lamin delete --force test-vitessce ``` -------------------------------- ### Ingest an entire directory as artifacts Source: https://github.com/laminlabs/lamindb/blob/main/docs/organize.md Create individual artifacts for every file within a specified directory. ```python artifacts = ln.Artifact.from_dir("./project1/").save() ``` -------------------------------- ### Create Additional Records Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/curate-any.md Create and save records for experiments and genes. ```python experiments = ln.Record.from_values( ["Experiment A", "Experiment B"], field=ln.Record.name, create=True, # create non-validated labels ).save() genes = bt.Gene.from_values( data["knockout_gene"][:], field=bt.Gene.ensembl_gene_id ).save() ``` -------------------------------- ### Cleanup test environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Remove the test storage and delete the environment. ```bash rm -r test-run-inputs lamin delete --force test-run-inputs ``` -------------------------------- ### Describe and retrieve run parameters Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve the most recent run matching a parameter and inspect its details. ```python run = ln.Run.filter(params__learning_rate=0.01).order_by("-started_at").first() run.describe() run.params ``` -------------------------------- ### Cleanup resources Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/keep-artifacts-local.md Delete artifacts and the test instance. ```python artifact.delete(permanent=True) artifact2.delete(permanent=True) artifact3.delete(permanent=True) my_existing_file.delete(permanent=True, storage=False) ``` ```python ln.setup.delete("keep-artifacts-local", force=True) ``` -------------------------------- ### Manage object lifecycle with trash and archive Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-changes.md Objects moved to trash are hidden from queries and scheduled for deletion, while archived objects are hidden but preserved. ```python artifact.delete() assert artifact.branch.name == "trash" # the artifact does not show up in a default query ln.Artifact.filter(key="my_file.txt") # you can still query for it by adding the trash branch to the filter ln.Artifact.filter(key="my_file.txt", branch__name="trash") # you can restore it from trash artifact.restore() ``` ```python artifact.branch_id = 0 artifact.save() ``` -------------------------------- ### Define a basic schema with features Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Creates a schema using Feature objects to define required columns and their data types. ```python schema = ln.Schema( name="experiment_schema", # human-readable name features=[ # required features ln.Feature(name="cell_type", dtype=bt.CellType), ln.Feature(name="treatment", dtype=str), ], otype="DataFrame" # object type (DataFrame, AnnData, etc.) ) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/laminlabs/lamindb/blob/main/tests/core/notebooks/with-title-initialized-consecutive-finish.ipynb Imports the lamindb library as ln and pytest for testing. ```python import lamindb as ln import pytest ``` -------------------------------- ### View global lineage Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Visualize the lineage of all tracked operations in the current environment. ```python ln.view() ``` -------------------------------- ### Create and Save Artifacts with Metadata Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/prepare-sync-local-to-cloud.ipynb Create an artifact from a Pandas DataFrame, save it, and associate it with features, organisms, and compounds. This demonstrates how to enrich artifacts with metadata before synchronization. ```python artifact = ln.Artifact.from_dataframe( pd.DataFrame({"a": [1, 2, 3]}), description="test-sync-to-cloud" ).save() features = bt.CellMarker.from_values( ["PD1", "CD21"], field=bt.CellMarker.name, organism="human" ).save() artifact.features._add_schema(ln.Schema(features), slot="var") organism = bt.Organism.from_source(name="human").save() artifact.labels.add(organism) compound = pertdb.Compound(name="compound-test-sync-to-cloud").save() artifact.compounds.add(compound) artifact.describe() ``` -------------------------------- ### Verify recovery Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Confirm that the artifact is no longer in an ongoing storage state. ```python assert not artifact._storage_ongoing assert artifact._aux is None ``` -------------------------------- ### Annotate an artifact with a simple label Source: https://github.com/laminlabs/lamindb/blob/main/docs/organize.md Use ULabel to add simple metadata tags to an artifact. ```python ulabel1 = ln.ULabel(name="raw_data").save() # create a ulabel artifact1.ulabels.add(ulabel1) # annotate artifact1 ``` -------------------------------- ### Verify manual tracking Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/track-run-inputs.md Confirm that the artifact was added to the run inputs. ```python for input in ln.Run.get(id=ln.context.run.id).input_artifacts.all(): print(input) ``` ```python artifact.view_lineage() ``` ```python assert len(ln.Run.get(id=ln.context.run.id).input_artifacts.all()) == 1 ``` -------------------------------- ### Track data versions Source: https://github.com/laminlabs/lamindb/blob/main/README.md Use tracking to manage artifact versions and retrieve history by key. ```python import lamindb as ln ln.track() open("sample.fasta", "w").write(">seq1\nTGCA\n") # a new sequence ln.Artifact("sample.fasta", key="sample.fasta", features={"experiment": "Experiment 1"}).save() # annotate with the new experiment ln.finish() ``` ```python artifact = ln.Artifact.get(key="sample.fasta") # get artifact by key artifact.versions.to_dataframe() # see all versions of that artifact ``` -------------------------------- ### Access transform metadata Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve transform details, source code, run history, and environment reports from the registry. ```python transform = ln.Transform.get(key="my_analyses/my_notebook.ipynb") transform.source_code # source code transform.runs.to_dataframe() # all runs in a dataframe transform.latest_run.report # report of latest run transform.latest_run.environment # environment of latest run ``` -------------------------------- ### Create records from values Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Returns validated records and automatically standardizes inputs. ```python bt.CellType.from_values(["fat cell", "blood forming stem cell"]) ``` -------------------------------- ### Replace artifact with new file Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Replaces the content of an existing artifact with a new file from a different path. The artifact's key remains the same, but its content and hash are updated. ```python artifact.replace("./test-files/iris.data") ``` -------------------------------- ### Run a workflow script Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Execute the Python script containing the workflow definition. ```bash python scripts/my_workflow.py ``` -------------------------------- ### Create artifact from DataFrame with manual key Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Creates an artifact directly from a Pandas DataFrame, assigning it a specific key. The artifact is then saved to storage. ```python import pandas as pd ``` ```python iris = pd.read_csv("./test-files/iris.csv") ``` ```python artifact = ln.Artifact.from_dataframe( iris, description="iris_store", key="iris.parquet" ) ``` ```python artifact.save() ``` ```python key_path = root / "iris.parquet" ``` ```python assert key_path.exists() ``` -------------------------------- ### Upload from Memory with Explicit Key Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/upload.ipynb Creates an artifact from an in-memory AnnData object and saves it to S3 storage with an explicitly defined semantic key. ```python pbmc68k_h5ad = ln.Artifact.from_anndata(pbmc68k, key="test-upload/pbmc68k.h5ad") ``` ```python pbmc68k_h5ad.save() ``` ```python pbmc68k_h5ad.delete(permanent=True) ``` -------------------------------- ### Curate TileDBSOMA Experiment Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Validates obs and var dataframes of a SOMA experiment without full memory loading. ```python .. literalinclude:: scripts/curate_soma_experiment.py :language: python :caption: curate_soma_experiment.py ``` -------------------------------- ### Cleanup search environment Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/search.md Stops the test database container and deletes the LaminDB instance. ```bash docker stop pgtest && docker rm pgtest lamin delete --force benchmark_search ``` -------------------------------- ### Verify artifact key after saving Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Asserts that the real key of the artifact ends with the expected filename, confirming the virtual key was applied. ```python assert artifact._real_key.endswith("iris.csv") ``` -------------------------------- ### Import gene registries Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Populate the Gene registry for specific organisms. ```python # let's also populate the Gene registry with human and mouse genes bt.Gene.import_source(organism="human") bt.Gene.import_source(organism="mouse") ``` -------------------------------- ### View artifact lineage Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve an artifact by key and visualize its lineage history. ```python subsetted_artifact = ln.Artifact.get(key=ouput_artifact_key) subsetted_artifact.view_lineage() ``` -------------------------------- ### Construct custom hierarchies Source: https://github.com/laminlabs/lamindb/blob/main/docs/manage-ontologies.md Create new records and manually define parent-child relationships. ```python # register a new cell type my_celltype = bt.CellType(name="my new T-cell subtype").save() # specify "gamma-delta T cell" as a parent my_celltype.parents.add(gdt_cell) # visualize hierarchy my_celltype.view_parents(distance=3) ``` -------------------------------- ### Replace artifact with virtual key - different content Source: https://github.com/laminlabs/lamindb/blob/main/docs/storage/add-replace-cache.ipynb Replaces an artifact with new content, changing its suffix and key. The old path is deleted, and a new path is created. ```python artifact.replace("./test-files/iris.data") ``` ```python artifact.save() ``` ```python assert artifact.key == "iris.data" ``` ```python assert not fpath.exists() ``` ```python fpath = artifact.path assert fpath.suffix == ".data" and fpath.stem == artifact.uid ``` ```python artifact.delete(permanent=True, storage=True) ``` -------------------------------- ### Describe and retrieve feature values Source: https://github.com/laminlabs/lamindb/blob/main/docs/track.md Retrieve the last run matching specific features and inspect its values. ```python run2 = ln.Run.filter( s3_folder="s3://my-bucket/my-folder", experiment="Experiment1" ).last() run2.describe() run2.features.get_values() ``` -------------------------------- ### Share data across databases Source: https://github.com/laminlabs/lamindb/blob/main/README.md Sync artifacts from a source database to the default database using zero-copy transfer. ```python db = ln.DB("laminlabs/lamindata") artifact = db.Artifact.get(key="example_datasets/mini_immuno/dataset1.h5ad") artifact.save() ``` -------------------------------- ### Load and inspect AnnData for validation Source: https://github.com/laminlabs/lamindb/blob/main/docs/curate.md Load a dataset with intentional typos to demonstrate validation workflows. ```python adata = ln.examples.datasets.mini_immuno.get_dataset1( with_gene_typo=True, with_cell_type_typo=True, otype="AnnData" ) adata ``` -------------------------------- ### Annotate dataset with Artifact constructor Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/pydantic-pandera.md Use the Artifact constructor directly when ontology updates or standardization are not required. ```python artifact = ln.Artifact.from_dataframe( df, key="our_datasets/dataset1.parquet", schema=lamindb_schema ).save() ``` -------------------------------- ### Perform successful save Source: https://github.com/laminlabs/lamindb/blob/main/docs/faq/acid.md Execute a standard save operation for the artifact. ```python artifact.save() ``` -------------------------------- ### Track with a valid UID Source: https://github.com/laminlabs/lamindb/blob/main/tests/core/notebooks/with-title-initialized-consecutive-finish.ipynb This snippet shows how to track an experiment using a valid, auto-generated UID. ```python # with uid passed ln.track("ujPaFZatnMLG0000") ```