Metadata-Version: 2.5
Name: baseqdb
Version: 0.14.0
Summary: Your baSeq datasets, analyses and results from Python, with lamindb's names
Project-URL: Homepage, https://baseq.bio
Project-URL: Documentation, https://baseq.bio/docs/python-and-r.html
Author-email: baSeq ApS <info@baseq.dk>
License-Expression: MIT
License-File: LICENSE
Keywords: baseq,bioinformatics,lineage,provenance,rna-seq,single-cell
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Requires-Dist: httpx>=0.24
Requires-Dist: pandas>=1.5
Provides-Extra: azure
Requires-Dist: adlfs>=2023.8; extra == 'azure'
Provides-Extra: pandas
Requires-Dist: pandas>=1.5; extra == 'pandas'
Provides-Extra: s3
Requires-Dist: s3fs>=2023.6; extra == 's3'
Description-Content-Type: text/markdown

# baseqdb

Your baSeq datasets, the analyses built on them, what they found and where a result came from, from Python.

```python
import baseqdb as bq
bq.login()                                      # reads BASEQ_API_KEY

bq.Dataset.filter(kind="bulk").to_dataframe()   # yours, newest versions
bq.Dataset.filter(organism="human", condition="dexamethasone")   # by any column of the sample sheets
bq.Dataset.search("dexamethasone")              # as the Data page's search
bq.Analysis.filter(kind="bulk").to_dataframe()  # the analyses you can open, newest first
ds = bq.Dataset.get("kTIqMTTm89P2gbNU0000")     # one version, by its uid
folder = ds.cache()                             # its files, downloaded once
sheet = ds.sample_sheet                         # a DataFrame
bq.Gene.standardize(["ENSG00000109906.15"])     # ['ZBTB16']: genes named as baSeq names them
genes = bq.Gene.df("human")                     # every gene: id, symbol, biotype

analysis = ds.analyses[0]
analysis.steps.to_dataframe()                   # each step, its settings, when it ran
analysis.findings.to_dataframe()                # what each step found
table = analysis.tables["dge_condition_dexamethasone_vs_untreated.csv"].load()

record = bq.Record.get("Z3HMY4V1wC6goA380000")  # a file a step wrote
record.run.inputs                               # the records it read
ds.run.initiated_by                             # the run a version added from code was added in

ds.describe()                                   # in one request: newest version or not, where it came from,
                                                # what was made from it, how its analyses stand
ds.view_lineage()                               # its Lineage tab, drawn in a notebook (elsewhere: in your browser)
```

With a key that may add data ("Read and add data"), add a dataset. With the name and kind of one you have, it is its
next version, which starts what that dataset's "When a new version is added" says:

```python
new = bq.Dataset(["counts_filtered.tsv"], name="Airway demo", kind="bulk", sample_sheet="samples.csv").save()
new.version                                     # 2: the next version
new.notes                                       # what else to know, such as what the new version started
```

## Track your code

One line at the top makes a script one run on baSeq, as lamindb's `ln.track()`: its code (kept as a version of the
script), its command line and environment, the files it downloads from baSeq (what it read), the datasets it adds and
the files it saves, and what it found when it says. Reads are counted, not listed one by one; everything a run adds is
kept. Its page on baSeq is under Scripts, Runs outside baSeq; what it found is in your lab's findings too, marked From
code, never taken for a step's checked finding.

```python
bq.track()                                      # this script, as one run
counts = ds.files["counts.tsv"].load()          # noted as what the run read
bq.Record("dge_dex.csv").save()                 # a file of the run
bq.finish(finding="Dexamethasone raised ZBTB16 and FKBP5 the most.",
          genes=["ZBTB16+", "FKBP5+"])          # what it found; or let the script end: an exception ends it as errored
```

## Your lab's own storage

Files in your lab's own storage (an S3 bucket, an Azure Blob container or a folder on your servers) are recorded where
they are, as lamindb records an artifact in place: baseqdb reads each one with your own login, works out its size and
hashes on your computer, and sends only those with its path. The bytes never reach baSeq.

```python
bq.Storage.add("s3://lab-raw/2026", lab="Hansen lab")   # the lab's owner, once (writes .baseq/storage_uid.txt)
rec = bq.Record("s3://lab-raw/2026/run7/counts.h5ad").save()   # recorded where it is, in a run or not
rec.path                                        # where it is
adata = bq.Record.get(rec.uid).load()           # read where it is; in a tracked run, one of its inputs
bq.Storage.get("x7k2m9q4p1z8").mount("/Volumes/lab")   # a folder location this computer mounts elsewhere
ds = bq.Dataset(["s3://lab-raw/2026/run7/counts.tsv"], name="Run 7", kind="bulk").save()   # a dataset, where it is
ds.files["counts.tsv"].load()                   # read where it is
bq.Storage.get("x7k2m9q4p1z8").scan()           # what is there now: new, changed and gone files recorded
```

Saved again with other bytes, a file is its record's next version. S3 needs `pip install "baseqdb[s3]"` and your AWS
login; Azure Blob storage `pip install "baseqdb[azure]"` and your Azure login; a folder nothing more.

## With an AI agent

An agent such as Claude Code can use baseqdb with your key. Ask it to begin each task with `baseqdb track` and end it
with `baseqdb finish`: everything it runs in that folder in between is one run, however many commands it takes.

```sh
baseqdb track "Dexamethasone response in Airway"
python filter_counts.py --min-reads 10          # joins the run
python dge_dex.py --padj 0.01                   # joins the run
baseqdb finish --finding "ZBTB16 and FKBP5 rose the most." --gene ZBTB16+ --gene FKBP5+
```

If you are an agent: begin the task with `baseqdb track "<what the task is>"` in its folder, call `bq.track()` at the
top of each script you write, save results you keep with `bq.Record(path).save()`, and end with `baseqdb finish`,
saying in one short paragraph what the task found (`--finding`, with `--gene` for each gene; `--errored` when the task
failed).

In Claude Code, `baseqdb finish` also keeps the conversation with the run, from the person's request to the finish,
with API keys, tokens and passwords removed; `baseqdb finish --no-conversation` leaves it out.

Data you fetch with a key leaves baSeq. Our Data Processing Agreement does not cover what an AI agent or another
service then does with it.

Make an API key on your baSeq Account page, under API keys, then:

```sh
pip install baseqdb
baseqdb login                                   # once: your key, kept on this computer
```

The whole guide, with R: https://baseq.bio/docs/python-and-r.html
