Your own scripts
Keep your lab's R and Python scripts on the platform, share them, and run them in a sandbox on any dataset you can see or as a step inside an analysis.
What it is
Every lab has an R or Python script that "everyone uses", living in someone's home directory. Scripts puts it on the platform: it is kept with its versions, shared with your lab if you choose, and run on any dataset you can see. Runs happen inside a sandbox, sealed off from the internet. Nothing else on the server is visible to the script.
Upload a script
Open Scripts in the left menu and click New script. Choose a .py or
.R file, give it a name and a description, and tick Share with your lab if members should be
able to run it. Start the file with a few header lines:
# baseq: name = DESeq2 with apeglm shrinkage
# baseq: for = bulk
# baseq: param padj = 0.05
# baseq: param contrast = treated vs control
# baseq: param shrink = true
- name
- Used when you leave the name field empty.
- for
bulk,scrna,proteomicsorany. Decides which datasets the script is offered for.- param
- One line per parameter with its default. A number,
true/false, or text; the default's shape sets the input you get on the run form.
Or import it from GitHub
A script in a public GitHub repository needs no upload. Click From GitHub next to
New script and paste where the file is: the address your browser shows when the script is open on
GitHub, such as https://github.com/your-lab/analysis/blob/main/de.R, or its Raw link. Name,
description and sharing work as for an upload.
baSeq asks GitHub which commit the branch or tag points to now and keeps the file as it is in that commit, so the script stays the same when the branch moves on. The script's page links to the file at that commit, and each run records the commit next to the version, as does the code of a step the script ran as.
- Update from GitHub
- On the script's page: takes the file as the branch has it now. When it changed, it becomes a new version; earlier runs keep pointing at the version they ran.
- A link to a commit
- A permalink (the address with the commit's number instead of a branch) pins the script to that commit; there is nothing to update.
- Replace file
- Still works: the new version is the file you upload, not one on GitHub, and Update from GitHub brings back the file there.
Only public repositories can be imported: baSeq's server asks GitHub for the file with no account and nothing about you. A file kept with Git LFS cannot be fetched; upload it instead.
What the script sees
The environment variable BASEQ_INPUT names a read-only folder with the dataset's files under their
original names, manifest.json (dataset name, organism, file list) and, when the dataset has one,
sample_sheet.csv. BASEQ_OUTPUT names the writable folder; it is also the working directory.
Parameters arrive as JSON in BASEQ_PARAMS and as command-line arguments (--padj 0.05,
flags as --shrink when on).
# R
p <- jsonlite::fromJSON(Sys.getenv("BASEQ_PARAMS"))
counts <- read.csv(file.path(Sys.getenv("BASEQ_INPUT"), "counts.csv"), row.names = 1)
write.csv(results, file.path(Sys.getenv("BASEQ_OUTPUT"), "de_results.csv"))
# Python
import json, os, pandas as pd
p = json.loads(os.environ["BASEQ_PARAMS"])
counts = pd.read_csv(os.path.join(os.environ["BASEQ_INPUT"], "counts.csv"), index_col=0)
fig.savefig(os.path.join(os.environ["BASEQ_OUTPUT"], "volcano.png"), dpi=200)
Available inside the sandbox: R with DESeq2, edgeR, limma, apeglm, tidyverse, pheatmap, ComplexHeatmap, EnhancedVolcano and clusterProfiler; Python with pandas, numpy, scipy, matplotlib, seaborn, scikit-learn, statsmodels, anndata, scanpy and pydeseq2. Nothing can be installed at run time (there is no network), so ask the team when a package is missing.
What comes back
Whatever the script writes to BASEQ_OUTPUT is kept with the run. PNG, SVG and JPEG files are shown
as plots, CSV and TSV files as tables, a result.json with a flat object as a summary, and everything
else is offered for download. The console output is kept as the log. A run stops after 30 minutes.
Run it
Open the script, pick a dataset under Run on a dataset, set the parameters and click Run. The run page refreshes itself until the worker is done. From a dataset page, Run a script lists the scripts that fit that kind of data, and the dataset page keeps the history of runs on it. Replacing a script's file makes a new version; earlier runs keep pointing at the version they ran.
Run it inside an analysis
Open a session and click Scripts in its top bar. The scripts that fit this kind of data are
listed with their parameters; Run as a step runs one in the sandbox on the data object at the
step you are looking at, and the result becomes a step in the timeline like any built-in method: its first plot is
the step's plot, its tables sit under the step's data summary, its result.json becomes the summary, and
its source is the step's code. The step goes into the frozen record, the export package, the deck and lab memory
like every other step. The data object itself is never changed by a script step.
What the script sees, in addition to manifest.json: in a bulk RNA-seq session, counts.csv
(genes by samples, raw), samples.csv, normalized_counts.csv once size factors exist,
de_results.csv once differential expression has run, design.txt, and the object itself as
dds.pkl; in a single-cell or proteomics session, data.h5ad with obs.csv and
var.csv. A script written for a dataset usually works unchanged inside a session: read the CSV named in
the manifest.
Changing the data
A script can also hand back a new data object, so your own filtering, normalisation or sample selection becomes a
real step that the following steps build on. Declare it in the header with # baseq: changes = data,
and inside a session write the new object under BASEQ_OUTPUT/new_data/:
- Bulk RNA-seq
counts.csvwith genes as rows and samples as columns (raw counts), and optionallysamples.csvwith one row per sample. Samples must already exist in the analysis unless samples.csv describes them; genes may be filtered freely. The platform rebuilds the DESeq2 object with the existing design (or a full-rank design from the sample table when a column disappeared), fits it, and saves it its own way.- Single-cell, proteomics
data.h5ad, an AnnData file. Platform flags the script left out are carried over from the previous object; data types are made safe for storage.
The platform never runs anything a script wrote: it reads tables and h5ad files, never pickles. When the hand-back is missing or unusable the step fails with the reason and the data stays as it was. When it works, the step is marked as changing the data, the steps after it use the new object, earlier steps keep theirs, and downstream parameters are refreshed as after a built-in changing step. On a dataset run (outside a session) the folder is kept as ordinary output files.
Who sees what
A script is yours until you share it with a lab; then every member can open it and run it, but only you can change or delete it. Running a script on a dataset needs access to both, checked separately: sharing a script does not share your data, and sharing data does not let anyone run code on it that they cannot see.
How AI agents work with baSeq: baseq.bio/integrations/ai