bedspace.md
280 lines · skills/geniml/references/bedspace.md at 5f2bc03
Most marks come from matching words in the file, so treat them as pointers.
BEDspace
Verified against geniml==0.8.4 release source, the official BEDbase tutorial, and the archived StarSpace repository on 2026-10-01.
Status
BEDspace jointly embeds region sets and metadata labels using the external StarSpace program. The primary paper evaluates label-to-region, region-to-label, and region-to-region retrieval.
Primary source: Gharavi et al. (2024), Joint representation learning for retrieval and annotation of genomic interval sets, doi:10.3390/bioengineering11030263.
The code path still exists in Geniml 0.8.4, but it is a legacy reproduction workflow:
- StarSpace is not a Python dependency and must be compiled separately.
facebookresearch/StarSpaceis archived.- Geniml does not state or enforce a compatible StarSpace version.
- several official examples and 0.8.4 CLI/API details disagree;
- with Gtars 0.10.0,
data_preparationcalls the removedunknown_token_id()API and assumes token objects instead of BatchEncoding; its broad exception handler prints an error and returns a blank document; - the eight-worker preprocessing pool passes a Rust Tokenizer between workers; native pickling/process compatibility needs separate verification;
- the 0.8.4
bedspace searchdispatcher imports amainfunction that is absent fromgeniml.bedspace.search.
Do not choose BEDspace by default for a new production search service. Use it when reproducing the published method or an existing pinned workflow, and record the limitations.
Raw lines 6 to 34Data and privacy contract
Required inputs:
- a local directory of validated BED files;
- a local metadata CSV with a file-path/name column and selected label columns;
- a local universe BED;
- explicit train/test manifests grouped by patient/donor;
- one assembly, coordinate convention, and contig policy.
Metadata values can reveal diagnoses, cell types, tissues, treatment, cohort, or donor identity. BEDspace places selected labels directly into training text and writes filenames/labels into result CSVs. Keep inputs and outputs in a restricted project directory. Default logs should report only row/file counts and schema names, not values.
Before preprocessing:
- Split complete patients/donors into train/validation/test.
- Build or select the universe using training data only.
- Validate every BED and the universe against the same chromosome sizes.
- Confirm metadata path values resolve to intended local regular files.
- Reject URLs, symlinks, duplicate paths, missing files, and mixed assemblies.
- Decide how missing/multi-valued labels are encoded.
python skills/geniml/scripts/corpus_auditor.py \
--manifest data/bedspace.tsv \
--group-column patient_id \
--split-column split \
--assembly-column assemblyRaw lines 35 to 67Exact 0.8.4 CLI surface
The release exposes:
geniml bedspace preprocess
geniml bedspace train
geniml bedspace distances
geniml bedspace searchThe following are source/parser-checked reproduction templates, not a working pipeline on the current stack. The synthetic data_preparation call was executed and returned a blank document for valid input. Resolve that upstream compatibility failure and verify nonempty documents before training; a zero exit status or file presence is insufficient. StarSpace was not built or run. Use installed --help as the final authority for flags.
Preprocess
geniml bedspace preprocess \
--input /absolute/project/beds/ \
--metadata /absolute/project/train.csv \
--universe /absolute/project/universe.bed \
--labels "cell_type,target" \
--output /absolute/project/preprocessed/The implementation creates a Gtars Tokenizer from the universe, uses a hard-coded pool of eight processes, and writes:
<output>train_input.txtThe code joins this filename by string concatenation, not os.path.join, so the output argument must end in a path separator. The metadata helper also concatenates the input directory and file_name, so --input and --files need trailing separators. Use the exact file_name metadata column; commas in path/label values are not preserved by its split-based representation. Create and validate the directory first. The preprocessing text contains labels and tokenized genomic content; protect it as sensitive derived data.
The current source does not expose worker bounds through the CLI. Run only after estimating memory and CPU impact, or invoke a reviewed wrapper that controls resources.
Raw lines 86 to 115Train
The long source flag is misspelled:
--path-to-starsapceUse the stable short form -s. Its value must be the directory containing the executable named starspace; despite some help text, do not pass the executable itself.
geniml bedspace train \
-s /absolute/project/vendor/StarSpace \
--input /absolute/project/preprocessed/train_input.txt \
--output /absolute/project/model/ \
--dim 100 \
--epochs 50 \
--lr 0.05Geniml invokes an argv list equivalent to:
starspace train
-trainFile INPUT
-model OUTPUT/starspace_trained_model
-trainMode 0
-dim DIM
-epoch EPOCHS
-negSearchLimit 5
-thread 20
-lr LEARNING_RATEThe thread count is hard-coded to 20. The implementation waits for the process but does not check a nonzero return code. Verify output existence, size, and checksums yourself. If an existing model path is present, Geniml adds -initModel and resumes/mutates training; use a fresh output directory unless resume is intentional.
Distances
geniml bedspace distances \
-i /absolute/project/model/starspace_trained_model \
-s /absolute/project/vendor/StarSpace \
--metadata-train /absolute/project/train.csv \
--metadata-test /absolute/project/test.csv \
--universe /absolute/project/universe.bed \
--project-name heldout \
--files /absolute/project/beds/ \
--labels "cell_type,target" \
--output /absolute/project/distances/ \
--threshold 0.5The current outputs are CSV/text files, not a single pickle:
raw_cosdist_rl.csvsimilarity_score_rl.csvsimilarity_score_rr.csv<project>_starspace_embed.txt<project>_train_starspace_embed.txt
The implementation also uses ~/.bedspace/test_documents.txt and ~/.bedspace/train_documents.txt. Use an isolated user account/environment or review that cache before running on sensitive data. Output CSVs contain filenames and labels; never paste unredacted rows into chat or CI logs.
Search
The CLI advertises search types l2r, r2l, and r2r, with the query as a positional argument:
geniml bedspace search QUERY -t l2r -d DISTANCES.csv -n 10Do not rely on this path in 0.8.4: the dispatcher imports geniml.bedspace.search.main, but the release file defines only run_scenario1, run_scenario2, and run_scenario3. There is no BEDSpaceModel class in the release API. Read the verified CSVs with a safe local data-frame workflow instead of loading an old .pkl or calling the broken dispatcher.
StarSpace setup: explicit legacy-only baseline
Only do this after the user approves network access and native compilation. There is no upstream Geniml compatibility pin. The only immutable baseline available from the archived upstream default branch is its final commit:
8aee0a950aa607c023e5c91cff518bec335b5df5A reproducible source checkout is:
git init vendor/StarSpace
git -C vendor/StarSpace remote add origin https://github.com/facebookresearch/StarSpace.git
git -C vendor/StarSpace fetch --depth 1 origin 8aee0a950aa607c023e5c91cff518bec335b5df5
git -C vendor/StarSpace checkout --detach FETCH_HEAD
make -C vendor/StarSpaceThis pin makes the source immutable; it does not establish compatibility with Geniml 0.8.4. Compile in an isolated build environment after reviewing the archived source and Boost/native toolchain. Record:
- commit and repository URL;
- compiler, make, Boost, OS, and architecture;
- build log;
- SHA-256 and executable permissions of
vendor/StarSpace/starspace; - a synthetic preprocess/train/distances smoke result.
Never execute an unverified StarSpace binary downloaded from a third party. Do not add its directory globally to PATH; pass the explicit local directory with -s.
Model and retrieval provenance
Keep one immutable manifest covering:
- Geniml/Gtars and StarSpace versions/commit;
- Python lockfile and native binary checksum;
- train/test manifest checksums and grouping;
- universe checksum, assembly, row order, and tokenizer special tokens;
- selected metadata columns and missing-value policy;
- preprocessing text checksum;
- dimension, epochs, learning rate, hard-coded thread count, and resume state;
- every model/embedding/distance output checksum.
Similarity is not a calibrated probability. Validate retrieval on held-out patients/donors, report per-query metrics and class support, and compare with metadata-only and interval-overlap baselines. Avoid searching the test set while selecting labels, thresholds, or the universe.
Raw lines 237 to 254Migration guidance
Old guidance to remove:
BEDSpaceModel.load(...)/.search(...): not present in 0.8.4.distances.pkl: current distance code writes CSV/text.--path-to-starspace: official docs show it, but release source spells the long flag--path-to-starsapce; use-s.- advice to install StarSpace from an unpinned branch.
For new systems, first define the retrieval task and privacy boundary. A maintained vector-search stack over locally generated, fully versioned embeddings may be safer than building new infrastructure around archived StarSpace, but it is not automatically method-equivalent to BEDspace.
Raw lines 255 to 269Official sources
- Official BEDspace tutorial (undated; accessed 2026-10-01)
- Geniml v0.8.4 BEDspace source (released 2026-01-14; accessed 2026-10-01)
- Archived StarSpace repository (final default-branch commit dated 2019-12-13; repository archived; accessed 2026-10-01)
- Primary BEDspace paper (2024)