Skill Tracer
Skills › Scientific Agent Skills › geniml › bedspace.md

bedspace.md

280 lines · skills/geniml/references/bedspace.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# BEDspace
2
3Verified against `geniml==0.8.4` release source, the official BEDbase tutorial,
4and the archived StarSpace repository on 2026-10-01.
5

BEDspace

Verified against geniml==0.8.4 release source, the official BEDbase tutorial, and the archived StarSpace repository on 2026-10-01.

Raw lines 1 to 5
6## Status
7
8BEDspace jointly embeds region sets and metadata labels using the external
9StarSpace program. The primary paper evaluates label-to-region,
10region-to-label, and region-to-region retrieval.
12Primary source: Gharavi et al. (2024), *Joint representation learning for
13retrieval and annotation of genomic interval sets*,
14doi:[10.3390/bioengineering11030263](https://doi.org/10.3390/bioengineering11030263).
16The code path still exists in Geniml 0.8.4, but it is a **legacy reproduction
17workflow**:
19- StarSpace is not a Python dependency and must be compiled separately.
20- `facebookresearch/StarSpace` is archived.
21- Geniml does not state or enforce a compatible StarSpace version.
22- several official examples and 0.8.4 CLI/API details disagree;
23- with Gtars 0.10.0, `data_preparation` calls the removed
24 `unknown_token_id()` API and assumes token objects instead of BatchEncoding;
25 its broad exception handler prints an error and returns a blank document;
26- the eight-worker preprocessing pool passes a Rust Tokenizer between workers;
27 native pickling/process compatibility needs separate verification;
28- the 0.8.4 `bedspace search` dispatcher imports a `main` function that is
29 absent from `geniml.bedspace.search`.
31Do not choose BEDspace by default for a new production search service. Use it
32when reproducing the published method or an existing pinned workflow, and
33record the limitations.

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/StarSpace is 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_preparation calls the removed unknown_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 search dispatcher imports a main function that is absent from geniml.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 34
35## Data and privacy contract
37Required inputs:
39- a local directory of validated BED files;
40- a local metadata CSV with a file-path/name column and selected label columns;
41- a local universe BED;
42- explicit train/test manifests grouped by patient/donor;
43- one assembly, coordinate convention, and contig policy.
45Metadata values can reveal diagnoses, cell types, tissues, treatment, cohort,
46or donor identity. BEDspace places selected labels directly into training text
47and writes filenames/labels into result CSVs. Keep inputs and outputs in a
48restricted project directory. Default logs should report only row/file counts
49and schema names, not values.
51Before preprocessing:
531. Split complete patients/donors into train/validation/test.
542. Build or select the universe using training data only.
553. Validate every BED and the universe against the same chromosome sizes.
564. Confirm metadata path values resolve to intended local regular files.
575. Reject URLs, symlinks, duplicate paths, missing files, and mixed assemblies.
586. Decide how missing/multi-valued labels are encoded.
60```bash
61python skills/geniml/scripts/corpus_auditor.py \
62 --manifest data/bedspace.tsv \
63 --group-column patient_id \
64 --split-column split \
65 --assembly-column assembly
66```

Data 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:

  1. Split complete patients/donors into train/validation/test.
  2. Build or select the universe using training data only.
  3. Validate every BED and the universe against the same chromosome sizes.
  4. Confirm metadata path values resolve to intended local regular files.
  5. Reject URLs, symlinks, duplicate paths, missing files, and mixed assemblies.
  6. 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 assembly
Raw lines 35 to 67
Runs code python skills/geniml/scripts/corpus_auditor.py :61
68## Exact 0.8.4 CLI surface
70The release exposes:
72```text
73geniml bedspace preprocess
74geniml bedspace train
75geniml bedspace distances
76geniml bedspace search
77```
79The following are source/parser-checked reproduction templates, not a working
80pipeline on the current stack. The synthetic `data_preparation` call was
81executed and returned a blank document for valid input. Resolve that upstream
82compatibility failure and verify nonempty documents before training; a zero
83exit status or file presence is insufficient. StarSpace was not built or run.
84Use installed `--help` as the final authority for flags.

Exact 0.8.4 CLI surface

The release exposes:

geniml bedspace preprocess
geniml bedspace train
geniml bedspace distances
geniml bedspace search

The 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.

Raw lines 68 to 85
86### Preprocess
88```bash
89geniml bedspace preprocess \
90 --input /absolute/project/beds/ \
91 --metadata /absolute/project/train.csv \
92 --universe /absolute/project/universe.bed \
93 --labels "cell_type,target" \
94 --output /absolute/project/preprocessed/
95```
97The implementation creates a Gtars `Tokenizer` from the universe, uses a
98hard-coded pool of eight processes, and writes:
100```text
101<output>train_input.txt
102```
104The code joins this filename by string concatenation, not `os.path.join`, so
105the output argument must end in a path separator. The metadata helper also
106concatenates the input directory and `file_name`, so `--input` and `--files`
107need trailing separators. Use the exact `file_name` metadata column; commas
108in path/label values are not preserved by its split-based representation. Create and validate the
109directory first. The preprocessing text contains labels and tokenized genomic
110content; protect it as sensitive derived data.
112The current source does not expose worker bounds through the CLI. Run only
113after estimating memory and CPU impact, or invoke a reviewed wrapper that
114controls resources.

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.txt

The 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 115
116### Train
118The long source flag is misspelled:
120```text
121--path-to-starsapce
122```
124Use the stable short form `-s`. Its value must be the **directory containing**
125the executable named `starspace`; despite some help text, do not pass the
126executable itself.
128```bash
129geniml bedspace train \
130 -s /absolute/project/vendor/StarSpace \
131 --input /absolute/project/preprocessed/train_input.txt \
132 --output /absolute/project/model/ \
133 --dim 100 \
134 --epochs 50 \
135 --lr 0.05
136```
138Geniml invokes an argv list equivalent to:
140```text
141starspace train
142 -trainFile INPUT
143 -model OUTPUT/starspace_trained_model
144 -trainMode 0
145 -dim DIM
146 -epoch EPOCHS
147 -negSearchLimit 5
148 -thread 20
149 -lr LEARNING_RATE
150```
152The thread count is hard-coded to 20. The implementation waits for the process
153but does not check a nonzero return code. Verify output existence, size, and
154checksums yourself. If an existing model path is present, Geniml adds
155`-initModel` and resumes/mutates training; use a fresh output directory unless
156resume is intentional.

Train

The long source flag is misspelled:

--path-to-starsapce

Use 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.05

Geniml 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_RATE

The 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.

Raw lines 116 to 157
158### Distances
160```bash
161geniml bedspace distances \
162 -i /absolute/project/model/starspace_trained_model \
163 -s /absolute/project/vendor/StarSpace \
164 --metadata-train /absolute/project/train.csv \
165 --metadata-test /absolute/project/test.csv \
166 --universe /absolute/project/universe.bed \
167 --project-name heldout \
168 --files /absolute/project/beds/ \
169 --labels "cell_type,target" \
170 --output /absolute/project/distances/ \
171 --threshold 0.5
172```
174The current outputs are CSV/text files, not a single pickle:
176- `raw_cosdist_rl.csv`
177- `similarity_score_rl.csv`
178- `similarity_score_rr.csv`
179- `<project>_starspace_embed.txt`
180- `<project>_train_starspace_embed.txt`
182The implementation also uses `~/.bedspace/test_documents.txt` and
183`~/.bedspace/train_documents.txt`. Use an isolated user account/environment or review that cache before
184running on sensitive data. Output CSVs contain filenames and labels; never
185paste unredacted rows into chat or CI logs.

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.5

The current outputs are CSV/text files, not a single pickle:

  • raw_cosdist_rl.csv
  • similarity_score_rl.csv
  • similarity_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.

Raw lines 158 to 186
187### Search
189The CLI advertises search types `l2r`, `r2l`, and `r2r`, with the query as a
190positional argument:
192```text
193geniml bedspace search QUERY -t l2r -d DISTANCES.csv -n 10
194```
196Do not rely on this path in 0.8.4: the dispatcher imports
197`geniml.bedspace.search.main`, but the release file defines only
198`run_scenario1`, `run_scenario2`, and `run_scenario3`. There is no
199`BEDSpaceModel` class in the release API. Read the verified CSVs with a safe
200local data-frame workflow instead of loading an old `.pkl` or calling the
201broken dispatcher.

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 10

Do 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.

Raw lines 187 to 202
203## StarSpace setup: explicit legacy-only baseline
205Only do this after the user approves network access and native compilation.
206There is no upstream Geniml compatibility pin. The only immutable baseline
207available from the archived upstream default branch is its final commit:
209```text
2108aee0a950aa607c023e5c91cff518bec335b5df5
211```
213A reproducible source checkout is:
215```bash
216git init vendor/StarSpace
217git -C vendor/StarSpace remote add origin https://github.com/facebookresearch/StarSpace.git
218git -C vendor/StarSpace fetch --depth 1 origin 8aee0a950aa607c023e5c91cff518bec335b5df5
219git -C vendor/StarSpace checkout --detach FETCH_HEAD
220make -C vendor/StarSpace
221```
223This pin makes the source immutable; it does **not** establish compatibility
224with Geniml 0.8.4. Compile in an isolated build environment after reviewing
225the archived source and Boost/native toolchain. Record:
227- commit and repository URL;
228- compiler, make, Boost, OS, and architecture;
229- build log;
230- SHA-256 and executable permissions of `vendor/StarSpace/starspace`;
231- a synthetic preprocess/train/distances smoke result.
233Never execute an unverified StarSpace binary downloaded from a third party.
234Do not add its directory globally to `PATH`; pass the explicit local directory
235with `-s`.

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:

8aee0a950aa607c023e5c91cff518bec335b5df5

A 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/StarSpace

This 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.

Raw lines 203 to 236
237## Model and retrieval provenance
239Keep one immutable manifest covering:
241- Geniml/Gtars and StarSpace versions/commit;
242- Python lockfile and native binary checksum;
243- train/test manifest checksums and grouping;
244- universe checksum, assembly, row order, and tokenizer special tokens;
245- selected metadata columns and missing-value policy;
246- preprocessing text checksum;
247- dimension, epochs, learning rate, hard-coded thread count, and resume state;
248- every model/embedding/distance output checksum.
250Similarity is not a calibrated probability. Validate retrieval on held-out
251patients/donors, report per-query metrics and class support, and compare with
252metadata-only and interval-overlap baselines. Avoid searching the test set
253while selecting labels, thresholds, or the universe.

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 254
255## Migration guidance
257Old guidance to remove:
259- `BEDSpaceModel.load(...)` / `.search(...)`: not present in 0.8.4.
260- `distances.pkl`: current distance code writes CSV/text.
261- `--path-to-starspace`: official docs show it, but release source spells the
262 long flag `--path-to-starsapce`; use `-s`.
263- advice to install StarSpace from an unpinned branch.
265For new systems, first define the retrieval task and privacy boundary. A
266maintained vector-search stack over locally generated, fully versioned
267embeddings may be safer than building new infrastructure around archived
268StarSpace, but it is not automatically method-equivalent to BEDspace.

Migration 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 269
270## Official sources
272- [Official BEDspace tutorial](https://docs.bedbase.org/geniml/tutorials/bedspace/)
273 (undated; accessed 2026-10-01)
274- [Geniml v0.8.4 BEDspace source](https://github.com/databio/geniml/tree/v0.8.4/geniml/bedspace)
275 (released 2026-01-14; accessed 2026-10-01)
276- [Archived StarSpace repository](https://github.com/facebookresearch/StarSpace)
277 (final default-branch commit dated 2019-12-13; repository archived; accessed
278 2026-10-01)
279- [Primary BEDspace paper](https://doi.org/10.3390/bioengineering11030263)
280 (2024)

Official sources

Raw lines 270 to 280