Skill Tracer
Skills › Scientific Agent Skills › flowkit › workspaces-and-results.md

workspaces-and-results.md

121 lines · skills/flowkit/references/workspaces-and-results.md at 5f2bc03

Open on GitHub
1# Workspaces and result interpretation
2

Workspaces and result interpretation

Raw lines 1 to 2
3## Match samples before interpreting results
4
5Use explicit FCS files and inspect the workspace's sample groups. Retaining
6missing-file metadata is essential: otherwise missing samples may be removed
7from group membership during construction and a partial analysis can look
8complete. `load_missing_file_data=True` retains workspace metadata for missing
9FCS files; it does not supply those files' events.
11The following example is exercised with the repository's synthetic FlowJo
12fixture. Replace paths, group name, and sample identity for real work:
14```python
15import flowkit as fk
17workspace = fk.Workspace(
18 "study.wsp",
19 fcs_samples=["data_set_simple_line_100.fcs"],
20 load_missing_file_data=True,
21 find_fcs_files_from_wsp=False,
23print(workspace.get_sample_groups())
24group = "my_group"
25expected = set(workspace.get_sample_ids(group_name=group, loaded_only=False))
26loaded = set(workspace.get_sample_ids(group_name=group, loaded_only=True))
27if not expected or expected != loaded:
28 raise ValueError(f"Empty group or missing FCS samples: {sorted(expected - loaded)}")
29workspace.analyze_samples(group_name=group, use_mp=False)
30print(workspace.get_analysis_report(group_name=group))
31```
33FCS `$FIL`, filesystem basename, and workspace sample name can disagree after
34renaming/export. Inspect these identities rather than matching by position.
35`filename_as_id=True` is useful only when current basenames match the workspace.
36When an explicit, reviewed mapping is necessary, construct
37`fk.Sample(path, sample_id=workspace_id, use_flowjo_labels=True)` objects and
38pass those to `Workspace`. Check uniqueness before building the list.
40For an intentionally partial group, use `analyze_samples(sample_id=...)` for
41the explicitly selected IDs and report included and missing IDs. The bundled
42CLI deliberately requires the complete named group.

Match samples before interpreting results

Use explicit FCS files and inspect the workspace's sample groups. Retaining missing-file metadata is essential: otherwise missing samples may be removed from group membership during construction and a partial analysis can look complete. load_missing_file_data=True retains workspace metadata for missing FCS files; it does not supply those files' events.

The following example is exercised with the repository's synthetic FlowJo fixture. Replace paths, group name, and sample identity for real work:

import flowkit as fk

workspace = fk.Workspace(
    "study.wsp",
    fcs_samples=["data_set_simple_line_100.fcs"],
    load_missing_file_data=True,
    find_fcs_files_from_wsp=False,
)
print(workspace.get_sample_groups())
group = "my_group"
expected = set(workspace.get_sample_ids(group_name=group, loaded_only=False))
loaded = set(workspace.get_sample_ids(group_name=group, loaded_only=True))
if not expected or expected != loaded:
    raise ValueError(f"Empty group or missing FCS samples: {sorted(expected - loaded)}")
workspace.analyze_samples(group_name=group, use_mp=False)
print(workspace.get_analysis_report(group_name=group))

FCS $FIL, filesystem basename, and workspace sample name can disagree after renaming/export. Inspect these identities rather than matching by position. filename_as_id=True is useful only when current basenames match the workspace. When an explicit, reviewed mapping is necessary, construct fk.Sample(path, sample_id=workspace_id, use_flowjo_labels=True) objects and pass those to Workspace. Check uniqueness before building the list.

For an intentionally partial group, use analyze_samples(sample_id=...) for the explicitly selected IDs and report included and missing IDs. The bundled CLI deliberately requires the complete named group.

Raw lines 3 to 43
44## Report paths and denominators
46FlowKit 1.3.2 reports individual quadrants with `gate_path` equal to the
47owning `QuadrantGate`'s path and puts that gate's name in `quadrant_parent`.
48For example, quadrant `High` in `Split` below `Cells` has report path
49`("root", "Cells")`, but strategy path `("root", "Cells", "Split")`.
50Its percentage denominator is the `Cells` count; `Split` is a collection of
51quadrants, not another population. A gate below `High` uses the full parent
52path `("root", "Cells", "Split", "High")`.
54The CLI adds a full `population_path`, including the population's own name
55and any quadrant owner, plus `sample_event_count` and `parent_event_count`.
56Use sample ID plus that path to join results. An empty parent gives an
57undefined percentage even when the child count is zero: the helper writes a
58blank `relative_percent` and `relative_percent_defined=False`. A zero-count
59gate under a nonempty parent retains its valid 0% value.
61The 1.3.2 membership API cannot disambiguate a repeated quadrant name across
62different owning QuadrantGates, even with a path; it raises `ValueError`.
63Use unique quadrant names when constructing strategies. For imported
64strategies, inspect the report and preserve its owner column; do not silently
65rename gates or use the wrong population's mask. The CLI's report export does
66not call this membership API and retains both populations correctly.

Report paths and denominators

FlowKit 1.3.2 reports individual quadrants with gate_path equal to the owning QuadrantGate's path and puts that gate's name in quadrant_parent. For example, quadrant High in Split below Cells has report path ("root", "Cells"), but strategy path ("root", "Cells", "Split"). Its percentage denominator is the Cells count; Split is a collection of quadrants, not another population. A gate below High uses the full parent path ("root", "Cells", "Split", "High").

The CLI adds a full population_path, including the population's own name and any quadrant owner, plus sample_event_count and parent_event_count. Use sample ID plus that path to join results. An empty parent gives an undefined percentage even when the child count is zero: the helper writes a blank relative_percent and relative_percent_defined=False. A zero-count gate under a nonempty parent retains its valid 0% value.

The 1.3.2 membership API cannot disambiguate a repeated quadrant name across different owning QuadrantGates, even with a path; it raises ValueError. Use unique quadrant names when constructing strategies. For imported strategies, inspect the report and preserve its owner column; do not silently rename gates or use the wrong population's mask. The CLI's report export does not call this membership API and retains both populations correctly.

Raw lines 44 to 67
68## FlowJo compatibility
70FlowKit supports a subset of FlowJo 10: documented transformations and
71polygon, rectangle, ellipse, quadrant, and Boolean gates. Plugins, derived
72parameters, specialized models, or other unsupported workspace features may
73not reproduce. Review parser warnings and imported gate inventories. Compare
74counts, percentages, and overlays against the original FlowJo export on
75representative samples, including sample-specific overrides and rare gates.
76Record both software versions and any mismatch; importing without an
77exception is insufficient.
79Prefer the original workspace for reproduction. A single GatingML template
80does not encode all custom sample gates. FlowKit's WSP exporter is not a
81guaranteed round-trip: in the tested 1.3.2 environment, re-importing a synthetic
82compensated `Session.export_wsp` result failed to resolve a `Comp-FL1-A`
83channel. Native FlowJo fixture import was tested separately. Validate any
84conversion independently before relying on it.

FlowJo compatibility

FlowKit supports a subset of FlowJo 10: documented transformations and polygon, rectangle, ellipse, quadrant, and Boolean gates. Plugins, derived parameters, specialized models, or other unsupported workspace features may not reproduce. Review parser warnings and imported gate inventories. Compare counts, percentages, and overlays against the original FlowJo export on representative samples, including sample-specific overrides and rare gates. Record both software versions and any mismatch; importing without an exception is insufficient.

Prefer the original workspace for reproduction. A single GatingML template does not encode all custom sample gates. FlowKit's WSP exporter is not a guaranteed round-trip: in the tested 1.3.2 environment, re-importing a synthetic compensated Session.export_wsp result failed to resolve a Comp-FL1-A channel. Native FlowJo fixture import was tested separately. Validate any conversion independently before relying on it.

Raw lines 68 to 85
86## Fluorescence summaries
88Choose mean or median explicitly, retain sample and gate path, and report the
89number of events. For a programmatic `Session`, obtain the gate mask, then
90apply the intended matrix to the Sample and summarize the desired detector
91from `source="comp"`. This keeps compensation separate from display transforms.
93For a `Workspace`, `get_gate_events(sample_id, gate_name, gate_path=path,
94source="comp")` applies the workspace matrix without display transforms.
95If `workspace.get_comp_matrix(sample_id)` is `None`, this silently returns
96raw events instead; confirm that this is the intended analysis provenance.
97Its default `source=None` uses the workspace's compensation **and transforms**,
98so choose the source explicitly for an untransformed intensity summary.
99The returned DataFrame has a string `sample_id` column and channel columns
100formed by joining PnN and PnS labels. Inspect those labels and select the
101intended detector before calculating a numeric summary.
103There is an API asymmetry: `Session.get_gate_events(...)` defaults to raw
104events unless `matrix` and/or `transform` are supplied. It does not
105automatically choose the preprocessing of the gate's dimensions. Therefore,
106identical-looking calls on Session and Workspace can summarize different
107numbers. Do not compare them until their coordinate systems agree.
109Empty gates have no defined mean/median; return missing values with count zero.
110Negative compensated values make geometric means inappropriate without a
111separately justified method. Across samples, account for panel, instrument,
112batch, controls, and calibration before interpreting intensity differences.

Fluorescence summaries

Choose mean or median explicitly, retain sample and gate path, and report the number of events. For a programmatic Session, obtain the gate mask, then apply the intended matrix to the Sample and summarize the desired detector from source="comp". This keeps compensation separate from display transforms.

For a Workspace, get_gate_events(sample_id, gate_name, gate_path=path, source="comp") applies the workspace matrix without display transforms. If workspace.get_comp_matrix(sample_id) is None, this silently returns raw events instead; confirm that this is the intended analysis provenance. Its default source=None uses the workspace's compensation and transforms, so choose the source explicitly for an untransformed intensity summary. The returned DataFrame has a string sample_id column and channel columns formed by joining PnN and PnS labels. Inspect those labels and select the intended detector before calculating a numeric summary.

There is an API asymmetry: Session.get_gate_events(...) defaults to raw events unless matrix and/or transform are supplied. It does not automatically choose the preprocessing of the gate's dimensions. Therefore, identical-looking calls on Session and Workspace can summarize different numbers. Do not compare them until their coordinate systems agree.

Empty gates have no defined mean/median; return missing values with count zero. Negative compensated values make geometric means inappropriate without a separately justified method. Across samples, account for panel, instrument, batch, controls, and calibration before interpreting intensity differences.

Raw lines 86 to 113
114## Primary sources
116- [Workspace API](https://flowkit.readthedocs.io/en/latest/workspace.html)
117- [Session API](https://flowkit.readthedocs.io/en/latest/session.html)
118- [GatingResults API](https://flowkit.readthedocs.io/en/latest/gating_results.html)
119- [Released report implementation](https://github.com/whitews/FlowKit/blob/1.3.2/src/flowkit/_models/gating_results.py)
120- [Released gating and percentage implementation](https://github.com/whitews/FlowKit/blob/1.3.2/src/flowkit/_models/gating_strategy.py)
121- [Upstream feature scope](https://github.com/whitews/FlowKit)